]> source.dussan.org Git - aspectj.git/commitdiff
beginnings of proper type variable support in Eclipse type world
authoracolyer <acolyer>
Mon, 11 Jul 2005 09:34:44 +0000 (09:34 +0000)
committeracolyer <acolyer>
Mon, 11 Jul 2005 09:34:44 +0000 (09:34 +0000)
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java

index ec8ed951d0005149aca363c8495d62a61a73b203..9f6c2cc28bb5c577aba689404cbee1ab57d9860b 100644 (file)
@@ -35,6 +35,7 @@ import org.aspectj.weaver.ResolvedMember;
 import org.aspectj.weaver.ResolvedTypeX;
 import org.aspectj.weaver.Shadow;
 import org.aspectj.weaver.TypeVariable;
+import org.aspectj.weaver.TypeVariableReferenceType;
 import org.aspectj.weaver.TypeX;
 import org.aspectj.weaver.World;
 import org.aspectj.org.eclipse.jdt.core.compiler.CharOperation;
@@ -174,6 +175,9 @@ public class EclipseFactory {
         * sure when/if this gets us unstuck?  It does mean we forget that it is a type variable when going back
         * the other way from the TypeX and that would seem a bad thing - but I've yet to see the reason we need to
         * remember the type variable.
+        * Adrian 10-July-05
+        * When we forget it's a type variable we come unstuck when getting the declared members of a parameterized
+        * type - since we don't know it's a type variable we can't replace it with the type parameter.
         */
        //??? going back and forth between strings and bindings is a waste of cycles
        public static TypeX fromBinding(TypeBinding binding) {
@@ -185,14 +189,7 @@ public class EclipseFactory {
                }
                // first piece of generics support!
                if (binding instanceof TypeVariableBinding) {
-                       // this is a type variable...
-                       TypeVariableBinding tvb = (TypeVariableBinding) binding;
-                       // This code causes us to forget its a TVB which we will need when going back the other way...
-                       if (tvb.firstBound!=null) {
-                         return TypeX.forName(getName(tvb.firstBound)); // XXX needs more investigation as to whether this is correct in all cases
-                       } else {
-                         return TypeX.forName(getName(tvb.superclass));
-                       }
+                       return fromTypeVariableBinding((TypeVariableBinding)binding);
                }
                
                if (binding instanceof ParameterizedTypeBinding) {
@@ -242,6 +239,25 @@ public class EclipseFactory {
                return TypeX.forName(getName(binding));
        }
 
+       private static TypeX fromTypeVariableBinding(TypeVariableBinding aTypeVariableBinding) {
+               // TODO -- what about lower bounds??
+//             String name = new String(aTypeVariableBinding.sourceName());
+//             TypeX superclassType = fromBinding(aTypeVariableBinding.superclass());
+//             TypeX[] superinterfaces = new TypeX[aTypeVariableBinding.superInterfaces.length];
+//             for (int i = 0; i < superinterfaces.length; i++) {
+//                     superinterfaces[i] = fromBinding(aTypeVariableBinding.superInterfaces[i]);
+//             }
+//             TypeVariable tv = new TypeVariable(name,superclassType,superinterfaces);
+//             TypeVariableReferenceType ret = null; /// how do we get a world???
+//             return ret;
+               // old code...
+               if (aTypeVariableBinding.firstBound!=null) {
+                 return TypeX.forName(getName(aTypeVariableBinding.firstBound)); // XXX needs more investigation as to whether this is correct in all cases
+               } else {
+                 return TypeX.forName(getName(aTypeVariableBinding.superclass));
+               }
+       }
+       
        public static TypeX[] fromBindings(TypeBinding[] bindings) {
                if (bindings == null) return TypeX.NONE;
                int len = bindings.length;
index c473d57c1a7c933fa40f4a2586e11e12669ef00c..d6ce0b6daf64f6538ca88b897e03e735ee1ca207 100644 (file)
@@ -30,6 +30,7 @@ import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.StringLiteral;
+import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeParameter;
 import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.*;
 
 /**
@@ -462,7 +463,19 @@ public class EclipseSourceType extends AbstractReferenceTypeDelegate {
        }
        
        public TypeVariable[] getTypeVariables() {
-               throw new UnsupportedOperationException("For Andy to implement!");
+               if (declaration.typeParameters == null) return new TypeVariable[0];
+               TypeVariable[] typeVariables = new TypeVariable[declaration.typeParameters.length];
+               for (int i = 0; i < typeVariables.length; i++) {
+                       typeVariables[i] = typeParameter2TypeVariable(declaration.typeParameters[i]);
+               }
+               return typeVariables;
        }
        
+       private TypeVariable typeParameter2TypeVariable(TypeParameter aTypeParameter) {
+               String name = new String(aTypeParameter.name);
+               ReferenceBinding superclassBinding = aTypeParameter.binding.superclass;
+               TypeX superclass = TypeX.forSignature(new String(superclassBinding.signature()));
+               // TODO AMC - superinterfaces
+               return new TypeVariable(name,superclass);
+       }
 }