aboutsummaryrefslogtreecommitdiffstats
path: root/org.aspectj.ajdt.core
diff options
context:
space:
mode:
authoracolyer <acolyer>2005-07-11 09:34:44 +0000
committeracolyer <acolyer>2005-07-11 09:34:44 +0000
commit28141bcd8d99a2867d7e9c840720340c89e21345 (patch)
tree41eb4e43dee23b611ca277c25049dd4221431f71 /org.aspectj.ajdt.core
parentf17c6344c9785d688c91aedfe42f0eae344c2660 (diff)
downloadaspectj-28141bcd8d99a2867d7e9c840720340c89e21345.tar.gz
aspectj-28141bcd8d99a2867d7e9c840720340c89e21345.zip
beginnings of proper type variable support in Eclipse type world
Diffstat (limited to 'org.aspectj.ajdt.core')
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java32
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java15
2 files changed, 38 insertions, 9 deletions
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java
index ec8ed951d..9f6c2cc28 100644
--- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java
+++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseFactory.java
@@ -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;
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java
index c473d57c1..d6ce0b6da 100644
--- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java
+++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java
@@ -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);
+ }
}