]> source.dussan.org Git - aspectj.git/commitdiff
Code polishing and extra diagnostics around types and parameterized types
authorAndy Clement <aclement@pivotal.io>
Thu, 12 May 2016 22:29:07 +0000 (15:29 -0700)
committerAndy Clement <aclement@pivotal.io>
Thu, 12 May 2016 22:29:07 +0000 (15:29 -0700)
org.aspectj.matcher/src/org/aspectj/weaver/TypeFactory.java
org.aspectj.matcher/src/org/aspectj/weaver/World.java
weaver5/java5-src/org/aspectj/weaver/reflect/Java15ReflectionBasedReferenceTypeDelegate.java
weaver5/java5-src/org/aspectj/weaver/reflect/JavaLangTypeToResolvedTypeConverter.java

index 204418346eb5a88880d24c0cd14ed552b6547fa9..e565e5bc85a6020d1c9bbee04eb59c031b4f0fa2 100644 (file)
@@ -28,10 +28,9 @@ public class TypeFactory {
        public static ReferenceType createParameterizedType(ResolvedType aBaseType, UnresolvedType[] someTypeParameters, World inAWorld) {
                ResolvedType baseType = aBaseType;
                if (!aBaseType.isGenericType()) {
-                       // try and find the generic type...
                        if (someTypeParameters != null && someTypeParameters.length > 0) {
                                if (!aBaseType.isRawType()) {
-                                       throw new IllegalStateException("Expecting raw type, not: " + aBaseType);
+                                       throw new IllegalStateException("Expecting raw type, but " + aBaseType+" is of type "+aBaseType.getTypekind());
                                }
                                baseType = baseType.getGenericType();
                                if (baseType == null) {
index 329fef88dae454c2030a1ebcc9b1f408a10cde7a..31b978028924a2cef55e68f2fa8ebb9a14a813d6 100644 (file)
@@ -1237,11 +1237,12 @@ public abstract class World implements Dump.INode {
                        }
 
                        // TODO should this be in as a permanent assertion?
-                       /*
-                        * if ((type instanceof ReferenceType) && type.getWorld().isInJava5Mode() && (((ReferenceType) type).getDelegate() !=
-                        * null) && type.isGenericType()) { throw new BCException("Attempt to add generic type to typemap " + type.toString() +
-                        * " (should be raw)"); }
-                        */
+                       
+                       if ((type instanceof ReferenceType) && type.getWorld().isInJava5Mode()
+                                       && (((ReferenceType) type).getDelegate() != null) && type.isGenericType()) {
+                               throw new BCException("Attempt to add generic type to typemap " + type.toString() + " (should be raw)");
+                       }
+                       
 
                        if (w.isExpendable(type)) {
                                if (useExpendableMap) {
index e9606790a0e092d767ccbf9a8a22a5328930c0da..6b65ed31e7114f362c4ef6c8c4cf47145bcc66d7 100644 (file)
@@ -37,8 +37,11 @@ import org.aspectj.weaver.tools.PointcutDesignatorHandler;
 import org.aspectj.weaver.tools.PointcutParameter;
 
 /**
- * @author colyer Provides Java 5 behaviour in reflection based delegates (overriding 1.4 behaviour from superclass where
- *         appropriate)
+ * Provides Java 5 behaviour in reflection based delegates (overriding 1.4 behaviour from superclass where
+ * appropriate)
+ * 
+ * @author Adrian Colyer
+ * @author Andy Clement
  */
 public class Java15ReflectionBasedReferenceTypeDelegate extends ReflectionBasedReferenceTypeDelegate {
 
@@ -145,17 +148,16 @@ public class Java15ReflectionBasedReferenceTypeDelegate extends ReflectionBasedR
                return superInterfaces;
        }
 
-       // If the superclass is null, return Object - same as bcel does
        @Override
        public ResolvedType getSuperclass() {
-               if (superclass == null && getBaseClass() != Object.class) {// superclass
-                       // of Object
-                       // is null
+               // Superclass of object is null
+               if (superclass == null && getBaseClass() != Object.class) {
                        Type t = this.getBaseClass().getGenericSuperclass();
                        if (t != null) {
                                superclass = typeConverter.fromType(t);
                        }
                        if (t == null) {
+                               // If the superclass is null, return Object - same as bcel does
                                superclass = getWorld().resolve(UnresolvedType.OBJECT);
                        }
                }
index 8e313dc40213dd9c4a4517632e0049bfe4cb567f..51a9a4e84762e7d09c3205f48566513e0a16c373 100644 (file)
@@ -5,9 +5,6 @@
  * under the terms of the Eclipse Public License v1.0 
  * which accompanies this distribution and is available at 
  * http://eclipse.org/legal/epl-v10.html 
- *  
- * Contributors: 
- *   Adrian Colyer                     Initial implementation
  * ******************************************************************/
 package org.aspectj.weaver.reflect;
 
@@ -30,6 +27,7 @@ import org.aspectj.weaver.World;
 /**
  * Handles the translation of java.lang.reflect.Type objects into AspectJ UnresolvedTypes.
  * 
+ * @author Adrian Colyer
  */
 public class JavaLangTypeToResolvedTypeConverter {
 
@@ -45,18 +43,21 @@ public class JavaLangTypeToResolvedTypeConverter {
                return this.world;
        }
 
-       public ResolvedType fromType(Type aType) {
-               if (aType instanceof Class) {
-                       Class clazz = (Class) aType;
+       public ResolvedType fromType(Type type) {
+               if (type instanceof Class) {
+                       Class clazz = (Class) type;
                        String name = clazz.getName();
                        /**
                         * getName() can return:
                         * 
-                        * 1. If this class object represents a reference type that is not an array type then the binary name of the class is
-                        * returned 2. If this class object represents a primitive type or void, then the name returned is a String equal to the
-                        * Java language keyword corresponding to the primitive type or void. 3. If this class object represents a class of
-                        * arrays, then the internal form of the name consists of the name of the element type preceded by one or more '['
-                        * characters representing the depth of the array nesting.
+                        * 1. If this class object represents a reference type that is not an 
+                        * array type then the binary name of the class is returned 
+                        * 2. If this class object represents a primitive type or void, then
+                        * the name returned is a String equal to the Java language keyword
+                        * corresponding to the primitive type or void. 
+                        * 3. If this class object represents a class of arrays, then the internal
+                        * form of the name consists of the name of the element type preceded by 
+                        * one or more '[' characters representing the depth of the array nesting.
                         */
                        if (clazz.isArray()) {
                                UnresolvedType ut = UnresolvedType.forSignature(name.replace('.', '/'));
@@ -64,31 +65,22 @@ public class JavaLangTypeToResolvedTypeConverter {
                        } else {
                                return getWorld().resolve(name);
                        }
-               } else if (aType instanceof ParameterizedType) {
-                       ParameterizedType pt = (ParameterizedType) aType;
-                       ResolvedType baseType = fromType(pt.getRawType());
-                       Type[] args = pt.getActualTypeArguments();
-                       ResolvedType[] resolvedArgs = fromTypes(args);
-                       /*
-                        * StringBuilder sb = new StringBuilder(); for (int i = 0; i < resolvedArgs.length; i++) {
-                        * sb.append(resolvedArgs[i]).append(" "); } for (int i = 0; i < resolvedArgs.length; i++) { if (resolvedArgs[i] ==
-                        * null) { String ss = ""; try { ss = aType.toString(); } catch (Exception e) { } throw new
-                        * IllegalStateException("Parameterized type problem.  basetype=" + baseType + " arguments=" + sb.toString() + " ss=" +
-                        * ss); } }
-                        */
-                       return TypeFactory.createParameterizedType(baseType, resolvedArgs, getWorld());
-               } else if (aType instanceof java.lang.reflect.TypeVariable) {
-                       TypeVariableReferenceType inprogressVar = typeVariablesInProgress.get(aType);
+               } else if (type instanceof ParameterizedType) {
+                       ParameterizedType parameterizedType = (ParameterizedType) type;
+                       ResolvedType baseType = fromType(parameterizedType.getRawType());
+                       if (!baseType.isRawType()) throw new IllegalStateException("Expected raw type form of "+parameterizedType.getRawType().getTypeName());
+                       Type[] typeArguments = parameterizedType.getActualTypeArguments();
+                       ResolvedType[] resolvedTypeArguments = fromTypes(typeArguments);
+                       return TypeFactory.createParameterizedType(baseType, resolvedTypeArguments, getWorld());
+               } else if (type instanceof java.lang.reflect.TypeVariable) {
+                       TypeVariableReferenceType inprogressVar = typeVariablesInProgress.get(type);
                        if (inprogressVar != null) {
                                return inprogressVar;
                        }
-
-                       java.lang.reflect.TypeVariable tv = (java.lang.reflect.TypeVariable) aType;
+                       java.lang.reflect.TypeVariable tv = (java.lang.reflect.TypeVariable) type;
                        TypeVariable rt_tv = new TypeVariable(tv.getName());
                        TypeVariableReferenceType tvrt = new TypeVariableReferenceType(rt_tv, getWorld());
-
-                       typeVariablesInProgress.put(aType, tvrt); // record what we are working on, for recursion case
-
+                       typeVariablesInProgress.put(type, tvrt); // record what we are working on, for recursion case
                        Type[] bounds = tv.getBounds();
                        ResolvedType[] resBounds = fromTypes(bounds);
                        ResolvedType upperBound = resBounds[0];
@@ -99,12 +91,10 @@ public class JavaLangTypeToResolvedTypeConverter {
                        }
                        rt_tv.setUpperBound(upperBound);
                        rt_tv.setAdditionalInterfaceBounds(additionalBounds);
-
-                       typeVariablesInProgress.remove(aType); // we have finished working on it
-
+                       typeVariablesInProgress.remove(type); // we have finished working on it
                        return tvrt;
-               } else if (aType instanceof WildcardType) {
-                       WildcardType wildType = (WildcardType) aType;
+               } else if (type instanceof WildcardType) {
+                       WildcardType wildType = (WildcardType) type;
                        Type[] lowerBounds = wildType.getLowerBounds();
                        Type[] upperBounds = wildType.getUpperBounds();
                        ResolvedType bound = null;
@@ -115,9 +105,9 @@ public class JavaLangTypeToResolvedTypeConverter {
                                bound = fromType(lowerBounds[0]);
                        }
                        return new BoundedReferenceType((ReferenceType) bound, isExtends, getWorld());
-               } else if (aType instanceof GenericArrayType) {
-                       GenericArrayType gt = (GenericArrayType) aType;
-                       Type componentType = gt.getGenericComponentType();
+               } else if (type instanceof GenericArrayType) {
+                       GenericArrayType genericArrayType = (GenericArrayType) type;
+                       Type componentType = genericArrayType.getGenericComponentType();
                        return UnresolvedType.makeArray(fromType(componentType), 1).resolve(getWorld());
                }
                return ResolvedType.MISSING;