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
|
@ -149,7 +149,7 @@ public class ASTStringUtil {
|
|||
final boolean takesVarArgs= standardFunctionDecl.takesVarArgs();
|
||||
final String[] parameterStrings= new String[parameters.length + (takesVarArgs ? 1 : 0)];
|
||||
int i;
|
||||
for (i=0; i < parameters.length; ++i) {
|
||||
for (i = 0; i < parameters.length; ++i) {
|
||||
parameterStrings[i]= getParameterSignatureString(parameters[i]);
|
||||
}
|
||||
if (takesVarArgs) {
|
||||
|
@ -160,10 +160,10 @@ public class ASTStringUtil {
|
|||
final ICASTKnRFunctionDeclarator knrDeclarator= (ICASTKnRFunctionDeclarator)functionDeclarator;
|
||||
final IASTName[] names= knrDeclarator.getParameterNames();
|
||||
final String[] result= new String[names.length];
|
||||
for(int i=0; i<names.length; i++) {
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
if (names[i] != null) {
|
||||
final IASTDeclarator declaratorForParameterName= knrDeclarator.getDeclaratorForParameterName(names[i]);
|
||||
if( declaratorForParameterName != null ) {
|
||||
if (declaratorForParameterName != null) {
|
||||
result[i]= getSignatureString(declaratorForParameterName);
|
||||
} else {
|
||||
result[i]= "?"; //$NON-NLS-1$
|
||||
|
@ -181,9 +181,9 @@ public class ASTStringUtil {
|
|||
* @param templateParams
|
||||
* @return a string array of template parameters
|
||||
*/
|
||||
public static String[] getTemplateParameterArray(ICPPASTTemplateParameter[] templateParams){
|
||||
public static String[] getTemplateParameterArray(ICPPASTTemplateParameter[] templateParams) {
|
||||
final String[] parameterTypes= new String[templateParams.length];
|
||||
for (int i= 0; i < templateParams.length; i++) {
|
||||
for (int i = 0; i < templateParams.length; i++) {
|
||||
final StringBuilder paramType= new StringBuilder();
|
||||
final ICPPASTTemplateParameter parameter= templateParams[i];
|
||||
appendTemplateParameterString(paramType, parameter);
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -199,20 +220,20 @@ public class ASTStringUtil {
|
|||
private static StringBuilder appendSignatureString(StringBuilder buffer, IASTDeclarator declarator) {
|
||||
// get the declaration node
|
||||
IASTNode node= declarator.getParent();
|
||||
while(node instanceof IASTDeclarator ){
|
||||
while (node instanceof IASTDeclarator) {
|
||||
declarator= (IASTDeclarator)node;
|
||||
node= node.getParent();
|
||||
}
|
||||
|
||||
// get the declSpec
|
||||
final IASTDeclSpecifier declSpec;
|
||||
if(node instanceof IASTParameterDeclaration)
|
||||
if (node instanceof IASTParameterDeclaration)
|
||||
declSpec= ((IASTParameterDeclaration) node).getDeclSpecifier();
|
||||
else if(node instanceof IASTSimpleDeclaration)
|
||||
else if (node instanceof IASTSimpleDeclaration)
|
||||
declSpec= ((IASTSimpleDeclaration)node).getDeclSpecifier();
|
||||
else if(node instanceof IASTFunctionDefinition)
|
||||
else if (node instanceof IASTFunctionDefinition)
|
||||
declSpec= ((IASTFunctionDefinition)node).getDeclSpecifier();
|
||||
else if(node instanceof IASTTypeId)
|
||||
else if (node instanceof IASTTypeId)
|
||||
declSpec= ((IASTTypeId)node).getDeclSpecifier();
|
||||
else
|
||||
declSpec= null;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -350,7 +371,7 @@ public class ASTStringUtil {
|
|||
|
||||
private static StringBuilder appendArrayQualifiersString(StringBuilder buffer, IASTArrayDeclarator declarator) {
|
||||
final IASTArrayModifier[] modifiers= declarator.getArrayModifiers();
|
||||
for (int i= 0; i < modifiers.length; i++) {
|
||||
for (int i = 0; i < modifiers.length; i++) {
|
||||
buffer.append(Keywords.cpLBRACKET).append(Keywords.cpRBRACKET);
|
||||
}
|
||||
return buffer;
|
||||
|
@ -396,7 +417,7 @@ public class ASTStringUtil {
|
|||
final IASTParameterDeclaration[] parameters= standardFunctionDecl.getParameters();
|
||||
final boolean takesVarArgs= standardFunctionDecl.takesVarArgs();
|
||||
buffer.append(Keywords.cpLPAREN);
|
||||
for (int i= 0; i < parameters.length; i++) {
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
if (i > 0) {
|
||||
buffer.append(COMMA_SPACE);
|
||||
}
|
||||
|
@ -413,13 +434,13 @@ public class ASTStringUtil {
|
|||
} else if (functionDeclarator instanceof ICASTKnRFunctionDeclarator) {
|
||||
final ICASTKnRFunctionDeclarator knrDeclarator= (ICASTKnRFunctionDeclarator)functionDeclarator;
|
||||
final IASTName[] names= knrDeclarator.getParameterNames();
|
||||
for(int i=0; i<names.length; i++) {
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
if (i > 0) {
|
||||
buffer.append(COMMA_SPACE);
|
||||
}
|
||||
if (names[i] != null) {
|
||||
final IASTDeclarator declaratorForParameterName= knrDeclarator.getDeclaratorForParameterName(names[i]);
|
||||
if(declaratorForParameterName != null) {
|
||||
if (declaratorForParameterName != null) {
|
||||
appendSignatureString(buffer, declaratorForParameterName);
|
||||
}
|
||||
}
|
||||
|
@ -611,7 +632,7 @@ public class ASTStringUtil {
|
|||
final ICPPASTQualifiedName qualifiedName= (ICPPASTQualifiedName)name;
|
||||
if (qualified) {
|
||||
final IASTName[] names= qualifiedName.getNames();
|
||||
for (int i= 0; i < names.length; i++) {
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
if (i > 0) {
|
||||
buffer.append(Keywords.cpCOLONCOLON);
|
||||
}
|
||||
|
@ -625,7 +646,7 @@ public class ASTStringUtil {
|
|||
appendQualifiedNameString(buffer, templateId.getTemplateName());
|
||||
final IASTNode[] templateArguments= templateId.getTemplateArguments();
|
||||
buffer.append(Keywords.cpLT);
|
||||
for (int i= 0; i < templateArguments.length; i++) {
|
||||
for (int i = 0; i < templateArguments.length; i++) {
|
||||
if (i > 0) {
|
||||
buffer.append(Keywords.cpCOMMA);
|
||||
}
|
||||
|
@ -652,7 +673,7 @@ public class ASTStringUtil {
|
|||
} else if (expression instanceof IASTExpressionList) {
|
||||
final IASTExpressionList expressionList= (IASTExpressionList)expression;
|
||||
final IASTExpression[] expressions= expressionList.getExpressions();
|
||||
for (int i= 0; i < expressions.length; i++) {
|
||||
for (int i = 0; i < expressions.length; i++) {
|
||||
if (i > 0) {
|
||||
buffer.append(COMMA_SPACE);
|
||||
}
|
||||
|
@ -675,7 +696,7 @@ public class ASTStringUtil {
|
|||
return buffer;
|
||||
}
|
||||
|
||||
private static StringBuilder appendTemplateParameterString(StringBuilder buffer, ICPPASTTemplateParameter parameter){
|
||||
private static StringBuilder appendTemplateParameterString(StringBuilder buffer, ICPPASTTemplateParameter parameter) {
|
||||
if (parameter instanceof ICPPASTParameterDeclaration) {
|
||||
appendParameterDeclarationString(buffer, (ICPPASTParameterDeclaration)parameter);
|
||||
} else if (parameter instanceof ICPPASTSimpleTypeTemplateParameter) {
|
||||
|
@ -698,7 +719,7 @@ public class ASTStringUtil {
|
|||
final ICPPASTTemplatedTypeTemplateParameter templatedTypeParameter= (ICPPASTTemplatedTypeTemplateParameter)parameter;
|
||||
final ICPPASTTemplateParameter[] subParameters= templatedTypeParameter.getTemplateParameters();
|
||||
buffer.append(Keywords.TEMPLATE).append(Keywords.cpLT);
|
||||
for (int i= 0; i < subParameters.length; i++) {
|
||||
for (int i = 0; i < subParameters.length; i++) {
|
||||
final ICPPASTTemplateParameter templateParameter= subParameters[i];
|
||||
if (i > 0) {
|
||||
buffer.append(COMMA_SPACE);
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -346,21 +347,13 @@ public class CPPNamespace extends PlatformObject implements ICPPNamespace, ICPPI
|
|||
public ILinkage getLinkage() {
|
||||
return Linkage.CPP_LINKAGE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
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>();
|
||||
|
@ -192,15 +194,24 @@ class PDOMCPPNamespace extends PDOMCPPBinding
|
|||
}
|
||||
});
|
||||
result = preresult.toArray(new IBinding[preresult.size()]);
|
||||
} catch(CoreException ce) {
|
||||
} catch (CoreException ce) {
|
||||
CCorePlugin.log(ce);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void addUsingDirective(ICPPUsingDirective directive) throws DOMException {fail();}
|
||||
public void addUsingDirective(ICPPUsingDirective directive) throws DOMException { fail(); }
|
||||
|
||||
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