1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 01:15:29 +02:00

More informative toString() method for methods.

Change-Id: Ia8c3f8c0d5a65d5465624bc02393600925559573
This commit is contained in:
Sergey Prigogin 2015-06-16 17:06:41 -07:00
parent 6d5abb70ef
commit c95216108a
2 changed files with 30 additions and 13 deletions

View file

@ -83,6 +83,19 @@ public class ASTTypeUtil {
return result.toString();
}
/**
* Returns a string representation for the parameters and the qualifiers of the given function type.
* The representation contains the comma-separated list of the normalized parameter
* type representations wrapped in parentheses followed by the method qualifiers, if any.
*
* @since 5.11
*/
public static String getParameterTypeStringAndQualifiers(IFunctionType type) {
StringBuilder result = new StringBuilder();
appendParameterTypeStringAndQualifiers(type, result);
return result.toString();
}
private static void appendParameterTypeString(IFunctionType ft, StringBuilder result) {
IType[] types = ft.getParameterTypes();
result.append(Keywords.cpLPAREN);
@ -103,6 +116,19 @@ public class ASTTypeUtil {
result.append(Keywords.cpRPAREN);
}
private static boolean appendParameterTypeStringAndQualifiers(IFunctionType ft, StringBuilder result) {
appendParameterTypeString(ft, result);
boolean needSpace = false;
if (ft instanceof ICPPFunctionType) {
ICPPFunctionType cppft= (ICPPFunctionType) ft;
needSpace= appendCVQ(result, needSpace, cppft.isConst(), cppft.isVolatile(), false);
if (cppft.hasRefQualifier()) {
appendRefQualifier(result, needSpace, cppft.isRValueReference()); needSpace = true;
}
}
return needSpace;
}
/**
* Returns whether the function matching the given function binding takes parameters or not.
*
@ -406,15 +432,7 @@ public class ASTTypeUtil {
result.append(SPACE);
appendNameCheckAnonymous((IEnumeration) type, result);
} else if (type instanceof IFunctionType) {
appendParameterTypeString((IFunctionType) type, result);
needSpace = false;
if (type instanceof ICPPFunctionType) {
ICPPFunctionType ft= (ICPPFunctionType) type;
needSpace= appendCVQ(result, needSpace, ft.isConst(), ft.isVolatile(), false);
if (ft.hasRefQualifier()) {
appendRefQualifier(result, needSpace, ft.isRValueReference()); needSpace = true;
}
}
needSpace = appendParameterTypeStringAndQualifiers((IFunctionType) type, result);
} else if (type instanceof IPointerType) {
if (type instanceof ICPPPointerToMemberType) {
appendTypeString(((ICPPPointerToMemberType) type).getMemberOfClass(), normalize, result);
@ -528,8 +546,7 @@ public class ASTTypeUtil {
ICPPReferenceType ref= null;
while (type != null && ++i < 100) {
if (type instanceof ITypedef) {
// If normalization was not requested, skip the typedef and proceed with its target
// type.
// If normalization was not requested, skip the typedef and proceed with its target type.
if (!normalize) {
// Output reference, qualifier and typedef, then stop.
if (ref != null) {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2014 IBM Corporation and others.
* Copyright (c) 2004, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -592,7 +592,7 @@ public class CPPFunction extends PlatformObject implements ICPPFunction, ICPPInt
StringBuilder result = new StringBuilder();
result.append(getName());
IFunctionType t = getType();
result.append(t != null ? ASTTypeUtil.getParameterTypeString(t) : "()"); //$NON-NLS-1$
result.append(t != null ? ASTTypeUtil.getParameterTypeStringAndQualifiers(t) : "()"); //$NON-NLS-1$
return result.toString();
}