1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-05 16:56:04 +02:00

Tightened up type constraints in ArrayUtil.

This commit is contained in:
Sergey Prigogin 2012-01-08 21:01:52 -08:00
parent a98cf9a89d
commit ea56585a4c
22 changed files with 166 additions and 132 deletions

View file

@ -17,6 +17,8 @@ package org.eclipse.cdt.core.dom.ast;
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface IASTLabelStatement extends IASTStatement, IASTNameOwner {
/** @since 5.4 */
public static final IASTStatement[] EMPTY_LABEL_STATEMENT_ARRAY = {};
public static final ASTNodeProperty NAME = new ASTNodeProperty("IASTLabelStatement.NAME - name for IASTLabelStatement"); //$NON-NLS-1$
public static final ASTNodeProperty NESTED_STATEMENT = new ASTNodeProperty( "IASTLabelStatement.NESTED_STATEMENT - statement for IASTLabelStatement" ); //$NON-NLS-1$

View file

@ -20,7 +20,7 @@ public interface IASTStatement extends IASTNode {
/**
* Constant.
*/
public static final IASTStatement[] EMPTY_STATEMENT_ARRAY = new IASTStatement[0];
public static final IASTStatement[] EMPTY_STATEMENT_ARRAY = {};
/**
* @since 5.1

View file

@ -26,7 +26,8 @@ import org.eclipse.core.runtime.IAdaptable;
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface IBinding extends IAdaptable {
public static final IBinding[] EMPTY_BINDING_ARRAY = new IBinding[0];
public static final IBinding[] EMPTY_BINDING_ARRAY = {};
/**
* Returns the unqualified name of the binding as a string.
*/

View file

@ -16,8 +16,7 @@ package org.eclipse.cdt.core.dom.ast;
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface IField extends IVariable {
public static final IField[] EMPTY_FIELD_ARRAY = new IField[0];
public static final IField[] EMPTY_FIELD_ARRAY = {};
/**
* Returns the composite type that owns the field.

View file

@ -18,7 +18,10 @@ package org.eclipse.cdt.core.dom.ast;
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface ILabel extends IBinding {
/**
/** @since 5.4 */
public static final IBinding[] EMPTY_LABEL_ARRAY = {};
/**
* Returns the label statement for this label.
*/
public IASTLabelStatement getLabelStatement();

View file

@ -15,6 +15,7 @@
package org.eclipse.cdt.core.parser.util;
import java.lang.reflect.Array;
import java.util.Arrays;
import org.eclipse.core.runtime.Assert;
@ -31,7 +32,7 @@ public abstract class ArrayUtil {
* the given class object.
*/
@SuppressWarnings("unchecked")
static public <T> T[] append(Class<? extends T> c, T[] array, T obj) {
static public <T> T[] append(Class<T> c, T[] array, T obj) {
if (obj == null)
return array;
if (array == null || array.length == 0) {
@ -52,26 +53,6 @@ public abstract class ArrayUtil {
return temp;
}
/**
* Assumes that array contains nulls at the end, only.
* @returns index of first null, or -1
*/
private static int findFirstNull(Object[] array) {
boolean haveNull= false;
int left= 0;
int right= array.length - 1;
while (left <= right) {
int mid= (left + right) / 2;
if (array[mid] == null) {
haveNull= true;
right= mid - 1;
} else {
left= mid + 1;
}
}
return haveNull ? right + 1 : -1;
}
/**
* Assumes that array contains nulls at the end, only.
* Appends element after the last non-null element.
@ -103,6 +84,26 @@ public abstract class ArrayUtil {
return temp;
}
/**
* Assumes that array contains nulls at the end, only.
* @returns index of first null, or -1
*/
private static int findFirstNull(Object[] array) {
boolean haveNull= false;
int left= 0;
int right= array.length - 1;
while (left <= right) {
int mid= (left + right) / 2;
if (array[mid] == null) {
haveNull= true;
right= mid - 1;
} else {
left= mid + 1;
}
}
return haveNull ? right + 1 : -1;
}
/**
* @deprecated Use {@link #appendAt(Class, Object[], int, Object)} instead.
* @since 4.0
@ -154,7 +155,7 @@ public abstract class ArrayUtil {
* @param forceNew
*/
@SuppressWarnings("unchecked")
static public <T> T[] trim(Class<? extends T> c, T[] array, boolean forceNew) {
static public <T> T[] trim(Class<T> c, T[] array, boolean forceNew) {
if (array == null)
return (T[]) Array.newInstance(c, 0);
@ -173,7 +174,7 @@ public abstract class ArrayUtil {
return temp;
}
public static <T> T[] trim(Class<? extends T> c, T[] array) {
public static <T> T[] trim(Class<T> c, T[] array) {
return trim(c, array, false);
}
@ -188,7 +189,6 @@ public abstract class ArrayUtil {
* @param forceNew
* @since 5.2
*/
@SuppressWarnings("unchecked")
static public <T> T[] trim(T[] array, boolean forceNew) {
int i = array.length;
if (i == 0 || array[i - 1] != null) {
@ -200,9 +200,7 @@ public abstract class ArrayUtil {
Assert.isTrue(i >= 0);
}
T[] temp = (T[]) Array.newInstance(array.getClass().getComponentType(), i);
System.arraycopy(array, 0, temp, 0, i);
return temp;
return Arrays.copyOf(array, i);
}
/**
@ -227,7 +225,7 @@ public abstract class ArrayUtil {
* @return The concatenated array, which may be the same as the first parameter.
*/
@SuppressWarnings("unchecked")
public static <T> T[] addAll(Class<? extends T> c, T[] dest, T[] source) {
public static <T> T[] addAll(Class<T> c, T[] dest, Object[] source) {
if (source == null || source.length == 0)
return dest;
@ -254,10 +252,9 @@ public abstract class ArrayUtil {
System.arraycopy(source, 0, dest, firstFree, numToAdd);
return dest;
}
T[] temp = (T[]) Array.newInstance(c, firstFree + numToAdd);
System.arraycopy(dest, 0, temp, 0, firstFree);
System.arraycopy(source, 0, temp, firstFree, numToAdd);
return temp;
dest = Arrays.copyOf(dest, firstFree + numToAdd);
System.arraycopy(source, 0, dest, firstFree, numToAdd);
return dest;
}
/**
@ -270,7 +267,7 @@ public abstract class ArrayUtil {
* @since 5.2
*/
@SuppressWarnings("unchecked")
public static <T> T[] addAll(T[] dest, T[] source) {
public static <T> T[] addAll(T[] dest, Object[] source) {
if (source == null || source.length == 0)
return dest;
@ -299,10 +296,9 @@ public abstract class ArrayUtil {
System.arraycopy(source, 0, dest, firstFree, numToAdd);
return dest;
}
T[] temp = (T[]) Array.newInstance(dest.getClass().getComponentType(), firstFree + numToAdd);
System.arraycopy(dest, 0, temp, 0, firstFree);
System.arraycopy(source, 0, temp, firstFree, numToAdd);
return temp;
dest = Arrays.copyOf(dest, firstFree + numToAdd);
System.arraycopy(source, 0, dest, firstFree, numToAdd);
return dest;
}
/**
@ -379,7 +375,7 @@ public abstract class ArrayUtil {
* If there are no nulls in the original array then the original array is returned.
*/
@SuppressWarnings("unchecked")
public static <T> T[] removeNulls(Class<? extends T> c, T[] array) {
public static <T> T[] removeNulls(Class<T> c, T[] array) {
if (array == null)
return (T[]) Array.newInstance(c, 0);
@ -469,7 +465,7 @@ public abstract class ArrayUtil {
* Assumes that array contains nulls at the end, only.
*/
@SuppressWarnings("unchecked")
public static <T> T[] prepend(Class<? extends T> c, T[] array, T obj) {
public static <T> T[] prepend(Class<T> c, T[] array, T obj) {
if (obj == null)
return array;
if (array == null || array.length == 0) {
@ -569,8 +565,8 @@ public abstract class ArrayUtil {
* runtime type.
* @param target the runtime type of the new array
* @param source the source array
* @return the current array stored in a new array with the
* specified runtime type, or null if source is null.
* @return the current array stored in a new array with the specified runtime type,
* or null if source is null.
*/
@SuppressWarnings("unchecked")
public static <S, T> T[] convert(Class<T> target, S[] source) {
@ -584,6 +580,30 @@ public abstract class ArrayUtil {
return result;
}
/**
* Reverses order of elements in an array.
* @param array the array
* @since 5.4
*/
public static void reverse(Object[] array) {
reverse(array, 0, array.length);
}
/**
* Reverses order of elements in a subsection of an array.
* @param array the array
* @param fromIndex the index of the first affected element (inclusive)
* @param toIndex the index of the last affected element (exclusive)
* @since 5.4
*/
public static void reverse(Object[] array, int fromIndex, int toIndex) {
for (int i = fromIndex, j = toIndex; i < --j; i++) {
Object tmp = array[i];
array[i] = array[j];
array[j] = tmp;
}
}
/**
* Returns a new array that contains all of the elements of the
* given array except the first one.

View file

@ -13,7 +13,6 @@
package org.eclipse.cdt.internal.core.dom.parser.c;
import org.eclipse.cdt.core.dom.ILinkage;
import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.ast.EScopeKind;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
@ -80,13 +79,13 @@ public class CASTTranslationUnit extends ASTTranslationUnit implements IASTAmbig
if (binding instanceof IMacroBinding) {
return getMacroDefinitionsInAST((IMacroBinding) binding);
}
IName[] names = CVisitor.getDeclarations(this, binding);
IASTName[] names = CVisitor.getDeclarations(this, binding);
for (int i = 0; i < names.length; i++) {
if (!names[i].isDefinition())
names[i] = null;
}
// nulls can be anywhere, don't use trim()
return (IASTName[])ArrayUtil.removeNulls(IASTName.class, names);
return ArrayUtil.removeNulls(IASTName.class, names);
}
/*

View file

@ -95,10 +95,10 @@ public class CCompositeTypeScope extends CScope implements ICCompositeTypeScope
}
// anonymous structures and unions
if (declarators.length == 0 && ((IASTSimpleDeclaration) node).getDeclSpecifier() instanceof IASTCompositeTypeSpecifier) {
IASTCompositeTypeSpecifier declSpec = (IASTCompositeTypeSpecifier) ((IASTSimpleDeclaration) node).getDeclSpecifier();
ICASTCompositeTypeSpecifier declSpec = (ICASTCompositeTypeSpecifier) ((IASTSimpleDeclaration) node).getDeclSpecifier();
IASTName n = declSpec.getName();
if (n.toCharArray().length == 0) {
specStack = (ICASTCompositeTypeSpecifier[]) ArrayUtil.append(ICASTCompositeTypeSpecifier.class, specStack, declSpec);
specStack = ArrayUtil.append(ICASTCompositeTypeSpecifier.class, specStack, declSpec);
}
}
}

View file

@ -24,57 +24,57 @@ import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
public class CFunctionScope extends CScope implements ICFunctionScope {
public CFunctionScope( IASTFunctionDefinition function ){
super( function, EScopeKind.eLocal);
public CFunctionScope(IASTFunctionDefinition function) {
super(function, EScopeKind.eLocal);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.c.ICFunctionScope#getBinding(char[])
*/
@Override
public IBinding getBinding( char[] name ) {
return super.getBinding( NAMESPACE_TYPE_OTHER, name );
public IBinding getBinding(char[] name) {
return super.getBinding(NAMESPACE_TYPE_OTHER, name);
}
@Override
public IScope getBodyScope(){
public IScope getBodyScope() {
IASTNode node = getPhysicalNode();
IASTStatement statement = ((IASTFunctionDefinition)node).getBody();
if( statement instanceof IASTCompoundStatement ){
return ((IASTCompoundStatement)statement).getScope();
if (statement instanceof IASTCompoundStatement) {
return ((IASTCompoundStatement) statement).getScope();
}
return null;
}
public ILabel[] getLabels(){
public ILabel[] getLabels() {
FindLabelsAction action = new FindLabelsAction();
getPhysicalNode().accept( action );
getPhysicalNode().accept(action);
ILabel [] result = null;
if( action.labels != null ){
for( int i = 0; i < action.labels.length && action.labels[i] != null; i++ ){
ILabel[] result = null;
if (action.labels != null) {
for (int i = 0; i < action.labels.length && action.labels[i] != null; i++) {
IASTLabelStatement labelStatement = action.labels[i];
IBinding binding = labelStatement.getName().resolveBinding();
if( binding != null )
result = (ILabel[]) ArrayUtil.append( ILabel.class, result, binding );
if (binding != null)
result = ArrayUtil.append(ILabel.class, result, (ILabel) binding);
}
}
return ArrayUtil.trim( ILabel.class, result );
return ArrayUtil.trim(ILabel.class, result);
}
static private class FindLabelsAction extends ASTVisitor {
public IASTLabelStatement [] labels = null;
public IASTLabelStatement[] labels = null;
public FindLabelsAction(){
public FindLabelsAction() {
shouldVisitStatements = true;
}
@Override
public int visit( IASTStatement statement ) {
if( statement instanceof IASTLabelStatement ){
labels = (IASTLabelStatement[]) ArrayUtil.append( IASTLabelStatement.class, labels, statement );
public int visit(IASTStatement statement) {
if (statement instanceof IASTLabelStatement) {
labels = ArrayUtil.append(IASTLabelStatement.class, labels, (IASTLabelStatement) statement);
}
return PROCESS_CONTINUE;
}

View file

@ -112,7 +112,7 @@ public class CScope implements ICScope, IASTInternalScope {
private IASTNode physicalNode = null;
private boolean isCached = false;
private CharArrayObjectMap<?> mapsToNameOrBinding[] = { CharArrayObjectMap.EMPTY_MAP, CharArrayObjectMap.EMPTY_MAP };
private final CharArrayObjectMap<?> mapsToNameOrBinding[] = { CharArrayObjectMap.EMPTY_MAP, CharArrayObjectMap.EMPTY_MAP };
private final EScopeKind kind;
public CScope(IASTNode physical, EScopeKind eKind) {
@ -134,7 +134,7 @@ public class CScope implements ICScope, IASTInternalScope {
}
protected static class CollectNamesAction extends ASTVisitor {
private char[] name;
private final char[] name;
private IASTName[] result = null;
CollectNamesAction(char[] n) {
@ -376,7 +376,7 @@ public class CScope implements ICScope, IASTInternalScope {
for (Object element : obj) {
if (element instanceof IBinding) {
result = (IBinding[]) ArrayUtil.append(IBinding.class, result, element);
result = ArrayUtil.append(IBinding.class, result, (IBinding) element);
} else {
IASTName n= null;
if (element instanceof IASTName) {

View file

@ -132,8 +132,8 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte
@Override
public IScope getScope() throws DOMException {
IASTDeclSpecifier declSpec = (IASTDeclSpecifier) ((definition != null) ? (IASTNode) definition
.getParent() : declarations[0].getParent());
IASTDeclSpecifier declSpec = (IASTDeclSpecifier) ((definition != null) ?
(IASTNode) definition.getParent() : declarations[0].getParent());
IScope scope = CVisitor.getContainingScope(declSpec);
while (scope instanceof ICCompositeTypeScope) {
scope = scope.getParent();
@ -149,8 +149,8 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte
IProblemBinding.SEMANTIC_DEFINITION_NOT_FOUND, getNameCharArray()) };
}
ICASTCompositeTypeSpecifier compSpec = (ICASTCompositeTypeSpecifier) definition.getParent();
IField[] fields = collectFields(compSpec, null);
return ArrayUtil.trim(IField.class, fields);
IField[] fields = collectFields(compSpec, IField.EMPTY_FIELD_ARRAY);
return ArrayUtil.trim(fields);
}
private IField[] collectFields(ICASTCompositeTypeSpecifier compSpec, IField[] fields) {
@ -171,7 +171,7 @@ public class CStructure extends PlatformObject implements ICompositeType, ICInte
IASTName name = ASTQueries.findInnermostDeclarator(declarator).getName();
IBinding binding = name.resolveBinding();
if (binding != null)
fields = (IField[]) ArrayUtil.append(IField.class, fields, binding);
fields = ArrayUtil.append(fields, (IField) binding);
}
}
}

View file

@ -91,7 +91,7 @@ public class CPPASTFunctionDeclarator extends CPPASTDeclarator implements ICPPAS
if (parameter != null) {
parameter.setParent(this);
parameter.setPropertyInParent(FUNCTION_PARAMETER);
parameters = (ICPPASTParameterDeclaration[]) ArrayUtil.append(ICPPASTParameterDeclaration.class, parameters, parameter);
parameters = ArrayUtil.append(ICPPASTParameterDeclaration.class, parameters, (ICPPASTParameterDeclaration) parameter);
}
}

View file

@ -288,22 +288,22 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
IBinding binding = null;
if (o instanceof ObjectSet<?>) {
ObjectSet<?> set = (ObjectSet<?>) o;
IBinding[] bs = null;
ICPPConstructor[] bs = ICPPConstructor.EMPTY_CONSTRUCTOR_ARRAY;
for (int i = 0; i < set.size(); i++) {
Object obj = set.keyAt(i);
if (obj instanceof IASTName) {
IASTName n = (IASTName) obj;
binding = shouldResolve(forceResolve, n, forName) ? n.resolveBinding() : n.getBinding();
if (binding instanceof ICPPConstructor) {
bs = ArrayUtil.append(ICPPConstructor.class, bs, binding);
bs = ArrayUtil.append(bs, (ICPPConstructor) binding);
}
} else if (obj instanceof ICPPConstructor) {
bs = (IBinding[]) ArrayUtil.append(ICPPConstructor.class, bs, obj);
bs = ArrayUtil.append(bs, (ICPPConstructor) obj);
}
}
return (ICPPConstructor[]) ArrayUtil.trim(ICPPConstructor.class, bs);
return ArrayUtil.trim(ICPPConstructor.class, bs);
} else if (o instanceof IASTName) {
if (shouldResolve(forceResolve, (IASTName) o, forName) || ((IASTName)o).getBinding() != null) {
if (shouldResolve(forceResolve, (IASTName) o, forName) || ((IASTName) o).getBinding() != null) {
// always store the name, rather than the binding, such that we can properly flush the scope.
nameMap.put(CONSTRUCTOR_KEY, o);
binding = ((IASTName)o).resolveBinding();
@ -409,11 +409,11 @@ public class CPPClassScope extends CPPScope implements ICPPClassScope {
* @see chapter 12 of the ISO specification
*/
class ImplicitsAnalysis {
private boolean hasUserDeclaredConstructor;
private final boolean hasUserDeclaredConstructor;
private boolean hasUserDeclaredCopyConstructor;
private boolean hasUserDeclaredCopyAssignmentOperator;
private boolean hasUserDeclaredDestructor;
private ICPPClassType classType;
private final boolean hasUserDeclaredDestructor;
private final ICPPClassType classType;
ImplicitsAnalysis(ICPPASTCompositeTypeSpecifier compSpec, ICPPClassType clsType) {
classType= clsType;

View file

@ -224,7 +224,7 @@ public abstract class CPPTemplateDefinition extends PlatformObject implements IC
for (ICPPASTTemplateParameter param : params) {
p= CPPTemplates.getTemplateParameterName(param).resolveBinding();
if (p instanceof ICPPTemplateParameter) {
result = (ICPPTemplateParameter[]) ArrayUtil.append(ICPPTemplateParameter.class, result, p);
result = ArrayUtil.append(ICPPTemplateParameter.class, result, (ICPPTemplateParameter) p);
}
}
templateParameters = ArrayUtil.trim(ICPPTemplateParameter.class, result);

View file

@ -79,14 +79,14 @@ public class CPPTemplateTemplateParameter extends CPPTemplateParameter implement
if (templateParameters == null) {
ICPPASTTemplatedTypeTemplateParameter template = (ICPPASTTemplatedTypeTemplateParameter) getPrimaryDeclaration().getParent();
ICPPASTTemplateParameter[] params = template.getTemplateParameters();
ICPPTemplateParameter[] result = null;
ICPPTemplateParameter[] result = ICPPTemplateParameter.EMPTY_TEMPLATE_PARAMETER_ARRAY;
for (ICPPASTTemplateParameter param : params) {
IBinding binding = CPPTemplates.getTemplateParameterName(param).resolvePreBinding();
if (binding instanceof ICPPTemplateParameter) {
result = (ICPPTemplateParameter[]) ArrayUtil.append(ICPPTemplateParameter.class, result, binding);
result = ArrayUtil.append(result, (ICPPTemplateParameter) binding);
}
}
templateParameters = ArrayUtil.trim(ICPPTemplateParameter.class, result);
templateParameters = ArrayUtil.trim(result);
}
return templateParameters;
}

View file

@ -221,7 +221,7 @@ public class ClassTypeHelper {
for (IASTDeclarator dtor : dtors) {
binding = ASTQueries.findInnermostDeclarator(dtor).getName().resolveBinding();
if (binding instanceof ICPPField)
result = (ICPPField[]) ArrayUtil.append(ICPPField.class, result, binding);
result = ArrayUtil.append(ICPPField.class, result, (ICPPField) binding);
}
} else if (decl instanceof ICPPASTUsingDeclaration) {
IASTName n = ((ICPPASTUsingDeclaration)decl).getName();
@ -230,10 +230,10 @@ public class ClassTypeHelper {
IBinding[] bs = ((ICPPUsingDeclaration)binding).getDelegates();
for (IBinding element : bs) {
if (element instanceof ICPPField)
result = (ICPPField[]) ArrayUtil.append(ICPPField.class, result, element);
result = ArrayUtil.append(ICPPField.class, result, (ICPPField) element);
}
} else if (binding instanceof ICPPField) {
result = (ICPPField[]) ArrayUtil.append(ICPPField.class, result, binding);
result = ArrayUtil.append(ICPPField.class, result, (ICPPField) binding);
}
}
}
@ -349,7 +349,7 @@ public class ClassTypeHelper {
for (IASTDeclarator dtor : dtors) {
binding = ASTQueries.findInnermostDeclarator(dtor).getName().resolveBinding();
if (binding instanceof ICPPMethod)
result = (ICPPMethod[]) ArrayUtil.append(ICPPMethod.class, result, binding);
result = ArrayUtil.append(ICPPMethod.class, result, (ICPPMethod) binding);
}
}
} else if (decl instanceof IASTFunctionDefinition) {
@ -359,7 +359,7 @@ public class ClassTypeHelper {
dtor = ASTQueries.findInnermostDeclarator(dtor);
binding = dtor.getName().resolveBinding();
if (binding instanceof ICPPMethod) {
result = (ICPPMethod[]) ArrayUtil.append(ICPPMethod.class, result, binding);
result = ArrayUtil.append(ICPPMethod.class, result, (ICPPMethod) binding);
}
}
} else if (decl instanceof ICPPASTUsingDeclaration) {
@ -369,10 +369,10 @@ public class ClassTypeHelper {
IBinding[] bs = ((ICPPUsingDeclaration)binding).getDelegates();
for (IBinding element : bs) {
if (element instanceof ICPPMethod)
result = (ICPPMethod[]) ArrayUtil.append(ICPPMethod.class, result, element);
result = ArrayUtil.append(ICPPMethod.class, result, (ICPPMethod) element);
}
} else if (binding instanceof ICPPMethod) {
result = (ICPPMethod[]) ArrayUtil.append(ICPPMethod.class, result, binding);
result = ArrayUtil.append(ICPPMethod.class, result, (ICPPMethod) binding);
}
}
}
@ -418,7 +418,7 @@ public class ClassTypeHelper {
binding = ((ICPPASTElaboratedTypeSpecifier)declSpec).getName().resolveBinding();
}
if (binding instanceof ICPPClassType)
result = (ICPPClassType[])ArrayUtil.append(ICPPClassType.class, result, binding);
result = ArrayUtil.append(ICPPClassType.class, result, (ICPPClassType) binding);
}
}
return ArrayUtil.trim(ICPPClassType.class, result);

View file

@ -19,7 +19,17 @@ import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.LVALUE;
import static org.eclipse.cdt.core.dom.ast.IASTExpression.ValueCategory.PRVALUE;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.typeOrFunctionSet;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.ExpressionTypes.valueCat;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.*;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.ALLCVQ;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.ARRAY;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.CVTYPE;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.MPTR;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.PTR;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.REF;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.calculateInheritanceDepth;
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 static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.isConversionOperator;
import java.util.ArrayList;
import java.util.Arrays;
@ -1782,10 +1792,11 @@ public class CPPSemantics {
IBinding[] result = null;
for (Object binding : bindings) {
if (binding instanceof IASTName)
if (binding instanceof IASTName) {
result = ArrayUtil.append(IBinding.class, result, ((IASTName) binding).resolveBinding());
else if (binding instanceof IBinding)
result = (IBinding[]) ArrayUtil.append(IBinding.class, result, binding);
} else if (binding instanceof IBinding) {
result = ArrayUtil.append(IBinding.class, result, (IBinding) binding);
}
}
return new CPPCompositeBinding(result);
}
@ -2019,13 +2030,13 @@ public class CPPSemantics {
}
}
IBinding[] bindings = null;
IBinding[] bindings = IBinding.EMPTY_BINDING_ARRAY;
if (cmp > 0) {
bindings = ArrayUtil.append(IBinding.class, bindings, obj);
bindings = ArrayUtil.append(IBinding.class, bindings, type);
bindings = ArrayUtil.append(bindings, obj);
bindings = ArrayUtil.append(bindings, type);
} else {
bindings = ArrayUtil.append(IBinding.class, bindings, type);
bindings = (IBinding[]) ArrayUtil.addAll(IBinding.class, bindings, fns.keyArray());
bindings = ArrayUtil.append(bindings, type);
bindings = ArrayUtil.addAll(bindings, fns.keyArray());
}
bindings = ArrayUtil.trim(IBinding.class, bindings);
ICPPUsingDeclaration composite = new CPPUsingDeclaration(data.astName, bindings);

View file

@ -531,7 +531,7 @@ public class CPPTemplates {
while (parent.getParent() instanceof ICPPASTTemplateDeclaration) {
parent = parent.getParent();
templates = (ICPPASTTemplateDeclaration[]) ArrayUtil.append(ICPPASTTemplateDeclaration.class, templates, parent);
templates = ArrayUtil.append(ICPPASTTemplateDeclaration.class, templates, (ICPPASTTemplateDeclaration) parent);
}
templates = ArrayUtil.trim(ICPPASTTemplateDeclaration.class, templates);

View file

@ -13,7 +13,11 @@
*******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp.semantics;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.*;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.ALLCVQ;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.CVTYPE;
import static org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil.TDEF;
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.Collections;
@ -209,6 +213,7 @@ public class CPPVisitor extends ASTQueries {
private static final char[] PTRDIFF_T = "ptrdiff_t".toCharArray(); //$NON-NLS-1$
private static final char[] TYPE_INFO= "type_info".toCharArray(); //$NON-NLS-1$
private static final char[] INITIALIZER_LIST = "initializer_list".toCharArray(); //$NON-NLS-1$
private static final char[][] EMPTY_CHAR_ARRAY_ARRAY = {};
public static final IASTInitializerClause[] NO_ARGS = {};
// Thread-local set of DeclSpecifiers for which auto types are being created.
@ -2301,7 +2306,8 @@ public class CPPVisitor extends ASTQueries {
}
public static char[][] getQualifiedNameCharArray(IBinding binding) {
char[][] ns = null;
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)
@ -2311,16 +2317,11 @@ public class CPPVisitor extends ASTQueries {
if (owner instanceof ICPPNamespace && n.length == 0)
continue;
ns = ArrayUtil.append(n.getClass(), ns, n);
ns = ArrayUtil.append(ns, n);
}
final char[] bname = binding.getNameCharArray();
ns = ArrayUtil.trim(bname.getClass(), ns);
char[][] result = new char[ns.length + 1][];
for (int i = ns.length - 1; i >= 0; i--) {
result[ns.length - i - 1] = ns[i];
}
result[ns.length]= bname;
return result;
ns = ArrayUtil.trim(ns);
ArrayUtil.reverse(ns);
return ns;
}
private static IScope getParentScope(IScope scope, IASTTranslationUnit unit) throws DOMException {

View file

@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Ferguson (Symbian) - Initial implementation
* Markus Schorn (Wind River Systems)
* Andrew Ferguson (Symbian) - Initial implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.index.composite.cpp;
@ -50,10 +50,9 @@ public class CompositeCPPClassTemplate extends CompositeCPPClassType
System.arraycopy(ss, 0, preresult[i], 0, ss.length);
}
return (ICPPClassTemplatePartialSpecialization[]) ArrayUtil.addAll(
ICPPClassTemplatePartialSpecialization.class,
ICPPClassTemplatePartialSpecialization.EMPTY_PARTIAL_SPECIALIZATION_ARRAY, cf
.getCompositeBindings(preresult));
return ArrayUtil.addAll(
ICPPClassTemplatePartialSpecialization.EMPTY_PARTIAL_SPECIALIZATION_ARRAY,
cf.getCompositeBindings(preresult));
} catch (CoreException ce) {
CCorePlugin.log(ce);
return ICPPClassTemplatePartialSpecialization.EMPTY_PARTIAL_SPECIALIZATION_ARRAY;
@ -97,5 +96,4 @@ public class CompositeCPPClassTemplate extends CompositeCPPClassType
ICPPTemplateArgument[] args = CPPTemplates.templateParametersAsArguments(getTemplateParameters());
return new CPPDeferredClassInstance(this, args, getCompositeScope());
}
}

View file

@ -93,9 +93,9 @@ public class CPPPopulateASTViewAction extends ASTGenericVisitor implements IPopu
tree.setFiltersFlag(DOMASTNodeLeaf.FLAG_PROBLEM);
if (node instanceof IASTProblemHolder)
astProblems = ArrayUtil.append(IASTProblem.class, astProblems, ((IASTProblemHolder)node).getProblem());
astProblems = ArrayUtil.append(IASTProblem.class, astProblems, ((IASTProblemHolder) node).getProblem());
else
astProblems = (IASTProblem[])ArrayUtil.append(IASTProblem.class, astProblems, node);
astProblems = ArrayUtil.append(IASTProblem.class, astProblems, (IASTProblem) node);
}
if (node instanceof IASTPreprocessorStatement)
tree.setFiltersFlag(DOMASTNodeLeaf.FLAG_PREPROCESSOR);

View file

@ -117,9 +117,9 @@ public class CPopulateASTViewAction extends ASTVisitor implements IPopulateDOMAS
tree.setFiltersFlag(DOMASTNodeLeaf.FLAG_PROBLEM);
if (node instanceof IASTProblemHolder)
astProblems = ArrayUtil.append(IASTProblem.class, astProblems, ((IASTProblemHolder)node).getProblem());
astProblems = ArrayUtil.append(IASTProblem.class, astProblems, ((IASTProblemHolder) node).getProblem());
else
astProblems = (IASTProblem[])ArrayUtil.append(IASTProblem.class, astProblems, node);
astProblems = ArrayUtil.append(IASTProblem.class, astProblems, (IASTProblem) node);
}
if (node instanceof IASTPreprocessorStatement)
tree.setFiltersFlag(DOMASTNodeLeaf.FLAG_PREPROCESSOR);