More informative toString() method for methods.
authorSergey Prigogin <eclipse.sprigogin@gmail.com>
Wed, 17 Jun 2015 00:06:41 +0000 (17:06 -0700)
committerSergey Prigogin <eclipse.sprigogin@gmail.com>
Wed, 17 Jun 2015 01:15:58 +0000 (21:15 -0400)
Change-Id: Ia8c3f8c0d5a65d5465624bc02393600925559573

core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/ast/ASTTypeUtil.java
core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPFunction.java

index d9f3fea..e886d52 100644 (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) {
index 3319836..415cfbd 100644 (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();
        }