diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java index fdd29789637..d6beee61919 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java @@ -59,6 +59,7 @@ import static org.eclipse.jdt.internal.compiler.ast.ExpressionContext.VANILLA_CONTEXT; import java.util.HashMap; +import java.util.Map; import org.eclipse.jdt.core.compiler.IProblem; import org.eclipse.jdt.internal.compiler.ASTVisitor; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; @@ -71,7 +72,6 @@ import org.eclipse.jdt.internal.compiler.impl.JavaFeature; import org.eclipse.jdt.internal.compiler.lookup.*; import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities; -import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; public class AllocationExpression extends Expression implements IPolyExpression, Invocation { @@ -89,7 +89,7 @@ public class AllocationExpression extends Expression implements IPolyExpression, public ExpressionContext expressionContext = VANILLA_CONTEXT; // hold on to this context from invocation applicability inference until invocation type inference (per method candidate): - private SimpleLookupTable/**/ inferenceContexts; + private Map inferenceContexts; public HashMap solutionsPerTargetType; private InferenceContext18 outerInferenceContext; // resolving within the context of an outer (lambda) inference? public boolean argsContainCast; @@ -826,7 +826,7 @@ public Expression[] arguments() { @Override public void registerInferenceContext(ParameterizedGenericMethodBinding method, InferenceContext18 infCtx18) { if (this.inferenceContexts == null) - this.inferenceContexts = new SimpleLookupTable(); + this.inferenceContexts = new HashMap<>(); this.inferenceContexts.put(method, infCtx18); } @@ -843,16 +843,16 @@ public void registerResult(TypeBinding targetType, MethodBinding method) { public InferenceContext18 getInferenceContext(ParameterizedMethodBinding method) { if (this.inferenceContexts == null) return null; - return (InferenceContext18) this.inferenceContexts.get(method); + return this.inferenceContexts.get(method); } @Override public void cleanUpInferenceContexts() { if (this.inferenceContexts == null) return; - for (Object value : this.inferenceContexts.valueTable) - if (value != null) - ((InferenceContext18) value).cleanUp(); + for (InferenceContext18 value : this.inferenceContexts.values()) { + value.cleanUp(); + } this.inferenceContexts = null; this.outerInferenceContext = null; this.solutionsPerTargetType = null; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/IntersectionCastTypeReference.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/IntersectionCastTypeReference.java index 0c530f8f747..22fe193c947 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/IntersectionCastTypeReference.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/IntersectionCastTypeReference.java @@ -28,7 +28,6 @@ import org.eclipse.jdt.internal.compiler.lookup.TagBits; import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; -@SuppressWarnings({"rawtypes"}) public class IntersectionCastTypeReference extends TypeReference { public TypeReference[] typeReferences; @@ -138,7 +137,7 @@ public TypeBinding resolveType(BlockScope scope, boolean checkBounds, int locati System.arraycopy(intersectingTypes, 1, interfaces = new ReferenceBinding[typeCount - 1], 0, typeCount - 1); } - Map invocations = new HashMap(2); + Map invocations = new HashMap<>(2); nextInterface: for (int i = 0, interfaceCount = interfaces.length; i < interfaceCount; i++) { ReferenceBinding one = interfaces[i]; if (one == null) continue nextInterface; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/MessageSend.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/MessageSend.java index 7932215dd15..61a1eeaeb77 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/MessageSend.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/MessageSend.java @@ -70,6 +70,7 @@ import static org.eclipse.jdt.internal.compiler.ast.ExpressionContext.VANILLA_CONTEXT; import java.util.HashMap; +import java.util.Map; import java.util.function.BiConsumer; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.ASTVisitor; @@ -86,7 +87,6 @@ import org.eclipse.jdt.internal.compiler.impl.ReferenceContext; import org.eclipse.jdt.internal.compiler.lookup.*; import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities; -import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; public class MessageSend extends Expression implements IPolyExpression, Invocation { @@ -106,7 +106,7 @@ public class MessageSend extends Expression implements IPolyExpression, Invocati public ExpressionContext expressionContext = VANILLA_CONTEXT; // hold on to this context from invocation applicability inference until invocation type inference (per method candidate): - private SimpleLookupTable/**/ inferenceContexts; + private Map inferenceContexts; private HashMap solutionsPerTargetType; private InferenceContext18 outerInferenceContext; // resolving within the context of an outer (lambda) inference? @@ -1312,7 +1312,7 @@ public void registerInferenceContext(ParameterizedGenericMethodBinding method, I System.out.println("Register inference context of "+this+" for "+method+":\n"+infCtx18); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } if (this.inferenceContexts == null) - this.inferenceContexts = new SimpleLookupTable(); + this.inferenceContexts = new HashMap<>(); this.inferenceContexts.put(method, infCtx18); } @@ -1331,7 +1331,7 @@ public void registerResult(TypeBinding targetType, MethodBinding method) { public InferenceContext18 getInferenceContext(ParameterizedMethodBinding method) { InferenceContext18 context = null; if (this.inferenceContexts != null) - context = (InferenceContext18) this.inferenceContexts.get(method); + context = this.inferenceContexts.get(method); if (InferenceContext18.DEBUG) { System.out.println("Retrieve inference context of "+this+" for "+method+":\n"+context); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } @@ -1341,9 +1341,9 @@ public InferenceContext18 getInferenceContext(ParameterizedMethodBinding method) public void cleanUpInferenceContexts() { if (this.inferenceContexts == null) return; - for (Object value : this.inferenceContexts.valueTable) - if (value != null) - ((InferenceContext18) value).cleanUp(); + for (InferenceContext18 value : this.inferenceContexts.values()) { + value.cleanUp(); + } this.inferenceContexts = null; this.outerInferenceContext = null; this.solutionsPerTargetType = null; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java index f50c11f9942..1b78c076536 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/BinaryTypeBinding.java @@ -51,6 +51,8 @@ import java.net.URI; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.ast.Annotation; import org.eclipse.jdt.internal.compiler.classfmt.AnnotationInfo; @@ -66,7 +68,6 @@ import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.compiler.impl.Constant; import org.eclipse.jdt.internal.compiler.problem.AbortCompilation; -import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; import org.eclipse.jdt.internal.compiler.util.Util; /* @@ -104,7 +105,7 @@ public class BinaryTypeBinding extends ReferenceBinding { // For the link with the principle structure protected LookupEnvironment environment; - protected SimpleLookupTable storedAnnotations = null; // keys are this ReferenceBinding & its fields and methods, value is an AnnotationHolder + protected Map storedAnnotations = null; // keys are this ReferenceBinding & its fields and methods, value is an AnnotationHolder private ReferenceBinding containerAnnotationType; int defaultNullness = 0; @@ -1991,7 +1992,7 @@ public void tagAsHavingDefectiveContainerType() { } @Override -SimpleLookupTable storedAnnotations(boolean forceInitialize, boolean forceStore) { +Map storedAnnotations(boolean forceInitialize, boolean forceStore) { if (!isPrototype()) return this.prototype.storedAnnotations(forceInitialize, forceStore); @@ -1999,7 +2000,7 @@ SimpleLookupTable storedAnnotations(boolean forceInitialize, boolean forceStore) if (forceInitialize && this.storedAnnotations == null) { if (!this.environment.globalOptions.storeAnnotations && !forceStore) return null; // not supported during this compile - this.storedAnnotations = new SimpleLookupTable(3); + this.storedAnnotations = new HashMap<>(); } return this.storedAnnotations; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java index 5e8ec7c07dd..fb10c20cf44 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java @@ -46,7 +46,6 @@ import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; import org.eclipse.jdt.internal.compiler.util.HashtableOfObject; -@SuppressWarnings({"rawtypes"}) public class ClassScope extends Scope { public TypeDeclaration referenceContext; @@ -1005,7 +1004,7 @@ public void checkParameterizedSuperTypeCollisions() { // check for parameterized interface collisions (when different parameterizations occur) SourceTypeBinding sourceType = this.referenceContext.binding; ReferenceBinding[] interfaces = sourceType.superInterfaces; - Map invocations = new HashMap(2); + Map invocations = new HashMap<>(2); ReferenceBinding itsSuperclass = sourceType.isInterface() ? null : sourceType.superclass; nextInterface: for (int i = 0, length = interfaces.length; i < length; i++) { ReferenceBinding one = interfaces[i]; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java index 303fe765988..0be0993719a 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java @@ -71,15 +71,13 @@ import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; import org.eclipse.jdt.internal.compiler.util.HashtableOfModule; import org.eclipse.jdt.internal.compiler.util.HashtableOfPackage; -import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; -@SuppressWarnings({"rawtypes", "unchecked"}) public class LookupEnvironment implements ProblemReasons, TypeConstants { /** * Map from typeBinding -> accessRestriction rule */ - private Map accessRestrictions; + private Map accessRestrictions; ImportBinding[] defaultImports; // ROOT_ONLY /** * The root environment driving the current compilation. @@ -109,11 +107,10 @@ public class LookupEnvironment implements ProblemReasons, TypeConstants { private CompleteTypeBindingsSteps stepCompleted = CompleteTypeBindingsSteps.NONE; // ROOT_ONLY public ITypeRequestor typeRequestor; // SHARED - private SimpleLookupTable uniqueParameterizedGenericMethodBindings; + private Map uniqueParameterizedGenericMethodBindings; - // key is a string with the method selector value is an array of method bindings - private SimpleLookupTable uniquePolymorphicMethodBindings; - private SimpleLookupTable uniqueGetClassMethodBinding; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=300734 + private Map uniquePolymorphicMethodBindings; + private Map uniqueGetClassMethodBinding; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=300734 boolean useModuleSystem; // true when compliance >= 9 and nameEnvironment is module aware // key is a string with the module name value is a module binding @@ -124,7 +121,7 @@ public class LookupEnvironment implements ProblemReasons, TypeConstants { private CompilationUnitDeclaration[] units = new CompilationUnitDeclaration[4]; // ROOT_ONLY private MethodVerifier verifier; - private ArrayList missingTypes; + private ArrayList missingTypes; Set typesBeingConnected; // SHARED public boolean isProcessingAnnotations = false; // ROOT_ONLY public boolean mayTolerateMissingType = false; @@ -214,11 +211,11 @@ public LookupEnvironment(ITypeRequestor typeRequestor, CompilerOptions globalOpt this.defaultPackage = new PlainPackageBinding(this); // assume the default package always exists this.defaultImports = null; this.nameEnvironment = nameEnvironment; - this.knownPackages = new HashtableOfPackage(); - this.uniqueParameterizedGenericMethodBindings = new SimpleLookupTable(3); - this.uniquePolymorphicMethodBindings = new SimpleLookupTable(3); + this.knownPackages = new HashtableOfPackage<>(); + this.uniqueParameterizedGenericMethodBindings = new HashMap<>(); + this.uniquePolymorphicMethodBindings = new HashMap<>(); this.missingTypes = null; - this.accessRestrictions = new HashMap(3); + this.accessRestrictions = new HashMap<>(); this.classFilePool = ClassFilePool.newInstance(); this.typesBeingConnected = new LinkedHashSet<>(); this.deferredEnumMethods = new ArrayList<>(); @@ -239,11 +236,11 @@ public LookupEnvironment(ITypeRequestor typeRequestor, CompilerOptions globalOpt this.defaultPackage = new PlainPackageBinding(this); // assume the default package always exists this.defaultImports = null; this.nameEnvironment = rootEnv.nameEnvironment; - this.knownPackages = new HashtableOfPackage(); - this.uniqueParameterizedGenericMethodBindings = new SimpleLookupTable(3); - this.uniquePolymorphicMethodBindings = new SimpleLookupTable(3); + this.knownPackages = new HashtableOfPackage<>(); + this.uniqueParameterizedGenericMethodBindings = new HashMap<>(); + this.uniquePolymorphicMethodBindings = new HashMap<>(); this.missingTypes = null; - this.accessRestrictions = new HashMap(3); + this.accessRestrictions = new HashMap<>(); this.classFilePool = rootEnv.classFilePool; this.typesBeingConnected = rootEnv.typesBeingConnected; this.deferredEnumMethods = rootEnv.deferredEnumMethods; @@ -1116,7 +1113,7 @@ public MissingTypeBinding createMissingType(PackageBinding packageBinding, char[ } packageBinding.addType(missingType); if (this.missingTypes == null) - this.missingTypes = new ArrayList(3); + this.missingTypes = new ArrayList<>(); this.missingTypes.add(missingType); return missingType; } @@ -1194,7 +1191,7 @@ public PlainPackageBinding createPlainPackage(char[][] compoundName) { public ParameterizedGenericMethodBinding createParameterizedGenericMethod(MethodBinding genericMethod, RawTypeBinding rawType) { // cached info is array of already created parameterized types for this type - ParameterizedGenericMethodBinding[] cachedInfo = (ParameterizedGenericMethodBinding[])this.uniqueParameterizedGenericMethodBindings.get(genericMethod); + ParameterizedGenericMethodBinding[] cachedInfo = this.uniqueParameterizedGenericMethodBindings.get(genericMethod); boolean needToGrow = false; int index = 0; if (cachedInfo != null){ @@ -1234,7 +1231,7 @@ public ParameterizedGenericMethodBinding createParameterizedGenericMethod(Method boolean inferredWithUncheckedConversion, boolean hasReturnProblem, TypeBinding targetType) { // cached info is array of already created parameterized types for this type - ParameterizedGenericMethodBinding[] cachedInfo = (ParameterizedGenericMethodBinding[])this.uniqueParameterizedGenericMethodBindings.get(genericMethod); + ParameterizedGenericMethodBinding[] cachedInfo = this.uniqueParameterizedGenericMethodBindings.get(genericMethod); int argLength = typeArguments == null ? 0: typeArguments.length; boolean needToGrow = false; int index = 0; @@ -1382,9 +1379,9 @@ public ParameterizedMethodBinding createGetClassMethod(TypeBinding receiverType, // see if we have already cached this method for the given receiver type. ParameterizedMethodBinding retVal = null; if (this.uniqueGetClassMethodBinding == null) { - this.uniqueGetClassMethodBinding = new SimpleLookupTable(3); + this.uniqueGetClassMethodBinding = new HashMap<>(); } else { - retVal = (ParameterizedMethodBinding)this.uniqueGetClassMethodBinding.get(receiverType); + retVal = this.uniqueGetClassMethodBinding.get(receiverType); } if (retVal == null) { retVal = ParameterizedMethodBinding.instantiateGetClass(receiverType, originalMethod, scope); @@ -1496,7 +1493,7 @@ public WildcardBinding createWildcard(ReferenceBinding genericType, int rank, Ty * Returns the access restriction associated to a given type, or null if none */ public AccessRestriction getAccessRestriction(TypeBinding type) { - return (AccessRestriction) this.accessRestrictions.get(type); + return this.accessRestrictions.get(type); } /** @@ -1892,16 +1889,14 @@ else if ((referenceBinding = packageBinding.getType0(compoundName[compoundName.l private TypeBinding[] getTypeArgumentsFromSignature(SignatureWrapper wrapper, TypeVariableBinding[] staticVariables, ReferenceBinding enclosingType, ReferenceBinding genericType, char[][][] missingTypeNames, ITypeAnnotationWalker walker) { - java.util.ArrayList args = new java.util.ArrayList(2); + List args = new ArrayList<>(2); int rank = 0; do { args.add(getTypeFromVariantTypeSignature(wrapper, staticVariables, enclosingType, genericType, rank, missingTypeNames, walker.toTypeArgument(rank++))); } while (wrapper.signature[wrapper.start] != '>'); wrapper.start++; // skip '>' - TypeBinding[] typeArguments = new TypeBinding[args.size()]; - args.toArray(typeArguments); - return typeArguments; + return args.toArray(TypeBinding[]::new); } /* Answer the type corresponding to the compound name. @@ -2274,7 +2269,7 @@ TypeBinding getTypeFromVariantTypeSignature( boolean isMissingType(char[] typeName) { for (int i = this.missingTypes == null ? 0 : this.missingTypes.size(); --i >= 0;) { - MissingTypeBinding missingType = (MissingTypeBinding) this.missingTypes.get(i); + MissingTypeBinding missingType = this.missingTypes.get(i); if (CharOperation.equals(missingType.sourceName, typeName)) return true; } @@ -2316,17 +2311,17 @@ public void reset() { this.defaultPackage = new PlainPackageBinding(this); // assume the default package always exists this.defaultImports = null; - this.knownPackages = new HashtableOfPackage(); - this.accessRestrictions = new HashMap(3); + this.knownPackages = new HashtableOfPackage<>(); + this.accessRestrictions = new HashMap<>(); this.verifier = null; // NOTE: remember to fix #updateCaches(...) when adding unique binding caches - this.uniqueParameterizedGenericMethodBindings = new SimpleLookupTable(3); - this.uniquePolymorphicMethodBindings = new SimpleLookupTable(3); + this.uniqueParameterizedGenericMethodBindings = new HashMap<>(); + this.uniquePolymorphicMethodBindings = new HashMap<>(); this.uniqueGetClassMethodBinding = null; this.missingTypes = null; - this.typesBeingConnected = new LinkedHashSet(); + this.typesBeingConnected = new LinkedHashSet<>(); for (int i = this.units.length; --i >= 0;) this.units[i] = null; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java index f50b8c38589..33ff6992054 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ModuleBinding.java @@ -31,7 +31,6 @@ import org.eclipse.jdt.internal.compiler.env.IModuleAwareNameEnvironment; import org.eclipse.jdt.internal.compiler.env.IUpdatableModule; import org.eclipse.jdt.internal.compiler.util.HashtableOfPackage; -import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; import org.eclipse.jdt.internal.compiler.util.SimpleSetOfCharArray; /** @@ -151,7 +150,7 @@ public String toString() { boolean isAuto = false; private final boolean[] isComplete = new boolean[UpdateKind.values().length]; private Set transitiveRequires; - SimpleLookupTable storedAnnotations = null; + Map storedAnnotations = null; /** * Packages declared in this module (indexed by qualified name). @@ -866,17 +865,17 @@ public int getDefaultNullness() { getAnnotationTagBits(); // ensure annotations are initialized return this.defaultNullness; } - SimpleLookupTable storedAnnotations(boolean forceInitialize, boolean forceStore) { + Map storedAnnotations(boolean forceInitialize, boolean forceStore) { if (forceInitialize && this.storedAnnotations == null) { if (!this.environment.globalOptions.storeAnnotations && !forceStore) return null; // not supported during this compile - this.storedAnnotations = new SimpleLookupTable(3); + this.storedAnnotations = new HashMap<>(); } return this.storedAnnotations; } public AnnotationHolder retrieveAnnotationHolder(Binding binding, boolean forceInitialization) { - SimpleLookupTable store = storedAnnotations(forceInitialization, false); + Map store = storedAnnotations(forceInitialization, false); return store == null ? null : (AnnotationHolder) store.get(binding); } @@ -891,11 +890,11 @@ public void setAnnotations(AnnotationBinding[] annotations, boolean forceStore) } void storeAnnotationHolder(Binding binding, AnnotationHolder holder) { if (holder == null) { - SimpleLookupTable store = storedAnnotations(false, false); + Map store = storedAnnotations(false, false); if (store != null) - store.removeKey(binding); + store.remove(binding); } else { - SimpleLookupTable store = storedAnnotations(true, false); + Map store = storedAnnotations(true, false); if (store != null) store.put(binding, holder); } @@ -904,14 +903,14 @@ void storeAnnotationHolder(Binding binding, AnnotationHolder holder) { void storeAnnotations(Binding binding, AnnotationBinding[] annotations, boolean forceStore) { AnnotationHolder holder = null; if (annotations == null || annotations.length == 0) { - SimpleLookupTable store = storedAnnotations(false, forceStore); + Map store = storedAnnotations(false, forceStore); if (store != null) - holder = (AnnotationHolder) store.get(binding); + holder = store.get(binding); if (holder == null) return; // nothing to delete } else { - SimpleLookupTable store = storedAnnotations(true, forceStore); + Map store = storedAnnotations(true, forceStore); if (store == null) return; // not supported - holder = (AnnotationHolder) store.get(binding); + holder = store.get(binding); if (holder == null) holder = new AnnotationHolder(); } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java index 88ef028cd08..0ae383e631c 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java @@ -55,8 +55,10 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.ast.LambdaExpression; @@ -65,7 +67,6 @@ import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.compiler.impl.ReferenceContext; -import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; /* Not all fields defined by this type (& its subclasses) are initialized when it is created. @@ -88,7 +89,7 @@ abstract public class ReferenceBinding extends TypeBinding { char[] constantPoolName; char[] signature; - private SimpleLookupTable compatibleCache; + private Map compatibleCache; int typeBits; // additional bits characterizing this type protected MethodBinding [] singleAbstractMethod; @@ -1441,9 +1442,9 @@ public boolean isCompatibleWith(TypeBinding otherType, /*@Nullable*/ Scope captu if (otherType.id == TypeIds.T_JavaLangObject) return true; - Object result; + Boolean result; if (this.compatibleCache == null) { - this.compatibleCache = new SimpleLookupTable(3); + this.compatibleCache = new HashMap<>(); result = null; } else { result = this.compatibleCache.get(otherType); // [dbg reset] this.compatibleCache.put(otherType,null) @@ -1894,8 +1895,8 @@ protected void appendNullAnnotation(StringBuilder nameBuffer, CompilerOptions op } public AnnotationHolder retrieveAnnotationHolder(Binding binding, boolean forceInitialization) { - SimpleLookupTable store = storedAnnotations(forceInitialization, false); - return store == null ? null : (AnnotationHolder) store.get(binding); + Map store = storedAnnotations(forceInitialization, false); + return store == null ? null : store.get(binding); } AnnotationBinding[] retrieveAnnotations(Binding binding) { @@ -2060,11 +2061,11 @@ public TypeBinding downwardsProjection(Scope scope, TypeBinding[] mentionedTypeV void storeAnnotationHolder(Binding binding, AnnotationHolder holder) { if (holder == null) { - SimpleLookupTable store = storedAnnotations(false, false); + Map store = storedAnnotations(false, false); if (store != null) - store.removeKey(binding); + store.remove(binding); } else { - SimpleLookupTable store = storedAnnotations(true, false); + Map store = storedAnnotations(true, false); if (store != null) store.put(binding, holder); } @@ -2073,21 +2074,21 @@ void storeAnnotationHolder(Binding binding, AnnotationHolder holder) { void storeAnnotations(Binding binding, AnnotationBinding[] annotations, boolean forceStore) { AnnotationHolder holder = null; if (annotations == null || annotations.length == 0) { - SimpleLookupTable store = storedAnnotations(false, forceStore); + Map store = storedAnnotations(false, forceStore); if (store != null) - holder = (AnnotationHolder) store.get(binding); + holder = store.get(binding); if (holder == null) return; // nothing to delete } else { - SimpleLookupTable store = storedAnnotations(true, forceStore); + Map store = storedAnnotations(true, forceStore); if (store == null) return; // not supported - holder = (AnnotationHolder) store.get(binding); + holder = store.get(binding); if (holder == null) holder = new AnnotationHolder(); } storeAnnotationHolder(binding, holder.setAnnotations(annotations)); } -SimpleLookupTable storedAnnotations(boolean forceInitialize, boolean forceStore) { +Map storedAnnotations(boolean forceInitialize, boolean forceStore) { return null; // overrride if interested in storing annotations for the receiver, its fields and methods } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/Scope.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/Scope.java index fe5bbebe33b..6f4efd59123 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/Scope.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/Scope.java @@ -84,10 +84,8 @@ import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; import org.eclipse.jdt.internal.compiler.util.HashtableOfObject; import org.eclipse.jdt.internal.compiler.util.ObjectVector; -import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; import org.eclipse.jdt.internal.compiler.util.SimpleSet; -@SuppressWarnings({ "rawtypes", "unchecked" }) public abstract class Scope { public static Binding NOT_REDUNDANT = new Binding() { @@ -185,7 +183,7 @@ public static int compareTypes(TypeBinding left, TypeBinding right) { * Returns a type where either all variables or specific ones got discarded. * e.g. {@code List (discarding )} will return: {@code List>} */ - public static TypeBinding convertEliminatingTypeVariables(TypeBinding originalType, ReferenceBinding genericType, int rank, Set eliminatedVariables) { + public static TypeBinding convertEliminatingTypeVariables(TypeBinding originalType, ReferenceBinding genericType, int rank, Set eliminatedVariables) { if ((originalType.tagBits & TagBits.HasTypeVariable) != 0) { switch (originalType.kind()) { case Binding.ARRAY_TYPE : @@ -231,7 +229,7 @@ public static TypeBinding convertEliminatingTypeVariables(TypeBinding originalTy } TypeBinding originalUpperBound = originalVariable.upperBound(); if (eliminatedVariables == null) { - eliminatedVariables = new HashSet(2); + eliminatedVariables = new HashSet<>(2); } eliminatedVariables.add(originalVariable); TypeBinding substitutedUpperBound = convertEliminatingTypeVariables(originalUpperBound, genericType, rank, eliminatedVariables); @@ -911,7 +909,7 @@ protected boolean connectTypeVariables(TypeParameter[] typeParameters, boolean c at all, we assume that the concerned java element has some legitimate business with them. */ if (typeParameters == null || typeParameters.length == 0) return true; - Map invocations = new HashMap(2); + Map invocations = new HashMap<>(2); boolean noProblems = true; // preinitializing each type variable int paramLength = typeParameters.length; @@ -3795,7 +3793,7 @@ public final Binding getTypeOrPackage(char[][] compoundName) { return qualifiedType; } - public boolean hasErasedCandidatesCollisions(TypeBinding one, TypeBinding two, Map invocations, ReferenceBinding type, ASTNode typeRef) { + public boolean hasErasedCandidatesCollisions(TypeBinding one, TypeBinding two, Map invocations, ReferenceBinding type, ASTNode typeRef) { invocations.clear(); TypeBinding[] mecs = minimalErasedCandidates(new TypeBinding[] {one, two}, invocations); if (mecs != null) { @@ -4115,7 +4113,7 @@ public boolean isSubtypeOfRawType(TypeBinding paramType) { return false; } - private TypeBinding leastContainingInvocation(TypeBinding mec, Object invocationData, ArrayList lubStack) { + private TypeBinding leastContainingInvocation(TypeBinding mec, Object invocationData, ArrayList lubStack) { if (invocationData == null) return mec; // no alternate invocation if (invocationData instanceof TypeBinding) { // only one invocation, simply return it (array only allocated if more than one) return (TypeBinding) invocationData; @@ -4137,7 +4135,7 @@ private TypeBinding leastContainingInvocation(TypeBinding mec, Object invocation case Binding.GENERIC_TYPE : TypeVariableBinding[] invocationVariables = invocation.typeVariables(); for (int j = 0; j < argLength; j++) { - TypeBinding bestArgument = leastContainingTypeArgument(bestArguments[j], invocationVariables[j], (ReferenceBinding) mec, j, (ArrayList)lubStack.clone()); + TypeBinding bestArgument = leastContainingTypeArgument(bestArguments[j], invocationVariables[j], (ReferenceBinding) mec, j, new ArrayList<>(lubStack)); if (bestArgument == null) return null; bestArguments[j] = bestArgument; } @@ -4145,7 +4143,7 @@ private TypeBinding leastContainingInvocation(TypeBinding mec, Object invocation case Binding.PARAMETERIZED_TYPE : ParameterizedTypeBinding parameterizedType = (ParameterizedTypeBinding)invocation; for (int j = 0; j < argLength; j++) { - TypeBinding bestArgument = leastContainingTypeArgument(bestArguments[j], parameterizedType.arguments[j], (ReferenceBinding) mec, j, (ArrayList)lubStack.clone()); + TypeBinding bestArgument = leastContainingTypeArgument(bestArguments[j], parameterizedType.arguments[j], (ReferenceBinding) mec, j, new ArrayList<>(lubStack)); if (bestArgument == null) return null; bestArguments[j] = bestArgument; } @@ -4159,7 +4157,7 @@ private TypeBinding leastContainingInvocation(TypeBinding mec, Object invocation } // JLS 15.12.2 - private TypeBinding leastContainingTypeArgument(TypeBinding u, TypeBinding v, ReferenceBinding genericType, int rank, ArrayList lubStack) { + private TypeBinding leastContainingTypeArgument(TypeBinding u, TypeBinding v, ReferenceBinding genericType, int rank, ArrayList lubStack) { if (u == null) return v; if (TypeBinding.equalsEquals(u, v)) return u; if (v.isWildcard()) { @@ -4245,11 +4243,11 @@ public TypeBinding lowerUpperBound(TypeBinding[] types) { TypeBinding type = types[0]; return type == null ? TypeBinding.VOID : type; } - return lowerUpperBound(types, new ArrayList(1)); + return lowerUpperBound(types, new ArrayList<>(1)); } // 15.12.2 - private TypeBinding lowerUpperBound(TypeBinding[] types, ArrayList lubStack) { + private TypeBinding lowerUpperBound(TypeBinding[] types, ArrayList lubStack) { int typeLength = types.length; if (typeLength == 1) { @@ -4259,7 +4257,7 @@ private TypeBinding lowerUpperBound(TypeBinding[] types, ArrayList lubStack) { // cycle detection int stackLength = lubStack.size(); nextLubCheck: for (int i = 0; i < stackLength; i++) { - TypeBinding[] lubTypes = (TypeBinding[])lubStack.get(i); + TypeBinding[] lubTypes = lubStack.get(i); int lubTypeLength = lubTypes.length; if (lubTypeLength < typeLength) continue nextLubCheck; nextTypeCheck: for (int j = 0; j < typeLength; j++) { @@ -4277,7 +4275,7 @@ private TypeBinding lowerUpperBound(TypeBinding[] types, ArrayList lubStack) { } lubStack.add(types); - Map invocations = new HashMap(1); + Map invocations = new HashMap<>(1); TypeBinding[] mecs = minimalErasedCandidates(types, invocations); if (mecs == null) return null; int length = mecs.length; @@ -4358,7 +4356,7 @@ public final MethodScope namedMethodScope() { * of minimal erased types, where some nulls may appear (and must simply be * ignored). */ - protected TypeBinding[] minimalErasedCandidates(TypeBinding[] types, Map allInvocations) { + protected TypeBinding[] minimalErasedCandidates(TypeBinding[] types, Map allInvocations) { int length = types.length; int indexOfFirst = -1, actualLength = 0; for (int i = 0; i < length; i++) { @@ -4379,7 +4377,7 @@ protected TypeBinding[] minimalErasedCandidates(TypeBinding[] types, Map allInvo // record all supertypes of type // intersect with all supertypes of otherType - ArrayList typesToVisit = new ArrayList(5); + List typesToVisit = new ArrayList<>(); int dim = firstType.dimensions(); TypeBinding leafType = firstType.leafComponentType(); @@ -4402,7 +4400,7 @@ protected TypeBinding[] minimalErasedCandidates(TypeBinding[] types, Map allInvo int max = 1; ReferenceBinding currentType; for (int i = 0; i < max; i++) { - TypeBinding typeToVisit = (TypeBinding) typesToVisit.get(i); + TypeBinding typeToVisit = typesToVisit.get(i); dim = typeToVisit.dimensions(); if (dim > 0) { leafType = typeToVisit.leafComponentType(); @@ -5337,7 +5335,7 @@ public void deferBoundCheck(TypeReference typeRef) { if (this.kind == CLASS_SCOPE) { ClassScope classScope = (ClassScope) this; if (classScope.deferredBoundChecks == null) { - classScope.deferredBoundChecks = new ArrayList(3); + classScope.deferredBoundChecks = new ArrayList<>(3); classScope.deferredBoundChecks.add(typeRef); } else if (!classScope.deferredBoundChecks.contains(typeRef)) { classScope.deferredBoundChecks.add(typeRef); @@ -5395,7 +5393,7 @@ public MethodBinding getStaticFactory (ParameterizedTypeBinding allocationType, MethodBinding targetMethod = isInterface ? new MethodBinding(method.original(), genericType) : method.original(); MethodBinding staticFactory = new SyntheticFactoryMethodBinding(targetMethod, environment, originalEnclosingType); staticFactory.typeVariables = new TypeVariableBinding[factoryArity]; - final SimpleLookupTable map = new SimpleLookupTable(factoryArity); + Map map = new HashMap<>(factoryArity); // Rename each type variable T of the type to T' or T'' or T''' based on the enclosing level to avoid a clash. String prime = ""; //$NON-NLS-1$ @@ -5430,7 +5428,7 @@ public boolean isRawSubstitution() { } @Override public TypeBinding substitute(TypeVariableBinding typeVariable) { - TypeBinding retVal = (TypeBinding) map.get(typeVariable.unannotated()); + TypeBinding retVal = map.get(typeVariable.unannotated()); return retVal == null ? typeVariable : typeVariable.hasTypeAnnotations() ? environment().createAnnotatedType(retVal, typeVariable.getTypeAnnotations()) : retVal; } }; @@ -5438,7 +5436,7 @@ public TypeBinding substitute(TypeVariableBinding typeVariable) { // initialize new variable bounds for (int j = 0; j < factoryArity; j++) { TypeVariableBinding originalVariable = j < classTypeVariablesArity ? classTypeVariables[j] : methodTypeVariables[j - classTypeVariablesArity]; - TypeVariableBinding substitutedVariable = (TypeVariableBinding) map.get(originalVariable.unannotated()); + TypeVariableBinding substitutedVariable = map.get(originalVariable.unannotated()); TypeBinding substitutedSuperclass = Scope.substitute(substitution, originalVariable.superclass); ReferenceBinding[] substitutedInterfaces = Scope.substitute(substitution, originalVariable.superInterfaces); @@ -5743,7 +5741,7 @@ public TypeBinding getMatchingUninitializedType(TypeBinding targetClass, boolean } // First iteration ignores superclasses, to prefer finding the target in outers, rather than supers. // Note on performance: while deeply nested loops look painful, poor-man's measurements showed good results. - for (Enum phase : phases) { + for (Enum phase : phases) { // 1. Scope in->out ClassScope currentEnclosing = classScope(); while (currentEnclosing != null) { diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/SourceModuleBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/SourceModuleBinding.java index b6186780d46..dfe32ec4e13 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/SourceModuleBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/SourceModuleBinding.java @@ -15,12 +15,12 @@ import java.util.Collection; import java.util.LinkedHashMap; +import java.util.Map; import java.util.function.IntFunction; import java.util.stream.Stream; import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.ModuleDeclaration; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; -import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; public class SourceModuleBinding extends ModuleBinding { @@ -154,9 +154,9 @@ public AnnotationBinding[] getAnnotations() { } @Override - SimpleLookupTable storedAnnotations(boolean forceInitialize, boolean forceStore) { + Map storedAnnotations(boolean forceInitialize, boolean forceStore) { if (this.scope != null) { // scope null when no annotation cached, and module got processed fully (159631) - SimpleLookupTable annotationTable = super.storedAnnotations(forceInitialize, forceStore); + Map annotationTable = super.storedAnnotations(forceInitialize, forceStore); if (annotationTable != null) this.scope.referenceCompilationUnit().compilationResult.hasAnnotations = true; return annotationTable; diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java index 881161fe30e..dbee8e55626 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java @@ -59,6 +59,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Comparator; +import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; @@ -77,7 +78,6 @@ import org.eclipse.jdt.internal.compiler.impl.Constant; import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities; -import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; import org.eclipse.jdt.internal.compiler.util.Util; @SuppressWarnings({ "rawtypes", "unchecked" }) @@ -106,7 +106,7 @@ public class SourceTypeBinding extends ReferenceBinding { Map[] synthetics; char[] genericReferenceTypeSignature; - private SimpleLookupTable storedAnnotations = null; // keys are this ReferenceBinding & its fields and methods, value is an AnnotationHolder + private Map storedAnnotations = null; // keys are this ReferenceBinding & its fields and methods, value is an AnnotationHolder public int defaultNullness; boolean memberTypesSorted = false; @@ -3150,7 +3150,7 @@ public final int sourceStart() { return this.scope.referenceContext.sourceStart; } @Override -SimpleLookupTable storedAnnotations(boolean forceInitialize, boolean forceStore) { +Map storedAnnotations(boolean forceInitialize, boolean forceStore) { if (!isPrototype()) return this.prototype.storedAnnotations(forceInitialize, forceStore); @@ -3159,7 +3159,7 @@ SimpleLookupTable storedAnnotations(boolean forceInitialize, boolean forceStore) final CompilerOptions globalOptions = this.scope.environment().globalOptions; if (!globalOptions.storeAnnotations && !forceStore) return null; // not supported during this compile - this.storedAnnotations = new SimpleLookupTable(3); + this.storedAnnotations = new HashMap<>(); } return this.storedAnnotations; } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeBindingVisitor.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeBindingVisitor.java index f0ff19ee373..309fbfa5aad 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeBindingVisitor.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeBindingVisitor.java @@ -13,13 +13,14 @@ *******************************************************************************/ package org.eclipse.jdt.internal.compiler.lookup; +import java.util.HashMap; +import java.util.Map; import org.eclipse.jdt.internal.compiler.ast.Wildcard; -import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; public class TypeBindingVisitor { - private SimpleLookupTable visitedCache; + private Map visitedCache; public void reset() { this.visitedCache = null; @@ -72,9 +73,9 @@ public static void visit(TypeBindingVisitor visitor, TypeBinding type) { if (type == null) return; - SimpleLookupTable visitedCache = visitor.visitedCache; + Map visitedCache = visitor.visitedCache; if (visitedCache == null) { - visitor.visitedCache = new SimpleLookupTable(3); + visitor.visitedCache = new HashMap<>(); visitedCache = visitor.visitedCache; } diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java index b788ddd938f..b8a048cf866 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaProject.java @@ -3627,7 +3627,7 @@ public String cycleAsString() { */ public void updateCycleParticipants( List prereqChain, - LinkedHashSet cycleParticipants, + LinkedHashSet cycleParticipants, Map> cyclesPerProject, IWorkspaceRoot workspaceRoot, HashSet traversed, diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathDirectory.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathDirectory.java index 6a9e53a8d45..7deb71ec64b 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathDirectory.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathDirectory.java @@ -16,7 +16,9 @@ import static org.eclipse.jdt.internal.core.JavaModelManager.trace; import java.io.IOException; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; import java.util.function.Predicate; import org.eclipse.core.resources.IContainer; @@ -33,7 +35,6 @@ import org.eclipse.jdt.internal.compiler.env.IBinaryType; import org.eclipse.jdt.internal.compiler.env.IModule; import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; -import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; import org.eclipse.jdt.internal.compiler.util.SuffixConstants; import org.eclipse.jdt.internal.core.JavaModelManager; import org.eclipse.jdt.internal.core.util.Util; @@ -44,7 +45,7 @@ public class ClasspathDirectory extends ClasspathLocation { final boolean isOnModulePath; IContainer binaryFolder; // includes .class files for a single directory boolean isOutputFolder; -SimpleLookupTable directoryCache; +final Map directoryCache = new HashMap<>(); String[] missingPackageHolder = new String[1]; ClasspathDirectory(IContainer binaryFolder, boolean isOutputFolder, AccessRuleSet accessRuleSet, @@ -52,7 +53,6 @@ public class ClasspathDirectory extends ClasspathLocation { { this.binaryFolder = binaryFolder; this.isOutputFolder = isOutputFolder || binaryFolder.getProjectRelativePath().isEmpty(); // if binaryFolder == project, then treat it as an outputFolder - this.directoryCache = new SimpleLookupTable(5); this.accessRuleSet = accessRuleSet; if (externalAnnotationPath != null) this.externalAnnotationPath = externalAnnotationPath.toOSString(); @@ -68,7 +68,7 @@ public void cleanup() { } this.annotationZipFile = null; } - this.directoryCache = null; + this.directoryCache.clear(); } IModule initializeModule() { @@ -102,7 +102,7 @@ IModule initializeModule() { } /** Lists all java-like files and also sub-directories (for recursive tests). */ String[] directoryList(String qualifiedPackageName) { - String[] dirList = (String[]) this.directoryCache.get(qualifiedPackageName); + String[] dirList = this.directoryCache.get(qualifiedPackageName); if (dirList == this.missingPackageHolder) return null; // package exists in another classpath directory or jar if (dirList != null) return dirList; @@ -238,7 +238,7 @@ public boolean hasCompilationUnit(String qualifiedPackageName, String moduleName @Override public void reset() { - this.directoryCache = new SimpleLookupTable(5); + this.directoryCache.clear(); } @Override diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathMultiDirectory.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathMultiDirectory.java index 724597f0315..664f3ab7831 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathMultiDirectory.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ClasspathMultiDirectory.java @@ -76,7 +76,7 @@ protected boolean isExcluded(IResource resource) { } @Override String[] directoryList(String qualifiedPackageName) { - String[] dirList = (String[]) this.directoryCache.get(qualifiedPackageName); + String[] dirList = this.directoryCache.get(qualifiedPackageName); if (dirList != null) return dirList; try { diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/IncrementalImageBuilder.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/IncrementalImageBuilder.java index fa394e7855b..1855f611d9d 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/IncrementalImageBuilder.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/IncrementalImageBuilder.java @@ -17,8 +17,11 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Date; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; import java.util.Set; import org.eclipse.core.resources.IContainer; @@ -45,7 +48,6 @@ import org.eclipse.jdt.internal.compiler.lookup.ModuleBinding; import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; import org.eclipse.jdt.internal.compiler.problem.AbortCompilation; -import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; import org.eclipse.jdt.internal.compiler.util.SuffixConstants; import org.eclipse.jdt.internal.core.CompilationGroup; import org.eclipse.jdt.internal.core.util.Messages; @@ -54,7 +56,6 @@ /** * The incremental image builder */ -@SuppressWarnings({"rawtypes", "unchecked"}) public class IncrementalImageBuilder extends AbstractImageBuilder { protected LinkedHashSet sourceFiles; @@ -62,7 +63,7 @@ public class IncrementalImageBuilder extends AbstractImageBuilder { protected Set qualifiedStrings; protected Set simpleStrings; protected Set rootStrings; -protected SimpleLookupTable secondaryTypesToRemove; +protected Map> secondaryTypesToRemove; protected boolean hasStructuralChanges; protected boolean makeOutputFolderConsistent; @@ -95,7 +96,7 @@ protected IncrementalImageBuilder(BatchImageBuilder batchBuilder, CompilationGro resetCollections(); } -public boolean build(SimpleLookupTable deltas) { +public boolean build(Map deltas) { if(this.sourceLocations.length == 0) { if (this.testImageBuilder != null) { return this.testImageBuilder.build(deltas); @@ -131,7 +132,7 @@ public boolean build(SimpleLookupTable deltas) { addAllSourceFiles(this.sourceFiles); this.notifier.updateProgressDelta(0.25f); } else { - IResourceDelta sourceDelta = (IResourceDelta) deltas.get(this.javaBuilder.currentProject); + IResourceDelta sourceDelta = deltas.get(this.javaBuilder.currentProject); if (sourceDelta != null) { if (!findSourceFiles(sourceDelta)) return this.testImageBuilder != null ? this.testImageBuilder.build(deltas) : false; if(this.testImageBuilder != null) { @@ -140,15 +141,14 @@ public boolean build(SimpleLookupTable deltas) { } this.notifier.updateProgressDelta(0.10f); - Object[] keyTable = deltas.keyTable; - Object[] valueTable = deltas.valueTable; - for (int i = 0, l = valueTable.length; i < l; i++) { - IResourceDelta delta = (IResourceDelta) valueTable[i]; + for (Entry entry : deltas.entrySet()) { + IResourceDelta delta = entry.getValue(); if (delta != null) { - IProject p = (IProject) keyTable[i]; - ClasspathLocation[] classFoldersAndJars = (ClasspathLocation[]) this.javaBuilder.binaryLocationsPerProject.get(p); + IProject p = entry.getKey(); + ClasspathLocation[] classFoldersAndJars = this.javaBuilder.binaryLocationsPerProject.get(p); if (classFoldersAndJars != null) - if (!findAffectedSourceFiles(delta, classFoldersAndJars, p)) return false; + if (!findAffectedSourceFiles(delta, classFoldersAndJars, p)) + return false; } } this.notifier.updateProgressDelta(0.10f); @@ -366,13 +366,13 @@ protected void compile(SourceFile[] units, SourceFile[] additionalUnits, boolean // add any source file from additionalUnits to units if it defines secondary types // otherwise its possible during testing with MAX_AT_ONCE == 1 that a secondary type // can cause an infinite loop as it alternates between not found and defined, see bug 146324 - ArrayList extras = null; + List extras = null; for (SourceFile unit : additionalUnits) { if (unit != null && this.newState.getDefinedTypeNamesFor(unit.typeLocator()) != null) { if (JavaBuilder.DEBUG) System.out.println("About to compile file with secondary types "+ unit.typeLocator()); //$NON-NLS-1$ if (extras == null) - extras = new ArrayList(3); + extras = new ArrayList<>(3); extras.add(unit); } } @@ -381,7 +381,7 @@ protected void compile(SourceFile[] units, SourceFile[] additionalUnits, boolean int toAdd = extras.size(); System.arraycopy(units, 0, units = new SourceFile[oldLength + toAdd], 0, oldLength); for (int i = 0; i < toAdd; i++) - units[oldLength++] = (SourceFile) extras.get(i); + units[oldLength++] = extras.get(i); } } super.compile(units, additionalUnits, compilingFirstGroup); @@ -516,7 +516,7 @@ protected void findAffectedSourceFiles(IResourceDelta binaryDelta, int segmentCo } protected boolean findSourceFiles(IResourceDelta delta) throws CoreException { - ArrayList visited = this.makeOutputFolderConsistent ? new ArrayList(this.sourceLocations.length) : null; + ArrayList visited = this.makeOutputFolderConsistent ? new ArrayList<>(this.sourceLocations.length) : null; for (ClasspathMultiDirectory md : this.sourceLocations) { if (this.makeOutputFolderConsistent && md.hasIndependentOutputFolder && !visited.contains(md.binaryFolder)) { // even a project which acts as its own source folder can have an independent/nested output folder @@ -768,10 +768,10 @@ protected void finishedWith(String sourceLocator, CompilationResult result, char packagePath = sourceFile.resource.getFullPath().removeFirstSegments(count).removeLastSegments(1); } if (this.secondaryTypesToRemove == null) - this.secondaryTypesToRemove = new SimpleLookupTable(); - ArrayList types = (ArrayList) this.secondaryTypesToRemove.get(sourceFile.sourceLocation.binaryFolder); + this.secondaryTypesToRemove = new HashMap<>(); + List types = this.secondaryTypesToRemove.get(sourceFile.sourceLocation.binaryFolder); if (types == null) - types = new ArrayList(definedTypeNames.size()); + types = new ArrayList<>(definedTypeNames.size()); types.add(packagePath.append(new String(previous))); this.secondaryTypesToRemove.put(sourceFile.sourceLocation.binaryFolder, types); } @@ -819,14 +819,12 @@ protected void removeClassFile(IPath typePath, IContainer outputFolder) throws C protected void removeSecondaryTypes() throws CoreException { if (this.secondaryTypesToRemove != null) { // delayed deleting secondary types until the end of the compile loop - Object[] keyTable = this.secondaryTypesToRemove.keyTable; - Object[] valueTable = this.secondaryTypesToRemove.valueTable; - for (int i = 0, l = keyTable.length; i < l; i++) { - IContainer outputFolder = (IContainer) keyTable[i]; + for (Entry> entry: this.secondaryTypesToRemove.entrySet()) { + IContainer outputFolder = entry.getKey(); if (outputFolder != null) { - ArrayList paths = (ArrayList) valueTable[i]; - for (Object path : paths) - removeClassFile((IPath) path, outputFolder); + List paths = entry.getValue(); + for (IPath path : paths) + removeClassFile(path, outputFolder); } } this.secondaryTypesToRemove = null; @@ -844,8 +842,7 @@ protected void resetCollections() { this.rootStrings = new HashSet<>(3); this.hasStructuralChanges = false; } else { - this.previousSourceFiles = this.sourceFiles.isEmpty() ? null : (LinkedHashSet) this.sourceFiles.clone(); - + this.previousSourceFiles = this.sourceFiles.isEmpty() ? null : new LinkedHashSet<>(this.sourceFiles); this.sourceFiles.clear(); this.qualifiedStrings.clear(); this.simpleStrings.clear(); diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/JavaBuilder.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/JavaBuilder.java index 364e3f7a8fa..71bb33a8d5d 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/JavaBuilder.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/JavaBuilder.java @@ -23,9 +23,9 @@ import java.util.Date; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import org.eclipse.core.resources.ICommand; import org.eclipse.core.resources.IMarker; @@ -47,7 +47,6 @@ import org.eclipse.jdt.core.compiler.CategorizedProblem; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.core.compiler.CompilationParticipant; -import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; import org.eclipse.jdt.internal.core.ClasspathEntry; import org.eclipse.jdt.internal.core.ClasspathValidation; import org.eclipse.jdt.internal.core.CompilationGroup; @@ -57,7 +56,6 @@ import org.eclipse.jdt.internal.core.util.Messages; import org.eclipse.jdt.internal.core.util.Util; -@SuppressWarnings({"rawtypes", "unchecked"}) public class JavaBuilder extends IncrementalProjectBuilder { IProject currentProject; @@ -66,7 +64,7 @@ public class JavaBuilder extends IncrementalProjectBuilder { CompilationParticipant[] participants; NameEnvironment nameEnvironment; NameEnvironment testNameEnvironment; -SimpleLookupTable binaryLocationsPerProject; // maps a project to its binary resources (output folders, class folders, zip/jar files) +Map binaryLocationsPerProject; // maps a project to its binary resources (output folders, class folders, zip/jar files) public State lastState; BuildNotifier notifier; char[][] extraResourceFileFilters; @@ -94,15 +92,14 @@ public static IMarker[] getProblemsFor(IResource resource) { try { if (resource != null && resource.exists()) { IMarker[] markers = resource.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE); - Set markerTypes = JavaModelManager.getJavaModelManager().compilationParticipants.managedMarkerTypes(); + Set markerTypes = JavaModelManager.getJavaModelManager().compilationParticipants.managedMarkerTypes(); if (markerTypes.isEmpty()) return markers; - ArrayList markerList = new ArrayList(5); + ArrayList markerList = new ArrayList<>(5); for (IMarker marker : markers) { markerList.add(marker); } - Iterator iterator = markerTypes.iterator(); - while (iterator.hasNext()) { - markers = resource.findMarkers((String) iterator.next(), false, IResource.DEPTH_INFINITE); + for (String markerType: markerTypes) { + markers = resource.findMarkers(markerType, false, IResource.DEPTH_INFINITE); for (IMarker marker : markers) { markerList.add(marker); } @@ -149,11 +146,11 @@ public static void removeProblemsFor(IResource resource) { resource.deleteMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE); // delete managed markers - Set markerTypes = JavaModelManager.getJavaModelManager().compilationParticipants.managedMarkerTypes(); + Set markerTypes = JavaModelManager.getJavaModelManager().compilationParticipants.managedMarkerTypes(); if (markerTypes.size() == 0) return; - Iterator iterator = markerTypes.iterator(); - while (iterator.hasNext()) - resource.deleteMarkers((String) iterator.next(), false, IResource.DEPTH_INFINITE); + for (String markerType: markerTypes) { + resource.deleteMarkers(markerType, false, IResource.DEPTH_INFINITE); + } } } catch (CoreException e) { // assume there were no problems @@ -176,11 +173,11 @@ public static void removeProblemsAndTasksFor(IResource resource) { resource.deleteMarkers(IJavaModelMarker.TASK_MARKER, false, IResource.DEPTH_INFINITE); // delete managed markers - Set markerTypes = JavaModelManager.getJavaModelManager().compilationParticipants.managedMarkerTypes(); + Set markerTypes = JavaModelManager.getJavaModelManager().compilationParticipants.managedMarkerTypes(); if (markerTypes.size() == 0) return; - Iterator iterator = markerTypes.iterator(); - while (iterator.hasNext()) - resource.deleteMarkers((String) iterator.next(), false, IResource.DEPTH_INFINITE); + for (String markerType: markerTypes) { + resource.deleteMarkers(markerType, false, IResource.DEPTH_INFINITE); + } } } catch (CoreException e) { // assume there were no problems @@ -196,7 +193,7 @@ public static void writeState(Object state, DataOutputStream out) throws IOExcep } @Override -protected IProject[] build(int kind, Map ignored, IProgressMonitor monitor) throws CoreException { +protected IProject[] build(int kind, Map ignoredArgs, IProgressMonitor monitor) throws CoreException { this.currentProject = getProject(); if (this.currentProject == null || !this.currentProject.isAccessible()) return new IProject[0]; @@ -233,13 +230,13 @@ protected IProject[] build(int kind, Map ignored, IProgressMonitor monitor) thro buildAll(); } else if (this.nameEnvironment.sourceLocations.length > 0 || this.testNameEnvironment.sourceLocations.length > 0) { // if there is no source to compile & no classpath changes then we are done - SimpleLookupTable deltas = findDeltas(); + Map deltas = findDeltas(); if (deltas == null) { if (DEBUG) { trace("JavaBuilder: Performing full build since deltas are missing after incremental request"); //$NON-NLS-1$ } buildAll(); - } else if (deltas.elementSize > 0) { + } else if (!deltas.isEmpty()) { if (hasJdtCoreSettingsChange(deltas) && !DISABLE_AUTO_BUILDING_ON_SETTINGS_CHANGE) { if (DEBUG) { trace("JavaBuilder: Performing full build since project settings have changed"); //$NON-NLS-1$ @@ -321,7 +318,7 @@ private void buildAll() { recordNewState(imageBuilder.newState); } -private void buildDeltas(SimpleLookupTable deltas) { +private void buildDeltas(Map deltas) { this.notifier.checkCancel(); this.notifier.subTask(Messages.bind(Messages.build_preparingBuild, this.currentProject.getName())); if (DEBUG && this.lastState != null) { @@ -435,10 +432,10 @@ boolean filterExtraResource(IResource resource) { return false; } -private SimpleLookupTable findDeltas() { +private Map findDeltas() { this.notifier.subTask(Messages.bind(Messages.build_readingDelta, this.currentProject.getName())); IResourceDelta delta = getDelta(this.currentProject); - SimpleLookupTable deltas = new SimpleLookupTable(3); + Map deltas = new HashMap<>(); if (delta != null) { if (delta.getKind() != IResourceDelta.NO_CHANGE) { if (DEBUG) { @@ -454,16 +451,14 @@ private SimpleLookupTable findDeltas() { return null; } - Object[] keyTable = this.binaryLocationsPerProject.keyTable; - Object[] valueTable = this.binaryLocationsPerProject.valueTable; - nextProject : for (int i = 0, l = keyTable.length; i < l; i++) { - IProject p = (IProject) keyTable[i]; + nextProject: for (Entry entry : this.binaryLocationsPerProject.entrySet()) { + IProject p = entry.getKey(); if (p != null && p != this.currentProject) { State s = getLastState(p); if (!this.lastState.wasStructurallyChanged(p, s)) { // see if we can skip its delta if (s.wasNoopBuild()) continue nextProject; // project has no source folders and can be skipped - ClasspathLocation[] classFoldersAndJars = (ClasspathLocation[]) valueTable[i]; + ClasspathLocation[] classFoldersAndJars = entry.getValue(); boolean canSkip = true; for (int j = 0, m = classFoldersAndJars.length; j < m; j++) { if (classFoldersAndJars[j].isOutputFolder()) @@ -554,12 +549,12 @@ boolean hasBuildpathErrors() throws CoreException { return false; } -private boolean hasJdtCoreSettingsChange(SimpleLookupTable deltas) { - Object resourceDelta = deltas.get(this.currentProject); - if (resourceDelta instanceof IResourceDelta) { - return ((IResourceDelta) resourceDelta).findMember(JDT_CORE_SETTINGS_PATH) != null; +private boolean hasJdtCoreSettingsChange(Map deltas) { + IResourceDelta resourceDelta = deltas.get(this.currentProject); + if (resourceDelta == null) { + return false; } - return false; + return resourceDelta.findMember(JDT_CORE_SETTINGS_PATH) != null; } private boolean hasClasspathChanged() { @@ -650,7 +645,7 @@ private boolean hasStructuralDelta() { // handle case when currentProject has only .class file folders and/or jar files... no source/output folders IResourceDelta delta = getDelta(this.currentProject); if (delta != null && delta.getKind() != IResourceDelta.NO_CHANGE) { - ClasspathLocation[] classFoldersAndJars = (ClasspathLocation[]) this.binaryLocationsPerProject.get(this.currentProject); + ClasspathLocation[] classFoldersAndJars = this.binaryLocationsPerProject.get(this.currentProject); if (classFoldersAndJars != null) { for (ClasspathLocation classFolderOrJar : classFoldersAndJars) { if (classFolderOrJar != null) { @@ -683,12 +678,12 @@ private int initializeBuilder(int kind, boolean forBuild) throws CoreException { // Flush the existing external files cache if this is the beginning of a build cycle String projectName = this.currentProject.getName(); if (builtProjects == null || builtProjects.contains(projectName)) { - builtProjects = new LinkedHashSet(); + builtProjects = new LinkedHashSet<>(); } builtProjects.add(projectName); } - this.binaryLocationsPerProject = new SimpleLookupTable(3); + this.binaryLocationsPerProject = new HashMap<>(3); this.nameEnvironment = new NameEnvironment(this.workspaceRoot, this.javaProject, this.binaryLocationsPerProject, this.notifier, CompilationGroup.MAIN); this.testNameEnvironment = new NameEnvironment(this.workspaceRoot, this.javaProject, this.binaryLocationsPerProject, this.notifier, CompilationGroup.TEST); @@ -816,13 +811,11 @@ private boolean isWorthBuilding() throws CoreException { * needs to propagate structural changes to the other projects in the cycle. */ void mustPropagateStructuralChanges() { - LinkedHashSet cycleParticipants = new LinkedHashSet(3); - this.javaProject.updateCycleParticipants(new ArrayList(), cycleParticipants, new HashMap<>(), this.workspaceRoot, new HashSet(3), null); + LinkedHashSet cycleParticipants = new LinkedHashSet<>(3); + this.javaProject.updateCycleParticipants(new ArrayList<>(), cycleParticipants, new HashMap<>(), this.workspaceRoot, new HashSet<>(3), null); IPath currentPath = this.javaProject.getPath(); Set toRebuild = new HashSet<>(); - Iterator i= cycleParticipants.iterator(); - while (i.hasNext()) { - IPath participantPath = (IPath) i.next(); + for (IPath participantPath : cycleParticipants) { if (participantPath != currentPath) { IProject project = this.workspaceRoot.getProject(participantPath.segment(0)); if (hasBeenBuilt(project)) { @@ -851,7 +844,7 @@ private void printLocations(ClasspathLocation[] newLocations, ClasspathLocation[ } private void recordNewState(State state) { - Object[] keyTable = this.binaryLocationsPerProject.keyTable; + Set keyTable = this.binaryLocationsPerProject.keySet(); for (Object proj : keyTable) { IProject prereqProject = (IProject) proj; if (prereqProject != null && prereqProject != this.currentProject) diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java index c691dcd784b..be64090613f 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/NameEnvironment.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; @@ -57,7 +58,6 @@ import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.compiler.problem.AbortCompilation; -import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; import org.eclipse.jdt.internal.compiler.util.SimpleSet; import org.eclipse.jdt.internal.compiler.util.SuffixConstants; import org.eclipse.jdt.internal.compiler.util.Util; @@ -68,7 +68,6 @@ import org.eclipse.jdt.internal.core.JavaProject; import org.eclipse.jdt.internal.core.ModuleUpdater; -@SuppressWarnings({"rawtypes", "unchecked"}) public class NameEnvironment implements IModuleAwareNameEnvironment, SuffixConstants { boolean isIncrementalBuild; @@ -78,12 +77,12 @@ public class NameEnvironment implements IModuleAwareNameEnvironment, SuffixConst BuildNotifier notifier; SimpleSet initialTypeNames; // assumed that each name is of the form "a/b/ClassName", or, if a module is given: "my.mod:a/b/ClassName" -SimpleLookupTable additionalUnits; +Map additionalUnits; private final CompilationGroup compilationGroup; /** Tasks resulting from add-reads or add-exports classpath attributes. */ ModuleUpdater moduleUpdater; -NameEnvironment(IWorkspaceRoot root, JavaProject javaProject, SimpleLookupTable binaryLocationsPerProject, BuildNotifier notifier, CompilationGroup compilationGroup) throws CoreException { +NameEnvironment(IWorkspaceRoot root, JavaProject javaProject, Map binaryLocationsPerProject, BuildNotifier notifier, CompilationGroup compilationGroup) throws CoreException { this.compilationGroup = compilationGroup; this.isIncrementalBuild = false; this.notifier = notifier; @@ -128,7 +127,7 @@ public NameEnvironment(IJavaProject javaProject, CompilationGroup compilationGro private void computeClasspathLocations( IWorkspaceRoot root, JavaProject javaProject, - SimpleLookupTable binaryLocationsPerProject) throws CoreException { + Map binaryLocationsPerProject) throws CoreException { /* Update cycle marker */ IMarker cycleMarker = javaProject.getCycleMarker(); @@ -143,7 +142,7 @@ private void computeClasspathLocations( IClasspathEntry[] classpathEntries = javaProject.getExpandedClasspath(this.compilationGroup == CompilationGroup.MAIN); ArrayList sLocations = new ArrayList<>(classpathEntries.length); ArrayList bLocations = new ArrayList<>(classpathEntries.length); - ArrayList sLocationsForTest = new ArrayList(classpathEntries.length); + ArrayList sLocationsForTest = new ArrayList<>(classpathEntries.length); Map moduleEntries = null; String compliance = javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true); if (CompilerOptions.versionToJdkLevel(compliance) >= ClassFileConstants.JDK9) { @@ -226,7 +225,7 @@ private void computeClasspathLocations( JavaProject prereqJavaProject = (JavaProject) JavaCore.create(prereqProject); IClasspathEntry[] prereqClasspathEntries = prereqJavaProject.getRawClasspath(); - ArrayList seen = new ArrayList(); + ArrayList seen = new ArrayList<>(); List projectLocations = new ArrayList<>(); nextPrereqEntry: for (int j = 0, m = prereqClasspathEntries.length; j < m; j++) { IClasspathEntry prereqEntry = prereqClasspathEntries[j]; @@ -266,7 +265,7 @@ private void computeClasspathLocations( bLocations.add(bLocation); projectLocations.add(bLocation); if (binaryLocationsPerProject != null) { // normal builder mode - ClasspathLocation[] existingLocations = (ClasspathLocation[]) binaryLocationsPerProject.get(prereqProject); + ClasspathLocation[] existingLocations = binaryLocationsPerProject.get(prereqProject); if (existingLocations == null) { existingLocations = new ClasspathLocation[] {bLocation}; } else { @@ -337,7 +336,7 @@ private void computeClasspathLocations( } if (binaryLocationsPerProject != null) { // normal builder mode IProject p = resource.getProject(); // can be the project being built - ClasspathLocation[] existingLocations = (ClasspathLocation[]) binaryLocationsPerProject.get(p); + ClasspathLocation[] existingLocations = binaryLocationsPerProject.get(p); if (existingLocations == null) { existingLocations = new ClasspathLocation[] {bLocation}; } else { @@ -382,7 +381,7 @@ private void computeClasspathLocations( } // now split the classpath locations... place the output folders ahead of the other .class file folders & jars - ArrayList outputFolders = new ArrayList(1); + ArrayList outputFolders = new ArrayList<>(1); this.sourceLocations = new ClasspathMultiDirectory[sLocations.size()]; if (!sLocations.isEmpty()) { sLocations.toArray(this.sourceLocations); @@ -557,13 +556,13 @@ private NameEnvironmentAnswer findClass(String qualifiedTypeName, char[] typeNam // when doing the lookup (https://bugs.eclipse.org/372418). // Also take care of $ in the name of the class (https://bugs.eclipse.org/377401) // and prefer name with '$' if unit exists rather than failing to search for nested class (https://bugs.eclipse.org/392727) - SourceFile unit = (SourceFile) this.additionalUnits.get(qualifiedTypeName); // doesn't have file extension + SourceFile unit = this.additionalUnits.get(qualifiedTypeName); // doesn't have file extension if (unit != null) return new NameEnvironmentAnswer(unit, null /*no access restriction*/); int index = qualifiedTypeName.indexOf('$'); if (index > 0) { String enclosingTypeName = qualifiedTypeName.substring(0, index); - unit = (SourceFile) this.additionalUnits.get(enclosingTypeName); // doesn't have file extension + unit = this.additionalUnits.get(enclosingTypeName); // doesn't have file extension if (unit != null) return new NameEnvironmentAnswer(unit, null /*no access restriction*/); } @@ -783,7 +782,7 @@ void setNames(String[] typeNames, SourceFile[] additionalFiles) { if (additionalFiles == null) { this.additionalUnits = null; } else { - this.additionalUnits = new SimpleLookupTable(additionalFiles.length); + this.additionalUnits = new HashMap<>(additionalFiles.length); for (SourceFile additionalUnit : additionalFiles) { if (additionalUnit != null) this.additionalUnits.put(additionalUnit.initialTypeName, additionalUnit); diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ProblemFactory.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ProblemFactory.java index cbd3cd6833a..a1c3ce2f3dc 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ProblemFactory.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/builder/ProblemFactory.java @@ -13,20 +13,21 @@ *******************************************************************************/ package org.eclipse.jdt.internal.core.builder; +import java.util.HashMap; import java.util.Locale; +import java.util.Map; import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; -import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; public class ProblemFactory extends DefaultProblemFactory { -static SimpleLookupTable factories = new SimpleLookupTable(5); +static Map factories = new HashMap<>(); private ProblemFactory(Locale locale) { super(locale); } public static ProblemFactory getProblemFactory(Locale locale) { - ProblemFactory factory = (ProblemFactory) factories.get(locale); + ProblemFactory factory = factories.get(locale); if (factory == null) factories.put(locale, factory = new ProblemFactory(locale)); return factory; diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ClasspathSourceDirectory.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ClasspathSourceDirectory.java index 4f678eb336a..cc22b0eda86 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ClasspathSourceDirectory.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/ClasspathSourceDirectory.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.jdt.internal.core.search.matching; +import java.util.HashMap; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Predicate; @@ -27,7 +28,6 @@ import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.internal.compiler.env.IModulePathEntry; import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; -import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; import org.eclipse.jdt.internal.core.JavaModelManager; import org.eclipse.jdt.internal.core.builder.ClasspathLocation; import org.eclipse.jdt.internal.core.util.ResourceCompilationUnit; @@ -36,8 +36,8 @@ public class ClasspathSourceDirectory extends ClasspathLocation implements IModulePathEntry { final IContainer sourceFolder; - final Map directoryCache = new ConcurrentHashMap<>(); - final SimpleLookupTable missingPackageHolder = new SimpleLookupTable(); + final Map> directoryCache = new ConcurrentHashMap<>(); + private static final Map missingPackageHolder = new HashMap<>(); final char[][] fullExclusionPatternChars; final char[][] fulInclusionPatternChars; @@ -52,16 +52,16 @@ public void cleanup() { this.directoryCache.clear(); } -SimpleLookupTable directoryTable(String qualifiedPackageName) { - SimpleLookupTable dirTable = this.directoryCache.get(qualifiedPackageName); - if (dirTable == this.missingPackageHolder) return null; // package exists in another classpath directory or jar +Map directoryTable(String qualifiedPackageName) { + Map dirTable = this.directoryCache.get(qualifiedPackageName); + if (dirTable == missingPackageHolder) return null; // package exists in another classpath directory or jar if (dirTable != null) return dirTable; try { IResource container = this.sourceFolder.findMember(qualifiedPackageName); // this is a case-sensitive check if (container instanceof IContainer) { IResource[] members = ((IContainer) container).members(); - dirTable = new SimpleLookupTable(); + dirTable = new HashMap<>(); for (IResource m : members) { String name; if (m.getType() == IResource.FILE) { @@ -96,7 +96,7 @@ SimpleLookupTable directoryTable(String qualifiedPackageName) { } catch(CoreException ignored) { // treat as if missing } - this.directoryCache.put(qualifiedPackageName, this.missingPackageHolder); + this.directoryCache.put(qualifiedPackageName, missingPackageHolder); return null; } @@ -114,8 +114,8 @@ public NameEnvironmentAnswer findClass(String typeName, String qualifiedPackageN } @Override public NameEnvironmentAnswer findClass(String sourceFileWithoutExtension, String qualifiedPackageName, String moduleName, String qualifiedSourceFileWithoutExtension) { - SimpleLookupTable dirTable = directoryTable(qualifiedPackageName); - if (dirTable != null && dirTable.elementSize > 0) { + Map dirTable = directoryTable(qualifiedPackageName); + if (dirTable != null && !dirTable.isEmpty()) { IFile file = (IFile) dirTable.get(sourceFileWithoutExtension); if (file != null) { return new NameEnvironmentAnswer(new ResourceCompilationUnit(file, @@ -145,8 +145,8 @@ public boolean isPackage(String qualifiedPackageName, String moduleName) { } @Override public boolean hasCompilationUnit(String qualifiedPackageName, String moduleName) { - SimpleLookupTable dirTable = directoryTable(qualifiedPackageName); - if (dirTable != null && dirTable.elementSize > 0) + Map dirTable = directoryTable(qualifiedPackageName); + if (dirTable != null && !dirTable.isEmpty()) return true; return false; } diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java index b9786d14471..06f5ed8d79e 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java @@ -2526,7 +2526,7 @@ protected void reportMatching(LambdaExpression lambdaExpression, IJavaElement p if (nodes != null) { int length = nodes.length; for (int i = 0; i < length; i++) { - Integer level = (Integer) nodeSet.matchingNodes.removeKey(nodes[i]); + Integer level = nodeSet.matchingNodes.remove(nodes[i]); if (report && level != null) { this.patternLocator.matchReportReference(nodes[i], enclosingElement, declarationVisitor.getLocalElement(i), declarationVisitor.getOtherElements(i), lambdaExpression.binding, level.intValue(), this); } @@ -2592,7 +2592,7 @@ protected void reportMatching(AbstractMethodDeclaration method, TypeDeclaration if (nodes != null) { int length = nodes.length; for (int i = 0; i < length; i++) { - Integer level = (Integer) nodeSet.matchingNodes.removeKey(nodes[i]); + Integer level = nodeSet.matchingNodes.remove(nodes[i]); if (report && level != null) { this.patternLocator.matchReportReference(nodes[i], enclosingElement, declarationVisitor.getLocalElement(i), declarationVisitor.getOtherElements(i), method.binding, level.intValue(), this); } @@ -2640,14 +2640,14 @@ protected void reportMatching(AbstractMethodDeclaration method, TypeDeclaration method.traverse(declarationVisitor, (ClassScope) null); int length = nodes.length; for (int i = 0; i < length; i++) { - Integer level = (Integer) nodeSet.matchingNodes.removeKey(nodes[i]); + Integer level = nodeSet.matchingNodes.remove(nodes[i]); if (level != null) { // ensure that the reference has not been already reported while visiting this.patternLocator.matchReportReference(nodes[i], enclosingElement, declarationVisitor.getLocalElement(i), declarationVisitor.getOtherElements(i), method.binding, level.intValue(), this); } } } else { for (ASTNode node : nodes) { - Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); + Integer level = nodeSet.matchingNodes.remove(node); if (level != null) { // ensure that the reference has not been already reported while visiting this.patternLocator.matchReportReference(node, enclosingElement, null, null, method.binding, level.intValue(), this); } @@ -2658,7 +2658,7 @@ protected void reportMatching(AbstractMethodDeclaration method, TypeDeclaration } // Remove all remaining nodes for (ASTNode node : nodes) { - nodeSet.matchingNodes.removeKey(node); + nodeSet.matchingNodes.remove(node); } } } @@ -2679,7 +2679,7 @@ protected void reportMatching(Annotation[] annotations, IJavaElement enclosingEl // Look for annotation type ref TypeReference typeRef = annotationType.type; - Integer level = (Integer) nodeSet.matchingNodes.removeKey(typeRef); + Integer level = nodeSet.matchingNodes.remove(typeRef); if (level != null && enclosesElement && matchedContainer) { localAnnotation = createHandle(annotationType, (IAnnotatable) enclosingElement); if (length > 0) { @@ -2695,7 +2695,7 @@ protected void reportMatching(Annotation[] annotations, IJavaElement enclosingEl // Look for attribute ref MemberValuePair[] pairs = annotationType.memberValuePairs(); for (MemberValuePair pair : pairs) { - level = (Integer) nodeSet.matchingNodes.removeKey(pair); + level = nodeSet.matchingNodes.remove(pair); if (level != null && enclosesElement) { ASTNode reference = (annotationType instanceof SingleMemberAnnotation) ? (ASTNode) annotationType: pair; if (!handlesCreated) { @@ -2717,11 +2717,11 @@ protected void reportMatching(Annotation[] annotations, IJavaElement enclosingEl if (nodes != null) { if (!matchedContainer) { for (ASTNode node : nodes) { - nodeSet.matchingNodes.removeKey(node); + nodeSet.matchingNodes.remove(node); } } else { for (ASTNode node : nodes) { - level = (Integer) nodeSet.matchingNodes.removeKey(node); + level = nodeSet.matchingNodes.remove(node); if (enclosesElement) { if (!handlesCreated) { localAnnotation = createHandle(annotationType, (IAnnotatable) enclosingElement); @@ -2758,7 +2758,7 @@ protected void reportMatching(CompilationUnitDeclaration unit, boolean mustResol if (nodeSet.mustResolve) this.patternLocator.mustResolve = true; if (BasicSearchEngine.VERBOSE) { trace("Report matching: "); //$NON-NLS-1$ - int size = nodeSet.matchingNodes==null ? 0 : nodeSet.matchingNodes.elementSize; + int size = nodeSet.matchingNodes==null ? 0 : nodeSet.matchingNodes.size(); trace(" - node set: accurate="+ size); //$NON-NLS-1$ size = nodeSet.possibleMatchingNodesSet==null ? 0 : nodeSet.possibleMatchingNodesSet.elementSize; trace(", possible="+size); //$NON-NLS-1$ @@ -2795,7 +2795,7 @@ protected void reportMatching(CompilationUnitDeclaration unit, boolean mustResol } nodeSet.possibleMatchingNodesSet = new SimpleSet(3); if (BasicSearchEngine.VERBOSE) { - int size = nodeSet.matchingNodes==null ? 0 : nodeSet.matchingNodes.elementSize; + int size = nodeSet.matchingNodes==null ? 0 : nodeSet.matchingNodes.size(); trace(" - node set: accurate="+size); //$NON-NLS-1$ size = nodeSet.possibleMatchingNodesSet==null ? 0 : nodeSet.possibleMatchingNodesSet.elementSize; trace(", possible="+size); //$NON-NLS-1$ @@ -2804,7 +2804,7 @@ protected void reportMatching(CompilationUnitDeclaration unit, boolean mustResol this.unitScope = null; } - if (nodeSet.matchingNodes.elementSize == 0) return; // no matching nodes were found + if (nodeSet.matchingNodes.isEmpty()) return; // no matching nodes were found this.methodHandles = new HashSet<>(); boolean matchedUnitContainer = (this.matchContainer & PatternLocator.COMPILATION_UNIT_CONTAINER) != 0; @@ -2815,11 +2815,11 @@ protected void reportMatching(CompilationUnitDeclaration unit, boolean mustResol if (nodes != null) { if (!matchedUnitContainer) { for (ASTNode node : nodes) - nodeSet.matchingNodes.removeKey(node); + nodeSet.matchingNodes.remove(node); } else { IJavaElement element = createPackageDeclarationHandle(unit); for (ASTNode node : nodes) { - Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); + Integer level = nodeSet.matchingNodes.remove(node); if (encloses(element)) { this.patternLocator.matchReportReference(node, element, null, null, null/*no binding*/, level.intValue(), this); } @@ -2840,7 +2840,7 @@ protected void reportMatching(CompilationUnitDeclaration unit, boolean mustResol ImportReference[] imports = unit.imports; if (imports != null) { for (ImportReference importRef : imports) { - Integer level = (Integer) nodeSet.matchingNodes.removeKey(importRef); + Integer level = nodeSet.matchingNodes.remove(importRef); if (level != null) { this.patternLocator.matchReportImportRef(importRef, null /*no binding*/, createImportHandle(importRef), level.intValue(), this); } @@ -2851,15 +2851,15 @@ protected void reportMatching(CompilationUnitDeclaration unit, boolean mustResol TypeDeclaration[] types = unit.types; if (types != null) { for (TypeDeclaration type : types) { - if (nodeSet.matchingNodes.elementSize == 0) return; // reported all the matching nodes - Integer level = (Integer) nodeSet.matchingNodes.removeKey(type); + if (nodeSet.matchingNodes.isEmpty()) return; // reported all the matching nodes + Integer level = nodeSet.matchingNodes.remove(type); int accuracy = (level != null && matchedUnitContainer) ? level.intValue() : -1; this.inTypeOccurrencesCounts = new HashtableOfIntValues(); reportMatching(type, null, accuracy, nodeSet, 1); } } else if (unit.moduleDeclaration != null) { ModuleDeclaration mod = unit.moduleDeclaration; - Integer level = (Integer) nodeSet.matchingNodes.removeKey(mod); + Integer level = nodeSet.matchingNodes.remove(mod); int accuracy = (level != null && matchedUnitContainer) ? level.intValue() : -1; reportMatching(mod, null, accuracy, nodeSet, 1); } @@ -2909,7 +2909,7 @@ protected void reportMatching(FieldDeclaration field, FieldDeclaration[] otherFi int length = nodes.length; for (int i = 0; i < length; i++) { ASTNode node = nodes[i]; - Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); + Integer level = nodeSet.matchingNodes.remove(node); if (report && level != null) { if (node instanceof TypeDeclaration) { // use field declaration to report match (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=88174) @@ -2943,13 +2943,13 @@ protected void reportMatching(FieldDeclaration field, FieldDeclaration[] otherFi if (nodes != null) { if ((this.matchContainer & PatternLocator.FIELD_CONTAINER) == 0) { for (ASTNode node : nodes) - nodeSet.matchingNodes.removeKey(node); + nodeSet.matchingNodes.remove(node); } else { if (enclosingElement == null) enclosingElement = createHandle(field, type, parent); if (encloses(enclosingElement)) { for (ASTNode node : nodes) { - Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); + Integer level = nodeSet.matchingNodes.remove(node); if (otherFields != null && otherElements == null) { otherElements = createHandles(otherFields, type, parent); } @@ -2966,7 +2966,7 @@ protected void reportMatching(FieldDeclaration field, FieldDeclaration[] otherFi if (nodes != null) { if ((this.matchContainer & PatternLocator.FIELD_CONTAINER) == 0) { for (ASTNode node : nodes) { - nodeSet.matchingNodes.removeKey(node); + nodeSet.matchingNodes.remove(node); } } else { if (enclosingElement == null) { @@ -2978,7 +2978,7 @@ protected void reportMatching(FieldDeclaration field, FieldDeclaration[] otherFi int length = nodes.length; for (int i = 0; i < length; i++) { ASTNode node = nodes[i]; - Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); + Integer level = nodeSet.matchingNodes.remove(node); if (level != null) { // ensure that the reference has not been already reported while visiting if (node instanceof TypeDeclaration) { // use field declaration to report match (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=88174) @@ -3039,7 +3039,7 @@ private void reportMatching(RequiresStatement[] reqs, ModuleDeclaration module, return; try { for (RequiresStatement req : reqs) { - Integer level = (Integer) nodeSet.matchingNodes.removeKey(req.module); + Integer level = nodeSet.matchingNodes.remove(req.module); if (level != null) { this.patternLocator.matchReportReference(req.module, moduleDesc, req.resolvedBinding, level.intValue(), this); } @@ -3054,7 +3054,7 @@ private void reportMatching(PackageVisibilityStatement[] psvs, MatchingNodeSet n if (psvs != null && psvs.length > 0) { for (PackageVisibilityStatement psv : psvs) { ImportReference importRef = psv.pkgRef; - Integer level = (Integer) nodeSet.matchingNodes.removeKey(importRef); + Integer level = nodeSet.matchingNodes.remove(importRef); if (level != null) { Binding binding = this.unitScope.getImport(importRef.tokens, true, 0); this.patternLocator.matchReportImportRef(importRef, binding, moduleDesc, level.intValue(), this); @@ -3062,7 +3062,7 @@ private void reportMatching(PackageVisibilityStatement[] psvs, MatchingNodeSet n ModuleReference[] tgts = psv.targets; if (tgts == null || tgts.length == 0) continue; for (ModuleReference tgt : tgts) { - level = (Integer) nodeSet.matchingNodes.removeKey(tgt); + level = nodeSet.matchingNodes.remove(tgt); if (level != null) { this.patternLocator.matchReportReference(tgt, moduleDesc, tgt.resolve(this.unitScope), level.intValue(), this); } @@ -3075,14 +3075,14 @@ private void reportMatching(ProvidesStatement[] provides, ModuleDeclaration modu for (ProvidesStatement service : provides) { TypeReference intf = service.serviceInterface; if (intf != null) { - Integer level = (Integer) nodeSet.matchingNodes.removeKey(intf); + Integer level = nodeSet.matchingNodes.remove(intf); if (level != null) this.patternLocator.matchReportReference(intf, moduleDesc, null, null, module.binding, level.intValue(), this); } TypeReference[] impls = service.implementations; for (TypeReference impl : impls) { if (impl != null) { - Integer level = (Integer) nodeSet.matchingNodes.removeKey(impl); + Integer level = nodeSet.matchingNodes.remove(impl); if (level != null) this.patternLocator.matchReportReference(impl, moduleDesc, null, null, module.binding, level.intValue(), this); } @@ -3096,7 +3096,7 @@ private void reportMatching(UsesStatement[] uses, ModuleDeclaration module, Matc for (UsesStatement service : uses) { TypeReference intf = service.serviceInterface; if (intf != null) { - Integer level = (Integer) nodeSet.matchingNodes.removeKey(intf); + Integer level = nodeSet.matchingNodes.remove(intf); if (level != null) { this.patternLocator.matchReportReference(intf, moduleDesc, null, null, module.binding, level.intValue(), this); } @@ -3157,10 +3157,10 @@ protected void reportMatching(TypeDeclaration type, IJavaElement parent, int acc if (nodes != null) { if (!matchedClassContainer) { for (ASTNode node : nodes) - nodeSet.matchingNodes.removeKey(node); + nodeSet.matchingNodes.remove(node); } else { for (ASTNode node : nodes) { - Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); + Integer level = nodeSet.matchingNodes.remove(node); if (enclosesElement) { this.patternLocator.matchReportReference(node, enclosingElement, null, null, type.binding, level.intValue(), this); } @@ -3173,7 +3173,7 @@ protected void reportMatching(TypeDeclaration type, IJavaElement parent, int acc if ((type.bits & ASTNode.IsAnonymousType) != 0) { TypeReference superType = type.allocation.type; if (superType != null) { - Integer level = (Integer) nodeSet.matchingNodes.removeKey(superType); + Integer level = nodeSet.matchingNodes.remove(superType); if (level != null && matchedClassContainer) this.patternLocator.matchReportReference(superType, enclosingElement, null, null, type.binding, level.intValue(), this); } @@ -3214,7 +3214,7 @@ protected void reportMatching(TypeDeclaration type, IJavaElement parent, int acc // Visit fields FieldDeclaration[] fields = type.fields; if (fields != null) { - if (nodeSet.matchingNodes.elementSize == 0) return; // end as all matching nodes were reported + if (nodeSet.matchingNodes.isEmpty()) return; // end as all matching nodes were reported FieldDeclaration[] otherFields = null; int first = -1; int length = fields.length; @@ -3238,7 +3238,7 @@ protected void reportMatching(TypeDeclaration type, IJavaElement parent, int acc // On last field, report match with all other elements if (last) { for (int j=first; j<=i; j++) { - Integer level = (Integer) nodeSet.matchingNodes.removeKey(fields[j]); + Integer level = nodeSet.matchingNodes.remove(fields[j]); int value = (level != null && matchedClassContainer) ? level.intValue() : -1; reportMatching(fields[j], otherFields, type, enclosingElement, value, typeInHierarchy, nodeSet); } @@ -3247,7 +3247,7 @@ protected void reportMatching(TypeDeclaration type, IJavaElement parent, int acc } } else { // Single field, report normally - Integer level = (Integer) nodeSet.matchingNodes.removeKey(field); + Integer level = nodeSet.matchingNodes.remove(field); int value = (level != null && matchedClassContainer) ? level.intValue() : -1; reportMatching(field, null, type, enclosingElement, value, typeInHierarchy, nodeSet); } @@ -3257,9 +3257,9 @@ protected void reportMatching(TypeDeclaration type, IJavaElement parent, int acc // Visit methods AbstractMethodDeclaration[] methods = type.methods; if (methods != null) { - if (nodeSet.matchingNodes.elementSize == 0) return; // end as all matching nodes were reported + if (nodeSet.matchingNodes.isEmpty()) return; // end as all matching nodes were reported for (AbstractMethodDeclaration method : methods) { - Integer level = (Integer) nodeSet.matchingNodes.removeKey(method); + Integer level = nodeSet.matchingNodes.remove(method); int value = (level != null && matchedClassContainer) ? level.intValue() : -1; reportMatching(method, type, enclosingElement, value, typeInHierarchy, nodeSet); } @@ -3269,8 +3269,8 @@ protected void reportMatching(TypeDeclaration type, IJavaElement parent, int acc TypeDeclaration[] memberTypes = type.memberTypes; if (memberTypes != null) { for (TypeDeclaration memberType : memberTypes) { - if (nodeSet.matchingNodes.elementSize == 0) return; // end as all matching nodes were reported - Integer level = (Integer) nodeSet.matchingNodes.removeKey(memberType); + if (nodeSet.matchingNodes.isEmpty()) return; // end as all matching nodes were reported + Integer level = nodeSet.matchingNodes.remove(memberType); int value = (level != null && matchedClassContainer) ? level.intValue() : -1; reportMatching(memberType, enclosingElement, value, nodeSet, 1); } @@ -3283,7 +3283,7 @@ protected void reportMatching(TypeParameter[] typeParameters, IJavaElement enclo if (typeParameters == null) return; for (TypeParameter typeParameter : typeParameters) { if (typeParameter != null) { - Integer level = (Integer) nodeSet.matchingNodes.removeKey(typeParameter); + Integer level = nodeSet.matchingNodes.remove(typeParameter); if (level != null) { if (level.intValue() > -1 && encloses(enclosingElement)) { int offset = typeParameter.sourceStart; @@ -3297,7 +3297,7 @@ protected void reportMatching(TypeParameter[] typeParameters, IJavaElement enclo } if (typeParameter.type != null) { reportMatching(typeParameter.type.annotations, enclosingElement, typeParameter.binding, nodeSet, matchedClassContainer); - level = (Integer) nodeSet.matchingNodes.removeKey(typeParameter.type); + level = nodeSet.matchingNodes.remove(typeParameter.type); if (level != null) { IJavaElement localElement = createHandle(typeParameter, enclosingElement); this.patternLocator.matchReportReference(typeParameter.type, enclosingElement, localElement, null, binding, level.intValue(), this); @@ -3309,7 +3309,7 @@ protected void reportMatching(TypeParameter[] typeParameters, IJavaElement enclo for (int k=0; k accuracy +Map matchingNodes = new HashMap<>(); // node -> accuracy private final HashtableOfLong matchingNodesKeys = new HashtableOfLong(3); // sourceRange -> node static Integer EXACT_MATCH = Integer.valueOf(SearchMatch.A_ACCURATE); static Integer POTENTIAL_MATCH = Integer.valueOf(SearchMatch.A_INACCURATE); @@ -110,7 +112,7 @@ void addTrustedMatch(ASTNode node, Integer level) { long key = (((long) node.sourceStart) << 32) + node.sourceEnd; ASTNode existing = (ASTNode) this.matchingNodesKeys.get(key); if (existing != null && existing.getClass().equals(node.getClass())) - this.matchingNodes.removeKey(existing); + this.matchingNodes.remove(existing); // map node to its accuracy level this.matchingNodes.put(node, level); @@ -123,9 +125,7 @@ protected boolean hasPossibleNodes(int start, int end) { if (node != null && start <= node.sourceStart && node.sourceEnd <= end) return true; } - nodes = this.matchingNodes.keyTable; - for (Object n : nodes) { - ASTNode node = (ASTNode) n; + for (ASTNode node : this.matchingNodes.keySet()) { if (node != null && start <= node.sourceStart && node.sourceEnd <= end) return true; } @@ -136,9 +136,7 @@ protected boolean hasPossibleNodes(int start, int end) { */ protected ASTNode[] matchingNodes(int start, int end) { List nodes = null; - Object[] keyTable = this.matchingNodes.keyTable; - for (Object o : keyTable) { - ASTNode node = (ASTNode) o; + for (ASTNode node : this.matchingNodes.keySet()) { if (node != null && start <= node.sourceStart && node.sourceEnd <= end) { if (nodes == null) nodes = new ArrayList<>(); nodes.add(node); @@ -172,20 +170,18 @@ public Object removeTrustedMatch(ASTNode node) { if (existing == null) return null; this.matchingNodesKeys.put(key, null); - return this.matchingNodes.removeKey(node); + return this.matchingNodes.remove(node); } @Override public String toString() { // TODO (jerome) should show both tables StringBuilder result = new StringBuilder(); result.append("Exact matches:"); //$NON-NLS-1$ - Object[] keyTable = this.matchingNodes.keyTable; - Object[] valueTable = this.matchingNodes.valueTable; - for (int i = 0, l = keyTable.length; i < l; i++) { - ASTNode node = (ASTNode) keyTable[i]; + for (Entry entry:this.matchingNodes.entrySet()) { + ASTNode node = entry.getKey(); if (node == null) continue; result.append("\n\t"); //$NON-NLS-1$ - switch (((Integer)valueTable[i]).intValue()) { + switch (entry.getValue().intValue()) { case SearchMatch.A_ACCURATE: result.append("ACCURATE_MATCH: "); //$NON-NLS-1$ break; diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MemberDeclarationVisitor.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MemberDeclarationVisitor.java index 67352e74b53..4d34bf2c604 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MemberDeclarationVisitor.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MemberDeclarationVisitor.java @@ -221,7 +221,7 @@ public boolean visit(Argument argument, BlockScope scope) { } @Override public boolean visit(LambdaExpression lambdaExpression, BlockScope scope) { - Integer level = (Integer) this.nodeSet.matchingNodes.removeKey(lambdaExpression); + Integer level = this.nodeSet.matchingNodes.remove(lambdaExpression); try { if (lambdaExpression.resolvedType != null && lambdaExpression.resolvedType.isValidBinding() && !(lambdaExpression.descriptor instanceof ProblemMethodBinding)) @@ -329,7 +329,7 @@ public boolean visit(TypeDeclaration typeDeclaration, BlockScope unused) { if ((typeDeclaration.bits & ASTNode.IsAnonymousType) != 0) { this.locator.reportMatching(typeDeclaration, this.enclosingElement, -1, this.nodeSet, occurrenceCount); } else { - Integer level = (Integer) this.nodeSet.matchingNodes.removeKey(typeDeclaration); + Integer level = this.nodeSet.matchingNodes.remove(typeDeclaration); this.locator.reportMatching(typeDeclaration, this.enclosingElement, level != null ? level.intValue() : -1, this.nodeSet, occurrenceCount); } this.locator.inTypeOccurrencesCounts = oldOccurencesCount; diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PossibleMatchSet.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PossibleMatchSet.java index a24bee7e1ff..dfc7b93784d 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PossibleMatchSet.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/PossibleMatchSet.java @@ -13,23 +13,24 @@ *******************************************************************************/ package org.eclipse.jdt.internal.core.search.matching; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import org.eclipse.core.runtime.IPath; import org.eclipse.jdt.core.IPackageFragmentRoot; import org.eclipse.jdt.internal.compiler.util.ObjectVector; -import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; /** * A set of PossibleMatches that is sorted by package fragment roots. */ public class PossibleMatchSet { -private SimpleLookupTable rootsToPossibleMatches = new SimpleLookupTable(5); +private Map rootsToPossibleMatches = new HashMap<>(); private int elementCount = 0; public void add(PossibleMatch possibleMatch) { IPath path = possibleMatch.openable.getPackageFragmentRoot().getPath(); - ObjectVector possibleMatches = (ObjectVector) this.rootsToPossibleMatches.get(path); + ObjectVector possibleMatches = this.rootsToPossibleMatches.get(path); if (possibleMatches != null) { PossibleMatch storedMatch = (PossibleMatch) possibleMatches.find(possibleMatch); if (storedMatch != null) { @@ -52,7 +53,7 @@ public PossibleMatch[] getPossibleMatches(IPackageFragmentRoot[] roots) { HashSet processedHash = new HashSet<>(); for (IPackageFragmentRoot root : roots) { IPath path = root.getPath(); - ObjectVector possibleMatches = (ObjectVector) this.rootsToPossibleMatches.get(path); + ObjectVector possibleMatches = this.rootsToPossibleMatches.get(path); if (possibleMatches != null && !processedHash.contains(path)) { possibleMatches.copyInto(result, index); index += possibleMatches.size(); @@ -64,7 +65,7 @@ public PossibleMatch[] getPossibleMatches(IPackageFragmentRoot[] roots) { return result; } public void reset() { - this.rootsToPossibleMatches = new SimpleLookupTable(5); + this.rootsToPossibleMatches = new HashMap<>(); this.elementCount = 0; } }