import java.util.Arrays;
import java.util.HashSet;
-import junit.framework.TestSuite;
-
import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.EScopeKind;
import org.eclipse.cdt.internal.core.index.IndexCPPSignatureUtil;
import org.eclipse.cdt.internal.core.parser.ParserException;
+import junit.framework.TestSuite;
+
public class AST2CPPTests extends AST2TestBase {
public AST2CPPTests() {
ICPPVariable v2 = (ICPPVariable) col.getName(3).resolveBinding();
String[] s = v1.getQualifiedName();
- assertEquals(s[0], "v1");
+ assertEquals("v1", s[0]);
assertFalse(v1.isGloballyQualified());
s = v2.getQualifiedName();
- assertEquals(s[0], "v2");
+ assertEquals("v2", s[0]);
assertFalse(v2.isGloballyQualified());
ICPPBlockScope scope = (ICPPBlockScope) v2.getScope();
- IBinding[] bs = scope.find("v1");
- assertEquals(bs.length, 1);
+ IBinding[] bs = scope.find("v1", tu);
+ assertEquals(1, bs.length);
assertSame(bs[0], v1);
}
ICPPMethod f = (ICPPMethod) col.getName(7).resolveBinding();
IScope scope = f.getFunctionScope();
- IBinding[] bs = scope.find("a");
- assertEquals(bs.length, 1);
+ IBinding[] bs = scope.find("a", tu);
+ assertEquals(1, bs.length);
assertSame(bs[0], a);
- bs = scope.find("~B");
- assertEquals(bs.length, 1);
+ bs = scope.find("~B", tu);
+ assertEquals(1, bs.length);
assertTrue(bs[0] instanceof ICPPMethod);
assertTrue(bs[0].getName().equals("~B"));
- bs = scope.find("A");
- assertEquals(bs.length, 1);
+ bs = scope.find("A", tu);
+ assertEquals(1, bs.length);
assertSame(bs[0], A);
}
IASTFunctionDefinition def = (IASTFunctionDefinition) col.getName(5).getParent().getParent();
IScope scope = ((IASTCompoundStatement) def.getBody()).getScope();
- IBinding[] bs = scope.find("f");
+ IBinding[] bs = scope.find("f", tu);
assertEquals(3, bs.length);
assertSame(bs[0], f3);
assertSame(bs[1], f1);
assertSame(bs[2], f2);
String[] s = ((ICPPBinding) bs[1]).getQualifiedName();
- assertEquals(s.length, 2);
- assertEquals(s[0], "A");
- assertEquals(s[1], "f");
+ assertEquals(2, s.length);
+ assertEquals("A", s[0]);
+ assertEquals("f", s[1]);
assertTrue(((ICPPBinding) bs[1]).isGloballyQualified());
}
IASTFunctionDefinition def = (IASTFunctionDefinition) col.getName(8).getParent().getParent();
IScope scope = ((IASTCompoundStatement) def.getBody()).getScope();
- IBinding[] bs = scope.find("f");
+ IBinding[] bs = scope.find("f", tu);
assertEquals(3, bs.length);
assertSame(bs[0], f);
assertSame(bs[1], f1);
IFunction f1 = (IFunction) col.getName(6).resolveBinding();
IScope classScope= f1.getScope();
assertTrue(classScope instanceof ICPPClassScope);
- IBinding[] bindings = classScope.find("bf");
+ IBinding[] bindings = classScope.find("bf", tu);
ICPPMethod method= extractSingleMethod(bindings);
- assertEquals(method.getQualifiedName()[0], "B");
+ assertEquals("B", method.getQualifiedName()[0]);
- bindings= classScope.find("f");
+ bindings= classScope.find("f", tu);
method= extractSingleMethod(bindings);
- assertEquals(method.getQualifiedName()[0], "A");
+ assertEquals("A", method.getQualifiedName()[0]);
- bindings= classScope.find("B");
+ bindings= classScope.find("B", tu);
ICPPClassType classType= extractSingleClass(bindings);
- assertEquals(classType.getQualifiedName()[0], "B");
+ assertEquals("B", classType.getQualifiedName()[0]);
- bindings= classScope.find("A");
+ bindings= classScope.find("A", tu);
classType= extractSingleClass(bindings);
- assertEquals(classType.getQualifiedName()[0], "A");
+ assertEquals("A", classType.getQualifiedName()[0]);
}
// class A {
ICPPMethod fb = (ICPPMethod) col.getName(6).resolveBinding();
Object[] result = B.getDeclaredFields();
- assertEquals(result.length, 1);
+ assertEquals(1, result.length);
assertSame(result[0], b);
result = B.getFields();
- assertEquals(result.length, 2);
+ assertEquals(2, result.length);
assertSame(result[0], b);
assertSame(result[1], a);
result = B.getDeclaredMethods();
- assertEquals(result.length, 1);
+ assertEquals(1, result.length);
assertSame(result[0], fb);
result = B.getAllDeclaredMethods();
- assertEquals(result.length, 2);
+ assertEquals(2, result.length);
assertSame(result[0], fb);
assertSame(result[1], fa);
ICPPMethod[] B_implicit = ((ICPPClassScope) B.getCompositeScope()).getImplicitMethods();
- assertEquals(B_implicit.length, 4);
+ assertEquals(4, B_implicit.length);
assertTrue(B_implicit[0].getName().equals("B"));
assertTrue(B_implicit[1].getName().equals("B"));
assertTrue(B_implicit[2].getName().equals("operator ="));
assertTrue(B_implicit[3].getName().equals("~B"));
ICPPMethod[] A_implicit = ((ICPPClassScope) A.getCompositeScope()).getImplicitMethods();
- assertEquals(A_implicit.length, 4);
+ assertEquals(4, A_implicit.length);
assertTrue(A_implicit[0].getName().equals("A"));
assertTrue(A_implicit[1].getName().equals("A"));
assertTrue(A_implicit[2].getName().equals("operator ="));
assertTrue(A_implicit[3].getName().equals("~A"));
result = B.getMethods();
- assertEquals(result.length, 10);
+ assertEquals(10, result.length);
assertSame(result[0], fb);
assertSame(result[1], B_implicit[0]);
assertSame(result[2], B_implicit[1]);
}
public void testBug87424() throws Exception {
- IASTTranslationUnit tu = parse(
- "int * __restrict x;", CPP, true);
+ IASTTranslationUnit tu = parse("int * __restrict x;", CPP, true);
NameCollector col = new NameCollector();
tu.accept(col);
}
public void testBug87705() throws Exception {
- IASTTranslationUnit tu = parse(
- "class A { friend class B::C; };", CPP, true);
+ IASTTranslationUnit tu = parse("class A { friend class B::C; };", CPP, true);
NameCollector col = new NameCollector();
tu.accept(col);
}
public void testBug88501_1() throws Exception {
- IASTTranslationUnit tu = parse(
- "void f(); void f(int); struct f;", CPP);
+ IASTTranslationUnit tu = parse("void f(); void f(int); struct f;", CPP);
NameCollector col = new NameCollector();
tu.accept(col);
// IProblemBinding p = (IProblemBinding) col.getName(1).resolveBinding();
// assertEquals(p.getID(), IProblemBinding.SEMANTIC_INVALID_REDEFINITION);
// }
-
public void testBug8342_2() throws Exception {
IASTTranslationUnit tu = parse("extern int a; extern char a;", CPP);
NameCollector col = new NameCollector();
IFunction f2 = (IFunction) col.getName(3).resolveBinding();
IScope scope = tu.getScope();
- IBinding[] bs = scope.find("f");
+ IBinding[] bs = scope.find("f", tu);
assertEquals(bs.length, 2);
assertSame(bs[0], f1);
assertSame(bs[1], f2);
import java.io.IOException;
-import junit.framework.TestSuite;
-
import org.eclipse.cdt.core.dom.ast.ASTTypeUtil;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.EScopeKind;
import org.eclipse.cdt.internal.core.model.ASTStringUtil;
import org.eclipse.cdt.internal.core.parser.ParserException;
+import junit.framework.TestSuite;
+
/**
* Test cases on the AST.
*/
}
public void testBug90253() throws Exception {
- IASTTranslationUnit tu = parse(
- "void f(int par) { int v1; };", C); //$NON-NLS-1$
+ IASTTranslationUnit tu = parse("void f(int par) { int v1; };", C); //$NON-NLS-1$
NameCollector col = new NameCollector();
tu.accept(col);
IASTFunctionDefinition fdef= getDeclaration(tu, 0);
IScope scope = ((IASTCompoundStatement) fdef.getBody()).getScope();
- IBinding[] bs = scope.find("par"); //$NON-NLS-1$
+ IBinding[] bs = scope.find("par", tu); //$NON-NLS-1$
assertEquals(1, bs.length);
assertSame(bs[0], p);
- bs = scope.find("v1"); //$NON-NLS-1$
+ bs = scope.find("v1", tu); //$NON-NLS-1$
assertEquals(bs.length, 1);
assertSame(bs[0], v1);
}
IASTFunctionDefinition fdef= getDeclaration(tu, 2);
IScope scope = ((IASTCompoundStatement) fdef.getBody()).getScope();
- IBinding[] bs = scope.find("S"); //$NON-NLS-1$
+ IBinding[] bs = scope.find("S", tu); //$NON-NLS-1$
assertNotNull(S2);
assertEquals(bs.length, 3);
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Markus Schorn - initial API and implementation
- *******************************************************************************/
+ * Markus Schorn - initial API and implementation
+ *******************************************************************************/
package org.eclipse.cdt.internal.index.tests;
import java.io.File;
import java.io.FileWriter;
-import junit.framework.TestSuite;
-
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
+import junit.framework.TestSuite;
+
public class Bug246129 extends IndexTestBase {
public static TestSuite suite() {
}
private ICProject fProject;
-
- private IFile fSource;
-
+ private IFile fSource;
private IFolder fWrapperIncludeFolder;
-
private IFolder fIncludeFolder;
-
private File fTmpDir;
-
private File fExternalWrapperIncludeFolder;
-
private File fExternalWrapperHeader;
-
private File fExternalIncludeFolder;
-
private File fExternalHeader;
-
private File fExternalExtFolder;
-
IIndex fIndex;
-
boolean fFalseFriendsAccepted;
-
+
public Bug246129(String name) {
super(name);
}
protected void setUp() throws Exception {
super.setUp();
if (fProject == null) {
-
// Populate workspace
fProject = createProject(true, "resources/indexTests/bug246129");
-
+
fSource = fProject.getProject().getFile("source.cpp");
-
- fWrapperIncludeFolder = fProject.getProject().getFolder(
- "wrapper_include");
-
+
+ fWrapperIncludeFolder = fProject.getProject().getFolder("wrapper_include");
+
fIncludeFolder = fProject.getProject().getFolder("include");
// Create header files external to the workspace.
fTmpDir = CProjectHelper.freshDir();
-
- fExternalWrapperIncludeFolder = new File(fTmpDir,
- "wrapper_include");
+
+ fExternalWrapperIncludeFolder = new File(fTmpDir, "wrapper_include");
fExternalWrapperIncludeFolder.mkdir();
-
- fExternalWrapperHeader = new File(
- fExternalWrapperIncludeFolder, "external_type.h");
+
+ fExternalWrapperHeader = new File(fExternalWrapperIncludeFolder, "external_type.h");
fExternalWrapperHeader.createNewFile();
FileWriter writer = new FileWriter(fExternalWrapperHeader);
writer.write("#ifndef EXTERNAL_WRAPPER_TYPE_H_\n");
writer.write("};\n");
writer.write("#endif\n");
writer.close();
-
+
fExternalIncludeFolder = new File(fTmpDir, "include");
fExternalIncludeFolder.mkdir();
-
+
fExternalExtFolder = new File(fExternalIncludeFolder, "ext");
fExternalExtFolder.mkdir();
- fExternalHeader = new File(fExternalIncludeFolder,
- "external_type.h");
+ fExternalHeader = new File(fExternalIncludeFolder, "external_type.h");
fExternalHeader.createNewFile();
writer = new FileWriter(fExternalHeader);
writer.write("#ifndef EXTERNAL_TYPE_H_\n");
// The indexer needs non-empty build info in order to index
// source files if index-all-files is turned off.
- IPathEntry[] entries = new IPathEntry[] { CoreModel
- .newIncludeEntry(fProject.getPath(), null,
- fWrapperIncludeFolder.getLocation()),
- CoreModel.newIncludeEntry(fProject.getPath(), null,
- fIncludeFolder.getLocation()) };
-
+ IPathEntry[] entries = new IPathEntry[] {
+ CoreModel.newIncludeEntry(fProject.getPath(), null, fWrapperIncludeFolder.getLocation()),
+ CoreModel.newIncludeEntry(fProject.getPath(), null, fIncludeFolder.getLocation()) };
+
fProject.setRawPathEntries(entries, npm());
// However, the scanner info provider used by the unit tests
IndexerPreferences.set(fProject.getProject(),
IndexerPreferences.KEY_INDEX_UNUSED_HEADERS_WITH_DEFAULT_LANG, "false");
- File falseFriendDirectory = new File(fWrapperIncludeFolder
- .getLocation().toOSString()
- + "/ext/..");
+ File falseFriendDirectory = new File(fWrapperIncludeFolder.getLocation().toOSString() + "/ext/..");
fFalseFriendsAccepted = falseFriendDirectory.exists();
-
+
CCorePlugin.getIndexManager().reindex(fProject);
waitForIndexer(fProject);
fIndex = CCorePlugin.getIndexManager().getIndex(fProject);
protected void tearDown() throws Exception {
fExternalWrapperHeader.delete();
fExternalWrapperIncludeFolder.delete();
-
+
fExternalHeader.delete();
fExternalExtFolder.delete();
fExternalIncludeFolder.delete();
fTmpDir.delete();
-
+
super.tearDown();
}
private void assertSymbolInIndex(String symbolName) throws Exception {
- IIndexBinding[] bindings = fIndex.findBindings(
- symbolName
- .toCharArray(), false, IndexFilter.ALL, npm());
- assertTrue(bindings.length > 0);
+ IIndexBinding[] bindings = fIndex.findBindings(symbolName.toCharArray(), false, IndexFilter.ALL, npm());
+ assertTrue(bindings.length != 0);
}
-
- public void testIndex() throws Exception {
+ public void testIndex() throws Exception {
try {
-
fIndex.acquireReadLock();
IIndexFile[] indexFiles = fIndex.getAllFiles();
} else {
assertEquals(5, indexFiles.length);
}
-
+
// The wrapper classes are found regardless whether false friends
- // are
- // accepted or not.
+ // are accepted or not.
assertSymbolInIndex("Wrapper");
assertSymbolInIndex("ExternalWrapper");
assertSymbolInIndex("Type");
assertSymbolInIndex("ExternalType");
}
-
+
// Check that all paths are normalized.
for (IIndexFile indexFile : indexFiles) {
-
IIndexInclude[] includes = indexFile.getIncludes();
-
+
for (IIndexInclude i : includes) {
IIndexFileLocation location = i.getIncludesLocation();
assertNotNull(location);
-
- assertFalse(location.getURI().toASCIIString()
- .contains(".."));
+
+ assertFalse(location.getURI().toASCIIString().contains(".."));
String fullPath = location.getFullPath();
if (fullPath != null) {
}
}
}
-
} finally {
fIndex.releaseReadLock();
}
}
-
- private void assertSymbolInAst(IScope scope, String symbolName)
- throws Exception {
- IBinding[] bindings = scope.find(symbolName);
+
+ private void assertSymbolInAst(IScope scope, String symbolName, IASTTranslationUnit ast) throws Exception {
+ IBinding[] bindings = scope.find(symbolName, ast);
assertTrue(bindings.length > 0);
}
-
+
public void testAst() throws Exception {
- ITranslationUnit tu = CoreModel.getDefault().createTranslationUnitFrom(
- fProject, fSource.getLocation());
+ ITranslationUnit tu =
+ CoreModel.getDefault().createTranslationUnitFrom(fProject, fSource.getLocation());
IASTTranslationUnit ast = tu.getAST();
-
+
// The wrapper classes are found regardless whether false friends
// are
// accepted or not.
IScope topLevel = ast.getScope();
- assertSymbolInAst(topLevel, "Wrapper");
- assertSymbolInAst(topLevel, "ExternalWrapper");
+ assertSymbolInAst(topLevel, "Wrapper", ast);
+ assertSymbolInAst(topLevel, "ExternalWrapper", ast);
// The Type class is only known on platforms with a File
// implementation sorting out the false friends.
if (!fFalseFriendsAccepted) {
- assertSymbolInAst(topLevel, "Type");
- assertSymbolInAst(topLevel, "ExternalType");
+ assertSymbolInAst(topLevel, "Type", ast);
+ assertSymbolInAst(topLevel, "ExternalType", ast);
}
// Check that all paths are normalized.
- IASTPreprocessorIncludeStatement[] includes = ast
- .getIncludeDirectives();
+ IASTPreprocessorIncludeStatement[] includes = ast.getIncludeDirectives();
for (IASTPreprocessorIncludeStatement i : includes) {
String includedPath = i.getPath();
import java.util.regex.Pattern;
-import junit.framework.Test;
-
import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
+import junit.framework.Test;
+
/**
* @author Doug Schaefer
- *
*/
public class ClassTests extends PDOMTestBase {
-
protected PDOM pdom;
public static Test suite() {
protected void tearDown() throws Exception {
pdom.releaseReadLock();
}
-
+
public void test1() throws Exception {
IBinding[] Bs = pdom.findBindings(Pattern.compile("B"), true, IndexFilter.ALL, npm());
assertEquals(1, Bs.length);
- ICPPClassType B = (ICPPClassType)Bs[0];
+ ICPPClassType B = (ICPPClassType) Bs[0];
ICPPMethod[] Bmethods = B.getAllDeclaredMethods();
assertEquals(4, Bmethods.length);
assertNotNull(findMethod(Bmethods, "B"));
IASTFileLocation loc = Bf_refs[0].getFileLocation();
assertEquals(offset("class.cpp", "b.f()") + 2, loc.getNodeOffset());
}
-
+
private ICPPMethod findMethod(ICPPMethod[] bmethods, String name) {
for (ICPPMethod method : bmethods) {
if (method.getName().equals(name)) {
IField[] fields = NestedB.getFields();
assertEquals(1, fields.length);
IField NestedB_x = fields[0];
-
+
IName[] refs = pdom.findNames(NestedB, IIndex.FIND_REFERENCES);
assertEquals(1, refs.length);
IASTFileLocation loc = refs[0].getFileLocation();
assertEquals(offset("nested.cpp", "::NestedB") + 2, loc.getNodeOffset());
-
+
refs = pdom.findNames(NestedB_x, IIndex.FIND_REFERENCES);
assertEquals(1, refs.length);
loc = refs[0].getFileLocation();
assertEquals(offset("nested.cpp", "x.x") + 2, loc.getNodeOffset());
}
-
+
public void test147903() throws Exception {
IBinding[] bindings = pdom.findBindings(Pattern.compile("pr147903"), false, IndexFilter.ALL, npm());
assertEquals(1, bindings.length);
- ICPPNamespaceScope ns = ((ICPPNamespace)bindings[0]).getNamespaceScope();
- bindings = ns.find("testRef");
+ ICPPNamespaceScope ns = ((ICPPNamespace) bindings[0]).getNamespaceScope();
+ bindings = ns.find("testRef", null);
assertEquals(1, bindings.length);
IName[] refs = pdom.findNames(bindings[0], IIndex.FIND_REFERENCES);
// for (int i = 0; i < refs.length; ++i)
// System.out.println(refs[i].getFileLocation().getNodeOffset());
assertEquals(5, refs.length);
}
-
+
/* Test friend relationships between classes */
public void testFriend() throws Exception {
IBinding[] bindings = pdom.findBindings(Pattern.compile("ClassA"), true, IndexFilter.ALL_DECLARED, npm());
IBinding[] friends = classA.getFriends();
assertEquals(1, friends.length);
assertEquals(classC, friends[0]); //ClassC is a friend class of ClassA
-
+
friends = classC.getFriends();
assertEquals(1, friends.length);
assertEquals(funcB, friends[0]); //functionB is a friend of ClassC
}
-
+
public void noTest_testConstructor() throws Exception {
// the source does not define Class1, so it is no surprise that the test is failing.
- //TODO PDOM doesn't have information on constructor
+ // TODO PDOM doesn't have information on constructor
IBinding[] bindings = pdom.findBindings(Pattern.compile("Class1"), false, IndexFilter.ALL, npm());
assertEquals(2, bindings.length);
assertTrue(bindings[0] instanceof ICPPClassType);
assertTrue(bindings[1] instanceof ICPPMethod);
-
+
IName[] decls = pdom.findNames(bindings[1], IIndex.FIND_DECLARATIONS_DEFINITIONS);
assertEquals(2, decls.length);
IASTFileLocation loc = decls[0].getFileLocation();
- assertEquals(offset("constructor.cpp","Class1(int num);"), loc.getNodeOffset()); //character offset
-
+ assertEquals(offset("constructor.cpp","Class1(int num);"), loc.getNodeOffset()); //character offset
+
loc = decls[1].getFileLocation();
assertEquals(offset("constructor.cpp","Class1::Class1") + 8, loc.getNodeOffset()); //character offset
-
+
/* Member initialization */
bindings = pdom.findBindings(Pattern.compile("number"), false, IndexFilter.ALL, npm());
assertEquals(1, bindings.length);
-
+
IName[] refs = pdom.findNames(bindings[0], IIndex.FIND_REFERENCES);
assertEquals(1, refs.length);
loc = refs[0].getFileLocation();
- assertEquals(offset("constructor.cpp","number(num)"), loc.getNodeOffset()); //character offset
-
+ assertEquals(offset("constructor.cpp", "number(num)"), loc.getNodeOffset()); //character offset
+
assertEquals(bindings[0], ((PDOMName)refs[0]).getBinding());
}
-
+
public void testAbsenceOfDefaultConstructorWhenExplicitNonDefaultPresentA() throws Exception {
IndexFilter JUST_CONSTRUCTORS= new IndexFilter() {
@Override
// expecting C(int) and C(const C &)
assertEquals(2, bindings.length);
}
-
+
public void testAbsenceOfDefaultConstructorWhenExplicitNonDefaultPresentB() throws Exception {
IndexFilter JUST_CONSTRUCTORS= new IndexFilter() {
@Override
// expecting just D(D &)
assertEquals(1, bindings.length);
}
-
+
public void testClassScope_bug185408() throws Exception {
char[][] name= {"B".toCharArray(), "bf".toCharArray()};
IBinding[] bindings= pdom.findBindings(name, IndexFilter.ALL, npm());
assertEquals(1, bindings.length);
IScope classScope= bindings[0].getScope();
-
+
assertTrue(classScope instanceof ICPPClassScope);
- bindings= classScope.find("bf");
+ bindings= classScope.find("bf", null);
ICPPMethod method= extractSingleMethod(bindings);
- assertEquals(method.getQualifiedName()[0], "B");
+ assertEquals("B", method.getQualifiedName()[0]);
- bindings= classScope.find("f");
+ bindings= classScope.find("f", null);
method= extractSingleMethod(bindings);
- assertEquals(method.getQualifiedName()[0], "A");
+ assertEquals("A", method.getQualifiedName()[0]);
- bindings= classScope.find("B");
+ bindings= classScope.find("B", null);
ICPPClassType classType= extractSingleClass(bindings);
- assertEquals(classType.getQualifiedName()[0], "B");
+ assertEquals("B", classType.getQualifiedName()[0]);
- bindings= classScope.find("A");
+ bindings= classScope.find("A", null);
classType= extractSingleClass(bindings);
- assertEquals(classType.getQualifiedName()[0], "A");
+ assertEquals("A", classType.getQualifiedName()[0]);
}
private ICPPMethod extractSingleMethod(IBinding[] bindings) {
assertEquals(1, bindings.length);
- assertTrue(bindings[0] instanceof ICPPMethod);
+ assertInstance(bindings[0], ICPPMethod.class);
return (ICPPMethod) bindings[0];
}
-
+
private ICPPClassType extractSingleClass(IBinding[] bindings) {
assertEquals(1, bindings.length);
- assertTrue(bindings[0] instanceof ICPPClassType);
+ assertInstance(bindings[0], ICPPClassType.class);
return (ICPPClassType) bindings[0];
}
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.core; singleton:=true
-Bundle-Version: 5.10.0.qualifier
+Bundle-Version: 5.11.0.qualifier
Bundle-Activator: org.eclipse.cdt.core.CCorePlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
* IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
* Bryan Wilkinson (QNX)
+ * Sergey Prigogin (Google)
*******************************************************************************/
package org.eclipse.cdt.core.dom.ast;
/**
* Scopes can be used to look-up names. With the exception of template-scopes the scopes
* can be arranged in a hierarchy.
- *
+ *
* @noextend This interface is not intended to be extended by clients.
* @noimplement This interface is not intended to be implemented by clients.
*/
EScopeKind getKind();
/**
- * Returns the IName for this scope, may be {@code null}
+ * Returns the IName for this scope, may be {@code null}.
+ *
* @return The name of this scope.
*/
public IName getScopeName();
-
+
/**
* Returns the first enclosing non-template scope, or {@code null} if this is the global scope.
*/
public IScope getParent() throws DOMException;
/**
- * This is the general lookup entry point. It returns the list of valid bindings for a given
- * name. The lookup proceeds as an unqualified lookup. Constructors are not considered during
- * this lookup and won't be returned. No attempt is made to resolve potential ambiguities or
+ * This is the general lookup entry point. It returns the list of valid bindings for a given name in this
+ * scope and its enclosing scopes. The name is treated as unqualified. Constructors are not considered
+ * during this lookup and won't be returned. No attempt is made to resolve potential ambiguities or
* perform access checking.
- *
+ *
* @param name the name of the bindings
- * @return An array of bindings.
+ * @param tu the translation unit determining the context for the lookup
+ * @return An array of bindings
+ * @since 5.11
*/
+ public IBinding[] find(String name, IASTTranslationUnit tu);
+
+ /**
+ * @deprecated Use {{@link #find(String, IASTTranslationUnit)}
+ */
+ @Deprecated
public IBinding[] find(String name);
-
+
/**
- * Returns the binding in this scope that the given name would resolve to. Could
- * return null if there is no matching binding in this scope, if the binding has not
- * yet been cached in this scope, or if resolve is {@code false} and the appropriate binding
- * has not yet been resolved.
- *
+ * Returns the binding in this scope that the given name would resolve to. Could return {@code null}
+ * if there is no matching binding in this scope, if the binding has not yet been cached in this scope,
+ * or if resolve is {@code false} and the appropriate binding has not yet been resolved.
+ *
* @param name the name of the binding
* @param resolve whether or not to resolve the matching binding if it has not been so already
* @return the binding in this scope that matches the name, or {@code null}
*/
public IBinding getBinding(IASTName name, boolean resolve);
-
+
/**
- * Returns the binding in this scope that the given name would resolve to. Could
- * return null if there is no matching binding in this scope, if the binding has not
- * yet been cached in this scope, or if resolve is {@code false} and the appropriate binding
- * has not yet been resolved. Accepts file local bindings from the index for the files
- * in the given set, only.
- *
+ * Returns the binding in this scope that the given name would resolve to. Could return {@code null}
+ * if there is no matching binding in this scope, if the binding has not yet been cached in this scope,
+ * or if resolve is {@code false} and the appropriate binding has not yet been resolved. Accepts file
+ * local bindings from the index for the files in the given set, only.
+ *
* @param name the name of the binding
* @param resolve whether or not to resolve the matching binding if it has not been so already
* @param acceptLocalBindings a set of files for which to accept local bindings
* @deprecated Use {@link #getBindings(ScopeLookupData)} instead
*/
@Deprecated
- public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet acceptLocalBindings);
+ public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup,
+ IIndexFileSet acceptLocalBindings);
-
/**
* @since 5.5
* @noextend This class is not intended to be subclassed by clients.
private boolean fResolve= true;
private boolean fPrefixLookup;
private boolean fIgnorePointOfDeclaration;
-
+
public ScopeLookupData(IASTName name, boolean resolve, boolean prefixLookup) {
if (name == null)
throw new IllegalArgumentException();
}
}
+ /**
+ * @since 5.11
+ */
+ public ScopeLookupData(char[] name, IASTTranslationUnit tu) {
+ fLookupPoint= null;
+ fLookupPointIsName= false;
+ fLookupKey= name;
+ fIgnorePointOfDeclaration= true;
+ fTu= tu;
+ }
+
public final void setPrefixLookup(boolean prefixLookup) {
fPrefixLookup = prefixLookup;
}
}
/**
- * Returns the bindings in this scope that the given name or prefix could resolve to. Could
- * return null if there is no matching bindings in this scope, if the bindings have not
- * yet been cached in this scope, or if resolve == false and the appropriate bindings
- * have not yet been resolved.
- *
+ * Returns the bindings in this scope that the given name or prefix could resolve to. Could return
+ * {@code null} if there is no matching bindings in this scope, if the bindings have not yet been cached
+ * in this scope, or if resolve is {@code false} and the appropriate bindings have not yet been resolved.
+ *
* @return the bindings in this scope that match the name or prefix, or {@code null}
* @since 5.5
*/
}
@Override
+ public IBinding[] find(String name, IASTTranslationUnit tu) {
+ return IBinding.EMPTY_BINDING_ARRAY;
+ }
+
+ @Override
public IBinding[] find(String name) {
return IBinding.EMPTY_BINDING_ARRAY;
}
}
@Override
+ public IBinding[] find(String name, IASTTranslationUnit tu) {
+ return find(name);
+ }
+
+ @Override
public IBinding[] find(String name) {
return CVisitor.findBindings(this, name);
}
static IType getPtrDiffType(IASTBinaryExpression expr) {
IScope scope = getContainingScope(expr);
- IBinding[] bs = scope.find(PTRDIFF_T);
+ IBinding[] bs = scope.find(PTRDIFF_T, expr.getTranslationUnit());
for (IBinding b : bs) {
if (b instanceof IType) {
if (!(b instanceof ICInternalBinding) ||
static IType get_SIZE_T(IASTExpression expr) {
IASTTranslationUnit tu= expr.getTranslationUnit();
if (tu != null) {
- IBinding[] bs = tu.getScope().find(SIZE_T);
+ IBinding[] bs = tu.getScope().find(SIZE_T, expr.getTranslationUnit());
for (IBinding b : bs) {
if (b instanceof IType) {
if (!(b instanceof ICInternalBinding) ||
}
// label names
- List<ILabel> b3 = new ArrayList<ILabel>();
+ List<ILabel> b3 = new ArrayList<>();
do {
char[] n = name.toCharArray();
if (scope instanceof ICFunctionScope) {
import org.eclipse.cdt.core.dom.ast.EScopeKind;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
}
@Override
+ public IBinding[] find(String name, IASTTranslationUnit tu) {
+ return find(name);
+ }
+
+ @Override
public IBinding[] find(String name) {
return CPPSemantics.findBindings(this, name, false);
}
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
}
@Override
+ public IBinding[] find(String name, IASTTranslationUnit tu) {
+ return find(name);
+ }
+
+ @Override
public IBinding[] find(String name) {
char[] n = name.toCharArray();
ICPPASTCompositeTypeSpecifier compType = (ICPPASTCompositeTypeSpecifier) getPhysicalNode();
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IField;
}
private IBinding[] getPrefixBindings(char[] name) {
- List<IBinding> result= new ArrayList<IBinding>();
+ List<IBinding> result= new ArrayList<>();
IContentAssistMatcher matcher = ContentAssistMatcherFactory.getInstance().createMatcher(name);
for (ICPPMethod m : getMethods()) {
if (!(m instanceof ICPPConstructor)) {
}
@Override
+ public IBinding[] find(String name, IASTTranslationUnit tu) {
+ return find(name);
+ }
+
+ @Override
public IBinding[] find(String name) {
return getBindings(name.toCharArray());
}
@Override
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup,
IIndexFileSet acceptLocalBindings) {
- return getBindings(new ScopeLookupData(name, resolve, prefixLookup));
- }
+ return getBindings(new ScopeLookupData(name, resolve, prefixLookup));
+ }
@Override
public IBinding[] getBindings(ScopeLookupData lookup) {
}
@Override
+ public IBinding[] find(String name, IASTTranslationUnit tu) {
+ return find(name);
+ }
+
+ @Override
public IBinding[] find(String name) {
return CPPSemantics.findBindings(this, name, false);
}
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
}
@Override
+ public IBinding[] find(String name, IASTTranslationUnit tu) {
+ return fScope.find(name, tu);
+ }
+
+ @Override @Deprecated
public IBinding[] find(String name) {
return fScope.find(name);
}
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
}
@Override
+ public IBinding[] find(String name, IASTTranslationUnit tu) {
+ return IBinding.EMPTY_BINDING_ARRAY;
+ }
+
+ @Override
public IBinding[] find(String name) {
return IBinding.EMPTY_BINDING_ARRAY;
}
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions.Context;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Conversions.UDCMode;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.Cost.Rank;
-import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
if (parent != null)
parent= parent.getParent(); // the loop
if (parent instanceof ICPPASTRangeBasedForStatement) {
- IBinding[] std= parent.getTranslationUnit().getScope().find(CPPVisitor.STD);
+ IASTTranslationUnit tu = parent.getTranslationUnit();
+ IBinding[] std= tu.getScope().find(CPPVisitor.STD, tu);
for (IBinding binding : std) {
if (binding instanceof ICPPNamespace) {
namespaces.add(((ICPPNamespace) binding).getNamespaceScope());
if (binding == null)
return null;
IScope scope = binding.getScope();
- if (tu != null) {
- scope= tu.mapToASTScope(scope);
- }
+ scope = SemanticUtil.mapToAST(scope, tu);
while (scope != null && !(scope instanceof ICPPNamespaceScope)) {
scope = getParentScope(scope, tu);
}
}
}
ICPPScope scope= useTemplScope ? nextTmplScope : nextScope;
- CPPASTTranslationUnit tu = data.getTranslationUnit();
- if (tu != null) {
- scope= (ICPPScope) tu.mapToASTScope((scope));
- }
+ scope = (ICPPScope) SemanticUtil.mapToAST(scope, data.getTranslationUnit());
if (!data.usingDirectivesOnly && !(data.ignoreMembers && scope instanceof ICPPClassScope)) {
mergeResults(data, getBindingsFromScope(scope, data), true);
return ((ICPPASTTemplateDeclaration) parent).getScope();
}
- static ICPPScope getParentScope(IScope scope, ICPPASTTranslationUnit unit) throws DOMException {
+ static ICPPScope getParentScope(IScope scope, IASTTranslationUnit unit) throws DOMException {
IScope parentScope= scope.getParent();
// The index cannot return the translation unit as parent scope.
- if (unit instanceof CPPASTTranslationUnit) {
- if (parentScope == null
- && (scope instanceof IIndexScope || scope instanceof ICPPClassSpecializationScope)) {
- parentScope = unit.getScope();
- } else {
- parentScope = ((CPPASTTranslationUnit) unit).mapToASTScope(parentScope);
- }
+ if (parentScope == null && scope instanceof ICPPClassSpecializationScope
+ && unit instanceof CPPASTTranslationUnit) {
+ parentScope = unit.getScope();
+ } else {
+ parentScope = SemanticUtil.mapToAST(parentScope, unit);
}
return (ICPPScope) parentScope;
}
return type instanceof ICPPClassType || type instanceof IEnumeration || type instanceof ICPPUnknownType;
}
+ public static IBinding[] findBindingsInScope(IScope scope, String name, IASTTranslationUnit tu) {
+ LookupData data = new LookupData(name.toCharArray(), null, tu);
+ return standardLookup(data, scope);
+ }
+
public static IBinding[] findBindings(IScope scope, String name, boolean qualified) {
return findBindings(scope, name.toCharArray(), qualified, null);
}
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownType;
-import org.eclipse.cdt.internal.core.index.IIndexScope;
/**
* Collection of methods to extract information from a C++ translation unit.
}
if (mustBeSimple) {
- // 3.3.1-5 ... the identifier is declared in the smallest non-class non-function-prototype scope that contains
- // the declaration
+ // 3.3.1-5 ... the identifier is declared in the smallest non-class non-function-prototype
+ // scope that contains the declaration.
while (scope instanceof ICPPClassScope || scope instanceof ICPPFunctionScope) {
- scope = (ICPPScope) getParentScope(scope, elabType.getTranslationUnit());
+ scope = CPPSemantics.getParentScope(scope, elabType.getTranslationUnit());
}
}
if (scope instanceof ICPPClassScope && isFriend && !qualified) {
while (scope instanceof ICPPClassScope) {
- scope = (ICPPScope) getParentScope(scope, elabType.getTranslationUnit());
+ scope = CPPSemantics.getParentScope(scope, elabType.getTranslationUnit());
}
}
if (scope != null) {
if (isFriendDecl) {
try {
while (scope.getKind() == EScopeKind.eClassType) {
- scope = (ICPPScope) getParentScope(scope, name.getTranslationUnit());
+ scope = CPPSemantics.getParentScope(scope, name.getTranslationUnit());
}
} catch (DOMException e1) {
}
if (node == null)
return null;
ASTTranslationUnit ast = (ASTTranslationUnit) node.getTranslationUnit();
- IBinding[] std= ast.getScope().find(STD);
+ IBinding[] std= ast.getScope().find(STD, ast);
for (IBinding binding : std) {
if (binding instanceof ICPPNamespace) {
final ICPPNamespaceScope scope = ((ICPPNamespace) binding).getNamespaceScope();
return ns;
}
- private static IScope getParentScope(IScope scope, IASTTranslationUnit unit) throws DOMException {
- IScope parentScope= scope.getParent();
- // Replace the global scope from index with the global scope of the translation unit.
- if ((parentScope == null || parentScope.getKind() == EScopeKind.eGlobal) &&
- scope instanceof IIndexScope && unit != null) {
- parentScope= unit.getScope();
- }
- return parentScope;
- }
-
public static boolean isExternC(IASTNode node) {
while (node != null) {
node= node.getParent();
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IScope.ScopeLookupData;
fTemplateArguments= templateArgs;
}
+ public LookupData(char[] name, ICPPTemplateArgument[] templateArgs, IASTTranslationUnit tu) {
+ super(name, tu);
+ fTemplateArguments= templateArgs;
+ }
+
@Override
public CPPASTTranslationUnit getTranslationUnit() {
return (CPPASTTranslationUnit) super.getTranslationUnit();
import java.util.HashSet;
import java.util.Set;
+import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException;
+import org.eclipse.cdt.core.dom.ast.EScopeKind;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
import org.eclipse.cdt.internal.core.dom.parser.cpp.OverloadableOperator;
+import org.eclipse.cdt.internal.core.index.IIndexScope;
/**
* Collection of static methods operating on C++ bindings.
}
public static IScope mapToAST(IScope scope, IASTNode point) {
- if (point != null) {
- IASTTranslationUnit ast = point.getTranslationUnit();
- if (ast instanceof ASTTranslationUnit) {
- return ((ASTTranslationUnit) ast).mapToASTScope(scope);
+ if (scope instanceof IIndexScope) {
+ if (point != null) {
+ IASTTranslationUnit ast = point.getTranslationUnit();
+ if (ast instanceof ASTTranslationUnit) {
+ return ((ASTTranslationUnit) ast).mapToASTScope(scope);
+ }
+ } else if (scope.getKind() == EScopeKind.eGlobal) {
+ CCorePlugin.log(new Exception(
+ "The point argument was not provided. Returning the global index scope.")); //$NON-NLS-1$
}
}
return scope;
import org.eclipse.cdt.core.dom.ast.EScopeKind;
import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
}
@Override
+ public IBinding[] find(String name, IASTTranslationUnit tu) {
+ IBinding[] preresult = ((ICompositeType) rbinding).getCompositeScope().find(name, tu);
+ return processUncertainBindings(preresult);
+ }
+
+ @Override @Deprecated
public IBinding[] find(String name) {
IBinding[] preresult = ((ICompositeType) rbinding).getCompositeScope().find(name);
return processUncertainBindings(preresult);
import org.eclipse.cdt.core.dom.ast.EScopeKind;
import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
}
@Override
+ public IBinding[] find(String name, IASTTranslationUnit tu) {
+ IBinding[] preresult = ((ICPPClassType) rbinding).getCompositeScope().find(name, tu);
+ return processUncertainBindings(preresult);
+ }
+
+ @Override @Deprecated
public IBinding[] find(String name) {
IBinding[] preresult = ((ICPPClassType) rbinding).getCompositeScope().find(name);
return processUncertainBindings(preresult);
import org.eclipse.cdt.core.dom.ast.EScopeKind;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
}
@Override
+ public IBinding[] find(String name, IASTTranslationUnit tu) {
+ createDelegate();
+ return fDelegate.find(name, tu);
+ }
+
+ @Override @Deprecated
public IBinding[] find(String name) {
createDelegate();
return fDelegate.find(name);
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Markus Schorn - initial API and implementation
+ * Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp;
import org.eclipse.cdt.core.dom.ast.EScopeKind;
import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumeration;
@Override
public IBinding[] getBindings(ScopeLookupData lookup) {
- IBinding[] bindings = ((ICPPEnumeration)rbinding).asScope().getBindings(lookup);
+ IBinding[] bindings = ((ICPPEnumeration) rbinding).asScope().getBindings(lookup);
return processUncertainBindings(bindings);
}
-
+
@Override
+ public IBinding[] find(String name, IASTTranslationUnit tu) {
+ IBinding[] preresult = ((ICPPEnumeration) rbinding).asScope().find(name, tu);
+ return processUncertainBindings(preresult);
+ }
+
+ @Override @Deprecated
public IBinding[] find(String name) {
- IBinding[] preresult = ((ICPPEnumeration)rbinding).asScope().find(name);
+ IBinding[] preresult = ((ICPPEnumeration) rbinding).asScope().find(name);
return processUncertainBindings(preresult);
}
-
+
@Override
public IIndexBinding getScopeBinding() {
return cf.getCompositeBinding(rbinding);
import org.eclipse.cdt.core.dom.ast.EScopeKind;
import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
}
@Override
+ final public IBinding[] find(String name, IASTTranslationUnit tu) {
+ IIndexFragmentBinding[][] preresult = new IIndexFragmentBinding[namespaces.length][];
+ for (int i= 0; i < namespaces.length; i++) {
+ IBinding[] raw = namespaces[i].getNamespaceScope().find(name, tu);
+ preresult[i] = new IIndexFragmentBinding[raw.length];
+ System.arraycopy(raw, 0, preresult[i], 0, raw.length);
+ }
+ return cf.getCompositeBindings(preresult);
+ }
+
+ @Override @Deprecated
final public IBinding[] find(String name) {
IIndexFragmentBinding[][] preresult = new IIndexFragmentBinding[namespaces.length][];
for (int i= 0; i < namespaces.length; i++) {
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom;
+import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.EScopeKind;
import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFileSet;
}
@Override
+ public IBinding[] find(String name, IASTTranslationUnit tu) {
+ logInvalidCallError();
+ return IBinding.EMPTY_BINDING_ARRAY;
+ }
+
+ @Override
public IBinding[] find(String name) {
- throw new UnsupportedOperationException();
+ logInvalidCallError();
+ return IBinding.EMPTY_BINDING_ARRAY;
}
@Override
public IBinding getBinding(IASTName name, boolean resolve) {
- throw new UnsupportedOperationException();
+ logInvalidCallError();
+ return null;
}
@Override
public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet acceptLocalBindings) {
- throw new UnsupportedOperationException();
+ logInvalidCallError();
+ return null;
}
@Override
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) {
- throw new UnsupportedOperationException();
+ logInvalidCallError();
+ return IBinding.EMPTY_BINDING_ARRAY;
}
@Override
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup,
IIndexFileSet acceptLocalBindings) {
- throw new UnsupportedOperationException();
+ logInvalidCallError();
+ return IBinding.EMPTY_BINDING_ARRAY;
}
@Override
public IBinding[] getBindings(ScopeLookupData lookup) {
- throw new UnsupportedOperationException();
+ logInvalidCallError();
+ return IBinding.EMPTY_BINDING_ARRAY;
}
@Override
public String toString() {
return "<global scope>"; //$NON-NLS-1$
}
+
+ private void logInvalidCallError() {
+ CCorePlugin.log(new UnsupportedOperationException(
+ "Global index scope has to be mapped to the global scope of a particular translation unit.")); //$NON-NLS-1$
+ }
}
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.EScopeKind;
import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IField;
}
@Override
+ public IBinding[] find(String name, IASTTranslationUnit tu) {
+ return getBindings(name.toCharArray());
+ }
+
+ @Override @Deprecated
public IBinding[] find(String name) {
return getBindings(name.toCharArray());
}
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.EScopeKind;
import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.ICompositeType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTConversionName;
}
@Override
+ public IBinding[] find(String name, IASTTranslationUnit tu) {
+ return CPPSemantics.findBindingsInScope(this, name, tu);
+ }
+
+ @Override @Deprecated
public IBinding[] find(String name) {
return CPPSemantics.findBindings(this, name, false);
}
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import org.eclipse.cdt.core.dom.ast.DOMException;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
+import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassSpecialization;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.internal.core.dom.parser.cpp.AbstractCPPClassSpecializationScope;
+import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics;
import org.eclipse.cdt.internal.core.index.IIndexScope;
/**
public IIndexName getScopeName() {
return null;
}
+
+ @Override
+ public IBinding[] find(String name, IASTTranslationUnit tu) {
+ return CPPSemantics.findBindingsInScope(this, name, tu);
+ }
}
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.EScopeKind;
import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPEnumScope;
}
@Override
+ public IBinding[] find(String name, IASTTranslationUnit tu) {
+ return CPPSemantics.findBindingsInScope(this, name, tu);
+ }
+
+ @Override @Deprecated
public IBinding[] find(String name) {
return CPPSemantics.findBindings(this, name, false);
}
import org.eclipse.cdt.core.dom.IPDOMVisitor;
import org.eclipse.cdt.core.dom.ast.EScopeKind;
import org.eclipse.cdt.core.dom.ast.IASTName;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
}
@Override
+ public IBinding[] find(String name, IASTTranslationUnit tu) {
+ return find(name);
+ }
+
+ @Override
public IBinding[] find(String name) {
try {
BindingCollector visitor = new BindingCollector(getLinkage(), name.toCharArray(),
<relativePath>../../pom.xml</relativePath>
</parent>
- <version>5.10.0-SNAPSHOT</version>
+ <version>5.11.0-SNAPSHOT</version>
<artifactId>org.eclipse.cdt.core</artifactId>
<packaging>eclipse-plugin</packaging>
</project>
}
}
- public static IBinding[] findInScope(final IScope scope, String name, boolean removeGlobalsWhenClassScope)
- throws DOMException {
+ public static IBinding[] findInScope(final IScope scope, String name, IASTTranslationUnit tu,
+ boolean removeGlobalsWhenClassScope) throws DOMException {
IBinding[] result= null;
- result = scope.find(name);
+ result = scope.find(name, tu);
if (result == null || result.length == 0) {
return result;
}
for (int i = 0; i < result.length; i++) {
IBinding binding = result[i];
IScope bscope= binding.getScope();
- if (! (bscope instanceof ICPPClassScope || bscope instanceof ICCompositeTypeScope)) {
+ if (!(bscope instanceof ICPPClassScope || bscope instanceof ICCompositeTypeScope)) {
result[i]= null;
} else {
count++;
if (scope != null) {
IBinding[] conflicting= null;
try {
- conflicting= findInScope(scope, fRenameTo, true);
+ conflicting= findInScope(scope, fRenameTo, name.getTranslationUnit(), true);
} catch (Exception e) {
CUIPlugin.log(e);
}
try {
oldBindingsScope = oldBinding.getScope();
if (oldBindingsScope != null) {
- newBindingsAboverOrEqual = ASTManager.findInScope(oldBindingsScope, fRenameTo, false);
+ newBindingsAboverOrEqual = ASTManager.findInScope(oldBindingsScope, fRenameTo, null, false);
}
} catch (DOMException e) {
handleDOMException(tu, e, status);
if (ctors != null) {
ArrayUtil.addAll(bindings, ctors);
}
-
+
IScope scope= ctype.getCompositeScope();
if (scope != null) {
- IBinding[] dtors= scope.find("~" + argument.getName()); //$NON-NLS-1$
+ IBinding[] dtors= scope.find("~" + argument.getName(), argument.getTranslationUnit()); //$NON-NLS-1$
if (dtors != null) {
ArrayUtil.addAll(bindings, dtors);
}
import org.eclipse.cdt.core.dom.ast.EScopeKind;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
+import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.index.IIndexFileSet;
*/
@SuppressWarnings({"restriction","unused"})
public class C99Scope implements IC99Scope, IASTInternalScope {
-
-
-
private IScope parent;
private IASTNode physicalNode;
private IName scopeName;
this.scopeName = scopeName;
}
-
@Override
- public IBinding[] find( String name) {
+ public IBinding[] find(String name, IASTTranslationUnit tu) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override @Deprecated
+ public IBinding[] find(String name) {
throw new UnsupportedOperationException();
}
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup) {
throw new UnsupportedOperationException();
}
-
-
-
@Override
public void addBinding(IBinding binding) {
}
@Override
- public IBinding getBinding(IASTName name, boolean resolve,
- IIndexFileSet acceptLocalBindings) {
- // TODO Auto-generated method stub
+ public IBinding getBinding(IASTName name, boolean resolve, IIndexFileSet acceptLocalBindings) {
return null;
}
@Deprecated
public IBinding[] getBindings(IASTName name, boolean resolve,
boolean prefixLookup, IIndexFileSet acceptLocalBindings) {
- return getBindings(new ScopeLookupData(name, resolve, prefixLookup));
- }
+ return getBindings(new ScopeLookupData(name, resolve, prefixLookup));
+ }
@Override
public IBinding[] getBindings(ScopeLookupData lookup) {
- // TODO Auto-generated method stub
- return null;
+ return IBinding.EMPTY_BINDING_ARRAY;
}
-
-
-
}