]> source.dussan.org Git - aspectj.git/commitdiff
code for 116679: targetting a 1.2.1 runtime
authoraclement <aclement>
Tue, 29 Nov 2005 13:21:24 +0000 (13:21 +0000)
committeraclement <aclement>
Tue, 29 Nov 2005 13:21:24 +0000 (13:21 +0000)
16 files changed:
lib/aspectj/lib/aspectjrt121.jar [new file with mode: 0644]
org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/messages.properties
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildConfig.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjCompilerOptions.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AspectJBuilder.java
tests/bugs150/pr111667/A.java [new file with mode: 0644]
tests/bugs150/pr111667/X.java [new file with mode: 0644]
tests/bugs150/pr111667/Y.java [new file with mode: 0644]
tests/compatibility/Simple.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java
tests/src/org/aspectj/systemtest/ajc150/ajc150.xml
weaver/src/org/aspectj/weaver/Constants.java
weaver/src/org/aspectj/weaver/World.java
weaver/src/org/aspectj/weaver/bcel/LazyClassGen.java

diff --git a/lib/aspectj/lib/aspectjrt121.jar b/lib/aspectj/lib/aspectjrt121.jar
new file mode 100644 (file)
index 0000000..ee43ae3
Binary files /dev/null and b/lib/aspectj/lib/aspectjrt121.jar differ
index 9db08913dc7165a18f241ad87ac28316529a2b2a..2f4eea60ed67c52baa509f66596aa54b817b3e10 100644 (file)
@@ -20,6 +20,7 @@ import java.util.*;
 import org.aspectj.ajdt.internal.core.builder.*;
 import org.aspectj.bridge.*;
 import org.aspectj.util.*;
+import org.aspectj.weaver.Constants;
 import org.aspectj.weaver.Dump;
 import org.aspectj.weaver.WeaverMessages;
 import org.aspectj.org.eclipse.jdt.core.compiler.InvalidInputException;
@@ -637,6 +638,14 @@ public class BuildArgParser extends Main {
                buildConfig.setProceedOnError(true);
             } else if (new File(arg).isDirectory()) {
                 showError("dir arg not permitted: " + arg);
+            } else if (arg.startsWith("-Xajruntimetarget")) {
+                       if (arg.endsWith(":1.2")) {
+                       buildConfig.setTargetAspectjRuntimeLevel(Constants.RUNTIME_LEVEL_12);
+                       } else if (arg.endsWith(":1.5")) {
+                       buildConfig.setTargetAspectjRuntimeLevel(Constants.RUNTIME_LEVEL_15);
+                       } else {
+                               showError("-Xajruntimetarget:<level> only supports a target level of 1.2 or 1.5");
+                       }
             } else if (arg.equals("-1.5")) {
                buildConfig.setBehaveInJava5Way(true);
                unparsedArgs.add("-1.5");
index a297978eca10f2209053d58fb8e8c92bd67d5621..3feed9b3dd8f925c7c0254c06cb4808f51dd51dd 100644 (file)
@@ -131,6 +131,8 @@ xoption.usage = {0} non-standard options:\n\
 \t-XserializableAspects allows aspects to implement serializable\n\
 \t-XnoWeave           compile classes but do not weave. Deprecated, use\n\
 \t                    reweavable instead.\n\
+\t-Xajruntimelevel:<level> allows code to be generated that targets\n\
+\t                    a 1.2 or a 1.5 level AspectJ runtime (default 1.5)\n\
 \t-XhasMember         allow hasmethod() and hasfield type patterns in\n\
 \t                    declare parents and declare @type\n
 ## options not documented above (per ..ajdt.ajc.BuildArgParser.java):
index 505b80844e8545fd3bab67ab8e3f05ec81c8b60a..25200a327cb16c8f31d73aa05d400a7032d6d7d2 100644 (file)
@@ -571,4 +571,12 @@ public class AjBuildConfig {
        public boolean getBehaveInJava5Way() {
                return options.behaveInJava5Way;
        }
+       
+       public void setTargetAspectjRuntimeLevel(String level) {
+               options.targetAspectjRuntimeLevel = level;
+       }
+
+       public String getTargetAspectjRuntimeLevel() {
+               return options.targetAspectjRuntimeLevel;
+       }
 }
index 63ad260afc34d4dc0aa56a55072c6e21369d56fd..0cbb761db5390b541cd0bd093890c9a5e6afc003 100644 (file)
@@ -608,6 +608,7 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc
                cp.addAll(buildConfig.getClasspath());
                BcelWorld bcelWorld = new BcelWorld(cp, handler, null);
                bcelWorld.setBehaveInJava5Way(buildConfig.getBehaveInJava5Way());
+               bcelWorld.setTargetAspectjRuntimeLevel(buildConfig.getTargetAspectjRuntimeLevel());
                bcelWorld.setXnoInline(buildConfig.isXnoInline());
                bcelWorld.setXlazyTjp(buildConfig.isXlazyTjp());
                bcelWorld.setXHasMemberSupportEnabled(buildConfig.isXHasMemberEnabled());
index 7481b4ffc5238fb33f5cba354c3c2999ada879ee..d5f04d885d92f4bd7ca38722f654346f97591c1e 100644 (file)
@@ -17,6 +17,7 @@ import java.util.Map;
 
 import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode;
 import org.aspectj.org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+import org.aspectj.weaver.Constants;
 
 
 /**
@@ -73,6 +74,9 @@ public class AjCompilerOptions extends CompilerOptions {
        // If true - autoboxing behaves differently ...
        public boolean behaveInJava5Way = false;
        
+       // Specifies the level of the aspectjrt.jar we are targetting
+       public String targetAspectjRuntimeLevel = Constants.RUNTIME_LEVEL_DEFAULT;
+       
        // these next four not exposed by IDEs
        public boolean generateModel = false;
        public boolean generateJavaDocsInModel = false;
index 8bfa9b9d6aa18a2f98d1ab4708b0f4ba5c7fd942..84371f08a56dd165ee74556f149c97e362600eed 100644 (file)
@@ -156,6 +156,7 @@ public class AspectJBuilder extends JavaBuilder implements ICompilerAdapterFacto
                cpManager = new EclipseClassPathManager(nameEnvironment);
                myBcelWorld = new BcelWorld(cpManager,new UnhandledMessageHandler(getProject()),null /*(xrefHandler)*/);
                myBcelWorld.setBehaveInJava5Way(options.behaveInJava5Way);
