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;
* 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) {
}
// 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) {
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;
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.*;
/**
}
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);
+ }
}