]> source.dussan.org Git - aspectj.git/commitdiff
fix for 103741 - use of java 5 specific language features now policed at < 1.5 source...
authoracolyer <acolyer>
Fri, 4 Nov 2005 09:05:41 +0000 (09:05 +0000)
committeracolyer <acolyer>
Fri, 4 Nov 2005 09:05:41 +0000 (09:05 +0000)
13 files changed:
weaver/src/org/aspectj/weaver/WeaverMessages.java
weaver/src/org/aspectj/weaver/patterns/AnnotationPointcut.java
weaver/src/org/aspectj/weaver/patterns/ArgsAnnotationPointcut.java
weaver/src/org/aspectj/weaver/patterns/DeclareAnnotation.java
weaver/src/org/aspectj/weaver/patterns/ThisOrTargetAnnotationPointcut.java
weaver/src/org/aspectj/weaver/patterns/WildAnnotationTypePattern.java
weaver/src/org/aspectj/weaver/patterns/WithinAnnotationPointcut.java
weaver/src/org/aspectj/weaver/patterns/WithinCodeAnnotationPointcut.java
weaver/src/org/aspectj/weaver/tools/WeavingAdaptor.java
weaver/src/org/aspectj/weaver/weaver-messages.properties
weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternMatchingTestCase.java
weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternTestCase.java
weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java