+               myBcelWorld.setTargetAspectjRuntimeLevel(options.targetAspectjRuntimeLevel);
                myBcelWorld.setXnoInline(options.xNoInline);
                myBcelWorld.setXlazyTjp(options.xLazyThisJoinPoint);
                myBcelWorld.setXHasMemberSupportEnabled(options.xHasMember);
diff --git a/tests/bugs150/pr111667/A.java b/tests/bugs150/pr111667/A.java
new file mode 100644 (file)
index 0000000..431af1b
--- /dev/null
@@ -0,0 +1,13 @@
+public class A{
+  public static void main(String []argv) {
+    A a = new A();
+    a.m1();
+    a.m2();
+    a.m3();
+  }
+
+  public void m1() {}
+  public void m2() {}
+  public void m3() {}
+}
+
diff --git a/tests/bugs150/pr111667/X.java b/tests/bugs150/pr111667/X.java
new file mode 100644 (file)
index 0000000..232adb7
--- /dev/null
@@ -0,0 +1,3 @@
+public aspect X {
+  before():execution(* m1()) {}
+}
diff --git a/tests/bugs150/pr111667/Y.java b/tests/bugs150/pr111667/Y.java
new file mode 100644 (file)
index 0000000..8ed31b5
--- /dev/null
@@ -0,0 +1,4 @@
+public aspect Y {
+
+  before():execution(* m1()) {}
+}
diff --git a/tests/compatibility/Simple.java b/tests/compatibility/Simple.java
new file mode 100644 (file)
index 0000000..72fec18
--- /dev/null
@@ -0,0 +1,21 @@
+public class Simple {
+  public static void main(String []argv) {
+    new Simple().a();
+  }
+
+  public void a() {}
+}
+
+aspect X {
+   before():execution(* a(..)) {
+     System.err.println(thisJoinPoint);
+     System.err.println(thisJoinPointStaticPart);
+     System.err.println(thisEnclosingJoinPointStaticPart);
+   }
+
+   before():execution(Simple.new(..)) {
+     System.err.println(thisJoinPoint);
+     System.err.println(thisEnclosingJoinPointStaticPart);
+     System.err.println(thisJoinPointStaticPart);
+   }
+}
index 282e04c8bee295cf8f7272425cb30c16c1cd0e19..c692b30d9579f18a6b40a815a6d4db6368a3c300 100644 (file)
@@ -48,6 +48,7 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
   public void testCunningDeclareParents_pr92311() { runTest("cunning declare parents");}
   public void testGenericITDsAndAbstractMethodError_pr102357() { runTest("generic itds and abstract method error");}
   */
+  public void testGeneratingCodeForAnOldRuntime_pr116679() { runTest("generating code for a 1.2.1 runtime");}
   
   public void testAtDeclareParents_pr117681() { runTest("at declare parents");}
   public void testPrivilegeProblem_pr87525() { runTest("privilege problem with switch");}
@@ -79,6 +80,7 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
 
   public void testVarargsITD_pr110906() { runTest("ITD varargs problem");}
   public void testBadRenderer_pr86903() { runTest("bcelrenderer bad");}
