1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-23 16:23:52 +02:00

Adjusted toString method and removed unused methods.

This commit is contained in:
Sergey Prigogin 2012-12-28 17:00:23 -08:00
parent 2cdce220b9
commit 77c3aa7a9c

View file

@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Andrew Niefer (IBM Corporation) - Initial API and implementation * Andrew Niefer (IBM Corporation) - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -40,29 +40,34 @@ import org.eclipse.cdt.internal.core.dom.Linkage;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding; import org.eclipse.cdt.internal.core.dom.parser.ProblemBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
import org.eclipse.cdt.internal.core.model.ASTStringUtil;
import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.PlatformObject;
public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPInternalBinding { public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPInternalBinding {
public static class CPPNamespaceProblem extends ProblemBinding implements ICPPNamespace, ICPPNamespaceScope{
public static class CPPNamespaceProblem extends ProblemBinding implements ICPPNamespace, ICPPNamespaceScope {
public CPPNamespaceProblem(IASTNode node, int id, char[] arg) { public CPPNamespaceProblem(IASTNode node, int id, char[] arg) {
super(node, id, arg); super(node, id, arg);
} }
@Override @Override
public ICPPNamespaceScope getNamespaceScope() { public ICPPNamespaceScope getNamespaceScope() {
return this; return this;
} }
@Override @Override
public IBinding[] getMemberBindings() { public IBinding[] getMemberBindings() {
return IBinding.EMPTY_BINDING_ARRAY; return IBinding.EMPTY_BINDING_ARRAY;
} }
@Override @Override
public void addUsingDirective(ICPPUsingDirective usingDirective) { public void addUsingDirective(ICPPUsingDirective usingDirective) {
} }
@Override @Override
public ICPPUsingDirective[] getUsingDirectives() { public ICPPUsingDirective[] getUsingDirectives() {
return ICPPUsingDirective.EMPTY_ARRAY; return ICPPUsingDirective.EMPTY_ARRAY;
} }
@Override @Override
public ICPPNamespaceScope[] getInlineNamespaces() { public ICPPNamespaceScope[] getInlineNamespaces() {
return ICPPNamespaceScope.EMPTY_NAMESPACE_SCOPE_ARRAY; return ICPPNamespaceScope.EMPTY_NAMESPACE_SCOPE_ARRAY;
@ -80,27 +85,21 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI
} }
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDeclarations()
*/
@Override @Override
public IASTNode[] getDeclarations() { public IASTNode[] getDeclarations() {
return namespaceDefinitions; return namespaceDefinitions;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPBinding#getDefinition()
*/
@Override @Override
public IASTNode getDefinition() { public IASTNode getDefinition() {
return (tu != null) ? tu : (IASTNode) namespaceDefinitions[0]; return tu != null ? tu : (IASTNode) namespaceDefinitions[0];
} }
static private class NamespaceCollector extends ASTVisitor { static private class NamespaceCollector extends ASTVisitor {
private ICPPASTNamespaceDefinition namespaceDef = null; private ICPPASTNamespaceDefinition namespaceDef;
private IASTName[] namespaces = null; private IASTName[] namespaces;
public NamespaceCollector(ICPPASTNamespaceDefinition ns ) { public NamespaceCollector(ICPPASTNamespaceDefinition ns) {
shouldVisitNamespaces = true; shouldVisitNamespaces = true;
shouldVisitDeclarations = true; shouldVisitDeclarations = true;
this.namespaceDef = ns; this.namespaceDef = ns;
@ -142,6 +141,7 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI
static private class NamespaceMemberCollector extends ASTVisitor { static private class NamespaceMemberCollector extends ASTVisitor {
public ObjectSet<IBinding> members = new ObjectSet<IBinding>(8); public ObjectSet<IBinding> members = new ObjectSet<IBinding>(8);
public NamespaceMemberCollector() { public NamespaceMemberCollector() {
shouldVisitNamespaces = true; shouldVisitNamespaces = true;
shouldVisitDeclarators = true; shouldVisitDeclarators = true;
@ -160,6 +160,7 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI
return PROCESS_SKIP; return PROCESS_SKIP;
} }
@Override @Override
public int visit(IASTDeclSpecifier declSpec) { public int visit(IASTDeclSpecifier declSpec) {
if (declSpec instanceof ICPPASTCompositeTypeSpecifier) { if (declSpec instanceof ICPPASTCompositeTypeSpecifier) {
@ -181,6 +182,7 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI
} }
return PROCESS_SKIP; return PROCESS_SKIP;
} }
@Override @Override
public int visit(ICPPASTNamespaceDefinition namespace) { public int visit(ICPPASTNamespaceDefinition namespace) {
IBinding binding = namespace.getName().resolveBinding(); IBinding binding = namespace.getName().resolveBinding();
@ -188,6 +190,7 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI
members.put(binding); members.put(binding);
return PROCESS_SKIP; return PROCESS_SKIP;
} }
@Override @Override
public int visit(IASTDeclaration declaration) { public int visit(IASTDeclaration declaration) {
if (declaration instanceof ICPPASTUsingDeclaration) { if (declaration instanceof ICPPASTUsingDeclaration) {
@ -201,6 +204,7 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI
return PROCESS_CONTINUE; return PROCESS_CONTINUE;
} }
} }
private void findAllDefinitions(ICPPASTNamespaceDefinition namespaceDef) { private void findAllDefinitions(ICPPASTNamespaceDefinition namespaceDef) {
NamespaceCollector collector = new NamespaceCollector(namespaceDef); NamespaceCollector collector = new NamespaceCollector(namespaceDef);
namespaceDef.getTranslationUnit().accept(collector); namespaceDef.getTranslationUnit().accept(collector);
@ -215,99 +219,52 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI
return namespaceDefinitions; return namespaceDefinitions;
} }
/**
* @param unit
*/
public CPPNamespace(CPPASTTranslationUnit unit) { public CPPNamespace(CPPASTTranslationUnit unit) {
tu = unit; tu = unit;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace#getNamespaceScope()
*/
@Override @Override
public ICPPNamespaceScope getNamespaceScope() { public ICPPNamespaceScope getNamespaceScope() {
if (scope == null) { if (scope == null) {
if (tu != null) if (tu != null) {
scope = (ICPPNamespaceScope) tu.getScope(); scope = (ICPPNamespaceScope) tu.getScope();
else } else {
scope = new CPPNamespaceScope(namespaceDefinitions[0].getParent()); scope = new CPPNamespaceScope(namespaceDefinitions[0].getParent());
}
} }
return scope; return scope;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getName()
*/
@Override @Override
public String getName() { public String getName() {
return new String(getNameCharArray()); return new String(getNameCharArray());
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getNameCharArray()
*/
@Override @Override
public char[] getNameCharArray() { public char[] getNameCharArray() {
return tu != null ? CharArrayUtils.EMPTY_CHAR_ARRAY : namespaceDefinitions[0].getSimpleID(); return tu != null ? CharArrayUtils.EMPTY_CHAR_ARRAY : namespaceDefinitions[0].getSimpleID();
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getScope()
*/
@Override @Override
public IScope getScope() { public IScope getScope() {
return tu != null ? null : CPPVisitor.getContainingScope(namespaceDefinitions[0]); return tu != null ? null : CPPVisitor.getContainingScope(namespaceDefinitions[0]);
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getPhysicalNode()
*/
public IASTNode getPhysicalNode() {
return tu != null ? (IASTNode) tu : namespaceDefinitions[0];
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getFullyQualifiedName()
*/
public String[] getFullyQualifiedName() {
return CPPVisitor.getQualifiedName(this);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IBinding#getFullyQualifiedNameCharArray()
*/
public char[][] getFullyQualifiedNameCharArray() {
return CPPVisitor.getQualifiedNameCharArray(this);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedName()
*/
@Override @Override
public String[] getQualifiedName() { public String[] getQualifiedName() {
return CPPVisitor.getQualifiedName(this); return CPPVisitor.getQualifiedName(this);
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#getQualifiedNameCharArray()
*/
@Override @Override
public char[][] getQualifiedNameCharArray() { public char[][] getQualifiedNameCharArray() {
return CPPVisitor.getQualifiedNameCharArray(this); return CPPVisitor.getQualifiedNameCharArray(this);
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding#isGloballyQualified()
*/
@Override @Override
public boolean isGloballyQualified() { public boolean isGloballyQualified() {
return true; return true;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDefinition(org.eclipse.cdt.core.dom.ast.IASTNode)
*/
@Override @Override
public void addDefinition(IASTNode node) { public void addDefinition(IASTNode node) {
if (!(node instanceof IASTName)) if (!(node instanceof IASTName))
@ -326,9 +283,6 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI
} }
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding#addDeclaration(org.eclipse.cdt.core.dom.ast.IASTNode)
*/
@Override @Override
public void addDeclaration(IASTNode node) { public void addDeclaration(IASTNode node) {
addDefinition(node); addDefinition(node);
@ -370,9 +324,15 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI
public String toString() { public String toString() {
String[] names = getQualifiedName(); String[] names = getQualifiedName();
if (names.length == 0) { if (names.length == 0) {
return "<unnamed namespace>"; //$NON-NLS-1$ return "<global namespace>"; //$NON-NLS-1$
} }
return ASTStringUtil.join(names, String.valueOf(Keywords.cpCOLONCOLON)); StringBuilder buf = new StringBuilder();
for (String name : names) {
if (buf.length() != 0)
buf.append(Keywords.cpCOLONCOLON);
buf.append(name.isEmpty() ? "<anonymous>" : name); //$NON-NLS-1$
}
return buf.toString();
} }
@Override @Override