Skip to main content
summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorNathan Ridge2019-03-14 21:01:35 -0400
committerNathan Ridge2019-03-21 01:50:14 -0400
commitd87b844e1218c55cd304cdcf0eebb81b64eefbe6 (patch)
tree05af2ff51c2618196fa80257e6bcd3cf0d833ce6 /core
parent084288dee990df2a961a62d46bd68d6452044920 (diff)
downloadorg.eclipse.cdt-d87b844e1218c55cd304cdcf0eebb81b64eefbe6.tar.gz
org.eclipse.cdt-d87b844e1218c55cd304cdcf0eebb81b64eefbe6.tar.xz
org.eclipse.cdt-d87b844e1218c55cd304cdcf0eebb81b64eefbe6.zip
Bug 545360 - Completion in namespace alias
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceAlias.java32
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java2
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java6
3 files changed, 38 insertions, 2 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceAlias.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceAlias.java
index bd400bff3f..ed23a36f82 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceAlias.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPASTNamespaceAlias.java
@@ -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;
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
index 1adf8819cc..a5ae420e97 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java
@@ -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);
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java
index 483f7f1c1b..37700348b6 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java
@@ -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::" });
+ }
}

Back to the top