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 853685f35c6..f3c39447e53 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 @@ -51,7 +51,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalBinding; * @author dsteffle */ public class ASTTypeUtil { - private static final String COMMA_SPACE = ", "; //$NON-NLS-1$ private static final String EMPTY_STRING = ""; //$NON-NLS-1$ private static final String SPACE = " "; //$NON-NLS-1$ @@ -72,10 +71,11 @@ public class ASTTypeUtil { String[] parms = getParameterTypeStringArray(type); result.append(Keywords.cpLPAREN); - for(int i=0; i=0; j--) { - if (types[j] != null && result.length() > 0) result.append(SPACE); // only add a space if this is not the first type being added - + for (int j = types.length - 1; j >= 0; j--) { if (types[j] != null) { - if (j > 0 && types[j-1] instanceof IQualifierType) { - result.append(getTypeString(types[j-1])); - result.append(SPACE); - result.append(getTypeString(types[j])); + if (j > 0 && types[j - 1] instanceof IQualifierType) { + smartAppend(result, getTypeString(types[j - 1])); + smartAppend(result, getTypeString(types[j])); --j; - } - else { - result.append(getTypeString(types[j])); + } else { + smartAppend(result, getTypeString(types[j])); } } } return result.toString(); } - + + private static void smartAppend(StringBuilder buf, String str) { + if (buf.length() > 0 && str.length() > 0 && "&*".indexOf(str.charAt(0)) < 0) { //$NON-NLS-1$ + buf.append(SPACE); + } + buf.append(str); + } + /** * Returns the type representation of the declarator (including parameters) as a String. * @@ -401,15 +506,15 @@ public class ASTTypeUtil { public static String getNodeType(IASTNode node) { try { if (node instanceof IASTDeclarator) - return getType((IASTDeclarator)node); - if (node instanceof IASTName && ((IASTName)node).resolveBinding() instanceof IVariable) - return getType(((IVariable)((IASTName)node).resolveBinding()).getType()); - if (node instanceof IASTName && ((IASTName)node).resolveBinding() instanceof IFunction) - return getType(((IFunction)((IASTName)node).resolveBinding()).getType()); - if (node instanceof IASTName && ((IASTName)node).resolveBinding() instanceof IType) - return getType((IType)((IASTName)node).resolveBinding()); + return getType((IASTDeclarator) node); + if (node instanceof IASTName && ((IASTName) node).resolveBinding() instanceof IVariable) + return getType(((IVariable)((IASTName) node).resolveBinding()).getType()); + if (node instanceof IASTName && ((IASTName) node).resolveBinding() instanceof IFunction) + return getType(((IFunction)((IASTName) node).resolveBinding()).getType()); + if (node instanceof IASTName && ((IASTName) node).resolveBinding() instanceof IType) + return getType((IType)((IASTName) node).resolveBinding()); if (node instanceof IASTTypeId) - return getType((IASTTypeId)node); + return getType((IASTTypeId) node); } catch (DOMException e) { return EMPTY_STRING; } return EMPTY_STRING; @@ -454,43 +559,43 @@ public class ASTTypeUtil { public static boolean isConst(IType type) { if (type instanceof IQualifierType) { try { - return ((IQualifierType)type).isConst(); + return ((IQualifierType) type).isConst(); } catch (DOMException e) { return false; } } else if (type instanceof ITypeContainer) { try { - return isConst(((ITypeContainer)type).getType()); + return isConst(((ITypeContainer) type).getType()); } catch (DOMException e) { return false; } } else if (type instanceof IArrayType) { try { - return isConst(((IArrayType)type).getType()); + return isConst(((IArrayType) type).getType()); } catch (DOMException e) { return false; } } else if (type instanceof ICPPReferenceType) { try { - return isConst(((ICPPReferenceType)type).getType()); + return isConst(((ICPPReferenceType) type).getType()); } catch (DOMException e) { return false; } } else if (type instanceof IFunctionType) { try { - return isConst(((IFunctionType)type).getReturnType()); + return isConst(((IFunctionType) type).getReturnType()); } catch (DOMException e) { return false; } } else if (type instanceof IPointerType) { try { - return isConst(((IPointerType)type).getType()); + return isConst(((IPointerType) type).getType()); } catch (DOMException e) { return false; } } else if (type instanceof ITypedef) { try { - return isConst(((ITypedef)type).getType()); + return isConst(((ITypedef) type).getType()); } catch (DOMException e) { return false; } @@ -504,7 +609,7 @@ public class ASTTypeUtil { LinkedList result= new LinkedList(); result.addFirst(getNameForAnonymous(binding)); ICPPScope scope = (ICPPScope) binding.getScope(); - while( scope != null ){ + while (scope != null) { if (scope instanceof ICPPBlockScope || scope instanceof ICPPFunctionScope) { break; } @@ -514,7 +619,7 @@ public class ASTTypeUtil { break; } char[] name= n.toCharArray(); - if (name.length == 0){ + if (name.length == 0) { if (!(scope instanceof ICPPNamespaceScope)) { name= createNameForAnonymous(scope); if (name == null) { @@ -522,8 +627,7 @@ public class ASTTypeUtil { } result.addFirst(new String(name)); } - } - else { + } else { result.addFirst(new String(name)); } } @@ -583,7 +687,7 @@ public class ASTTypeUtil { private static int findFileNameStart(char[] fname) { - for (int i= fname.length-2; i>=0; i--) { + for (int i= fname.length - 2; i >= 0; i--) { switch (fname[i]) { case '/': case '\\': diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPReferenceType.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPReferenceType.java index 8e595b55dbe..09f059b970f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPReferenceType.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/CPPReferenceType.java @@ -14,6 +14,7 @@ */ package org.eclipse.cdt.internal.core.dom.parser.cpp; +import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; @@ -30,7 +31,7 @@ public class CPPReferenceType implements ICPPReferenceType, ITypeContainer { * @param type * @param operator */ - public CPPReferenceType( IType type ) { + public CPPReferenceType(IType type) { this.type = type; } /* (non-Javadoc) @@ -40,36 +41,41 @@ public class CPPReferenceType implements ICPPReferenceType, ITypeContainer { return type; } - public void setType( IType t ){ + public void setType(IType t) { type = t; } public boolean isSameType(IType obj) { - if( obj == this ) + if (obj == this) return true; - if( obj instanceof ITypedef ) - return ((ITypedef)obj).isSameType( this ); + if (obj instanceof ITypedef) + return ((ITypedef)obj).isSameType(this); - if( type == null ) + if (type == null) return (obj == null); - if( obj instanceof ICPPReferenceType ){ + if (obj instanceof ICPPReferenceType) { try { - return type.isSameType( ((ICPPReferenceType) obj).getType() ); - } catch ( DOMException e ) { + return type.isSameType(((ICPPReferenceType) obj).getType()); + } catch (DOMException e) { return false; } } return false; } - public Object clone(){ + public Object clone() { IType t = null; try { t = (IType) super.clone(); - } catch ( CloneNotSupportedException e ) { - //not going to happen + } catch (CloneNotSupportedException e) { + // not going to happen } return t; } + + @Override + public String toString() { + return ASTTypeUtil.getType(this); + } }