mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 319175: Parser adds proposals for preferred namespaces.
This commit is contained in:
parent
6048a19e1c
commit
96c5c7725a
12 changed files with 224 additions and 74 deletions
|
@ -2327,7 +2327,7 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
|
||||
IASTName name = col.getName(11);
|
||||
assertEquals("a", name.toString());
|
||||
IBinding[] bs = CPPSemantics.findBindingsForContentAssist(name, true);
|
||||
IBinding[] bs = CPPSemantics.findBindingsForContentAssist(name, true, null);
|
||||
|
||||
// check the result
|
||||
HashSet result= new HashSet();
|
||||
|
@ -2341,7 +2341,34 @@ public class AST2CPPTests extends AST2BaseTest {
|
|||
assertTrue(result.contains("A"));
|
||||
assertEquals(7, bs.length); // the bindings above + 2 constructors
|
||||
}
|
||||
|
||||
|
||||
// namespace ns {
|
||||
// int v_outer;
|
||||
// namespace inner {
|
||||
// int v_inner;
|
||||
// }
|
||||
// }
|
||||
// void test(){
|
||||
// v_;
|
||||
// }
|
||||
public void testAdditionalNamespaceLookup() throws Exception {
|
||||
IASTTranslationUnit tu = parse(getAboveComment(), ParserLanguage.CPP);
|
||||
CPPNameCollector col = new CPPNameCollector();
|
||||
tu.accept(col);
|
||||
|
||||
IASTName name = col.getName(5);
|
||||
assertEquals("v_", name.toString());
|
||||
IBinding[] bs = CPPSemantics.findBindingsForContentAssist(name, true, new String[] {"ns::inner"});
|
||||
|
||||
// check the result
|
||||
HashSet result= new HashSet();
|
||||
for (IBinding binding : bs) {
|
||||
result.add(binding.getName());
|
||||
}
|
||||
assertTrue(result.contains("v_inner"));
|
||||
assertEquals(1, bs.length); // the bindings above
|
||||
}
|
||||
|
||||
// static void f();
|
||||
// void f() {}
|
||||
public void testIsStatic() throws Exception {
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2010 Tomasz Wesolowski and others
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Tomasz Wesolowski - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.dom.ast;
|
||||
|
||||
/**
|
||||
* Interface for a code completion's context. Used for context-sensitive finding of bindings with a certain
|
||||
* name or prefix, including additional lookup requested namespaces.
|
||||
*
|
||||
* @noextend This interface is not intended to be extended by clients.
|
||||
* @noimplement This interface is not intended to be implemented by clients.
|
||||
* @since 5.3
|
||||
*/
|
||||
public interface ICPPASTCompletionContext extends IASTCompletionContext {
|
||||
|
||||
/**
|
||||
* Returns bindings that start with the given name or prefix, only considering those that are valid for
|
||||
* this context, including those in the requested set of namespaces.
|
||||
*
|
||||
* @param n
|
||||
* the name containing a prefix
|
||||
* @param namespaces
|
||||
* the qualified names of additional namespaces to check for bindings, or null
|
||||
* @return valid bindings in this context for the given prefix
|
||||
*/
|
||||
IBinding[] findBindings(IASTName n, boolean isPrefix, String[] namespaces);
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2009 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2010 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -17,19 +17,19 @@ import java.util.List;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
||||
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.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier.ICPPASTBaseSpecifier;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
|
||||
|
||||
/**
|
||||
* Base class specifier
|
||||
*/
|
||||
public class CPPASTBaseSpecifier extends ASTNode implements ICPPASTBaseSpecifier, IASTCompletionContext {
|
||||
public class CPPASTBaseSpecifier extends ASTNode implements ICPPASTBaseSpecifier, ICPPASTCompletionContext {
|
||||
|
||||
private boolean isVirtual;
|
||||
private int visibility;
|
||||
|
@ -117,8 +117,8 @@ public class CPPASTBaseSpecifier extends ASTNode implements ICPPASTBaseSpecifier
|
|||
return r_unclear;
|
||||
}
|
||||
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix);
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix, String[] namespaces) {
|
||||
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix, namespaces);
|
||||
List<IBinding> filtered = new ArrayList<IBinding>();
|
||||
|
||||
ICPPClassType classType = null;
|
||||
|
@ -155,4 +155,8 @@ public class CPPASTBaseSpecifier extends ASTNode implements ICPPASTBaseSpecifier
|
|||
assertNotFrozen();
|
||||
fIsPackExpansion= val;
|
||||
}
|
||||
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
return findBindings(n, isPrefix, null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ 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.IASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTImplicitName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner;
|
||||
|
@ -23,6 +22,7 @@ import org.eclipse.cdt.core.dom.ast.IASTInitializer;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICPPASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCompositeTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorChainInitializer;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConstructorInitializer;
|
||||
|
@ -44,7 +44,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
|
|||
* {@code Base()} and {@code field()} are the constructor chain initializers.<br>
|
||||
*/
|
||||
public class CPPASTConstructorChainInitializer extends ASTNode implements
|
||||
ICPPASTConstructorChainInitializer, IASTImplicitNameOwner, IASTCompletionContext {
|
||||
ICPPASTConstructorChainInitializer, IASTImplicitNameOwner, ICPPASTCompletionContext {
|
||||
private IASTName name;
|
||||
private IASTImplicitName[] implicitNames;
|
||||
private IASTInitializer initializer;
|
||||
|
@ -128,8 +128,8 @@ public class CPPASTConstructorChainInitializer extends ASTNode implements
|
|||
return r_unclear;
|
||||
}
|
||||
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix);
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix, String[] namespaces) {
|
||||
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix, namespaces);
|
||||
|
||||
ICPPASTBaseSpecifier[] baseClasses = null;
|
||||
|
||||
|
@ -238,4 +238,8 @@ public class CPPASTConstructorChainInitializer extends ASTNode implements
|
|||
|
||||
return implicitNames;
|
||||
}
|
||||
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
return findBindings(n, isPrefix, null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,12 @@ import java.util.List;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTImplicitName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICPPASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IPointerType;
|
||||
|
@ -46,7 +46,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CVQualifier;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
|
||||
|
||||
public class CPPASTFieldReference extends ASTNode implements ICPPASTFieldReference, IASTAmbiguityParent,
|
||||
IASTCompletionContext {
|
||||
ICPPASTCompletionContext {
|
||||
|
||||
private boolean isTemplate;
|
||||
private IASTExpression owner;
|
||||
|
@ -258,8 +258,8 @@ public class CPPASTFieldReference extends ASTNode implements ICPPASTFieldReferen
|
|||
return false;
|
||||
}
|
||||
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix);
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix, String[] namespaces) {
|
||||
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix, namespaces);
|
||||
List<IBinding> filtered = new ArrayList<IBinding>();
|
||||
|
||||
for (IBinding binding : bindings) {
|
||||
|
@ -274,4 +274,8 @@ public class CPPASTFieldReference extends ASTNode implements ICPPASTFieldReferen
|
|||
|
||||
return filtered.toArray(new IBinding[filtered.size()]);
|
||||
}
|
||||
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
return findBindings(n, isPrefix, null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,10 +14,10 @@ package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||
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.IEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
|
@ -31,7 +31,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
|
||||
|
||||
public class CPPASTIdExpression extends ASTNode implements IASTIdExpression, IASTCompletionContext {
|
||||
public class CPPASTIdExpression extends ASTNode implements IASTIdExpression, ICPPASTCompletionContext {
|
||||
|
||||
private IASTName name;
|
||||
|
||||
|
@ -134,12 +134,16 @@ public class CPPASTIdExpression extends ASTNode implements IASTIdExpression, IAS
|
|||
return false;
|
||||
}
|
||||
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
return CPPSemantics.findBindingsForContentAssist(n, isPrefix);
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix, String[] namespaces) {
|
||||
return CPPSemantics.findBindingsForContentAssist(n, isPrefix, namespaces);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name != null ? name.toString() : "<unnamed>"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
return findBindings(n, isPrefix, null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICPPASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTElaboratedTypeSpecifier;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||
|
@ -33,7 +34,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
|||
/**
|
||||
* Unqualified name, also base class for operator and conversion name.
|
||||
*/
|
||||
public class CPPASTName extends CPPASTNameBase implements IASTCompletionContext {
|
||||
public class CPPASTName extends CPPASTNameBase implements ICPPASTCompletionContext {
|
||||
public static IASTName NOT_INITIALIZED= new CPPASTName(null);
|
||||
|
||||
private char[] name;
|
||||
|
@ -71,7 +72,7 @@ public class CPPASTName extends CPPASTNameBase implements IASTCompletionContext
|
|||
return null;
|
||||
}
|
||||
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix, String[] namespaces) {
|
||||
IASTNode parent = getParent();
|
||||
if (parent instanceof ICPPASTElaboratedTypeSpecifier) {
|
||||
ICPPASTElaboratedTypeSpecifier specifier = (ICPPASTElaboratedTypeSpecifier) parent;
|
||||
|
@ -84,11 +85,11 @@ public class CPPASTName extends CPPASTNameBase implements IASTCompletionContext
|
|||
default:
|
||||
return null;
|
||||
}
|
||||
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix);
|
||||
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix, namespaces);
|
||||
return filterByElaboratedTypeSpecifier(kind, bindings);
|
||||
}
|
||||
else if (parent instanceof IASTDeclarator) {
|
||||
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix);
|
||||
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix, namespaces);
|
||||
for (int i = 0; i < bindings.length; i++) {
|
||||
if (bindings[i] instanceof ICPPNamespace || bindings[i] instanceof ICPPClassType) {
|
||||
} else {
|
||||
|
@ -177,4 +178,8 @@ public class CPPASTName extends CPPASTNameBase implements IASTCompletionContext
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
return findBindings(n, isPrefix, null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2010 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* Bryan Wilkinson (QNX)
|
||||
* John Camelon (IBM) - Initial API and implementation
|
||||
* Bryan Wilkinson (QNX)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
|
@ -15,9 +15,9 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
||||
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.IEnumeration;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNamedTypeSpecifier;
|
||||
|
@ -26,11 +26,8 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*/
|
||||
public class CPPASTNamedTypeSpecifier extends CPPASTBaseDeclSpecifier implements
|
||||
ICPPASTNamedTypeSpecifier, IASTCompletionContext {
|
||||
ICPPASTNamedTypeSpecifier, ICPPASTCompletionContext {
|
||||
|
||||
private boolean typename;
|
||||
private IASTName name;
|
||||
|
@ -107,20 +104,24 @@ public class CPPASTNamedTypeSpecifier extends CPPASTBaseDeclSpecifier implements
|
|||
return r_unclear;
|
||||
}
|
||||
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix);
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix, String[] namespaces) {
|
||||
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix, namespaces);
|
||||
List<IBinding> filtered = new ArrayList<IBinding>();
|
||||
|
||||
for (int i = 0; i < bindings.length; i++) {
|
||||
if (bindings[i] instanceof ICPPClassType
|
||||
|| bindings[i] instanceof IEnumeration
|
||||
|| bindings[i] instanceof ICPPNamespace
|
||||
|| bindings[i] instanceof ITypedef
|
||||
|| bindings[i] instanceof ICPPTemplateTypeParameter) {
|
||||
filtered.add(bindings[i]);
|
||||
for (IBinding binding : bindings) {
|
||||
if (binding instanceof ICPPClassType
|
||||
|| binding instanceof IEnumeration
|
||||
|| binding instanceof ICPPNamespace
|
||||
|| binding instanceof ITypedef
|
||||
|| binding instanceof ICPPTemplateTypeParameter) {
|
||||
filtered.add(binding);
|
||||
}
|
||||
}
|
||||
|
||||
return filtered.toArray(new IBinding[filtered.size()]);
|
||||
}
|
||||
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
return findBindings(n, isPrefix, null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ import java.util.List;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
|
@ -25,6 +24,7 @@ import org.eclipse.cdt.core.dom.ast.IASTNameOwner;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.ICPPASTCompletionContext;
|
||||
import org.eclipse.cdt.core.dom.ast.IEnumerator;
|
||||
import org.eclipse.cdt.core.dom.ast.IField;
|
||||
import org.eclipse.cdt.core.dom.ast.IScope;
|
||||
|
@ -52,7 +52,7 @@ import org.eclipse.core.runtime.Assert;
|
|||
* template id).
|
||||
*/
|
||||
public class CPPASTQualifiedName extends CPPASTNameBase
|
||||
implements ICPPASTQualifiedName, IASTCompletionContext {
|
||||
implements ICPPASTQualifiedName, ICPPASTCompletionContext {
|
||||
|
||||
private IASTName[] names = null;
|
||||
private int namesPos= -1;
|
||||
|
@ -246,8 +246,8 @@ public class CPPASTQualifiedName extends CPPASTNameBase
|
|||
return false;
|
||||
}
|
||||
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix);
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix, String[] namespaces) {
|
||||
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix, namespaces);
|
||||
|
||||
if (namesPos > 0) {
|
||||
IBinding binding = names[namesPos-1].resolveBinding();
|
||||
|
@ -344,4 +344,8 @@ public class CPPASTQualifiedName extends CPPASTNameBase
|
|||
Assert.isLegal(false);
|
||||
return null;
|
||||
}
|
||||
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
return findBindings(n, isPrefix, null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2009 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2010 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* John Camelon (IBM) - Initial API and implementation
|
||||
* Bryan Wilkinson (QNX)
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
|
@ -16,19 +16,17 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
||||
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.ICPPASTUsingDeclaration;
|
||||
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 CPPASTUsingDeclaration extends ASTNode
|
||||
implements ICPPASTUsingDeclaration, IASTCompletionContext {
|
||||
implements ICPPASTUsingDeclaration, ICPPASTCompletionContext {
|
||||
|
||||
private boolean typeName;
|
||||
private IASTName name;
|
||||
|
@ -97,13 +95,13 @@ public class CPPASTUsingDeclaration extends ASTNode
|
|||
return r_unclear;
|
||||
}
|
||||
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix);
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix, String[] namespaces) {
|
||||
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix, namespaces);
|
||||
List<IBinding> filtered = new ArrayList<IBinding>();
|
||||
|
||||
for (int i = 0; i < bindings.length; i++) {
|
||||
if (bindings[i] instanceof ICPPNamespace) {
|
||||
filtered.add(bindings[i]);
|
||||
for (IBinding binding : bindings) {
|
||||
if (binding instanceof ICPPNamespace) {
|
||||
filtered.add(binding);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,4 +112,8 @@ public class CPPASTUsingDeclaration extends ASTNode
|
|||
public String toString() {
|
||||
return name.toString();
|
||||
}
|
||||
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
return findBindings(n, isPrefix, null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2008 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2010 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM - Initial API and implementation
|
||||
* Bryan Wilkinson (QNX)
|
||||
* John Camelon (IBM) - Initial API and implementation
|
||||
* Bryan Wilkinson (QNX)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.dom.parser.cpp;
|
||||
|
||||
|
@ -15,19 +15,17 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTCompletionContext;
|
||||
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.ICPPASTUsingDirective;
|
||||
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 CPPASTUsingDirective extends ASTNode implements
|
||||
ICPPASTUsingDirective, IASTCompletionContext {
|
||||
ICPPASTUsingDirective, ICPPASTCompletionContext {
|
||||
|
||||
private IASTName name;
|
||||
|
||||
|
@ -87,16 +85,20 @@ public class CPPASTUsingDirective extends ASTNode implements
|
|||
return r_unclear;
|
||||
}
|
||||
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix);
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix, String[] namespaces) {
|
||||
IBinding[] bindings = CPPSemantics.findBindingsForContentAssist(n, isPrefix, namespaces);
|
||||
List<IBinding> filtered = new ArrayList<IBinding>();
|
||||
|
||||
for (int i = 0;i < bindings.length; i++) {
|
||||
if (bindings[i] instanceof ICPPNamespace) {
|
||||
filtered.add(bindings[i]);
|
||||
for (IBinding binding : bindings) {
|
||||
if (binding instanceof ICPPNamespace) {
|
||||
filtered.add(binding);
|
||||
}
|
||||
}
|
||||
|
||||
return filtered.toArray(new IBinding[filtered.size()]);
|
||||
}
|
||||
|
||||
public IBinding[] findBindings(IASTName n, boolean isPrefix) {
|
||||
return findBindings(n, isPrefix, null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3291,18 +3291,77 @@ public class CPPSemantics {
|
|||
return standardLookup(data, scope);
|
||||
}
|
||||
|
||||
public static IBinding[] findBindingsForContentAssist(IASTName name, boolean prefixLookup) {
|
||||
public static IBinding[] findBindingsForContentAssist(IASTName name, boolean prefixLookup,
|
||||
String[] additionalNamespaces) {
|
||||
LookupData data = createLookupData(name, true);
|
||||
data.contentAssist = true;
|
||||
data.prefixLookup = prefixLookup;
|
||||
data.foundItems = new CharArrayObjectMap(2);
|
||||
|
||||
return contentAssistLookup(data, null);
|
||||
// Convert namespaces to scopes.
|
||||
List<ICPPScope> nsScopes= new ArrayList<ICPPScope>();
|
||||
IASTTranslationUnit tu = name.getTranslationUnit();
|
||||
if (additionalNamespaces != null && tu != null) {
|
||||
for (String nsName : additionalNamespaces) {
|
||||
nsName= nsName.trim();
|
||||
if (nsName.startsWith("::")) { //$NON-NLS-1$
|
||||
nsName= nsName.substring(2);
|
||||
}
|
||||
String[] namespaceParts = nsName.split("::"); //$NON-NLS-1$
|
||||
try {
|
||||
ICPPScope nsScope = getNamespaceScope(tu, namespaceParts);
|
||||
if (nsScope != null) {
|
||||
nsScopes.add(nsScope);
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
// Errors in source code, continue with next candidate.
|
||||
}
|
||||
}
|
||||
}
|
||||
return contentAssistLookup(data, nsScopes);
|
||||
}
|
||||
|
||||
private static IBinding[] contentAssistLookup(LookupData data, IScope start) {
|
||||
private static ICPPScope getNamespaceScope(IASTTranslationUnit tu, String[] namespaceParts)
|
||||
throws DOMException {
|
||||
ICPPScope nsScope= (ICPPScope) tu.getScope();
|
||||
outer: for (String nsPart : namespaceParts) {
|
||||
nsPart= nsPart.trim();
|
||||
if (nsPart.length() != 0) {
|
||||
CPPASTName searchName= new CPPASTName(nsPart.toCharArray());
|
||||
searchName.setParent(tu);
|
||||
searchName.setPropertyInParent(STRING_LOOKUP_PROPERTY);
|
||||
IBinding[] nsBindings = nsScope.getBindings(searchName, true, false);
|
||||
for (IBinding nsBinding : nsBindings) {
|
||||
if (nsBinding instanceof ICPPNamespace) {
|
||||
nsScope= ((ICPPNamespace) nsBinding).getNamespaceScope();
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
// There was no matching namespace
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Name did not specify a namespace, e.g. "::"
|
||||
if (nsScope == tu.getScope())
|
||||
return null;
|
||||
|
||||
return nsScope;
|
||||
}
|
||||
|
||||
private static IBinding[] contentAssistLookup(LookupData data, List<ICPPScope> additionalNamespaces) {
|
||||
try {
|
||||
lookup(data, start);
|
||||
lookup(data, null);
|
||||
|
||||
if (additionalNamespaces != null) {
|
||||
data.ignoreUsingDirectives = true;
|
||||
data.forceQualified = true;
|
||||
for (ICPPScope nsScope : additionalNamespaces) {
|
||||
if (!data.visited.containsKey(nsScope)) {
|
||||
lookup(data, nsScope);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (DOMException e) {
|
||||
}
|
||||
CharArrayObjectMap map = (CharArrayObjectMap) data.foundItems;
|
||||
|
|
Loading…
Add table
Reference in a new issue