From c95216108ae06009ff12f41caab498cb5a3efaa2 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Tue, 16 Jun 2015 17:06:41 -0700 Subject: [PATCH] More informative toString() method for methods. Change-Id: Ia8c3f8c0d5a65d5465624bc02393600925559573 --- .../eclipse/cdt/core/dom/ast/ASTTypeUtil.java | 39 +++++++++++++------ .../core/dom/parser/cpp/CPPFunction.java | 4 +- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java index d9f3feaa0f4..e886d525fdb 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java @@ -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) { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java index 3319836ad37..415cfbddb18 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java @@ -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(); }