]> source.dussan.org Git - aspectj.git/commitdiff
Support annotation conversion for class annotation values
authorAndy Clement <aclement@pivotal.io>
Thu, 6 Aug 2015 20:53:56 +0000 (13:53 -0700)
committerAndy Clement <aclement@pivotal.io>
Thu, 6 Aug 2015 20:53:56 +0000 (13:53 -0700)
Issue: https://bugs.eclipse.org/bugs/show_bug.cgi?id=474165

org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseAnnotationConvertor.java
tests/bugs187/474165/B.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc187/Ajc187Tests.java
tests/src/org/aspectj/systemtest/ajc187/ajc187.xml

index efd2a152a6d84672af8a2d7059511a690aeb7a3a..47c56f93903f1644107d2b7f5b1cfae0a09936e3 100644 (file)
@@ -14,6 +14,7 @@ package org.aspectj.ajdt.internal.compiler.lookup;
 import org.aspectj.apache.bcel.classfile.annotation.ElementValue;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ArrayInitializer;
+import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Expression;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.MarkerAnnotation;
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.MemberValuePair;
@@ -33,6 +34,7 @@ import org.aspectj.weaver.AnnotationAJ;
 import org.aspectj.weaver.AnnotationNameValuePair;
 import org.aspectj.weaver.AnnotationValue;
 import org.aspectj.weaver.ArrayAnnotationValue;
+import org.aspectj.weaver.ClassAnnotationValue;
 import org.aspectj.weaver.EnumAnnotationValue;
 import org.aspectj.weaver.ResolvedType;
 import org.aspectj.weaver.SimpleAnnotationValue;
@@ -218,24 +220,14 @@ public class EclipseAnnotationConvertor {
                                }
                        } else {
                                // class type
+                               if (defaultValue instanceof ClassLiteralAccess) {
+                                       ClassLiteralAccess cla = (ClassLiteralAccess)defaultValue;
+                                       ClassAnnotationValue cav = new ClassAnnotationValue(new String(cla.targetType.signature()));
+                                       return cav;                                     
+                               }
                                throw new MissingImplementationException(
                                                "Please raise an AspectJ bug.  AspectJ does not know how to convert this annotation value [" + defaultValue
                                                                + "]");
-                               // if (contentsOffset + 3 >= this.contents.length) {
-                               // resizeContents(3);
-                               // }
-                               // contents[contentsOffset++] = (byte) 'c';
-                               // if (defaultValue instanceof ClassLiteralAccess) {
-                               // ClassLiteralAccess classLiteralAccess = (ClassLiteralAccess)
-                               // defaultValue;
-                               // final int classInfoIndex =
-                               // constantPool.literalIndex(classLiteralAccess
-                               // .targetType.signature());
-                               // contents[contentsOffset++] = (byte) (classInfoIndex >> 8);
-                               // contents[contentsOffset++] = (byte) classInfoIndex;
-                               // } else {
-                               // contentsOffset = attributeOffset;
-                               // }
                        }
                } else {
                        throw new MissingImplementationException(
diff --git a/tests/bugs187/474165/B.java b/tests/bugs187/474165/B.java
new file mode 100644 (file)
index 0000000..7b1bb19
--- /dev/null
@@ -0,0 +1,20 @@
+// HasMethod with anno value matching
+
+@interface I {
+  Class i();
+}
+aspect A {
+  declare parents: hasmethod(@I(i=String.class) * *(..)) implements java.io.Serializable;
+}
+
+public class B {
+@I(i=String.class)  public void m() {}
+  public static void main(String []argv) {
+    B b = new B();
+    if (!(b instanceof java.io.Serializable)) throw new IllegalStateException("");
+  }
+}
+class C {
+@I(i=Integer.class)  public void m() {}
+}
+
index 14831793306ecf22ebf1ab92a8884b37f7e54690..4907eeafe9b6c1dc2a9284a50f84ce857fd4b7e3 100644 (file)
@@ -24,6 +24,10 @@ import org.aspectj.testing.XMLBasedAjcTestCase;
  */
 public class Ajc187Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
 
+       public void testAnnoConversion_474165() throws Exception {
+               runTest("anno conversion");
+       }
+       
        public void testLambda_470633() throws Exception {
                runTest("lambda");
        }
index 0413c55ef02910b02d364b20659e1bc86b49b446..ccf87e34fbc8378e7c5098dfd9b94dac7f997472 100644 (file)
 <compile files="Maps.java" options="-1.8"/>
 </ajc-test>
 
+<ajc-test dir="bugs187/474165" title="anno conversion">
+<compile files="B.java" options="-XhasMember -1.8 -showWeaveInfo">
+<message kind="weave" text="Extending interface set for type 'B' (B.java) to include 'java.io.Serializable' (B.java)"/>
+</compile>
+<run class="B"></run>
+</ajc-test>
+
 </suite>