+  //public void testLintForAdviceSorting_pr111667() { runTest("lint for advice sorting");}
   
   public void testIncompatibleClassChangeError_pr113630_1() {runTest("IncompatibleClassChangeError - errorscenario");}
   public void testIncompatibleClassChangeError_pr113630_2() {runTest("IncompatibleClassChangeError - workingscenario");}
index bc6d6d0099dd500847664e84d5b2539260a881c0..fc64570434ad72f4ea3cb924d418b8eb4078f513 100644 (file)
      <run class="Test"/>
     </ajc-test>
     
+    <ajc-test dir="bugs150/pr111667" pr="111667" title="lint for advice sorting">
+     <compile files="A.java,X.java,Y.java" options="-1.5">
+     </compile>
+    </ajc-test>
+
     <ajc-test dir="bugs150/pr117296" pr="117296" title="self bounding generic types">
      <compile files="PropertySupport.java" options="-1.5"/>
      <run class="PropertySupport"/>
                <run class="ReflectOnAjcCompiledPointcuts" classpath="../lib/bcel/bcel.jar"/>
        </ajc-test>
        
+       <ajc-test dir="compatibility" title="generating code for a 1.2.1 runtime">
+               <compile files="Simple.java" options="-Xajruntimetarget:1.2"></compile>
+               <run class="Simple" classpath="../lib/aspectj/lib/aspectjrt121.jar"/>
+       </ajc-test>
+       
        <ajc-test dir="java5/reflection" pr="114322" title="reflection on abstract ITDs (Billing example)">
                <compile files="ReflectBilling.java,Billing.aj" options="-1.5"/>
                <run class="ReflectBilling">
index e51bf96c26c5a55a9ac2d8c0bb61da68a970f783..9962f893c3183d874d7c86fc2f82698990411084 100644 (file)
@@ -21,4 +21,10 @@ public interface Constants {
 
        public final static int ACC_BRIDGE  = 0x0040;
        public final static int ACC_VARARGS = 0x0080;
+       
+       public final static String RUNTIME_LEVEL_12 = "1.2";
+       public final static String RUNTIME_LEVEL_15 = "1.5";
+       
+       // Default for 1.5.0
+       public final static String RUNTIME_LEVEL_DEFAULT = RUNTIME_LEVEL_15;
 }
index 31db56be9308b2ec92272c6c9e4f6adccf5ac99b..3f1bd7faf9497218d42c8f6a397f9a0f7eb810f6 100644 (file)
@@ -79,6 +79,9 @@ public abstract class World implements Dump.INode {
     /** When behaving in a Java 5 way autoboxing is considered */
     private boolean behaveInJava5Way = false;
     
+    /** The level of the aspectjrt.jar the code we generate needs to run on */
+    private String targetAspectjRuntimeLevel = Constants.RUNTIME_LEVEL_DEFAULT;
+    
     /** 
      * A list of RuntimeExceptions containing full stack information for every
      * type we couldn't find.
@@ -644,6 +647,14 @@ public abstract class World implements Dump.INode {
                return behaveInJava5Way;
        }
        
+       public void setTargetAspectjRuntimeLevel(String s) {
+               targetAspectjRuntimeLevel = s;
+       }
+       
+       public String getTargetAspectjRuntimeLevel() {
+               return targetAspectjRuntimeLevel;
+       }
+       
        /*
         *  Map of types in the world, with soft links to expendable ones.
         *  An expendable type is a reference type that is not exposed to the weaver (ie
index f97eacbdffc7e90b833b0ba758f27a539e3591d4..806b4e82ccad484d00fa7cd0e082ff3d6d7c5f04 100644 (file)
@@ -999,7 +999,14 @@ public final class LazyClassGen {
        // create the signature
        list.append(InstructionFactory.createLoad(factoryType, 0));
        
-       if (sig.getKind().equals(Member.METHOD)) {
+       if (world.getTargetAspectjRuntimeLevel().equals(org.aspectj.weaver.Constants.RUNTIME_LEVEL_12)) {
+               list.append(new PUSH(getConstantPoolGen(), sig.getSignatureString(shadow.getWorld())));
+               list.append(fact.createInvoke(factoryType.getClassName(), 
+                                       sig.getSignatureMakerName(),
+                                       new ObjectType(sig.getSignatureType()),
+                                       new Type[] { Type.STRING },
+                                       Constants.INVOKEVIRTUAL));
+       } else  if (sig.getKind().equals(Member.METHOD)) {
                BcelWorld w = shadow.getWorld();
                // For methods, push the parts of the signature on.
                list.append(new PUSH(getConstantPoolGen(),makeString(sig.getModifiers(w))));
@@ -1079,6 +1086,7 @@ public final class LazyClassGen {
                                   new Type[] { Type.STRING },
                                   Constants.INVOKEVIRTUAL));
        }       
+       
        //XXX should load source location from shadow
        list.append(Utility.createConstant(fact, shadow.getSourceLine()));