1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 09:46:02 +02:00

Use CPPVisitor.getQualifiedName instead of IIndexBinding.getQualifiedName.

This commit is contained in:
Sergey Prigogin 2011-03-09 18:32:32 +00:00
parent 9efcf6f96c
commit e5b9283973
5 changed files with 19 additions and 13 deletions

View file

@ -30,6 +30,7 @@ import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.CTestPlugin; import org.eclipse.cdt.core.testplugin.CTestPlugin;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase; import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.core.testplugin.util.TestSourceReader; import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
@ -271,7 +272,7 @@ public class IndexNamesTests extends BaseTestCase {
for (IIndexName indexName : names) { for (IIndexName indexName : names) {
if (indexName.isReference() && indexName.toString().equals("vm")) { if (indexName.isReference() && indexName.toString().equals("vm")) {
assertEquals(couldbepolymorphic[j], indexName.couldBePolymorphicMethodCall()); assertEquals(couldbepolymorphic[j], indexName.couldBePolymorphicMethodCall());
assertEquals(container[j], fIndex.findBinding(indexName).getQualifiedName()[0]); assertEquals(container[j], CPPVisitor.getQualifiedName(fIndex.findBinding(indexName))[0]);
j++; j++;
} }
else { else {
@ -279,8 +280,7 @@ public class IndexNamesTests extends BaseTestCase {
} }
} }
assertEquals(couldbepolymorphic.length, j); assertEquals(couldbepolymorphic.length, j);
} } finally {
finally {
fIndex.releaseReadLock(); fIndex.releaseReadLock();
} }
} }

View file

