]> source.dussan.org Git - aspectj.git/commitdiff
Reduced duplication of vm checking logic.
authoraclement <aclement>
Thu, 12 May 2005 10:49:25 +0000 (10:49 +0000)
committeraclement <aclement>
Thu, 12 May 2005 10:49:25 +0000 (10:49 +0000)
ajde/testsrc/org/aspectj/ajde/ShowWeaveMessagesTestCase.java
org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/AjcTestCase.java
tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java
util/src/org/aspectj/util/LangUtil.java
weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternMatchingTestCase.java
weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternTestCase.java

index 2ea90022a92d7a5179ab7f4bfe64fe197812a87b..525e91e526d043e0443b74ed98316430a486f69f 100644 (file)
@@ -24,7 +24,9 @@ import java.util.Set;
 
 import org.aspectj.ajde.internal.CompilerAdapter;
 import org.aspectj.bridge.IMessage;
+import org.aspectj.tools.ajc.AjcTestCase;
 import org.aspectj.util.FileUtil;
+import org.aspectj.util.LangUtil;
 
 /**
  * Weaving messages are complicated things.  There are multiple places where weaving
@@ -68,19 +70,6 @@ public class ShowWeaveMessagesTestCase extends AjdeTestCase {
                // 'expected weaving messages' files.
                regenerate = false;
        }
-       
-       private static boolean is13VMOrGreater = true;
-       private static boolean is14VMOrGreater = true;
-       private static boolean is15VMOrGreater = false;
-       
-       static {
-               String vm = System.getProperty("java.vm.version");
-               if (vm.startsWith("1.3")) {
-                       is14VMOrGreater = false;
-               } else if (vm.startsWith("1.5")) {
-                       is15VMOrGreater = true;
-               }
-       }
 
        
        private CompilerAdapter compilerAdapter;
@@ -175,7 +164,7 @@ public class ShowWeaveMessagesTestCase extends AjdeTestCase {
         * Weave 'declare @type, @constructor, @method and @field' and check the weave messages that come out.
         */
        public void testWeaveMessagesDeclareAnnotation() {
-               if (!is15VMOrGreater) return; // annotation classes won't be about pre 15
+               if (!LangUtil.is15VMOrGreater()) return; // annotation classes won't be about pre 15
                if (debugTests) System.out.println("\ntestWeaveMessagesDeclareAnnotation: Building with Six.lst");
                compilerAdapter = new CompilerAdapter();
                compilerAdapter.showInfoMessages(true);
index c4cace3b30a7409e0da1f974897babd7b3f3b1ad..41bb20bc3ef4fa60824c4c2c31f0da3344cac0e3 100644 (file)
@@ -52,18 +52,6 @@ public class AjcTestCase extends TestCase {
 
        private RunResult lastRunResult;
        
-       protected static boolean is13VMOrGreater = true;
-       protected static boolean is14VMOrGreater = true;
-       protected static boolean is15VMOrGreater = false;
-       
-       static {
-               String vm = System.getProperty("java.vm.version");
-               if (vm.startsWith("1.3")) {
-                       is14VMOrGreater = false;
-               } else if (vm.startsWith("1.5")) {
-                       is15VMOrGreater = true;
-               }
-       }
        
        /**
         * The Ajc (compiler) instance used for thet test. Created afresh
index b84ee076e0715c5ddfe1108078bc7da0731b6c2b..4bae9cf4c4cad6660c0c9348599d5026f6650c40 100644 (file)
@@ -23,6 +23,7 @@ import org.aspectj.apache.bcel.util.ClassPath;
 import org.aspectj.apache.bcel.util.SyntheticRepository;
 import org.aspectj.asm.AsmManager;
 import org.aspectj.testing.XMLBasedAjcTestCase;
+import org.aspectj.util.LangUtil;
 
 /**
  * These are tests that will run on Java 1.4 and use the old harness format for test specification.
@@ -115,7 +116,7 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
   public void testBadASMforEnums() throws IOException {
        runTest("bad asm for enums");
        
-       if (System.getProperty("java.vm.version").startsWith("1.5")) {
+       if (LangUtil.is15VMOrGreater()) {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                PrintWriter pw = new PrintWriter(baos);
                AsmManager.dumptree(pw,AsmManager.getDefault().getHierarchy().getRoot(),0);
index ce339e0a173a1164631be387dc9f24875e6eec86..9d3103011d0ad7305ecd2f9e6e1535cc7e99b2f5 100644 (file)
@@ -86,6 +86,24 @@ public class LangUtil {
             return false;
         }        
     }
+       
+       private static boolean is13VMOrGreater = true;
+       private static boolean is14VMOrGreater = true;
+       private static boolean is15VMOrGreater = false;
+       
+       static {
+               String vm = System.getProperty("java.runtime.version");
+               if (vm==null) vm = System.getProperty("java.vm.version");
+               if (vm.startsWith("1.3")) {
+                       is14VMOrGreater = false;
+               } else if (vm.startsWith("1.5")) {
+                       is15VMOrGreater = true;
+               }
+       }
+       
+       public static boolean is13VMOrGreater() { return is13VMOrGreater;}
+       public static boolean is14VMOrGreater() { return is14VMOrGreater;}
+       public static boolean is15VMOrGreater() { return is15VMOrGreater;}
     
     /**
      * Shorthand for "if null, throw IllegalArgumentException"
index 35c191bbbc2693b88dc9f7ab827649979b9fd53b..37506ad484c56fa00bf04de68cae23d17e2be7fb 100644 (file)
@@ -20,6 +20,7 @@ import org.aspectj.bridge.AbortException;
 import org.aspectj.bridge.IMessage;
 import org.aspectj.bridge.IMessageHandler;
 import org.aspectj.bridge.IMessage.Kind;
+import org.aspectj.util.LangUtil;
 import org.aspectj.weaver.BcweaverTests;
 import org.aspectj.weaver.ResolvedMember;
 import org.aspectj.weaver.ResolvedTypeX;
@@ -61,19 +62,6 @@ public class AnnotationPatternMatchingTestCase extends TestCase {
        private BcelWorld world;
        private AnnotationTypePattern fooTP,simpleAnnotationTP;
        
-       private static boolean is13VMOrGreater = true;
-       private static boolean is14VMOrGreater = true;
-       private static boolean is15VMOrGreater = false;
-       
-       static {
-               String vm = System.getProperty("java.vm.version");
-               if (vm.startsWith("1.3")) {
-                       is14VMOrGreater = false;
-               } else if (vm.startsWith("1.5")) {
-                       is15VMOrGreater = true;
-               }
-       }
-       
        private ResolvedTypeX loadType(String name) {
                if (world == null) {
                  world = new BcelWorld(BcweaverTests.TESTDATA_PATH + "/testcode.jar");
@@ -93,7 +81,7 @@ public class AnnotationPatternMatchingTestCase extends TestCase {
        
        
        public void testAnnotationPatternMatchingOnTypes() {
-               if (is15VMOrGreater) {
+               if (LangUtil.is15VMOrGreater()) {
                ResolvedTypeX rtx = loadType("AnnotatedClass");
         initAnnotationTypePatterns();          
                
@@ -170,7 +158,7 @@ public class AnnotationPatternMatchingTestCase extends TestCase {
        }
        
        public void testAnnotationPatternMatchingOnMethods() {
-               if (is15VMOrGreater) {
+               if (LangUtil.is15VMOrGreater()) {
                ResolvedTypeX rtx = loadType("AnnotatedClass");
                ResolvedMember aMethod = rtx.getDeclaredMethods()[1];
         
@@ -188,7 +176,7 @@ public class AnnotationPatternMatchingTestCase extends TestCase {
        }
        
        public void testAnnotationPatternMatchingOnFields() {
-               if (is15VMOrGreater) {
+               if (LangUtil.is15VMOrGreater()) {
                ResolvedTypeX rtx = loadType("AnnotatedClass");
                ResolvedMember aField = rtx.getDeclaredFields()[0];
 
index 02f0e274ec9683292de76055eeca845f049de11e..7697b43d793a1aedb59941e3b6245d0e315006f8 100644 (file)
@@ -10,6 +10,7 @@
 package org.aspectj.weaver.patterns;
 
 import org.aspectj.bridge.AbortException;
+import org.aspectj.util.LangUtil;
 import org.aspectj.weaver.AnnotatedElement;
 import org.aspectj.weaver.ResolvedTypeX;
 import org.aspectj.weaver.BcweaverTests;
@@ -20,18 +21,7 @@ import junit.framework.TestCase;
 
 public class AnnotationPatternTestCase extends TestCase {
        
-       private static boolean is13VMOrGreater = true;
-       private static boolean is14VMOrGreater = true;
-       private static boolean is15VMOrGreater = false;
-       
-       static {
-               String vm = System.getProperty("java.vm.version");
-               if (vm.startsWith("1.3")) {
-                       is14VMOrGreater = false;
-               } else if (vm.startsWith("1.5")) {
-                       is15VMOrGreater = true;
-               }
-       }
+
        
        public void testParseSimpleAnnotationPattern() {
                PatternParser p = new PatternParser("@Foo");
@@ -254,7 +244,7 @@ public class AnnotationPatternTestCase extends TestCase {
        }
        
        public void testExactAnnotationPatternMatching() {
-               if (is15VMOrGreater) {
+               if (LangUtil.is15VMOrGreater()) {
                PatternParser p = new PatternParser("@Foo");
                AnnotationTypePattern ap = p.maybeParseAnnotationPattern();
                ap = ap.resolveBindings(makeSimpleScope(),new Bindings(3),true);
@@ -266,7 +256,7 @@ public class AnnotationPatternTestCase extends TestCase {
        }
        
        public void testBindingAnnotationPatternMatching() {
-               if (is15VMOrGreater) {
+               if (LangUtil.is15VMOrGreater()) {
                PatternParser p = new PatternParser("foo");
                AnnotationTypePattern ap = p.parseAnnotationNameOrVarTypePattern();
                try {
@@ -283,7 +273,7 @@ public class AnnotationPatternTestCase extends TestCase {
        }
        
        public void testAndAnnotationPatternMatching() {
-               if (is15VMOrGreater) {
+               if (LangUtil.is15VMOrGreater()) {
                PatternParser p = new PatternParser("@Foo @Boo");
                AnnotationTypePattern ap = p.maybeParseAnnotationPattern();
                ap = ap.resolveBindings(makeSimpleScope(),new Bindings(3),true);
@@ -313,7 +303,7 @@ public class AnnotationPatternTestCase extends TestCase {
 //     }
 //     
        public void testNotAnnotationPatternMatching() {
-               if (is15VMOrGreater) {
+               if (LangUtil.is15VMOrGreater()) {
                PatternParser p = new PatternParser("!@Foo");
                AnnotationTypePattern ap = p.maybeParseAnnotationPattern();
                ap = ap.resolveBindings(makeSimpleScope(),new Bindings(3),true);