]> source.dussan.org Git - aspectj.git/commitdiff
TypeX hierarchy members for bounded reference types and type variables
authoracolyer <acolyer>
Fri, 8 Jul 2005 10:21:35 +0000 (10:21 +0000)
committeracolyer <acolyer>
Fri, 8 Jul 2005 10:21:35 +0000 (10:21 +0000)
weaver/src/org/aspectj/weaver/BoundedReferenceType.java [new file with mode: 0644]
weaver/src/org/aspectj/weaver/GenericsWildcardTypeX.java [new file with mode: 0644]
weaver/src/org/aspectj/weaver/TypeVariableReferenceType.java [new file with mode: 0644]

diff --git a/weaver/src/org/aspectj/weaver/BoundedReferenceType.java b/weaver/src/org/aspectj/weaver/BoundedReferenceType.java
new file mode 100644 (file)
index 0000000..70085f2
--- /dev/null
@@ -0,0 +1,183 @@
+/* *******************************************************************
+ * Copyright (c) 2005 Contributors.
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * 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;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import org.aspectj.weaver.patterns.PerClause;
+
+/**
+ * A BoundedReferenceType is the result of a generics wildcard expression
+ * ? extends String, ? super Foo etc..
+ * The "signature" for a bounded reference type follows the generic signature
+ * specification in section 4.4 of JVM spec: *,+,- plus signature strings
+ */
+public class BoundedReferenceType extends ReferenceType {
+       protected ReferenceType upperBound;
+       protected ReferenceType[] additionalInterfaceBounds = new ReferenceType[0];
+       protected ReferenceType lowerBound = null;
+       protected boolean isExtends = true;
+       protected boolean isSuper = false;
+       
+       public BoundedReferenceType(ReferenceType aBound, boolean isExtends, World world) {
+               super((isExtends ? "+" : "-") + aBound.signature,world);
+               this.isExtends = isExtends; this.isSuper=!isExtends;
+               if (isExtends) { 
+                       this.upperBound = aBound;
+               } else {
+                       this.lowerBound = aBound;
+                       this.upperBound = (ReferenceType) world.resolve(TypeX.OBJECT);
+               }
+               setDelegate(new ReferenceTypeReferenceTypeDelegate(upperBound));
+       }
+       
+       public BoundedReferenceType(ReferenceType aBound, boolean isExtends, World world, ReferenceType[] additionalInterfaces) {
+               this(aBound,isExtends,world);
+               this.additionalInterfaceBounds = additionalInterfaces;
+       }
+       
+       /**
+        * only for use when resolving GenericsWildcardTypeX
+        */
+       BoundedReferenceType(String sig, World world) {
+               super(sig,world);
+               this.upperBound = (ReferenceType) world.resolve(TypeX.OBJECT);
+       }
+       
+       public ReferenceType getUpperBound() { return upperBound; }
+       
+       public ReferenceType[] getInterfaceBounds() { return additionalInterfaceBounds; }
+       
+       public boolean hasLowerBound() {
+               return lowerBound != null;
+       }
+       
+       public ReferenceType getLowerBound() { return lowerBound; }
+       
+       public boolean isExtends() { return isExtends; }
+       public boolean isSuper() { return isSuper; }
+       
+       // override to include additional interface bounds...
+       public ResolvedTypeX[] getDeclaredInterfaces() {
+               ResolvedTypeX[] interfaces = super.getDeclaredInterfaces();
+               if (additionalInterfaceBounds.length > 0) {
+                       ResolvedTypeX[] allInterfaces = 
+                               new ResolvedTypeX[interfaces.length + additionalInterfaceBounds.length];
+                       System.arraycopy(interfaces, 0, allInterfaces, 0, interfaces.length);
+                       System.arraycopy(additionalInterfaceBounds,0,allInterfaces,interfaces.length,additionalInterfaceBounds.length);
+                       return allInterfaces;
+               } else {
+                       return interfaces;
+               }
+       }
+       
+       private static class ReferenceTypeReferenceTypeDelegate extends AbstractReferenceTypeDelegate {
+
+               public ReferenceTypeReferenceTypeDelegate(ReferenceType backing) {
+                       super(backing,false);
+               }
+               
+               public void addAnnotation(AnnotationX annotationX) {
+                       throw new UnsupportedOperationException("What on earth do you think you are doing???");
+               }
+
+               public boolean isAspect() {
+                       return resolvedTypeX.isAspect();
+               }
+
+               public boolean isAnnotationStyleAspect() {
+                       return resolvedTypeX.isAnnotationStyleAspect();
+               }
+
+               public boolean isInterface() {
+                       return resolvedTypeX.isInterface();
+               }
+
+               public boolean isEnum() {
+                       return resolvedTypeX.isEnum();
+               }
+
+               public boolean isAnnotation() {
+                       return resolvedTypeX.isAnnotation();
+               }
+
+               public boolean isAnnotationWithRuntimeRetention() {
+                       return resolvedTypeX.isAnnotationWithRuntimeRetention();
+               }
+
+               public boolean isGeneric() {
+                       return resolvedTypeX.isGeneric();
+               }
+
+               public String getDeclaredGenericSignature() {
+                       return resolvedTypeX.getDeclaredGenericSignature();
+               }
+               
+               public boolean hasAnnotation(TypeX ofType) {
+                       return resolvedTypeX.hasAnnotation(ofType);
+               }
+
+               public AnnotationX[] getAnnotations() {
+                       return resolvedTypeX.getAnnotations();
+               }
+
+               public ResolvedTypeX[] getAnnotationTypes() {
+                       return resolvedTypeX.getAnnotationTypes();
+               }
+
+               public ResolvedMember[] getDeclaredFields() {
+                       return resolvedTypeX.getDeclaredFields();
+               }
+
+               public ResolvedTypeX[] getDeclaredInterfaces() {
+                       return resolvedTypeX.getDeclaredInterfaces();
+               }
+
+               public ResolvedMember[] getDeclaredMethods() {
+                       return resolvedTypeX.getDeclaredMethods();
+               }
+
+               public ResolvedMember[] getDeclaredPointcuts() {
+                       return resolvedTypeX.getDeclaredPointcuts();
+               }
+
+               public PerClause getPerClause() {
+                       return resolvedTypeX.getPerClause();
+               }
+
+               public Collection getDeclares() {
+                       return resolvedTypeX.getDeclares();
+               }
+
+               public Collection getTypeMungers() {
+                       return resolvedTypeX.getTypeMungers();
+               }
+
+               public Collection getPrivilegedAccesses() {
+                       return Collections.EMPTY_LIST;
+               }
+
+               public int getModifiers() {
+                       return resolvedTypeX.getModifiers();
+               }
+
+               public ResolvedTypeX getSuperclass() {
+                       return resolvedTypeX.getSuperclass();
+               }
+
+               public WeaverStateInfo getWeaverState() {
+                       return null;
+               }
+
+       }
+}
diff --git a/weaver/src/org/aspectj/weaver/GenericsWildcardTypeX.java b/weaver/src/org/aspectj/weaver/GenericsWildcardTypeX.java
new file mode 100644 (file)
index 0000000..cd341be
--- /dev/null
@@ -0,0 +1,35 @@
+/* *******************************************************************
+ * Copyright (c) 2005 Contributors.
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * 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;
+
+/**
+ * Represents the ? type in a generics signature prior to resolving.
+ *
+ */
+public class GenericsWildcardTypeX extends TypeX {
+
+       public static final GenericsWildcardTypeX GENERIC_WILDCARD = 
+               new GenericsWildcardTypeX();
+       
+       private BoundedReferenceType resolved = null;
+       
+       private GenericsWildcardTypeX() {
+               super("?");
+       }
+       
+       public ResolvedTypeX resolve(World world) {
+               if (resolved == null) {
+                       resolved = new BoundedReferenceType("?",world);
+               }
+               return resolved;
+       }
+}
diff --git a/weaver/src/org/aspectj/weaver/TypeVariableReferenceType.java b/weaver/src/org/aspectj/weaver/TypeVariableReferenceType.java
new file mode 100644 (file)
index 0000000..38f086f
--- /dev/null
@@ -0,0 +1,49 @@
+/* *******************************************************************
+ * Copyright (c) 2005 Contributors.
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * 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;
+
+/**
+ * Represents a type variable in a type or generic method declaration
+ */
+public class TypeVariableReferenceType extends BoundedReferenceType {
+
+       private String name;
+       
+       public TypeVariableReferenceType(
+                       String aTypeVariableName,
+                       ReferenceType aBound,
+                       boolean isExtends,
+                       World aWorld
+                       ) {
+               super(aBound,isExtends,aWorld);
+               this.name = aTypeVariableName;
+       }
+       
+       public TypeVariableReferenceType(
+                       TypeVariable aTypeVariable,
+                       World aWorld) {
+               super((ReferenceType)aTypeVariable.getUpperBound(),true,aWorld);
+               this.name = aTypeVariable.getName();
+               if (aTypeVariable.getLowerBound() != null) {
+                       this.isExtends = false;
+                       this.isSuper = true;
+                       this.lowerBound = (ReferenceType) aTypeVariable.getLowerBound();
+               }
+               if (aTypeVariable.getAdditionalInterfaceBounds().length > 0) {
+                       this.additionalInterfaceBounds = (ReferenceType[]) aTypeVariable.getAdditionalInterfaceBounds();
+               }
+       }
+       
+       public String getTypeVariableName() {
+               return name;
+       }
+}