]> source.dussan.org Git - aspectj.git/commitdiff
Update org.aspectj.matcher code to use generics. 104/head
authorAndrey Turbanov <turbanoff@gmail.com>
Sat, 20 Nov 2021 19:40:35 +0000 (22:40 +0300)
committerAndrey Turbanov <turbanoff@gmail.com>
Sat, 20 Nov 2021 19:40:35 +0000 (22:40 +0300)
Generics make code more type-safe and allows removing ugly type-casts.

16 files changed:
org.aspectj.matcher/src/main/java/org/aspectj/weaver/NewConstructorTypeMunger.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/NewFieldTypeMunger.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/ResolvedPointcutDefinition.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/Shadow.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/WeakClassLoaderReference.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/internal/tools/PointcutExpressionImpl.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/internal/tools/StandardPointcutExpressionImpl.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/AnnotationPointcut.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/HasMemberTypePattern.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/IfPointcut.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegateFactory.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/reflect/ReflectionShadow.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/reflect/StandardShadow.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/tools/DefaultMatchingContext.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/tools/StandardPointcutParser.java
org.aspectj.matcher/src/main/java/org/aspectj/weaver/tools/TraceFactory.java

index 133b1684210318f9c442ebc7edca29185fa01ae1..b7451cdd4f3caa0b9a7db669eb95be955ae03559 100644 (file)
@@ -89,9 +89,9 @@ public class NewConstructorTypeMunger extends ResolvedTypeMunger {
                ResolvedMember sig = ResolvedMemberImpl.readResolvedMember(s, context);
                ResolvedMember syntheticCtor = ResolvedMemberImpl.readResolvedMember(s, context);
                ResolvedMember explicitCtor = ResolvedMemberImpl.readResolvedMember(s, context);
-               Set superMethodsCalled = readSuperMethodsCalled(s);
+               Set<ResolvedMember> superMethodsCalled = readSuperMethodsCalled(s);
                sloc = readSourceLocation(s);
-               List typeVarAliases = readInTypeAliases(s);
+               List<String> typeVarAliases = readInTypeAliases(s);
                ResolvedTypeMunger munger = new NewConstructorTypeMunger(sig, syntheticCtor, explicitCtor, superMethodsCalled,
                                typeVarAliases);
                if (sloc != null) {
index 7e53c0f44c7b92b5dd8e61f5a552bbe244fe80d9..ed708a9b5f6717992af6319e5ac927f6115caf6a 100644 (file)
@@ -57,9 +57,9 @@ public class NewFieldTypeMunger extends ResolvedTypeMunger {
        public static ResolvedTypeMunger readField(VersionedDataInputStream s, ISourceContext context) throws IOException {
                ISourceLocation sloc = null;
                ResolvedMember fieldSignature = ResolvedMemberImpl.readResolvedMember(s, context);
-               Set superMethodsCalled = readSuperMethodsCalled(s);
+               Set<ResolvedMember> superMethodsCalled = readSuperMethodsCalled(s);
                sloc = readSourceLocation(s);
-               List aliases = readInTypeAliases(s);
+               List<String> aliases = readInTypeAliases(s);
                NewFieldTypeMunger munger = new NewFieldTypeMunger(fieldSignature, superMethodsCalled, aliases);
                if (sloc != null) {
                        munger.setSourceLocation(sloc);
index 09d0f8ac46a39d270085eb3c84f3585fe7cdf075..f924a100d0c5cbc3987e3050022adde11ce6194d 100644 (file)
@@ -101,7 +101,7 @@ public class ResolvedPointcutDefinition extends ResolvedMemberImpl {
                if (isParameterized && (typeVariables.length != typeParameters.length)) {
                        throw new IllegalStateException("Wrong number of type parameters supplied");
                }
-               Map typeMap = new HashMap();
+               Map<String, UnresolvedType> typeMap = new HashMap<>();
                boolean typeParametersSupplied = typeParameters != null && typeParameters.length > 0;
                if (typeVariables != null) {
                        // If no 'replacements' were supplied in the typeParameters array then collapse
index 5ab8feae0bdce8f78b5363bd8777664bc3a56b1c..29a0fc600569fafd8dc4e2f153f15bc5d5fd1ba8 100644 (file)
@@ -549,7 +549,7 @@ public abstract class Shadow {
 
        private void sortMungers() {
 
-               List sorted = PartialOrder.sort(mungers);
+               List<ShadowMunger> sorted = PartialOrder.sort(mungers);
 
                // Bunch of code to work out whether to report xlints for advice that isn't ordered at this Joinpoint
                possiblyReportUnorderedAdvice(sorted);
@@ -565,7 +565,7 @@ public abstract class Shadow {
        }
 
        // not quite optimal... but the xlint is ignore by default
-       private void possiblyReportUnorderedAdvice(List sorted) {
+       private void possiblyReportUnorderedAdvice(List<ShadowMunger> sorted) {
                if (sorted != null && getIWorld().getLint().unorderedAdviceAtShadow.isEnabled() && mungers.size() > 1) {
 
                        // Stores a set of strings of the form 'aspect1:aspect2' which indicates there is no
index 64c2fc65cbe6334a53862e99b963e619b847d0ce..8bbfd3f4234cb2eea2225e07aa93458807f2fd42 100644 (file)
@@ -36,10 +36,10 @@ public class WeakClassLoaderReference{
 
        protected final int hashcode;
 
-       private final WeakReference loaderRef;
+       private final WeakReference<ClassLoader> loaderRef;
 
        public WeakClassLoaderReference(ClassLoader loader) {
-               loaderRef = new WeakReference(loader);
+               loaderRef = new WeakReference<>(loader);
                if(loader == null){
                        // Bug: 363962
                        // Check that ClassLoader is not null, for instance when loaded from BootStrapClassLoader
index cad972987aee380001d5992ecee32dba8496648e..133beef2f69cdb19e8d7bac3633448cb42bf5c34 100644 (file)
@@ -411,8 +411,8 @@ public class PointcutExpressionImpl implements PointcutExpression {
 
        public static class Handler implements Member {
 
-               private Class decClass;
-               private Class exType;
+               private Class<?> decClass;
+               private Class<?> exType;
 
                public Handler(Class decClass, Class exType) {
                        this.decClass = decClass;
index edc686c1fc0531c91fce6dde2be807916fba5790..07e7f3facb61751f2f89e89defdf68b32a5d4bb6 100644 (file)
@@ -354,8 +354,8 @@ public class StandardPointcutExpressionImpl implements StandardPointcutExpressio
 
        public static class Handler implements Member {
 
-               private Class decClass;
-               private Class exType;
+               private Class<?> decClass;
+               private Class<?> exType;
 
                public Handler(Class decClass, Class exType) {
                        this.decClass = decClass;
index 292df0a8abd1ceab0996793834e73d7336c53d8e..2371456034e70a399c83afd63661843c2e1f2871 100644 (file)
@@ -139,7 +139,7 @@ public class AnnotationPointcut extends NameBindingPointcut {
                        if (rMember.isAnnotatedElsewhere()) {
                                if (kind == Shadow.FieldGet || kind == Shadow.FieldSet) {
                                        // FIXME asc should include supers with getInterTypeMungersIncludingSupers ?
-                                       List mungers = rMember.getDeclaringType().resolve(shadow.getIWorld()).getInterTypeMungers();
+                                       List<ConcreteTypeMunger> mungers = rMember.getDeclaringType().resolve(shadow.getIWorld()).getInterTypeMungers();
                                        for (Object munger : mungers) {
                                                ConcreteTypeMunger typeMunger = (ConcreteTypeMunger) munger;
                                                if (typeMunger.getMunger() instanceof NewFieldTypeMunger) {
index 38512a73f0f14099e8ee64d98b9f122d06dbea28..002297de01f59978bd4b017a52f2e52829fad379 100644 (file)
@@ -61,7 +61,7 @@ public class HasMemberTypePattern extends TypePattern {
        private boolean hasField(ResolvedType type) {
                // TODO what about ITDs
                World world = type.getWorld();
-               for (Iterator iter = type.getFields(); iter.hasNext();) {
+               for (Iterator<ResolvedMember> iter = type.getFields(); iter.hasNext();) {
                        Member field = (Member) iter.next();
                        if (field.getName().startsWith(declareAtPrefix)) {
                                continue;
index e1e747e35c499e61d0d916161dc11feb974c0a15..edadaf481170e36a6f6f03982c1b1224a443fe0c 100644 (file)
@@ -354,7 +354,7 @@ public class IfPointcut extends Pointcut {
                        ResolvedPointcutDefinition def = bindings.peekEnclosingDefinition();
                        if (def != null) {
                                ResolvedType aspect = inAspect.getWorld().resolve(def.getDeclaringType());
-                               for (Iterator memberIter = aspect.getMethods(true, true); memberIter.hasNext();) {
+                               for (Iterator<ResolvedMember> memberIter = aspect.getMethods(true, true); memberIter.hasNext();) {
                                        ResolvedMember method = (ResolvedMember) memberIter.next();
                                        if (def.getName().equals(method.getName())
                                                        && def.getParameterTypes().length == method.getParameterTypes().length) {
index 8da8151cf3529e497ea213f65887c9ce509f3080..35f92e300564735c43ed5b2683cfacfbb168bd52 100644 (file)
@@ -34,7 +34,7 @@ public class ReflectionBasedReferenceTypeDelegateFactory {
        public static ReflectionBasedReferenceTypeDelegate createDelegate(ReferenceType forReferenceType, World inWorld,
                        ClassLoader usingClassLoader) {
                try {
-                       Class c = Class.forName(forReferenceType.getName(), false, usingClassLoader);
+                       Class<?> c = Class.forName(forReferenceType.getName(), false, usingClassLoader);
                        ReflectionBasedReferenceTypeDelegate rbrtd = create15Delegate(forReferenceType, c, usingClassLoader, inWorld);
                        if (rbrtd != null) {
                                return rbrtd; // can be null if we didn't find the class the delegate logic loads
@@ -57,7 +57,7 @@ public class ReflectionBasedReferenceTypeDelegateFactory {
        public static ReflectionBasedReferenceTypeDelegate create14Delegate(ReferenceType forReferenceType, World inWorld,
                        ClassLoader usingClassLoader) {
                try {
-                       Class c = Class.forName(forReferenceType.getName(), false, usingClassLoader);
+                       Class<?> c = Class.forName(forReferenceType.getName(), false, usingClassLoader);
                        return new ReflectionBasedReferenceTypeDelegate(c, usingClassLoader, inWorld, forReferenceType);
                } catch (ClassNotFoundException cnfEx) {
                        return null;
@@ -68,7 +68,7 @@ public class ReflectionBasedReferenceTypeDelegateFactory {
        private static ReflectionBasedReferenceTypeDelegate create15Delegate(ReferenceType forReferenceType, Class forClass,
                        ClassLoader usingClassLoader, World inWorld) {
                try {
-                       Class delegateClass = Class.forName("org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate");
+                       Class<?> delegateClass = Class.forName("org.aspectj.weaver.reflect.Java15ReflectionBasedReferenceTypeDelegate");
                        ReflectionBasedReferenceTypeDelegate ret = (ReflectionBasedReferenceTypeDelegate) delegateClass.getDeclaredConstructor().newInstance();
                        ret.initialize(forReferenceType, forClass, usingClassLoader, inWorld);
                        return ret;
@@ -92,8 +92,8 @@ public class ReflectionBasedReferenceTypeDelegateFactory {
 
        private static GenericSignatureInformationProvider createGenericSignatureProvider(World inWorld) {
                try {
-                       Class providerClass = Class.forName("org.aspectj.weaver.reflect.Java15GenericSignatureInformationProvider");
-                       Constructor cons = providerClass.getConstructor(new Class[] { World.class });
+                       Class<?> providerClass = Class.forName("org.aspectj.weaver.reflect.Java15GenericSignatureInformationProvider");
+                       Constructor<?> cons = providerClass.getConstructor(new Class[] { World.class });
                        GenericSignatureInformationProvider ret = (GenericSignatureInformationProvider) cons
                                        .newInstance(new Object[] { inWorld });
                        return ret;
@@ -204,7 +204,7 @@ public class ReflectionBasedReferenceTypeDelegateFactory {
                }
        }
 
-       private static ResolvedType toResolvedType(Class aClass, IReflectionWorld aWorld) {
+       private static ResolvedType toResolvedType(Class<?> aClass, IReflectionWorld aWorld) {
                return aWorld.resolve(aClass);
        }
 
index f92a51301aca2d4c6ac05bf9ecb51eff103e27a9..55e8a957bbfb095aced2c851fd0c2996144a6f45 100644 (file)
@@ -42,10 +42,10 @@ public class ReflectionShadow extends Shadow {
        private Var[] argsVars = null;
        private Var atThisVar = null;
        private Var atTargetVar = null;
-       private Map atArgsVars = new HashMap();
-       private Map withinAnnotationVar = new HashMap();
-       private Map withinCodeAnnotationVar = new HashMap();
-       private Map annotationVar = new HashMap();
+       private Map<ResolvedType, Var[]> atArgsVars = new HashMap<>();
+       private Map<ResolvedType, Var> withinAnnotationVar = new HashMap<>();
+       private Map<ResolvedType, Var> withinCodeAnnotationVar = new HashMap<>();
+       private Map<ResolvedType, Var> annotationVar = new HashMap<>();
        private AnnotationFinder annotationFinder;
 
        public static Shadow makeExecutionShadow(World inWorld, java.lang.reflect.Member forMethod, MatchingContext withContext) {
index 59fcb9082a51b52219bec14c85f40734bec5152a..c44d5c54cbc0a0e2a586beb27dd304669bce840b 100644 (file)
@@ -44,10 +44,10 @@ public class StandardShadow extends Shadow {
        private Var[] argsVars = null;
        private Var atThisVar = null;
        private Var atTargetVar = null;
-       private Map atArgsVars = new HashMap();
-       private Map withinAnnotationVar = new HashMap();
-       private Map withinCodeAnnotationVar = new HashMap();
-       private Map annotationVar = new HashMap();
+       private Map<ResolvedType, Var[]> atArgsVars = new HashMap<>();
+       private Map<ResolvedType, Var> withinAnnotationVar = new HashMap<>();
+       private Map<ResolvedType, Var> withinCodeAnnotationVar = new HashMap<>();
+       private Map<ResolvedType, Var> annotationVar = new HashMap<>();
        private AnnotationFinder annotationFinder;
 
        public static Shadow makeExecutionShadow(World inWorld, java.lang.reflect.Member forMethod, MatchingContext withContext) {
index 293696a92692170b6248a7e870a57f6ff628741e..e44b81d7efce134e1c28bb96250feda4938ab686 100644 (file)
@@ -20,7 +20,7 @@ import java.util.Map;
  */
 public class DefaultMatchingContext implements MatchingContext {
 
-       private Map contextMap = new HashMap();
+       private Map<String, Object> contextMap = new HashMap<>();
 
        /* (non-Javadoc)
         * @see org.aspectj.weaver.tools.MatchingContext#hasContextParameter(java.lang.String)
index 1fdb2905505ae4e5540d513b83b39fcc35ca4c59..0f4c34073ba0f8a590a16b95d015ca825365be22 100644 (file)
@@ -146,7 +146,7 @@ public class StandardPointcutParser {
         * @param supportedPointcutKinds a set of PointcutPrimitives this parser should support
         * @throws UnsupportedOperationException if the set contains if, cflow, or cflow below
         */
-       private StandardPointcutParser(Set/* <PointcutPrimitives> */supportedPointcutKinds, World world) {
+       private StandardPointcutParser(Set<PointcutPrimitive> supportedPointcutKinds, World world) {
                supportedPrimitives = supportedPointcutKinds;
                for (Object supportedPointcutKind : supportedPointcutKinds) {
                        PointcutPrimitive element = (PointcutPrimitive) supportedPointcutKind;
@@ -306,7 +306,7 @@ public class StandardPointcutParser {
                return current;
        }
 
-       private IScope buildResolutionScope(Class inScope, PointcutParameter[] formalParameters) {
+       private IScope buildResolutionScope(Class<?> inScope, PointcutParameter[] formalParameters) {
                if (formalParameters == null) {
                        formalParameters = new PointcutParameter[0];
                }
@@ -342,7 +342,7 @@ public class StandardPointcutParser {
                }
        }
 
-       private UnresolvedType toUnresolvedType(Class clazz) {
+       private UnresolvedType toUnresolvedType(Class<?> clazz) {
                if (clazz.isArray()) {
                        return UnresolvedType.forSignature(clazz.getName().replace('.', '/'));
                } else {
index 8154636534de5cbcb9ba9fa4b5cdb76069503eb6..69a633da89d6b53cebdfedfbbc5a4c88b550c334 100644 (file)
@@ -44,7 +44,7 @@ public abstract class TraceFactory {
                                instance = new DefaultTraceFactory();
                        }
                        else {
-                       Class factoryClass = Class.forName(factoryName);
+                       Class<?> factoryClass = Class.forName(factoryName);
                        instance = (TraceFactory)factoryClass.getDeclaredConstructor().newInstance();
                        }
                }
@@ -57,7 +57,7 @@ public abstract class TraceFactory {
                 */
        if (instance == null) try {
                        {
-                       Class factoryClass = Class.forName("org.aspectj.weaver.tools.Jdk14TraceFactory");
+                       Class<?> factoryClass = Class.forName("org.aspectj.weaver.tools.Jdk14TraceFactory");
                        instance = (TraceFactory)factoryClass.getDeclaredConstructor().newInstance();
                        }
        }