]> source.dussan.org Git - aspectj.git/commitdiff
Fix 449739: support is(FinalType)
authorAndy Clement <aclement@gopivotal.com>
Wed, 5 Nov 2014 16:27:45 +0000 (08:27 -0800)
committerAndy Clement <aclement@gopivotal.com>
Wed, 5 Nov 2014 16:27:45 +0000 (08:27 -0800)
org.aspectj.matcher/src/org/aspectj/weaver/patterns/PatternParser.java
org.aspectj.matcher/src/org/aspectj/weaver/patterns/TypeCategoryTypePattern.java
tests/bugs184/449739/Code.java [new file with mode: 0644]
tests/bugs184/449739/Code2.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc184/Ajc184Tests.java
tests/src/org/aspectj/systemtest/ajc184/ajc184.xml

index 6bcb4ce4aa8c2bc3b06659b3fd96d2c8ab4ec5b1..106376aada0a94afeee16d81d8e92dc12147ad68 100644 (file)
@@ -1064,6 +1064,8 @@ public class PatternParser {
                                typeIsPattern = new TypeCategoryTypePattern(TypeCategoryTypePattern.ENUM);
                        } else if (category.equals("AnnotationType")) {
                                typeIsPattern = new TypeCategoryTypePattern(TypeCategoryTypePattern.ANNOTATION);
+                       } else if (category.equals("FinalType")) {
+                               typeIsPattern = new TypeCategoryTypePattern(TypeCategoryTypePattern.FINAL);
                        }
                }
                if (typeIsPattern == null) {
index 9f565b20d5e7f1d66cce046d613c70d9cb86c37f..72efea400addbbb6d6d95b5698ce30326898dd56 100644 (file)
@@ -14,6 +14,7 @@
 package org.aspectj.weaver.patterns;
 
 import java.io.IOException;
+import java.lang.reflect.Modifier;
 import java.util.Map;
 
 import org.aspectj.util.FuzzyBoolean;
@@ -40,6 +41,7 @@ public class TypeCategoryTypePattern extends TypePattern {
        public static final int ANONYMOUS = 5;
        public static final int ENUM = 6;
        public static final int ANNOTATION = 7;
+       public static final int FINAL = 8;
 
        private int category;
 
@@ -104,6 +106,7 @@ public class TypeCategoryTypePattern extends TypePattern {
                writeLocation(s);
        }
 
+       @SuppressWarnings("unused")
        public static TypePattern read(VersionedDataInputStream s, ISourceContext context) throws IOException {
                int version = s.readInt();
                int category = s.readInt();
@@ -131,6 +134,8 @@ public class TypeCategoryTypePattern extends TypePattern {
                        return type.isEnum();
                case ANNOTATION:
                        return type.isAnnotation();
+               case FINAL:
+                       return Modifier.isFinal(type.getModifiers());
                }
                return false;
        }
diff --git a/tests/bugs184/449739/Code.java b/tests/bugs184/449739/Code.java
new file mode 100644 (file)
index 0000000..452c1d7
--- /dev/null
@@ -0,0 +1,20 @@
+public class Code {
+  public static void main(String[] argv) {
+    new Code().run();
+  }
+
+  public void run() {
+    new Code2().run();
+  }
+}
+
+final class Code2 {
+  public void run() {
+  }
+}
+
+aspect X {
+  before(): execution(* (!is(FinalType)).run(..)) {
+    System.out.println(thisJoinPointStaticPart);
+  }
+}
diff --git a/tests/bugs184/449739/Code2.java b/tests/bugs184/449739/Code2.java
new file mode 100644 (file)
index 0000000..1ad0fee
--- /dev/null
@@ -0,0 +1,20 @@
+public class Code2 {
+  public static void main(String[] argv) {
+    new Code2().run();
+  }
+
+  public void run() {
+    new Helper().run();
+  }
+}
+
+final class Helper {
+  public void run() {
+  }
+}
+
+aspect X {
+  before(): execution(* (is(FinalType)).run(..)) {
+    System.out.println(thisJoinPointStaticPart);
+  }
+}
index 7ba5654abb8f1cfefede3830a41db7487d5a1028..7e1265a0b5b618d8c818994ce92e3c0476874786 100644 (file)
@@ -97,6 +97,15 @@ public class Ajc184Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
                // abstract aspects
                runTest("thisAspectInstance - 15");
        }
+       
+       public void testIsFinal_449739() {
+               runTest("is final");
+       }
+
+       public void testIsFinal_449739_2() {
+               runTest("is final - 2");
+       }
+       
        // ---
 
        public static Test suite() {
index 01d4d2312b546178ebbf2b155262150242353d24..3010ce1690a9276f484b33aa2ebef2cb8a6e4687 100644 (file)
 </compile>
 </ajc-test>
 
+<ajc-test dir="bugs184/449739" title="is final">
+<compile files="Code.java" options="-1.8"/>
+<run class="Code">
+  <stdout>
+  <line text="execution(void Code.run())"/>
+  </stdout>
+</run>
+</ajc-test>
+
+<ajc-test dir="bugs184/449739" title="is final - 2">
+<compile files="Code2.java" options="-1.8"/>
+<run class="Code2">
+  <stdout>
+  <line text="execution(void Helper.run())"/>
+  </stdout>
+</run>
+</ajc-test>
+
 <ajc-test dir="bugs1612/pr239649" title="thisAspectInstance - 12">
 <compile files="Twelve.java" options="-1.8"/>
 <run class="Twelve">