@ -34,6 +34,7 @@ import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexFileSet; import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.index.IIndexName; import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPScopeMapper.InlineNamespaceDirective; import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPScopeMapper.InlineNamespaceDirective;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.core.index.IIndexScope; import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
@ -97,23 +98,23 @@ public class CPPNamespaceScope extends CPPScope implements ICPPInternalNamespace
@Override @Override
public IName getScopeName() { public IName getScopeName() {
IASTNode node = getPhysicalNode(); IASTNode node = getPhysicalNode();
if( node instanceof ICPPASTNamespaceDefinition ){ if (node instanceof ICPPASTNamespaceDefinition) {
return ((ICPPASTNamespaceDefinition)node).getName(); return ((ICPPASTNamespaceDefinition)node).getName();
} }
return null; return null;
} }
public IScope findNamespaceScope(IIndexScope scope) { public IScope findNamespaceScope(IIndexScope scope) {
final String[] qname= scope.getScopeBinding().getQualifiedName(); final String[] qname= CPPVisitor.getQualifiedName(scope.getScopeBinding());
final IScope[] result= {null}; final IScope[] result= {null};
final ASTVisitor visitor= new ASTVisitor () { final ASTVisitor visitor= new ASTVisitor() {
private int depth= 0; private int depth= 0;
{ {
shouldVisitNamespaces= shouldVisitDeclarations= true; shouldVisitNamespaces= shouldVisitDeclarations= true;
} }
@Override @Override
public int visit( IASTDeclaration declaration ){ public int visit( IASTDeclaration declaration ){
if( declaration instanceof ICPPASTLinkageSpecification ) if (declaration instanceof ICPPASTLinkageSpecification)
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
return PROCESS_SKIP; return PROCESS_SKIP;
} }

View file

@ -10,6 +10,8 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.index; package org.eclipse.cdt.internal.core.index;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
/** /**
* Binding comparator suitable for C/C++ across index implementations. This will not be used * Binding comparator suitable for C/C++ across index implementations. This will not be used
* unless we ever have non-PDOM implementations of IIndexFragment, and in that case we may find * unless we ever have non-PDOM implementations of IIndexFragment, and in that case we may find
@ -17,7 +19,7 @@ package org.eclipse.cdt.internal.core.index;
*/ */
public class DefaultFragmentBindingComparator implements IIndexFragmentBindingComparator { public class DefaultFragmentBindingComparator implements IIndexFragmentBindingComparator {
public int compare(IIndexFragmentBinding a, IIndexFragmentBinding b) { public int compare(IIndexFragmentBinding a, IIndexFragmentBinding b) {
int cmp= compareQualifiedNames(a.getQualifiedName(), b.getQualifiedName()); int cmp= compareQualifiedNames(CPPVisitor.getQualifiedName(a), CPPVisitor.getQualifiedName(b));
if (cmp == 0) { if (cmp == 0) {
int ac= a.getBindingConstant(), bc= b.getBindingConstant(); int ac= a.getBindingConstant(), bc= b.getBindingConstant();
cmp= ac < bc ? -1 : (ac > bc ? 1 : 0); cmp= ac < bc ? -1 : (ac > bc ? 1 : 0);

View file

@ -31,6 +31,7 @@ import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.parser.Keywords; import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.core.parser.util.ArrayUtil; import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPSemantics; 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.index.IIndexCPPBindingConstants; import org.eclipse.cdt.internal.core.index.IIndexCPPBindingConstants;
import org.eclipse.cdt.internal.core.index.IIndexScope; import org.eclipse.cdt.internal.core.index.IIndexScope;
import org.eclipse.cdt.internal.core.model.ASTStringUtil; import org.eclipse.cdt.internal.core.model.ASTStringUtil;
@ -246,7 +247,7 @@ class PDOMCPPNamespace extends PDOMCPPBinding
@Override @Override
protected String toStringBase() { protected String toStringBase() {
String[] names = getQualifiedName(); String[] names = CPPVisitor.getQualifiedName(this);
if (names.length == 0) { if (names.length == 0) {
return "<unnamed namespace>"; //$NON-NLS-1$ return "<unnamed namespace>"; //$NON-NLS-1$
} }
@ -255,7 +256,8 @@ class PDOMCPPNamespace extends PDOMCPPBinding
public ICPPNamespaceScope[] getInlineNamespaces() { public ICPPNamespaceScope[] getInlineNamespaces() {
if (fInlineNamespaces == null) { if (fInlineNamespaces == null) {
List<PDOMCPPNamespace> nslist = collectInlineNamespaces(getDB(), getLinkage(), record+FIRST_NAMESPACE_CHILD_OFFSET); List<PDOMCPPNamespace> nslist = collectInlineNamespaces(getDB(), getLinkage(),
record + FIRST_NAMESPACE_CHILD_OFFSET);
if (nslist == null) { if (nslist == null) {
fInlineNamespaces= new PDOMCPPNamespace[0]; fInlineNamespaces= new PDOMCPPNamespace[0];
} else { } else {
@ -265,8 +267,8 @@ class PDOMCPPNamespace extends PDOMCPPBinding
return fInlineNamespaces; return fInlineNamespaces;
} }
public static List<PDOMCPPNamespace> collectInlineNamespaces(Database db, public static List<PDOMCPPNamespace> collectInlineNamespaces(Database db, PDOMLinkage linkage,
PDOMLinkage linkage, long listRecord) { long listRecord) {
List<PDOMCPPNamespace> nslist= null; List<PDOMCPPNamespace> nslist= null;
try { try {
long rec= db.getRecPtr(listRecord); long rec= db.getRecPtr(listRecord);

View file

@ -86,6 +86,7 @@ import org.eclipse.cdt.ui.text.ICHelpInvocationContext;
import org.eclipse.cdt.ui.text.SharedASTJob; import org.eclipse.cdt.ui.text.SharedASTJob;
import org.eclipse.cdt.utils.PathUtil; import org.eclipse.cdt.utils.PathUtil;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil;
import org.eclipse.cdt.internal.core.resources.ResourceLookup; import org.eclipse.cdt.internal.core.resources.ResourceLookup;
import org.eclipse.cdt.internal.corext.codemanipulation.AddIncludesOperation; import org.eclipse.cdt.internal.corext.codemanipulation.AddIncludesOperation;
@ -647,7 +648,7 @@ public class AddIncludeOnSelectionAction extends TextEditorAction {
* @throws CoreException * @throws CoreException
*/ */
private static String getBindingQualifiedName(IIndexBinding binding) throws CoreException { private static String getBindingQualifiedName(IIndexBinding binding) throws CoreException {
String[] qname= binding.getQualifiedName(); String[] qname= CPPVisitor.getQualifiedName(binding);
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
boolean needSep= false; boolean needSep= false;
for (String element : qname) { for (String element : qname) {