index e97867c41c7f6f09b6093c9ba5cfdc670440ce06..8b0ecf8d4e807fc079e8fd399f421e3fa3fcdc89 100644 (file)
@@ -142,6 +142,19 @@ public class WeaverMessages {
        public static final String INCORRECT_TARGET_FOR_DECLARE_ANNOTATION = "incorrectTargetForDeclareAnnotation";
        public static final String NO_MATCH_BECAUSE_SOURCE_RETENTION = "noMatchBecauseSourceRetention";
        
+       // < Java5 messages
+       public static final String ATANNOTATION_ONLY_SUPPORTED_AT_JAVA5_LEVEL = "atannotationNeedsJava5";
+       public static final String ATWITHIN_ONLY_SUPPORTED_AT_JAVA5_LEVEL = "atwithinNeedsJava5";
+       public static final String ATWITHINCODE_ONLY_SUPPORTED_AT_JAVA5_LEVEL = "atwithincodeNeedsJava5";
+       public static final String ATTHIS_ONLY_SUPPORTED_AT_JAVA5_LEVEL = "atthisNeedsJava5";
+       public static final String ATTARGET_ONLY_SUPPORTED_AT_JAVA5_LEVEL = "attargetNeedsJava5";
+       public static final String ATARGS_ONLY_SUPPORTED_AT_JAVA5_LEVEL = "atargsNeedsJava5";
+       public static final String DECLARE_ATTYPE_ONLY_SUPPORTED_AT_JAVA5_LEVEL = "declareAtTypeNeedsJava5";
+       public static final String DECLARE_ATMETHOD_ONLY_SUPPORTED_AT_JAVA5_LEVEL = "declareAtMethodNeedsJava5";
+       public static final String DECLARE_ATFIELD_ONLY_SUPPORTED_AT_JAVA5_LEVEL = "declareAtFieldNeedsJava5";
+       public static final String DECLARE_ATCONS_ONLY_SUPPORTED_AT_JAVA5_LEVEL = "declareAtConsNeedsJava5";
+       public static final String ANNOTATIONS_NEED_JAVA5 = "annotationsRequireJava5";
+       
        // Generics
        public static final String CANT_DECP_MULTIPLE_PARAMETERIZATIONS="cantDecpMultipleParameterizations";
        public static final String HANDLER_PCD_DOESNT_SUPPORT_PARAMETERS="noParameterizedTypePatternInHandler";
index 32fd6c0a10db6f53115d7fac0aecba1005a8a707..3cf61459a1654df076514a48662455afbd5c20ef 100644 (file)
@@ -19,6 +19,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.aspectj.bridge.MessageUtil;
 import org.aspectj.util.FuzzyBoolean;
 import org.aspectj.weaver.AjcMemberMaker;
 import org.aspectj.weaver.AnnotatedElement;
@@ -34,6 +35,7 @@ import org.aspectj.weaver.Shadow;
 import org.aspectj.weaver.ShadowMunger;
 import org.aspectj.weaver.UnresolvedType;
 import org.aspectj.weaver.VersionedDataInputStream;
+import org.aspectj.weaver.WeaverMessages;
 import org.aspectj.weaver.ast.Literal;
 import org.aspectj.weaver.ast.Test;
 import org.aspectj.weaver.ast.Var;
@@ -161,6 +163,11 @@ public class AnnotationPointcut extends NameBindingPointcut {
         * @see org.aspectj.weaver.patterns.Pointcut#resolveBindings(org.aspectj.weaver.patterns.IScope, org.aspectj.weaver.patterns.Bindings)
         */
        protected void resolveBindings(IScope scope, Bindings bindings) {
+               if (!scope.getWorld().isInJava5Mode()) {
+                       scope.message(MessageUtil.error(WeaverMessages.format(WeaverMessages.ATANNOTATION_ONLY_SUPPORTED_AT_JAVA5_LEVEL),
+                                       getSourceLocation()));
+                       return;
+               }
                annotationTypePattern = (ExactAnnotationTypePattern) annotationTypePattern.resolveBindings(scope,bindings,true);
                // must be either a Var, or an annotation type pattern
        }
index c2e7d7931f5fc15d5b1d65c147bd11619254e0cf..f289c585d39795888c4f2bca4112ca24655446e2 100644 (file)
@@ -20,6 +20,7 @@ import java.util.Set;
 import org.aspectj.bridge.IMessage;
 import org.aspectj.bridge.ISourceLocation;
 import org.aspectj.bridge.Message;
+import org.aspectj.bridge.MessageUtil;
 import org.aspectj.util.FuzzyBoolean;
 import org.aspectj.weaver.ISourceContext;
 import org.aspectj.weaver.IntMap;
@@ -86,6 +87,11 @@ public class ArgsAnnotationPointcut extends NameBindingPointcut {
         * @see org.aspectj.weaver.patterns.Pointcut#resolveBindings(org.aspectj.weaver.patterns.IScope, org.aspectj.weaver.patterns.Bindings)
         */
        protected void resolveBindings(IScope scope, Bindings bindings) {
+               if (!scope.getWorld().isInJava5Mode()) {
+                       scope.message(MessageUtil.error(WeaverMessages.format(WeaverMessages.ATARGS_ONLY_SUPPORTED_AT_JAVA5_LEVEL),
+                                       getSourceLocation()));
+                       return;
+               }
                arguments.resolveBindings(scope, bindings, true);
                if (arguments.ellipsisCount > 1) {
                        scope.message(IMessage.ERROR, this,
index 2c504f7479fff181ae732997572e9c10d88ab839..51563fce25ae97a9fd83c57300dcbbdf3828ef88 100644 (file)
@@ -17,12 +17,14 @@ import java.io.IOException;
 import java.util.Iterator;
 import java.util.Map;
 
+import org.aspectj.bridge.MessageUtil;
 import org.aspectj.weaver.AnnotationX;
 import org.aspectj.weaver.ISourceContext;
 import org.aspectj.weaver.ResolvedMember;
 import org.aspectj.weaver.ResolvedType;
 import org.aspectj.weaver.UnresolvedType;
 import org.aspectj.weaver.VersionedDataInputStream;
+import org.aspectj.weaver.WeaverMessages;
 import org.aspectj.weaver.World;
 
 public class DeclareAnnotation extends Declare {
@@ -106,6 +108,16 @@ public class DeclareAnnotation extends Declare {
        }
        
        public void resolve(IScope scope) {
+               if (!scope.getWorld().isInJava5Mode()) {
+                       String msg = null;
+                       if (kind == AT_TYPE) { msg = WeaverMessages.DECLARE_ATTYPE_ONLY_SUPPORTED_AT_JAVA5_LEVEL; }
+                       else if (kind == AT_METHOD) { msg = WeaverMessages.DECLARE_ATMETHOD_ONLY_SUPPORTED_AT_JAVA5_LEVEL;}
+                       else if (kind == AT_FIELD) { msg = WeaverMessages.DECLARE_ATFIELD_ONLY_SUPPORTED_AT_JAVA5_LEVEL;}
+                       else if (kind == AT_CONSTRUCTOR) { msg = WeaverMessages.DECLARE_ATCONS_ONLY_SUPPORTED_AT_JAVA5_LEVEL;}
+                       scope.message(MessageUtil.error(WeaverMessages.format(msg),
+                                       getSourceLocation()));
+                       return;
+               }
                if (typePattern != null) {
                        typePattern = typePattern.resolveBindings(scope,Bindings.NONE,false,false);
                }
index 2a0f0ef4e7730a8c14426349a148c9f95bbc4f1b..72c262c649d334d55a43834306b9060a83fd8c7c 100644 (file)
@@ -118,6 +118,12 @@ public class ThisOrTargetAnnotationPointcut extends NameBindingPointcut {
         * @see org.aspectj.weaver.patterns.Pointcut#resolveBindings(org.aspectj.weaver.patterns.IScope, org.aspectj.weaver.patterns.Bindings)
         */
        protected void resolveBindings(IScope scope, Bindings bindings) {
+               if (!scope.getWorld().isInJava5Mode()) {
+                       scope.message(MessageUtil.error(WeaverMessages.format(
+                                       isThis ? WeaverMessages.ATTHIS_ONLY_SUPPORTED_AT_JAVA5_LEVEL : WeaverMessages.ATTARGET_ONLY_SUPPORTED_AT_JAVA5_LEVEL),
+                                       getSourceLocation()));
+                       return;
+               }
                annotationTypePattern = (ExactAnnotationTypePattern) annotationTypePattern.resolveBindings(scope,bindings,true);
                // must be either a Var, or an annotation type pattern
                // if annotationType does not have runtime retention, this is an error
index f4b19f720d34c5cb2c891cca8b84bcec3a67d790..3b317cbf7432fbe095a748a7f8df8d403cfa5118 100644 (file)
@@ -80,7 +80,12 @@ public class WildAnnotationTypePattern extends AnnotationTypePattern {
     public AnnotationTypePattern resolveBindings(IScope scope, Bindings bindings, 
                                                                             boolean allowBinding)
     { 
-               if (resolved) return this;
+       if (!scope.getWorld().isInJava5Mode()) {
+               scope.message(MessageUtil.error(WeaverMessages.format(WeaverMessages.ANNOTATIONS_NEED_JAVA5),
+                               getSourceLocation()));
+               return this;
+       }
+       if (resolved) return this;
        this.typePattern = typePattern.resolveBindings(scope,bindings,false,false);
        resolved = true;
        if (typePattern instanceof ExactTypePattern) {
index 886faf6db4d79d4210067771a02debb58c8dbdc4..fc87efde1c76ef3ee01e3a8066bf82530580f4c0 100644 (file)
@@ -20,6 +20,7 @@ import java.util.Set;
 import org.aspectj.bridge.IMessage;
 import org.aspectj.bridge.ISourceLocation;
 import org.aspectj.bridge.Message;
+import org.aspectj.bridge.MessageUtil;
 import org.aspectj.util.FuzzyBoolean;
 import org.aspectj.weaver.BCException;
 import org.aspectj.weaver.ISourceContext;
@@ -101,6 +102,11 @@ public class WithinAnnotationPointcut extends NameBindingPointcut {
         * @see org.aspectj.weaver.patterns.Pointcut#resolveBindings(org.aspectj.weaver.patterns.IScope, org.aspectj.weaver.patterns.Bindings)
         */
        protected void resolveBindings(IScope scope, Bindings bindings) {
+               if (!scope.getWorld().isInJava5Mode()) {
+                       scope.message(MessageUtil.error(WeaverMessages.format(WeaverMessages.ATWITHIN_ONLY_SUPPORTED_AT_JAVA5_LEVEL),
+                                       getSourceLocation()));
+                       return;
+               }
                annotationTypePattern = (ExactAnnotationTypePattern) annotationTypePattern.resolveBindings(scope,bindings,true);
                // must be either a Var, or an annotation type pattern
        }
index d61d13e79f7fb53edae1dfe86ada6c8fef048da2..7a4bc988f5dcc7d2963b613c0ff6fa3124df3093 100644 (file)
@@ -18,6 +18,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.aspectj.bridge.MessageUtil;
 import org.aspectj.util.FuzzyBoolean;
 import org.aspectj.weaver.AnnotatedElement;
 import org.aspectj.weaver.BCException;
@@ -31,6 +32,7 @@ import org.aspectj.weaver.Shadow;
 import org.aspectj.weaver.ShadowMunger;
 import org.aspectj.weaver.UnresolvedType;
 import org.aspectj.weaver.VersionedDataInputStream;
+import org.aspectj.weaver.WeaverMessages;
 import org.aspectj.weaver.ast.Literal;
 import org.aspectj.weaver.ast.Test;
 import org.aspectj.weaver.ast.Var;
@@ -112,6 +114,11 @@ public class WithinCodeAnnotationPointcut extends NameBindingPointcut {
         * @see org.aspectj.weaver.patterns.Pointcut#resolveBindings(org.aspectj.weaver.patterns.IScope, org.aspectj.weaver.patterns.Bindings)
         */
        protected void resolveBindings(IScope scope, Bindings bindings) {
+               if (!scope.getWorld().isInJava5Mode()) {
+                       scope.message(MessageUtil.error(WeaverMessages.format(WeaverMessages.ATWITHINCODE_ONLY_SUPPORTED_AT_JAVA5_LEVEL),
+                                       getSourceLocation()));
+                       return;
+               }
                annotationTypePattern = (ExactAnnotationTypePattern) annotationTypePattern.resolveBindings(scope,bindings,true);
                // must be either a Var, or an annotation type pattern
        }
index 0846b7a93a4909adf17ced3b3485bc4c3d1994a4..1019ca617dfd3c78b54cd180c856b02155d5ea87 100644 (file)
@@ -35,6 +35,7 @@ import org.aspectj.bridge.MessageUtil;
 import org.aspectj.bridge.MessageWriter;
 import org.aspectj.bridge.IMessage.Kind;
 import org.aspectj.util.FileUtil;
+import org.aspectj.util.LangUtil;
 import org.aspectj.weaver.IClassFileProvider;
 import org.aspectj.weaver.IWeaveRequestor;
 import org.aspectj.weaver.bcel.BcelWeaver;
@@ -144,6 +145,9 @@ public class WeavingAdaptor {
                bcelWorld = new BcelWorld(classPath,messageHandler,null);
                bcelWorld.setXnoInline(false);
                bcelWorld.getLint().loadDefaultProperties();
+               if (LangUtil.is15VMOrGreater()) {
+                       bcelWorld.setBehaveInJava5Way(true);
+               }
 
                weaver = new BcelWeaver(bcelWorld);
                registerAspectLibraries(aspectPath);
index 734b7221d42ffda51671fa22bf8300a5c7e70090..c274d8f13940c2cfc17823c3d0f91576018d6639 100644 (file)
@@ -172,6 +172,19 @@ noRawTypePointcutReferences=cannot use a raw type reference to refer to a pointc
 
 hasMemberNotEnabled=the type pattern {0} can only be used when the -XhasMember option is set
 
+# Java5 features used in pre-Java 5 environment
+atannotationNeedsJava5=the @annotation pointcut expression is only supported at Java 5 compliance level or above
+atwithinNeedsJava5=the @within pointcut expression is only supported at Java 5 compliance level or above
+atwithincodeNeedsJava5=the @withincode pointcut expression is only supported at Java 5 compliance level or above
+atthisNeedsJava5=the @this pointcut expression is only supported at Java 5 compliance level or above
+attargetNeedsJava5=the @target pointcut expression is only supported at Java 5 compliance level or above
+atargsNeedsJava5=the @args pointcut expression is only supported at Java 5 compliance level or above
+declareAtTypeNeedsJava5=declare @type is only supported at Java 5 compliance level or above
+declareAtMethodNeedsJava5=declare @method is only supported at Java 5 compliance level or above
+declareAtFieldNeedsJava5=declare @field is only supported at Java 5 compliance level or above
+declareAtConsNeedsJava5=declare @constructor is only supported at Java 5 compliance level or above
+annotationsRequireJava5=annotation type patterns are only supported at Java 5 compliance level or above
+
 # @AspectJ
 returningFormalNotDeclaredInAdvice=the last parameter of this advice must be named ''{0}'' to bind the returning value
 thrownFormalNotDeclaredInAdvice=the last parameter of this advice must be named ''{0}'' and be of a subtype of Throwable
\ No newline at end of file
index bdf27dff3d5387422c020193276139346eaac99d..892bbe638df5a4fa56ab496975195f88f3756a4e 100644 (file)
@@ -65,6 +65,7 @@ public class AnnotationPatternMatchingTestCase extends TestCase {
        private ResolvedType loadType(String name) {
                if (world == null) {
                  world = new BcelWorld(BcweaverTests.TESTDATA_PATH + "/testcode.jar");
+                 world.setBehaveInJava5Way(true);
                }
                return world.resolve(name);
        }
index d681b638fa67ca7ebc44146038c1abc5ae1b9bf0..3551775f4e7f35e3ee1819836192505d9b34b8c4 100644 (file)
@@ -324,6 +324,7 @@ public class AnnotationPatternTestCase extends TestCase {
        
        public TestScope makeSimpleScope() {
                BcelWorld bWorld = new BcelWorld(BcweaverTests.TESTDATA_PATH + "/testcode.jar"); // testcode contains Foo/Boo/Goo/etc
+               bWorld.setBehaveInJava5Way(true);
                return new TestScope(new String[] {"int", "java.lang.String","Foo","Boo","Goo"}, 
                                             new String[] {"a", "b","foo","boo","goo"}, 
                                                         bWorld);
index 60e1e2d32baf76d56c3767a576991d0d20e92edd..a018e338cfafec802fb2e7c5711095d1cd5c2911 100644 (file)
@@ -677,6 +677,7 @@ public class ParserTestCase extends TestCase {
 
        
        public TestScope makeSimpleScope() {
+               world.setBehaveInJava5Way(true);
                TestScope s = new TestScope(new String[] {"int", "java.lang.String"}, new String[] {"a", "b"}, world);
                s.setImportedPrefixes(new String[]{"p."});
                return s;