1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2013-09-04 15:17:29 -07:00
parent 364783cb62
commit afecac9ccd
7 changed files with 81 additions and 92 deletions

View file

@ -313,10 +313,10 @@ public class IndexUpdateTests extends IndexTestBase {
throws DOMException {
assertEquals(msg(), types[0], ASTTypeUtil.getType(func.getType().getReturnType()));
IParameter[] params= func.getParameters();
assertEquals(msg(), types.length-1, params.length);
assertEquals(msg(), types.length - 1, params.length);
for (int i = 0; i < params.length; i++) {
IParameter parameter = params[i];
assertEquals(msg(), types[i+1], ASTTypeUtil.getType(parameter.getType()));
assertEquals(msg(), types[i + 1], ASTTypeUtil.getType(parameter.getType()));
}
checkModifier(modifiers, INLINE, func.isInline());
checkModifier(modifiers, STATIC, func.isStatic());

View file

@ -39,8 +39,8 @@ import org.eclipse.cdt.internal.core.dom.parser.ASTProblem;
import org.eclipse.cdt.internal.core.model.ASTStringUtil;
/**
* This is a utility class to help convert AST elements to Strings corresponding to the AST element's
* signature.
* This is a utility class to help convert AST elements to Strings corresponding to the AST
* element's signature.
*
* @noextend This interface is not intended to be extended by clients.
* @noinstantiate This class is not intended to be instantiated by clients.
@ -52,13 +52,11 @@ public class ASTSignatureUtil {
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$
private static final String[] EMPTY_STRING_ARRAY = new String[0];
private static final String[] EMPTY_STRING_ARRAY = {};
/**
* Return's the String representation of a node's type (if available). This is currently only being used
* for testing.
*
* TODO Remove this function when done testing if it is no longer needed
* Return's the String representation of a node's type (if available). This is currently only
* being used for testing.
*
* @param node
*/
@ -71,7 +69,7 @@ public class ASTSignatureUtil {
return getSignature((IASTTypeId) node);
if (node instanceof IASTSimpleDeclaration) {
IASTSimpleDeclaration decl = (IASTSimpleDeclaration) node;
StringBuffer buffer = new StringBuffer(getSignature(decl.getDeclSpecifier()));
StringBuilder buffer = new StringBuilder(getSignature(decl.getDeclSpecifier()));
IASTDeclarator[] declarators = decl.getDeclarators();
for (int i = 0; i < declarators.length; ++i) {
@ -108,7 +106,7 @@ public class ASTSignatureUtil {
if (!(decltor instanceof IASTStandardFunctionDeclarator || decltor instanceof ICASTKnRFunctionDeclarator))
return EMPTY_STRING;
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
String[] parms = getParameterSignatureArray(decltor);
@ -175,7 +173,7 @@ public class ASTSignatureUtil {
}
private static String getDeclaratorSpecificSignature(IASTDeclarator declarator) {
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
IASTPointerOperator[] ops = declarator.getPointerOperators();
boolean needSpace = false;
@ -278,7 +276,7 @@ public class ASTSignatureUtil {
if (declarator == null)
return EMPTY_STRING;
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
result.append(getDeclaratorSpecificSignature(declarator));
@ -298,14 +296,11 @@ public class ASTSignatureUtil {
/**
* This function is used to return the signature of an IASTInitializer.
*
* TODO this function is used for testing and probably should not public once this Utility class has been
* finalized as it will likely never be used publicly except for testing
*
* @param init
* @param init an initializer
* @return the signature of an IASTInitializer
*/
public static String getInitializerString(IASTInitializer init) {
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
if (init instanceof IASTEqualsInitializer) {
result.append(Keywords.cpASSIGN);
@ -332,7 +327,7 @@ public class ASTSignatureUtil {
return result.toString();
}
private static void appendExpressionList(StringBuffer result, IASTInitializerClause[] inits) {
private static void appendExpressionList(StringBuilder result, IASTInitializerClause[] inits) {
for (int i = 0; i < inits.length; i++) {
result.append(getInitializerClauseString(inits[i]));
if (i < inits.length - 1)
@ -351,7 +346,7 @@ public class ASTSignatureUtil {
}
private static String getDesignatorSignature(ICASTDesignator designator) {
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
if (designator instanceof ICASTArrayDesignator) {
result.append(Keywords.cpLBRACKET);
@ -374,15 +369,15 @@ public class ASTSignatureUtil {
}
/**
* Returns the String signature corresponding to an IASTDeclarator. This includes the signature of the
* parameters which is built via ASTSignatureUtil#getParameterSignature(IASTDeclarator) if the declarator
* is for a function.
* Returns the String signature corresponding to an IASTDeclarator. This includes the signature
* of the parameters which is built via ASTSignatureUtil#getParameterSignature(IASTDeclarator)
* if the declarator is for a function.
*
* @param declarator
* @return the String signature corresponding to an IASTDeclarator
*/
public static String getSignature(IASTDeclarator declarator) {
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
// get the declSpec
IASTDeclSpecifier declSpec = null;
@ -429,7 +424,7 @@ public class ASTSignatureUtil {
return EMPTY_STRING;
boolean needSpace = false;
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
if (declSpec.getStorageClass() == IASTDeclSpecifier.sc_mutable) {
result.append(Keywords.MUTABLE);
@ -863,7 +858,7 @@ public class ASTSignatureUtil {
}
private static String getArraySubscriptExpression(IASTArraySubscriptExpression expression) {
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
result.append(getExpressionString(expression.getArrayExpression()));
result.append(Keywords.cpLBRACKET);
result.append(getInitializerClauseString(expression.getArgument()));
@ -872,7 +867,7 @@ public class ASTSignatureUtil {
}
private static String getCastExpression(IASTCastExpression expression) {
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
boolean normalCast = false;
if (expression.getOperator() == IASTCastExpression.op_cast)
@ -897,7 +892,7 @@ public class ASTSignatureUtil {
}
private static String getFieldReference(IASTFieldReference expression) {
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
result.append(getExpressionString(expression.getFieldOwner()));
if (expression.isPointerDereference())
result.append(Keywords.cpARROW);
@ -909,7 +904,7 @@ public class ASTSignatureUtil {
}
private static String getFunctionCallExpression(IASTFunctionCallExpression expression) {
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
result.append(getExpressionString(expression.getFunctionNameExpression()));
result.append(Keywords.cpLPAREN);
IASTInitializerClause[] clauses = expression.getArguments();
@ -924,7 +919,7 @@ public class ASTSignatureUtil {
}
private static String getTypeIdInitializerExpression(ICASTTypeIdInitializerExpression expression) {
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
result.append(Keywords.cpLPAREN);
result.append(getSignature(expression.getTypeId()));
result.append(Keywords.cpRPAREN);
@ -933,7 +928,7 @@ public class ASTSignatureUtil {
}
private static String getDeleteExpression(ICPPASTDeleteExpression expression) {
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
result.append(Keywords.DELETE);
result.append(SPACE);
if (expression.getOperand() != null)
@ -942,7 +937,7 @@ public class ASTSignatureUtil {
}
private static String getSimpleTypeConstructorExpression(ICPPASTSimpleTypeConstructorExpression expression) {
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
result.append(getSignature(expression.getDeclSpecifier()));
result.append(getInitializerString(expression.getInitializer()));
return result.toString();
@ -954,7 +949,7 @@ public class ASTSignatureUtil {
}
private static String getTypeIdExpression(IASTTypeIdExpression expression) {
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
String operator = getTypeIdExpressionOperator(expression);
if (operator != null && !operator.equals(EMPTY_STRING))
result.append(operator);
@ -970,7 +965,7 @@ public class ASTSignatureUtil {
}
private static String getExpressionList(IASTExpressionList expression) {
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
IASTExpression[] exps = expression.getExpressions();
if (exps != null && exps.length > 0) {
for (int i = 0; i < exps.length; i++) {
@ -996,7 +991,7 @@ public class ASTSignatureUtil {
}
private static String getConditionalExpression(IASTConditionalExpression expression) {
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
result.append(getExpressionString(expression.getLogicalConditionExpression()));
result.append(SPACE);
result.append(Keywords.cpQUESTION);
@ -1013,7 +1008,7 @@ public class ASTSignatureUtil {
}
private static String getNewExpression(ICPPASTNewExpression expression) {
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
result.append(Keywords.NEW);
result.append(SPACE);
final IASTInitializerClause[] args = expression.getPlacementArguments();
@ -1030,7 +1025,7 @@ public class ASTSignatureUtil {
}
private static String getBinaryExpression(IASTBinaryExpression expression) {
StringBuffer buffer = new StringBuffer();
StringBuilder buffer = new StringBuilder();
buffer.append(getExpressionString(expression.getOperand1()));
buffer.append(SPACE);
buffer.append(getBinaryOperatorString(expression));
@ -1040,7 +1035,7 @@ public class ASTSignatureUtil {
}
private static String getUnaryExpression(IASTUnaryExpression expression) {
StringBuffer buffer = new StringBuffer();
StringBuilder buffer = new StringBuilder();
boolean postOperator = false;
boolean primaryBracketed = false;

View file

@ -193,8 +193,8 @@ public class ASTTypeUtil {
}
/**
* Returns an array of normalized string representations for the parameter types of the
* given function type.
* Returns an array of normalized string representations for the parameter types of the given
* function type.
* @see #getType(IType, boolean)
*/
public static String[] getParameterTypeStringArray(IFunctionType type) {
@ -367,7 +367,7 @@ public class ASTTypeUtil {
boolean qualify = normalize || (type instanceof ITypedef && type instanceof ICPPSpecialization);
appendCppName((ICPPBinding) type, normalize, qualify, result);
} else if (type instanceof ICompositeType) {
// 101114 fix, do not display class, and for consistency don't display struct/union as well
// Don't display class, and for consistency don't display struct/union as well (bug 101114).
appendNameCheckAnonymous((ICompositeType) type, result);
} else if (type instanceof ITypedef) {
result.append(((ITypedef) type).getNameCharArray());
@ -511,26 +511,26 @@ public class ASTTypeUtil {
}
} else {
if (type instanceof ICPPReferenceType) {
// reference types ignore cv-qualifiers
// Reference types ignore cv-qualifiers
cvq= null;
// lvalue references win over rvalue references
// Lvalue references win over rvalue references
if (ref == null || ref.isRValueReference()) {
// delay reference to see if there are more
// Delay reference to see if there are more
ref= (ICPPReferenceType) type;
}
} else {
if (cvq != null) {
// merge cv qualifiers
// Merge cv qualifiers
if (type instanceof IQualifierType || type instanceof IPointerType) {
type= SemanticUtil.addQualifiers(type, cvq.isConst(), cvq.isVolatile(), false);
cvq= null;
}
}
if (type instanceof IQualifierType) {
// delay cv qualifier to merge it with others
// Delay cv qualifier to merge it with others
cvq= (IQualifierType) type;
} else {
// no reference, no cv qualifier: output reference and cv-qualifier
// No reference, no cv qualifier: output reference and cv-qualifier
if (ref != null) {
types = ArrayUtil.append(IType.class, types, ref);
ref= null;
@ -552,12 +552,12 @@ public class ASTTypeUtil {
}
}
// pop all of the types off of the stack, and build the string representation while doing so
// Pop all of the types off of the stack, and build the string representation while doing so.
List<IType> postfix= null;
BitSet parenthesis= null;
boolean needParenthesis= false;
boolean needSpace= false;
for (int j = types.length - 1; j >= 0; j--) {
for (int j = types.length; --j >= 0;) {
IType tj = types[j];
if (tj != null) {
if (j > 0 && types[j - 1] instanceof IQualifierType) {
@ -569,7 +569,7 @@ public class ASTTypeUtil {
needSpace= true;
--j;
} else {
// handle post-fix
// Handle post-fix
if (tj instanceof IFunctionType || tj instanceof IArrayType) {
if (j == 0) {
if (needSpace)

View file

@ -61,35 +61,32 @@ public interface ICPPClassType extends ICompositeType, ICPPBinding {
public IField findField(String name);
/**
* Returns a list of ICPPField objects representing fields declared in this
* class. It does not include fields inherited from base classes.
* Returns a list of ICPPField objects representing fields declared in this class. It does not
* include fields inherited from base classes.
*
* @return List of ICPPField
*/
public ICPPField[] getDeclaredFields();
/**
* Returns a list of ICPPMethod objects representing all methods defined for
* this class including those declared, inherited, or generated (e.g.
* default constructors and the like).
* Returns a list of ICPPMethod objects representing all methods defined for this class
* including those declared, inherited, or generated (e.g. default constructors and the like).
*
* @return List of ICPPMethod
*/
public ICPPMethod[] getMethods();
/**
* Returns a list of ICPPMethod objects representing all method explicitly
* declared by this class and inherited from base classes. It does not
* include automatically generated methods.
* Returns a list of ICPPMethod objects representing all method explicitly declared by this
* class and inherited from base classes. It does not include automatically generated methods.
*
* @return List of ICPPMethod
*/
public ICPPMethod[] getAllDeclaredMethods();
/**
* Returns a list of ICPPMethod objects representing all methods explicitly
* declared by this class. It does not include inherited methods or
* automatically generated methods.
* Returns a list of ICPPMethod objects representing all methods explicitly declared by this
* class. It does not include inherited methods or automatically generated methods.
*
* @return List of ICPPMethod
*/
@ -97,14 +94,12 @@ public interface ICPPClassType extends ICompositeType, ICPPBinding {
/**
* Returns an array of ICPPConstructor objects representing the constructors
* for this class. This list includes both declared and implicit
* constructors.
* for this class. This list includes both declared and implicit constructors.
*/
public ICPPConstructor[] getConstructors();
/**
* Returns an array of bindings for those classes/functions declared as
* friends of this class.
* Returns an array of bindings for those classes/functions declared as friends of this class.
*/
public IBinding[] getFriends();
@ -121,14 +116,13 @@ public interface ICPPClassType extends ICompositeType, ICPPBinding {
public boolean isFinal();
/**
* Gets the access specifier of the <code>member</code>.
* Gets the access specifier of the {@code member}.
*
* @param member The binding of the member to get the visibility for.
* <code>member</code> must be a member of this type.
* {@code member} must be a member of this class.
*
* @return the visibility of the specified member.
*
* @throws IllegalArgumentException if <code>member</code> is not a member of this type.
* @throws IllegalArgumentException if {@code member} is not a member of this class.
*
* @since 5.5
*/

View file

@ -22,6 +22,13 @@ import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUti
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getNestedType;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.getUltimateTypeUptoPointers;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.cdt.core.dom.ast.ASTGenericVisitor;
import org.eclipse.cdt.core.dom.ast.ASTNodeProperty;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
@ -208,13 +215,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownType;
import org.eclipse.cdt.internal.core.index.IIndexScope;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Collection of methods to extract information from a C++ translation unit.
*/
@ -2381,21 +2381,21 @@ public class CPPVisitor extends ASTQueries {
if (owner instanceof ICPPEnumeration && !((ICPPEnumeration) owner).isScoped()) {
continue;
}
String n= owner.getName();
if (n == null)
String name= owner.getName();
if (name == null)
break;
if (owner instanceof ICPPFunction)
break;
if (owner instanceof ICPPNamespace && n.length() == 0) {
if (owner instanceof ICPPNamespace && name.length() == 0) {
// TODO(sprigogin): Do not ignore anonymous namespaces.
continue;
}
ns = ArrayUtil.append(String.class, ns, n);
ns = ArrayUtil.append(String.class, ns, name);
}
ns = ArrayUtil.trim(String.class, ns);
String[] result = new String[ns.length + 1];
for (int i = ns.length - 1; i >= 0; i--) {
for (int i = ns.length; --i >= 0;) {
result[ns.length - i - 1] = ns[i];
}
result[ns.length]= binding.getName();
@ -2406,15 +2406,15 @@ public class CPPVisitor extends ASTQueries {
char[][] ns = EMPTY_CHAR_ARRAY_ARRAY;
ns = ArrayUtil.append(ns, binding.getNameCharArray());
for (IBinding owner= binding.getOwner(); owner != null; owner= owner.getOwner()) {
char[] n= owner.getNameCharArray();
if (n == null)
char[] name= owner.getNameCharArray();
if (name == null)
break;
if (owner instanceof ICPPFunction)
break;
if (owner instanceof ICPPNamespace && n.length == 0)
if (owner instanceof ICPPNamespace && name.length == 0)
continue;
ns = ArrayUtil.append(ns, n);
ns = ArrayUtil.append(ns, name);
}
ns = ArrayUtil.trim(ns);
ArrayUtil.reverse(ns);

View file

@ -14,6 +14,10 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
@ -130,10 +134,6 @@ import org.eclipse.cdt.internal.core.pdom.dom.PDOMName;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNode;
import org.eclipse.core.runtime.CoreException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
/**
* Container for c++-entities.
*/
@ -341,7 +341,7 @@ class PDOMCPPLinkage extends PDOMLinkage implements IIndexCPPBindingConstants {
PDOMBinding pdomBinding= attemptFastAdaptBinding(inputBinding);
if (pdomBinding == null) {
// assign names to anonymous types.
// Assign names to anonymous types.
IBinding binding= PDOMASTAdapter.getAdapterForAnonymousASTBinding(inputBinding);
if (binding == null)
return null;

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Markus Schorn - initial API and implementation
* Markus Schorn - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.core.pdom.dom.cpp;
@ -30,7 +30,7 @@ public class PDOMInstanceCache {
public static PDOMInstanceCache getCache(PDOMBinding binding) {
final PDOM pdom= binding.getPDOM();
final long record= binding.getRecord();
final Long key = record+PDOMCPPLinkage.CACHE_INSTANCES;
final Long key = record + PDOMCPPLinkage.CACHE_INSTANCES;
Object cache= pdom.getCachedResult(key);
if (cache instanceof PDOMInstanceCache) {
return (PDOMInstanceCache) cache;