mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 06:02:11 +02:00
Bug 545360 - Completion in namespace alias
Change-Id: Ica4955409780f4d5000356ffe5d56dc0ce787ee7
This commit is contained in:
parent
084288dee9
commit
d87b844e12
3 changed files with 38 additions and 2 deletions
|
@ -13,15 +13,21 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICPPASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamespaceAlias;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CPPASTNamespaceAlias extends ASTNode implements ICPPASTNamespaceAlias {
|
||||
public class CPPASTNamespaceAlias extends ASTNode implements ICPPASTNamespaceAlias, ICPPASTCompletionContext {
|
||||
private IASTName alias;
|
||||
private IASTName qualifiedName;
|
||||
|
||||
|
@ -111,4 +117,28 @@ public class CPPASTNamespaceAlias extends ASTNode implements ICPPASTNamespaceAli
|
|||
return r_reference;
|
||||
return r_unclear;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
return findBindings(n, isPrefix, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix, String[] namespaces) {
|
||||
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix, namespaces);
|
||||
|
||||
int j = 0;
|
||||
for (int i = 0; i < bindings.length; i++) {
|
||||
IBinding binding = bindings[i];
|
||||
if (binding instanceof ICPPNamespace) {
|
||||
if (i != j)
|
||||
bindings[j] = binding;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
if (j < bindings.length)
|
||||
return Arrays.copyOfRange(bindings, 0, j);
|
||||
return bindings;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2790,7 +2790,7 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser {
|
|||
}
|
||||
|
||||
IASTName qualifiedName = qualifiedName();
|
||||
endOffset = consume(IToken.tSEMI).getEndOffset();
|
||||
endOffset = consumeOrEOC(IToken.tSEMI).getEndOffset();
|
||||
|
||||
ICPPASTNamespaceAlias alias = getNodeFactory().newNamespaceAlias(name, qualifiedName);
|
||||
((ASTNode) alias).setOffsetAndLength(offset, endOffset - offset);
|
||||
|
|
|
@ -1965,4 +1965,10 @@ public class CompletionTests extends CompletionTestBase {
|
|||
int expectedPos = getDocument().get().lastIndexOf("fin") + 6;
|
||||
assertCursorPositionsAfterReplacement(new int[] { expectedPos });
|
||||
}
|
||||
|
||||
// namespace outer { namespace inner {} }
|
||||
// namespace alias = o/*cursor*/
|
||||
public void testCompletionInNamespaceAlias_545360() throws Exception {
|
||||
assertCompletionResults(new String[] { "outer::" });
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue