mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
toString method.
This commit is contained in:
parent
545e4ae027
commit
6aa23c119f
3 changed files with 68 additions and 44 deletions
|
@ -192,6 +192,27 @@ public class ASTStringUtil {
|
|||
return parameterTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Joins strings together using a given delimiter.
|
||||
* @param strings the strings to join.
|
||||
* @param delimiter the delimiter that is put between the strings when joining them.
|
||||
* @return the joined string.
|
||||
*/
|
||||
public static String join(String[] strings, CharSequence delimiter) {
|
||||
if (strings.length == 0) {
|
||||
return ""; //$NON-NLS-1$
|
||||
} else if (strings.length == 1) {
|
||||
return strings[0];
|
||||
} else {
|
||||
StringBuilder buf = new StringBuilder(strings[0]);
|
||||
for (int i = 1; i < strings.length; i++) {
|
||||
buf.append(delimiter);
|
||||
buf.append(strings[i]);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
|
||||
private static String getParameterSignatureString(IASTParameterDeclaration parameterDeclaration) {
|
||||
return trimRight(appendParameterDeclarationString(new StringBuilder(), parameterDeclaration)).toString();
|
||||
}
|
||||
|
@ -229,7 +250,8 @@ public class ASTStringUtil {
|
|||
return buffer;
|
||||
}
|
||||
|
||||
private static StringBuilder appendDeclaratorString(StringBuilder buffer, IASTDeclarator declarator, boolean addParams) {
|
||||
private static StringBuilder appendDeclaratorString(StringBuilder buffer, IASTDeclarator declarator,
|
||||
boolean addParams) {
|
||||
if (declarator == null) {
|
||||
return buffer;
|
||||
}
|
||||
|
@ -248,8 +270,7 @@ public class ASTStringUtil {
|
|||
buffer.append(Keywords.cpLPAREN);
|
||||
buffer.append(tmp);
|
||||
buffer.append(Keywords.cpRPAREN);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
buffer.append(tmp);
|
||||
}
|
||||
}
|
||||
|
@ -710,5 +731,4 @@ public class ASTStringUtil {
|
|||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ 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.ProblemBinding;
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -352,15 +353,7 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI
|
|||
String[] names = getQualifiedName();
|
||||
if (names.length == 0) {
|
||||
return "<unnamed namespace>"; //$NON-NLS-1$
|
||||
} else if (names.length == 1) {
|
||||
return names[0];
|
||||
} else {
|
||||
StringBuilder buf = new StringBuilder(names[0]);
|
||||
for (int i = 1; i < names.length; i++) {
|
||||
buf.append(Keywords.cpCOLONCOLON);
|
||||
buf.append(names[i]);
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
return ASTStringUtil.join(names, String.valueOf(Keywords.cpCOLONCOLON));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,10 +27,12 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDirective;
|
|||
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||
import org.eclipse.cdt.core.index.IIndexFileSet;
|
||||
import org.eclipse.cdt.core.index.IndexFilter;
|
||||
import org.eclipse.cdt.core.parser.Keywords;
|
||||
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.index.IIndexCPPBindingConstants;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexScope;
|
||||
import org.eclipse.cdt.internal.core.model.ASTStringUtil;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.BTree;
|
||||
import org.eclipse.cdt.internal.core.pdom.db.IBTreeVisitor;
|
||||
|
@ -41,7 +43,6 @@ import org.eclipse.core.runtime.CoreException;
|
|||
|
||||
/**
|
||||
* @author Doug Schaefer
|
||||
*
|
||||
*/
|
||||
class PDOMCPPNamespace extends PDOMCPPBinding
|
||||
implements ICPPNamespace, ICPPNamespaceScope, IIndexScope {
|
||||
|
@ -74,12 +75,10 @@ class PDOMCPPNamespace extends PDOMCPPBinding
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("hiding")
|
||||
public void accept(final IPDOMVisitor visitor) throws CoreException {
|
||||
if (visitor instanceof IBTreeVisitor) {
|
||||
getIndex().accept((IBTreeVisitor) visitor);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
getIndex().accept(new IBTreeVisitor() {
|
||||
public int compare(int record) throws CoreException {
|
||||
return 0;
|
||||
|
@ -112,7 +111,8 @@ class PDOMCPPNamespace extends PDOMCPPBinding
|
|||
|
||||
public IBinding[] find(String name) {
|
||||
try {
|
||||
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(), IndexFilter.ALL_DECLARED_OR_IMPLICIT,false, true);
|
||||
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name.toCharArray(),
|
||||
IndexFilter.ALL_DECLARED_OR_IMPLICIT,false, true);
|
||||
getIndex().accept(visitor);
|
||||
return visitor.getBindings();
|
||||
} catch (CoreException e) {
|
||||
|
@ -136,13 +136,15 @@ class PDOMCPPNamespace extends PDOMCPPBinding
|
|||
}
|
||||
|
||||
@Override
|
||||
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet) throws DOMException {
|
||||
public IBinding[] getBindings(IASTName name, boolean resolve, boolean prefixLookup, IIndexFileSet fileSet)
|
||||
throws DOMException {
|
||||
IBinding[] result = null;
|
||||
try {
|
||||
if (!prefixLookup) {
|
||||
return getBindingsViaCache(name.toCharArray());
|
||||
}
|
||||
BindingCollector visitor= new BindingCollector(getLinkageImpl(), name.toCharArray(), IndexFilter.ALL_DECLARED_OR_IMPLICIT, prefixLookup, !prefixLookup);
|
||||
BindingCollector visitor= new BindingCollector(getLinkageImpl(), name.toCharArray(),
|
||||
IndexFilter.ALL_DECLARED_OR_IMPLICIT, prefixLookup, !prefixLookup);
|
||||
getIndex().accept(visitor);
|
||||
IBinding[] bindings = visitor.getBindings();
|
||||
if (fileSet != null) {
|
||||
|
@ -161,7 +163,8 @@ class PDOMCPPNamespace extends PDOMCPPBinding
|
|||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name, IndexFilter.ALL_DECLARED_OR_IMPLICIT, false, true);
|
||||
BindingCollector visitor = new BindingCollector(getLinkageImpl(), name,
|
||||
IndexFilter.ALL_DECLARED_OR_IMPLICIT, false, true);
|
||||
getIndex().accept(visitor);
|
||||
result = visitor.getBindings();
|
||||
pdom.putCachedResult(key, result);
|
||||
|
@ -177,7 +180,6 @@ class PDOMCPPNamespace extends PDOMCPPBinding
|
|||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("hiding")
|
||||
public IBinding[] getMemberBindings() throws DOMException {
|
||||
IBinding[] result = null;
|
||||
final List<PDOMNode> preresult = new ArrayList<PDOMNode>();
|
||||
|
@ -203,4 +205,13 @@ class PDOMCPPNamespace extends PDOMCPPBinding
|
|||
public IIndexBinding getScopeBinding() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String[] names = getQualifiedName();
|
||||
if (names.length == 0) {
|
||||
return "<unnamed namespace>"; //$NON-NLS-1$
|
||||
}
|
||||
return ASTStringUtil.join(names, String.valueOf(Keywords.cpCOLONCOLON));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue