1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 18:05:33 +02:00

Fix for 193779, name resolution shall ignore bindings without declarations.

This commit is contained in:
Markus Schorn 2007-07-04 13:30:13 +00:00
parent 8ecd3b539e
commit c00f123a5f
26 changed files with 244 additions and 130 deletions

View file

@ -31,6 +31,7 @@ import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexManager;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ILanguage;
@ -352,7 +353,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
((PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter());
}
index= CCorePlugin.getIndexManager().getIndex(cproject);
index= CCorePlugin.getIndexManager().getIndex(cproject, IIndexManager.ADD_DEPENDENCIES);
index.acquireReadLock();
ast= TestSourceReader.createIndexBasedAST(index, cproject, references);
}

View file

@ -129,7 +129,10 @@ public class IndexBugsTests extends BaseTestCase {
// void four() {}
// void five() {}
// };
public void _test154563() throws Exception {
public void test154563() throws Exception {
// because of fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=193779
// this test case passes. However https://bugs.eclipse.org/bugs/show_bug.cgi?id=154563
// remains to be fixed.
StringBuffer[] content= getContentsForTest(3);
IFile file= createFile(getProject(), "header.h", content[0].toString());
@ -415,7 +418,7 @@ public class IndexBugsTests extends BaseTestCase {
index = CCorePlugin.getIndexManager().getIndex(cproject);
index.acquireReadLock();
try {
IBinding[] bindings = index.findBindings(Pattern.compile(".*"), false, IndexFilter.ALL, new NullProgressMonitor());
IBinding[] bindings = index.findBindings(Pattern.compile(".*"), false, IndexFilter.ALL_DECLARED, new NullProgressMonitor());
assertEquals(4, bindings.length);
}
finally {

View file

@ -1130,18 +1130,10 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
assertEquals(binding2, getBindingFromASTName("f(const_int_ptr_const)", 1));
assertEquals(binding2, getBindingFromASTName("f(int_const_ptr_const)", 1));
if(strategy.isCompositeIndex()) {
// getIndex() returns the index for the referencing content only
assertEquals(0, getIndex().findNames(binding1, IIndex.FIND_DECLARATIONS).length);
assertEquals(0, getIndex().findNames(binding2, IIndex.FIND_DECLARATIONS).length);
assertEquals(1, getIndex().findNames(binding1, IIndex.FIND_DEFINITIONS).length);
assertEquals(1, getIndex().findNames(binding2, IIndex.FIND_DEFINITIONS).length);
} else {
assertEquals(2, getIndex().findNames(binding1, IIndex.FIND_DECLARATIONS).length);
assertEquals(4, getIndex().findNames(binding2, IIndex.FIND_DECLARATIONS).length);
assertEquals(1, getIndex().findNames(binding1, IIndex.FIND_DEFINITIONS).length);
assertEquals(1, getIndex().findNames(binding2, IIndex.FIND_DEFINITIONS).length);
}
assertEquals(2, getIndex().findNames(binding1, IIndex.FIND_DECLARATIONS).length);
assertEquals(4, getIndex().findNames(binding2, IIndex.FIND_DECLARATIONS).length);
assertEquals(1, getIndex().findNames(binding1, IIndex.FIND_DEFINITIONS).length);
assertEquals(1, getIndex().findNames(binding2, IIndex.FIND_DEFINITIONS).length);
}
/* CPP assertion helpers */

View file

@ -25,6 +25,7 @@ import org.eclipse.cdt.core.dom.IPDOMManager;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexManager;
@ -41,7 +42,7 @@ import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
/**
* Tests the behaviour of the IIndex API when dealing with multiple projects
* Tests the behavior of the IIndex API when dealing with multiple projects
*/
public class IndexCompositeTests extends BaseTestCase {
@ -51,6 +52,14 @@ public class IndexCompositeTests extends BaseTestCase {
private static final int NONE = 0, REFS = IIndexManager.ADD_DEPENDENCIES;
private static final int REFD = IIndexManager.ADD_DEPENDENT, BOTH = REFS | REFD;
private static final IndexFilter FILTER= new IndexFilter() {
public boolean acceptBinding(IBinding binding) throws CoreException {
if (binding instanceof ICPPMethod) {
return !((ICPPMethod) binding).isImplicit();
}
return true;
}
};
IIndex index;
@ -387,21 +396,21 @@ public class IndexCompositeTests extends BaseTestCase {
* @throws CoreException
*/
private IIndex assertBCount(int global, int all) throws CoreException {
IBinding[] bindings = index.findBindings(Pattern.compile(".*"), true, IndexFilter.ALL, new NullProgressMonitor());
IBinding[] bindings = index.findBindings(Pattern.compile(".*"), true, FILTER, new NullProgressMonitor());
assertEquals(global, bindings.length);
bindings = index.findBindings(Pattern.compile(".*"), false, IndexFilter.ALL, new NullProgressMonitor());
bindings = index.findBindings(Pattern.compile(".*"), false, FILTER, new NullProgressMonitor());
assertEquals(all, bindings.length);
return index;
}
private void assertNamespaceXMemberCount(int count) throws CoreException, DOMException {
IBinding[] bindings = index.findBindings(Pattern.compile("X"), true, IndexFilter.ALL, new NullProgressMonitor());
IBinding[] bindings = index.findBindings(Pattern.compile("X"), true, FILTER, new NullProgressMonitor());
assertEquals(1, bindings.length);
assertEquals(count, ((ICPPNamespace)bindings[0]).getMemberBindings().length);
}
private void assertFieldCount(String qnPattern, int count) throws CoreException, DOMException {
IBinding[] bindings = index.findBindings(Pattern.compile(qnPattern), true, IndexFilter.ALL, new NullProgressMonitor());
IBinding[] bindings = index.findBindings(Pattern.compile(qnPattern), true, FILTER, new NullProgressMonitor());
assertEquals(1, bindings.length);
assertEquals(count, ((ICompositeType)bindings[0]).getFields().length);
}

View file

@ -39,7 +39,7 @@ import org.eclipse.core.runtime.CoreException;
public class IndexSearchTest extends IndexTestBase {
private static final IndexFilter INDEX_FILTER = IndexFilter.ALL;
private static final IndexFilter INDEX_FILTER = IndexFilter.ALL_DECLARED;
public static TestSuite suite() {
TestSuite suite= suite(IndexSearchTest.class, "_");

View file

@ -86,7 +86,7 @@ public class ClassTests extends PDOMTestBase {
}
public void testNested() throws Exception {
IBinding[] bindings = pdom.findBindings(Pattern.compile("NestedA"), false, IndexFilter.ALL, NPM);
IBinding[] bindings = pdom.findBindings(Pattern.compile("NestedA"), false, IndexFilter.ALL_DECLARED, NPM);
assertEquals(1, bindings.length);
ICPPClassType NestedA = (ICPPClassType)bindings[0];
ICPPClassType[] nested = NestedA.getNestedClasses();
@ -174,9 +174,6 @@ public class ClassTests extends PDOMTestBase {
public boolean acceptBinding(IBinding binding) {
return binding instanceof ICPPConstructor;
}
public boolean acceptImplicitMethods() {
return true;
}
};
IBinding[] bindings = pdom.findBindings(Pattern.compile("C"), false, JUST_CONSTRUCTORS, NPM);
// expecting C(int) and C(const C &)
@ -188,9 +185,6 @@ public class ClassTests extends PDOMTestBase {
public boolean acceptBinding(IBinding binding) {
return binding instanceof ICPPConstructor;
}
public boolean acceptImplicitMethods() {
return true;
}
};
IBinding[] bindings = pdom.findBindings(Pattern.compile("D"), false, JUST_CONSTRUCTORS, NPM);
// expecting just D(D &)

View file

@ -55,7 +55,7 @@ public class OverloadsWithinSingleTUTests extends PDOMTestBase {
IBinding[] barBs = pdom.findBindings(Pattern.compile("bar"), false, IndexFilter.ALL, new NullProgressMonitor());
assertEquals(8, barBs.length);
IBinding[] FooBs = pdom.findBindings(Pattern.compile("Foo"), false, IndexFilter.ALL, new NullProgressMonitor());
IBinding[] FooBs = pdom.findBindings(Pattern.compile("Foo"), false, IndexFilter.ALL_DECLARED, new NullProgressMonitor());
assertEquals(4, FooBs.length);
Pattern[] XBarAbsPath = makePatternArray(new String[] {"X","bar"});

View file

@ -45,7 +45,7 @@ public class PDOMSearchTest extends PDOMTestBase {
protected ICProject project;
protected PDOM pdom;
protected IProgressMonitor NULL_MONITOR = new NullProgressMonitor();
protected IndexFilter INDEX_FILTER = IndexFilter.ALL;
protected IndexFilter INDEX_FILTER = IndexFilter.ALL_DECLARED;
public static Test suite() {
return suite(PDOMSearchTest.class);

View file

@ -73,7 +73,7 @@ public class TypesTests extends PDOMTestBase {
public void testCPP() throws Exception {
// Get the binding for A::f
IBinding [] As = pdom.findBindings(Pattern.compile("A"), false, IndexFilter.ALL, new NullProgressMonitor());
IBinding [] As = pdom.findBindings(Pattern.compile("A"), true, IndexFilter.ALL, new NullProgressMonitor());
assertEquals(1, As.length);
ICPPClassType A = (ICPPClassType)As[0];
ICPPMethod[] Amethods = A.getDeclaredMethods();

View file

@ -31,7 +31,10 @@ import org.eclipse.core.runtime.CoreException;
abstract public class IndexFilter {
public static final IndexFilter ALL = new IndexFilter() {};
public static final IndexFilter ALL_DECLARED = new DeclaredBindingsFilter();
public static final IndexFilter ALL_DECLARED = getDeclaredBindingFilter(null, false);
public static final IndexFilter ALL_DECLARED_OR_IMPLICIT = getDeclaredBindingFilter(null, true);
public static final IndexFilter CPP_DECLARED_OR_IMPLICIT= getDeclaredBindingFilter(ILinkage.CPP_LINKAGE_ID, true);
public static final IndexFilter C_DECLARED_OR_IMPLICIT= getDeclaredBindingFilter(ILinkage.C_LINKAGE_ID, true);
/**
* Get an IndexFilter that filters out bindings from linkages other than that
@ -47,6 +50,16 @@ abstract public class IndexFilter {
};
}
/**
* Get an IndexFilter that filters out bindings without declarations and those
* from linkages other than that specified.
* @param linkageID the id of the linkage whose bindings should be retained
* @return an IndexFilter instance
*/
public static IndexFilter getDeclaredBindingFilter(final String linkageID, boolean acceptImplicit) {
return new DeclaredBindingsFilter(linkageID, acceptImplicit);
}
/**
* Returns whether or not to include objects of the given linkage in the query.
* @see IIndex#findBindings(java.util.regex.Pattern, boolean, IndexFilter, org.eclipse.core.runtime.IProgressMonitor)
@ -56,17 +69,7 @@ abstract public class IndexFilter {
public boolean acceptLinkage(ILinkage linkage) {
return true;
}
/**
* Returns whether or not to include implicit methods in the query.
* @see IIndex#findBindings(java.util.regex.Pattern, boolean, IndexFilter, org.eclipse.core.runtime.IProgressMonitor)
* @return whether or not to include implicit methods in the query.
* @since 4.0
*/
public boolean acceptImplicitMethods() {
return false;
}
/**
* Determines whether or not a binding is valid.
*

View file

@ -66,6 +66,29 @@ public class CScope implements ICScope, IASTInternalScope {
public static final int NAMESPACE_TYPE_OTHER = 1;
public static final int NAMESPACE_TYPE_BOTH = 2;
private static final IndexFilter[] INDEX_FILTERS = {
new IndexFilter() { // namespace type tag
public boolean acceptBinding(IBinding binding) throws CoreException {
return IndexFilter.C_DECLARED_OR_IMPLICIT.acceptBinding(binding) &&
(binding instanceof ICompositeType || binding instanceof IEnumeration);
}
public boolean acceptLinkage(ILinkage linkage) {
return IndexFilter.C_DECLARED_OR_IMPLICIT.acceptLinkage(linkage);
}
},
new IndexFilter() { // namespace type other
public boolean acceptBinding(IBinding binding) throws CoreException {
return IndexFilter.C_DECLARED_OR_IMPLICIT.acceptBinding(binding) &&
!(binding instanceof ICompositeType || binding instanceof IEnumeration);
}
public boolean acceptLinkage(ILinkage linkage) {
return IndexFilter.C_DECLARED_OR_IMPLICIT.acceptLinkage(linkage);
}
},
// namespace type both
IndexFilter.C_DECLARED_OR_IMPLICIT
};
private IASTNode physicalNode = null;
private boolean isFullyCached = false;
@ -185,7 +208,7 @@ public class CScope implements ICScope, IASTInternalScope {
IIndex index= ((IASTTranslationUnit)physicalNode).getIndex();
if(index!=null) {
try {
IBinding[] bindings= index.findBindings(name.toCharArray(), getIndexFilter(type), new NullProgressMonitor());
IBinding[] bindings= index.findBindings(name.toCharArray(), INDEX_FILTERS[type], new NullProgressMonitor());
result= processIndexResults(name, bindings);
} catch(CoreException ce) {
CCorePlugin.log(ce);
@ -240,8 +263,8 @@ public class CScope implements ICScope, IASTInternalScope {
if(index!=null) {
try {
IBinding[] bindings = prefixLookup ?
index.findBindingsForPrefix(name.toCharArray(), true, getIndexFilter(NAMESPACE_TYPE_BOTH), null) :
index.findBindings(name.toCharArray(), getIndexFilter(NAMESPACE_TYPE_BOTH), null);
index.findBindingsForPrefix(name.toCharArray(), true, INDEX_FILTERS[NAMESPACE_TYPE_BOTH], null) :
index.findBindings(name.toCharArray(), INDEX_FILTERS[NAMESPACE_TYPE_BOTH], null);
obj = ArrayUtil.addAll(Object.class, obj, bindings);
} catch(CoreException ce) {
CCorePlugin.log(ce);
@ -295,41 +318,7 @@ public class CScope implements ICScope, IASTInternalScope {
return candidate;
}
/**
* Returns a C-linkage filter suitable for searching the index for the types of bindings
* specified
* @param type the types of bindings to search for. One of {@link CScope#NAMESPACE_TYPE_TAG}
* or {@link CScope#NAMESPACE_TYPE_OTHER}, otherwise the C-linkage will not be filtered
* @return a C-linkage filter suitable for searching the index for the types of bindings
* specified
*/
private IndexFilter getIndexFilter(final int type) {
switch(type) {
case NAMESPACE_TYPE_TAG:
return new IndexFilter() {
public boolean acceptBinding(IBinding binding) {
return binding instanceof ICompositeType || binding instanceof IEnumeration;
}
public boolean acceptLinkage(ILinkage linkage) {
return linkage.getID().equals(ILinkage.C_LINKAGE_ID);
}
};
case NAMESPACE_TYPE_OTHER:
return new IndexFilter() {
public boolean acceptBinding(IBinding binding) {
return !(binding instanceof ICompositeType || binding instanceof IEnumeration);
}
public boolean acceptLinkage(ILinkage linkage) {
return linkage.getID().equals(ILinkage.C_LINKAGE_ID);
}
};
default:
return IndexFilter.getFilter(ILinkage.C_LINKAGE_ID);
}
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.c.ICScope#setFullyCached(boolean)
*/

View file

@ -18,7 +18,6 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
@ -1357,7 +1356,7 @@ public class CVisitor {
IIndex index = tu.getIndex();
if (index != null) {
try {
IndexFilter filter = IndexFilter.getFilter(ILinkage.C_LINKAGE_ID);
IndexFilter filter = IndexFilter.C_DECLARED_OR_IMPLICIT;
IBinding[] bindings= prefix
? index.findBindingsForPrefix(name.toCharArray(), true, filter, null)
: index.findBindings(name.toCharArray(), filter, null);

View file

@ -17,7 +17,6 @@
package org.eclipse.cdt.internal.core.dom.parser.cpp;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
@ -104,7 +103,7 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
// Try looking this up in the PDOM
if (physicalNode instanceof IASTTranslationUnit) {
try {
IBinding[] bindings= index.findBindings(name.toCharArray(), IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID), NPM);
IBinding[] bindings= index.findBindings(name.toCharArray(), IndexFilter.CPP_DECLARED_OR_IMPLICIT, NPM);
binding= CPPSemantics.resolveAmbiguities(name, bindings);
} catch (CoreException e) {
CCorePlugin.log(e);
@ -182,7 +181,7 @@ abstract public class CPPScope implements ICPPScope, IASTInternalScope {
if (index != null) {
if (physicalNode instanceof IASTTranslationUnit) {
try {
IndexFilter filter = IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID);
IndexFilter filter = IndexFilter.CPP_DECLARED_OR_IMPLICIT;
IBinding[] bindings = prefixLookup ?
index.findBindingsForPrefix(name.toCharArray(), true, filter, null) :
index.findBindings(name.toCharArray(), filter, null);

View file

@ -1065,7 +1065,7 @@ public class CPPSemantics {
if (data.contentAssist) {
Object[] objs = ArrayUtil.addAll(Object.class, null, inScope);
for (int i = 0; i < b.length; i++) {
if (b[i] instanceof IIndexBinding)
if (isFromIndex(b[i]))
objs = ArrayUtil.append(Object.class, objs, b[i]);
}
mergeResults(data, objs, true);
@ -1073,7 +1073,7 @@ public class CPPSemantics {
mergeResults(data, inScope, true);
}
} else if (!data.contentAssist) {
if (b != null && b[0] instanceof IIndexBinding) {
if (b != null && isFromIndex(b[0])) {
mergeResults(data, b, true);
}
} else if (b != null){
@ -2025,7 +2025,7 @@ public class CPPSemantics {
} else {
if( fns == ObjectSet.EMPTY_SET )
fns = new ObjectSet(2);
if (temp instanceof IIndexBinding) {
if (isFromIndex(temp)) {
// accept bindings from index only, in case we have none in the AST
if (!fnsFromAST) {
fns.put(temp);
@ -2065,8 +2065,8 @@ public class CPPSemantics {
}
else {
// ignore index stuff in case we have bindings from the ast
boolean ibobj= obj instanceof IIndexBinding;
boolean ibtemp= temp instanceof IIndexBinding;
boolean ibobj= isFromIndex(obj);
boolean ibtemp= isFromIndex(temp);
// blame it on the index
if (ibobj != ibtemp) {
if (ibobj)
@ -2124,6 +2124,16 @@ public class CPPSemantics {
return obj;
}
private static boolean isFromIndex(IBinding binding) {
if (binding instanceof IIndexBinding) {
return true;
}
if (binding instanceof ICPPSpecialization) {
return ((ICPPSpecialization) binding).getSpecializedBinding() instanceof IIndexBinding;
}
return false;
}
static private boolean functionHasParameters( IFunction function, IASTParameterDeclaration [] params ) throws DOMException{
IFunctionType ftype = function.getType();

View file

@ -448,9 +448,6 @@ public class CIndex implements IIndex {
public boolean acceptBinding(IBinding binding) throws CoreException {
return filter.acceptBinding(binding);
}
public boolean acceptImplicitMethods() {
return filter.acceptImplicitMethods();
}
public boolean acceptLinkage(ILinkage other) {
return linkage.getID().equals(other.getID());
}

View file

@ -11,15 +11,42 @@
package org.eclipse.cdt.internal.core.index;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.core.runtime.CoreException;
public class DeclaredBindingsFilter extends IndexFilter {
final private String fLinkageID;
final private boolean fAcceptImplicit;
public DeclaredBindingsFilter() {
this(null, false);
}
public DeclaredBindingsFilter(String linkageID, boolean acceptImplicit) {
fLinkageID= linkageID;
fAcceptImplicit= acceptImplicit;
}
public boolean acceptLinkage(ILinkage linkage) {
return fLinkageID == null || fLinkageID.equals(linkage.getID());
}
public boolean acceptBinding(IBinding binding) throws CoreException {
if (binding instanceof IIndexFragmentBinding) {
return ((IIndexFragmentBinding) binding).hasDeclaration();
return ((IIndexFragmentBinding) binding).hasDeclaration() ||
(fAcceptImplicit && isImplicit(binding));
}
return true; // composite bindings don't support that kind of check.
// composite bindings don't support that kind of check.
return fAcceptImplicit || !isImplicit(binding);
}
private boolean isImplicit(IBinding binding) {
if (binding instanceof ICPPMethod) {
return ((ICPPMethod) binding).isImplicit();
}
return false;
}
}

View file

@ -34,7 +34,6 @@ import org.eclipse.cdt.core.dom.IPDOMNode;
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexLinkage;
@ -341,11 +340,8 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
// check if we have a complete match.
final int lastIdx = pattern.length-1;
if (matchesUpToLevel.get(lastIdx) && pattern[lastIdx].matcher(name).matches()) {
if (filter.acceptImplicitMethods() || !(binding instanceof ICPPMethod) ||
!((ICPPMethod)binding).isImplicit()) {
if (filter.acceptBinding(binding)) {
bindings.add(binding);
}
if (filter.acceptBinding(binding)) {
bindings.add(binding);
}
}

View file

@ -162,9 +162,6 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType
public boolean acceptBinding(IBinding binding) {
return !(binding instanceof ICPPTemplateParameter || binding instanceof ICPPSpecialization);
}
public boolean acceptImplicitMethods() {
return true;
}
public boolean acceptLinkage(ILinkage linkage) {
return linkage.getID() == ILinkage.CPP_LINKAGE_ID;
}
@ -192,9 +189,6 @@ class PDOMCPPClassTemplate extends PDOMCPPClassType
public boolean acceptBinding(IBinding binding) {
return !(binding instanceof ICPPTemplateParameter || binding instanceof ICPPSpecialization);
}
public boolean acceptImplicitMethods() {
return true;
}
public boolean acceptLinkage(ILinkage linkage) {
return linkage.getID() == ILinkage.CPP_LINKAGE_ID;
}

View file

@ -38,6 +38,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPClassScope;
@ -341,7 +342,7 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
if (!prefixLookup) {
return getBindingsViaCache(nameChars);
}
BindingCollector visitor = new BindingCollector(getLinkageImpl(), nameChars, null, prefixLookup, !prefixLookup);
BindingCollector visitor = new BindingCollector(getLinkageImpl(), nameChars, IndexFilter.ALL_DECLARED_OR_IMPLICIT, prefixLookup, !prefixLookup);
if (getDBName().comparePrefix(nameChars, false) == 0) {
// 9.2 ... The class-name is also inserted into the scope of
// the class itself
@ -362,7 +363,7 @@ class PDOMCPPClassType extends PDOMCPPBinding implements ICPPClassType,
if (result != null) {
return result;
}
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name, null, false, true);
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name, IndexFilter.ALL_DECLARED_OR_IMPLICIT, false, true);
if (getDBName().compare(name, true) == 0) {
visitor.visit(this);
}

View file

@ -27,6 +27,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPDelegate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPNamespace;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPSemantics;
@ -109,7 +110,7 @@ class PDOMCPPNamespace extends PDOMCPPBinding
public IBinding[] find(String name) {
try {
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray());
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), IndexFilter.ALL_DECLARED_OR_IMPLICIT,false, true);
getIndex().accept(visitor);
return visitor.getBindings();
} catch (CoreException e) {
@ -134,7 +135,7 @@ class PDOMCPPNamespace extends PDOMCPPBinding
if (!prefixLookup) {
return getBindingsViaCache(name.toCharArray());
}
BindingCollector visitor= new BindingCollector(getLinkageImpl(), name.toCharArray(), null, prefixLookup, !prefixLookup);
BindingCollector visitor= new BindingCollector(getLinkageImpl(), name.toCharArray(), IndexFilter.ALL_DECLARED_OR_IMPLICIT, prefixLookup, !prefixLookup);
getIndex().accept(visitor);
result = (IBinding[]) ArrayUtil.addAll(IBinding.class, result, visitor.getBindings());
} catch (CoreException e) {

View file

@ -6,7 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial API and implementation
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
@ -18,6 +19,7 @@ import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.core.runtime.CoreException;
@ -28,8 +30,12 @@ class PDOMClassUtil {
static class FieldCollector implements IPDOMVisitor {
private List fields = new ArrayList();
public boolean visit(IPDOMNode node) throws CoreException {
if (node instanceof ICPPField)
fields.add(node);
if (node instanceof ICPPField) {
ICPPField field= (ICPPField) node;
if (IndexFilter.ALL_DECLARED_OR_IMPLICIT.acceptBinding(field)) {
fields.add(node);
}
}
return false;
}
public void leave(IPDOMNode node) throws CoreException {
@ -42,8 +48,12 @@ class PDOMClassUtil {
static class ConstructorCollector implements IPDOMVisitor {
private List fConstructors = new ArrayList();
public boolean visit(IPDOMNode node) throws CoreException {
if (node instanceof ICPPConstructor)
fConstructors.add(node);
if (node instanceof ICPPConstructor) {
ICPPConstructor cons= (ICPPConstructor) node;
if (IndexFilter.ALL_DECLARED_OR_IMPLICIT.acceptBinding(cons)) {
fConstructors.add(cons);
}
}
return false;
}
public void leave(IPDOMNode node) throws CoreException {
@ -55,20 +65,23 @@ class PDOMClassUtil {
static class MethodCollector implements IPDOMVisitor {
private final List methods;
private final boolean acceptImplicit;
private final boolean acceptAll;
private final boolean acceptNonImplicit;
private final IndexFilter filter;
public MethodCollector(boolean acceptImplicit) {
this(acceptImplicit, true);
}
public MethodCollector(boolean acceptImplicit, boolean acceptExplicit) {
public MethodCollector(boolean acceptImplicit, boolean acceptNonImplicit) {
this.methods = new ArrayList();
this.acceptImplicit= acceptImplicit;
this.acceptAll= acceptImplicit && acceptExplicit;
this.acceptNonImplicit= acceptNonImplicit;
this.filter= acceptImplicit ? IndexFilter.ALL_DECLARED_OR_IMPLICIT : IndexFilter.ALL_DECLARED;
}
public boolean visit(IPDOMNode node) throws CoreException {
if (node instanceof ICPPMethod) {
if (acceptAll || ((ICPPMethod) node).isImplicit() == acceptImplicit) {
methods.add(node);
ICPPMethod method= (ICPPMethod) node;
if (filter.acceptBinding(method)) {
if (acceptNonImplicit || method.isImplicit()) {
methods.add(node);
}
}
}
return false; // don't visit the method

View file

@ -53,6 +53,7 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase {
private ICProject fCProject;
private IFile fCFile;
protected ITextEditor fEditor;
private boolean fIsCpp;
private final static Set fgAllKeywords= new HashSet();
@ -62,13 +63,19 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase {
fgAllKeywords.addAll(ParserFactory.getKeywordSet(KeywordSetKey.KEYWORDS, ParserLanguage.CPP));
fgAllKeywords.addAll(ParserFactory.getKeywordSet(KeywordSetKey.TYPES, ParserLanguage.CPP));
}
public AbstractContentAssistTest(String name) {
public AbstractContentAssistTest(String name, boolean isCpp) {
super(name);
fIsCpp= isCpp;
}
protected void setUp() throws Exception {
super.setUp();
fCProject= CProjectHelper.createCCProject(getName(), "unused", IPDOMManager.ID_FAST_INDEXER);
if (fIsCpp) {
fCProject= CProjectHelper.createCCProject(getName(), "unused", IPDOMManager.ID_FAST_INDEXER);
}
else {
fCProject= CProjectHelper.createCProject(getName(), "unused", IPDOMManager.ID_FAST_INDEXER);
}
fCFile= setUpProjectContent(fCProject.getProject());
assertNotNull(fCFile);
fEditor= (ITextEditor)EditorTestHelper.openInEditor(fCFile, true);

View file

@ -35,7 +35,11 @@ public abstract class CompletionProposalsBaseTest extends AbstractContentAssistT
private boolean fFailingTest;
public CompletionProposalsBaseTest(String name) {
super(name);
super(name, true);
}
public CompletionProposalsBaseTest(String name, boolean isCpp) {
super(name, isCpp);
}
/*

View file

@ -18,6 +18,7 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.jface.text.IDocument;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
/**
@ -30,9 +31,31 @@ public class CompletionTests extends AbstractContentAssistTest {
private static final String HEADER_FILE_NAME = "CompletionTest.h";
private static final String SOURCE_FILE_NAME = "CompletionTest.cpp";
private static final String CURSOR_LOCATION_TAG = "/*cursor*/";
private static final String DISTURB_FILE_NAME= "DisturbWith.cpp";
protected int fCursorOffset;
private boolean fCheckExtraResults= true;
private IProject fProject;
//{DisturbWith.cpp}
// int gTemp;
// void gFunc();
// typedef struct {
// int mem;
// } gStruct;
// class gClass {};
// namespace gns {
// int gnsTemp;
// void gnsFunc();
// typedef struct {
// int mem;
// } gnsStruct;
// class gnsClass {};
// };
//{CompletionTest.h}
//class C1;
@ -120,7 +143,7 @@ public class CompletionTests extends AbstractContentAssistTest {
//};
public CompletionTests(String name) {
super(name);
super(name, true);
}
public static Test suite() {
@ -131,6 +154,7 @@ public class CompletionTests extends AbstractContentAssistTest {
* @see org.eclipse.cdt.ui.tests.text.contentassist2.AbstractCompletionTest#setUpProjectContent(org.eclipse.core.resources.IProject)
*/
protected IFile setUpProjectContent(IProject project) throws Exception {
fProject= project;
String headerContent= readTaggedComment(HEADER_FILE_NAME);
StringBuffer sourceContent= getContentsForTest(1)[0];
sourceContent.insert(0, "#include \""+HEADER_FILE_NAME+"\"\n");
@ -784,4 +808,26 @@ public class CompletionTests extends AbstractContentAssistTest {
};
assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_DISP_STRINGS);
}
// namespace gns {
// void test() {
// g/*cursor*/
public void testBindingsWithoutDeclaration() throws Exception {
final String[] expected= {
"gC1", "gC2", "gfC1()", "gfC2()",
"gns::", "gnsClass", "gnsFunc()", "gnsStruct", "gnsTemp",
"gClass", "gFunc()", "gStruct", "gTemp"
};
final String[] expected2= {
"gC1", "gC2", "gfC1()", "gfC2()", "gns::"
};
String disturbContent= readTaggedComment(DISTURB_FILE_NAME);
IFile dfile= createFile(fProject, DISTURB_FILE_NAME, disturbContent);
assertTrue(CCorePlugin.getIndexManager().joinIndexer(8000, NPM));
assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS);
dfile.delete(true, NPM);
assertTrue(CCorePlugin.getIndexManager().joinIndexer(8000, NPM));
assertCompletionResults(fCursorOffset, expected2, AbstractContentAssistTest.COMPARE_REP_STRINGS);
}
}

View file

@ -16,6 +16,7 @@ import junit.framework.Test;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
/**
@ -28,12 +29,21 @@ public class CompletionTests_PlainC extends AbstractContentAssistTest {
private static final String HEADER_FILE_NAME = "CompletionTest.h";
private static final String SOURCE_FILE_NAME = "CompletionTest.c";
private static final String CURSOR_LOCATION_TAG = "/*cursor*/";
private static final String DISTURB_FILE_NAME= "DisturbWith.c";
protected int fCursorOffset;
private IProject fProject;
//{CompletionTest.h}
//int gGlobalInt;
//{DisturbWith.c}
// int gTemp;
// void gFunc();
// typedef struct {
// int mem;
// } gStruct;
public static Test suite() {
return BaseTestCase.suite(CompletionTests_PlainC.class, "_");
}
@ -42,13 +52,14 @@ public class CompletionTests_PlainC extends AbstractContentAssistTest {
* @param name
*/
public CompletionTests_PlainC(String name) {
super(name);
super(name, false);
}
/*
* @see org.eclipse.cdt.ui.tests.text.contentassist2.AbstractContentAssistTest#setUpProjectContent(org.eclipse.core.resources.IProject)
*/
protected IFile setUpProjectContent(IProject project) throws Exception {
fProject= project;
String headerContent= readTaggedComment(HEADER_FILE_NAME);
StringBuffer sourceContent= getContentsForTest(1)[0];
sourceContent.insert(0, "#include \""+HEADER_FILE_NAME+"\"\n");
@ -93,4 +104,22 @@ public class CompletionTests_PlainC extends AbstractContentAssistTest {
assertCompletionResults(expected);
}
// void test() {
// g/*cursor*/
public void testBindingsWithoutDeclaration() throws Exception {
final String[] expected= {
"gGlobalInt", "gTemp", "gFunc(void)", "gStruct"
};
final String[] expected2= {
"gGlobalInt"
};
String disturbContent= readTaggedComment(DISTURB_FILE_NAME);
IFile dfile= createFile(fProject, DISTURB_FILE_NAME, disturbContent);
assertTrue(CCorePlugin.getIndexManager().joinIndexer(8000, NPM));
assertCompletionResults(expected);
dfile.delete(true, NPM);
assertTrue(CCorePlugin.getIndexManager().joinIndexer(8000, NPM));
assertCompletionResults(expected2);
}
}

View file

@ -43,7 +43,7 @@ public class ParameterHintTests extends AbstractContentAssistTest {
//template<class T>void tFunc(T x, T y);
public ParameterHintTests(String name) {
super(name);
super(name, true);
}
public static Test suite() {