diff options
author | acolyer <acolyer> | 2005-04-29 20:21:59 +0000 |
---|---|---|
committer | acolyer <acolyer> | 2005-04-29 20:21:59 +0000 |
commit | 9cc00566ff2209410037b752b47ca941fe6bf3dd (patch) | |
tree | 1784d60e202a26a3cfbb083a87f053662f1a2025 /org.aspectj.ajdt.core/src | |
parent | a6291f59f0bd11e85b5018bb68d9d6e61ece43ec (diff) | |
download | aspectj-9cc00566ff2209410037b752b47ca941fe6bf3dd.tar.gz aspectj-9cc00566ff2209410037b752b47ca941fe6bf3dd.zip |
it's a whole new compiler in there...
Diffstat (limited to 'org.aspectj.ajdt.core/src')
17 files changed, 264 insertions, 213 deletions
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java index af7cc30fa..9aaf068c3 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/BuildArgParser.java @@ -49,11 +49,11 @@ public class BuildArgParser extends Main { /** @return multi-line String usage for the compiler */ public static String getUsage() { - return Main.bind("misc.usage"); + return Main.bind("misc.usage",Main.bind("compiler.name")); } public static String getXOptionUsage() { - return Main.bind("xoption.usage"); + return Main.bind("xoption.usage",Main.bind("compiler.name")); } /** diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/messages.properties b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/messages.properties index 2777b867a..a696691cf 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/messages.properties +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/ajc/messages.properties @@ -12,7 +12,7 @@ compiler.name = AspectJ Compiler configure.directoryNotExist = invalid option: {0} ## 3456789012345678901234567890123456789012345678901234567890123456789012345 ### miscellaneous -misc.usage = {compiler.name}\n\ +misc.usage = {0}\n\ \n\ \tUsage: <options> <source file | @argfile>..\n\ \n\ @@ -118,7 +118,7 @@ Standard Eclipse compiler options:\n\ \ -v -version print compiler version\n\ \ -showversion print compiler version and continue\n -xoption.usage = {compiler.name} non-standard options:\n\ +xoption.usage = {0} non-standard options:\n\ \n\ \t-XnoInline don't inline advice\n\ \t-XlazyTjp create thisJoinPoint objects lazily\n\ diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AddAtAspectJAnnotationsVisitor.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AddAtAspectJAnnotationsVisitor.java index 8b4ade56e..35ae2fb9b 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AddAtAspectJAnnotationsVisitor.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AddAtAspectJAnnotationsVisitor.java @@ -19,6 +19,19 @@ import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.BlockScope; import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ClassScope; import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope; +/** + * Adds runtime visible annotations to code-style aspect declarations so that the + * MAP can provide aspect information at runtime. + * + * Done: + * - AspectDeclaration + * - AdviceDeclaration + * - PointcutDeclaration + * + * To Do: + * - DeclareDeclaration + * - Inter-Type Declaration + */ public class AddAtAspectJAnnotationsVisitor extends ASTVisitor { private CompilationUnitDeclaration unit; @@ -33,8 +46,7 @@ public class AddAtAspectJAnnotationsVisitor extends ASTVisitor { } return true; } - - + public boolean visit(TypeDeclaration memberTypeDeclaration,ClassScope scope) { if (memberTypeDeclaration instanceof AspectDeclaration) { ((AspectDeclaration) memberTypeDeclaration).addAtAspectJAnnotations(); @@ -53,7 +65,9 @@ public class AddAtAspectJAnnotationsVisitor extends ASTVisitor { ((AdviceDeclaration)methodDeclaration).addAtAspectJAnnotations(); } else if (methodDeclaration instanceof PointcutDeclaration) { ((PointcutDeclaration)methodDeclaration).addAtAspectJAnnotations(); - } + } else if (methodDeclaration instanceof DeclareDeclaration) { + ((DeclareDeclaration)methodDeclaration).addAtAspectJAnnotations(); + } return false; } diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AdviceDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AdviceDeclaration.java index 6e2d95591..5e1ff36c4 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AdviceDeclaration.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AdviceDeclaration.java @@ -291,14 +291,7 @@ public class AdviceDeclaration extends AjMethodDeclaration { } else if (kind == AdviceKind.Around) { adviceAnnotation = AtAspectJAnnotationFactory.createAroundAnnotation(pointcutExpression,declarationSourceStart); } - if (annotations == null) { - annotations = new Annotation[] { adviceAnnotation }; - } else { - Annotation[] old = annotations; - annotations = new Annotation[old.length +1]; - System.arraycopy(old,0,annotations,0,old.length); - annotations[old.length] = adviceAnnotation; - } + AtAspectJAnnotationFactory.addAnnotation(this, adviceAnnotation); } // override, Called by ClassScope.postParse diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AjMethodDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AjMethodDeclaration.java index efaedf2b5..ae91da894 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AjMethodDeclaration.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AjMethodDeclaration.java @@ -22,6 +22,7 @@ import org.aspectj.org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; * Root class for all MethodDeclaration objects created by the parser. * Enables us to generate extra attributes in the method_info attribute * to support aspectj. + * */ public class AjMethodDeclaration extends MethodDeclaration { diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java index f9beb3f85..681096b24 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AspectDeclaration.java @@ -1011,7 +1011,7 @@ public class AspectDeclaration extends TypeDeclaration { checkSpec(classScope); if (ignoreFurtherInvestigation) return; - + buildPerClause(scope); if (methods != null) { diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AtAspectJAnnotationFactory.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AtAspectJAnnotationFactory.java index 304cd4761..c58ab7a2b 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AtAspectJAnnotationFactory.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/AtAspectJAnnotationFactory.java @@ -17,7 +17,10 @@ import org.aspectj.org.eclipse.jdt.internal.compiler.ast.MemberValuePair; import org.aspectj.org.eclipse.jdt.internal.compiler.ast.NormalAnnotation; import org.aspectj.org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference; import org.aspectj.org.eclipse.jdt.internal.compiler.ast.StringLiteral; +import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TrueLiteral; +import org.aspectj.org.eclipse.jdt.internal.compiler.ast.FalseLiteral; import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference; +import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.TagBits; /** * @author colyer @@ -40,6 +43,7 @@ public class AtAspectJAnnotationFactory { static final char[] afterThrowing = "AfterThrowing".toCharArray(); static final char[] around = "Around".toCharArray(); static final char[] pointcut = "Pointcut".toCharArray(); + static final char[] declareErrorOrWarning = "ajcDeclareEoW".toCharArray(); /** * Create an @Aspect annotation for a code style aspect declaration starting at @@ -70,26 +74,12 @@ public class AtAspectJAnnotationFactory { public static Annotation createBeforeAnnotation(String pointcutExpression, int pos) { char[][] typeName = new char[][] {org,aspectj,lang,annotation,before}; - long[] positions = new long[] {pos,pos,pos,pos,pos}; - TypeReference annType = new QualifiedTypeReference(typeName,positions); - NormalAnnotation ann = new NormalAnnotation(annType,pos); - Expression pcExpr = new StringLiteral(pointcutExpression.toCharArray(),pos,pos); - MemberValuePair[] mvps = new MemberValuePair[1]; - mvps[0] = new MemberValuePair(value,pos,pos,pcExpr); - ann.memberValuePairs = mvps; - return ann; + return makeSingleStringMemberAnnotation(typeName, pos, pointcutExpression); } public static Annotation createAfterAnnotation(String pointcutExpression, int pos) { char[][] typeName = new char[][] {org,aspectj,lang,annotation,after}; - long[] positions = new long[] {pos,pos,pos,pos,pos}; - TypeReference annType = new QualifiedTypeReference(typeName,positions); - NormalAnnotation ann = new NormalAnnotation(annType,pos); - Expression pcExpr = new StringLiteral(pointcutExpression.toCharArray(),pos,pos); - MemberValuePair[] mvps = new MemberValuePair[1]; - mvps[0] = new MemberValuePair(value,pos,pos,pcExpr); - ann.memberValuePairs = mvps; - return ann; + return makeSingleStringMemberAnnotation(typeName, pos, pointcutExpression); } public static Annotation createAfterReturningAnnotation(String pointcutExpression, String extraArgumentName, int pos) { @@ -122,25 +112,60 @@ public class AtAspectJAnnotationFactory { public static Annotation createAroundAnnotation(String pointcutExpression, int pos) { char[][] typeName = new char[][] {org,aspectj,lang,annotation,around}; - long[] positions = new long[] {pos,pos,pos,pos,pos}; - TypeReference annType = new QualifiedTypeReference(typeName,positions); - NormalAnnotation ann = new NormalAnnotation(annType,pos); - Expression pcExpr = new StringLiteral(pointcutExpression.toCharArray(),pos,pos); - MemberValuePair[] mvps = new MemberValuePair[1]; - mvps[0] = new MemberValuePair(value,pos,pos,pcExpr); - ann.memberValuePairs = mvps; - return ann; + return makeSingleStringMemberAnnotation(typeName, pos, pointcutExpression); } public static Annotation createPointcutAnnotation(String pointcutExpression, int pos) { char[][] typeName = new char[][] {org,aspectj,lang,annotation,pointcut}; - long[] positions = new long[] {pos,pos,pos,pos,pos}; + return makeSingleStringMemberAnnotation(typeName, pos, pointcutExpression); + } + + public static Annotation createDeclareErrorOrWarningAnnotation(String pointcutExpression, String message, boolean isError, int pos) { + char[][] typeName = new char[][] {org,aspectj,internal,lang,annotation,declareErrorOrWarning}; + long[] positions = new long[typeName.length]; + for (int i = 0; i < positions.length; i++) positions[i] = pos; TypeReference annType = new QualifiedTypeReference(typeName,positions); NormalAnnotation ann = new NormalAnnotation(annType,pos); - Expression pcExpr = new StringLiteral(pointcutExpression.toCharArray(),pos,pos); - MemberValuePair[] mvps = new MemberValuePair[1]; - mvps[0] = new MemberValuePair(value,pos,pos,pcExpr); + Expression pcutExpr = new StringLiteral(pointcutExpression.toCharArray(),pos,pos); + Expression msgExpr = new StringLiteral(message.toCharArray(),pos,pos); + Expression isErrorExpr; + if (isError) { + isErrorExpr = new TrueLiteral(pos,pos); + } else { + isErrorExpr = new FalseLiteral(pos,pos); + } + MemberValuePair[] mvps = new MemberValuePair[3]; + mvps[0] = new MemberValuePair("pointcut".toCharArray(),pos,pos,pcutExpr); + mvps[1] = new MemberValuePair("message".toCharArray(),pos,pos,msgExpr); + mvps[2] = new MemberValuePair("isError".toCharArray(),pos,pos,isErrorExpr); ann.memberValuePairs = mvps; return ann; } + + private static Annotation makeSingleStringMemberAnnotation(char[][] name, int pos, String annValue) { + long[] positions = new long[name.length]; + for (int i = 0; i < positions.length; i++) positions[i] = pos; + TypeReference annType = new QualifiedTypeReference(name,positions); + NormalAnnotation ann = new NormalAnnotation(annType,pos); + Expression valueExpr = new StringLiteral(annValue.toCharArray(),pos,pos); + MemberValuePair[] mvps = new MemberValuePair[1]; + mvps[0] = new MemberValuePair(value,pos,pos,valueExpr); + ann.memberValuePairs = mvps; + return ann; + } + + public static void addAnnotation(AjMethodDeclaration decl, Annotation annotation) { + if (decl.annotations == null) { + decl.annotations = new Annotation[] { annotation }; + } else { + Annotation[] old = decl.annotations; + decl.annotations = new Annotation[old.length +1]; + System.arraycopy(old,0,decl.annotations,0,old.length); + decl.annotations[old.length] = annotation; + } + if (decl.binding!= null) { + decl.binding.tagBits -= TagBits.AnnotationResolved; + } + } + } diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/DeclareDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/DeclareDeclaration.java index a34a36a61..e9988b6e0 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/DeclareDeclaration.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/DeclareDeclaration.java @@ -18,6 +18,7 @@ package org.aspectj.ajdt.internal.compiler.ast; import org.aspectj.ajdt.internal.compiler.lookup.EclipseScope; import org.aspectj.org.eclipse.jdt.internal.compiler.ClassFile; import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult; +import org.aspectj.org.eclipse.jdt.internal.compiler.ast.Annotation; import org.aspectj.org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeReference; @@ -25,6 +26,11 @@ import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.ClassScope; import org.aspectj.org.eclipse.jdt.internal.compiler.parser.Parser; import org.aspectj.weaver.AjAttribute; import org.aspectj.weaver.patterns.Declare; +import org.aspectj.weaver.patterns.DeclareAnnotation; +import org.aspectj.weaver.patterns.DeclareErrorOrWarning; +import org.aspectj.weaver.patterns.DeclareParents; +import org.aspectj.weaver.patterns.DeclarePrecedence; +import org.aspectj.weaver.patterns.DeclareSoft; import org.aspectj.weaver.patterns.FormalBinding; public class DeclareDeclaration extends AjMethodDeclaration { @@ -48,6 +54,24 @@ public class DeclareDeclaration extends AjMethodDeclaration { this.returnType = TypeReference.baseTypeReference(T_void, 0); } + + public void addAtAspectJAnnotations() { + Annotation annotation = null; + if (declareDecl instanceof DeclareAnnotation) { + + } else if (declareDecl instanceof DeclareErrorOrWarning) { + DeclareErrorOrWarning dd = (DeclareErrorOrWarning) declareDecl; + annotation = AtAspectJAnnotationFactory + .createDeclareErrorOrWarningAnnotation(dd.getPointcut().toString(),dd.getMessage(),dd.isError(),declarationSourceStart); + } else if (declareDecl instanceof DeclareParents) { + + } else if (declareDecl instanceof DeclarePrecedence) { + + } else if (declareDecl instanceof DeclareSoft) { + + } + if (annotation != null) AtAspectJAnnotationFactory.addAnnotation(this,annotation); + } /** * A declare declaration exists in a classfile only as an attibute on the @@ -65,7 +89,7 @@ public class DeclareDeclaration extends AjMethodDeclaration { } protected boolean shouldDelegateCodeGeneration() { - return false; + return true; } public void parseStatements( diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeConstructorDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeConstructorDeclaration.java index c715533b2..7b09a4d07 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeConstructorDeclaration.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeConstructorDeclaration.java @@ -43,6 +43,10 @@ public class InterTypeConstructorDeclaration extends InterTypeDeclaration { return; parser.parse(this, unit); } + + protected char[] getPrefix() { + return (NameMangler.ITD_PREFIX + "interConstructor$").toCharArray(); + } public void resolve(ClassScope upperScope) { if (munger == null || binding == null) ignoreFurtherInvestigation = true; diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeDeclaration.java index 07b35dc7a..4e6201661 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeDeclaration.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeDeclaration.java @@ -59,8 +59,12 @@ public abstract class InterTypeDeclaration extends AjMethodDeclaration { public void setSelector(char[] selector) { declaredSelector = selector; this.selector = CharOperation.concat(selector, Integer.toHexString(sourceStart).toCharArray()); + this.selector = CharOperation.concat(getPrefix(),this.selector); } + // return the selector prefix for this itd that is to be used before resolution replaces it with a "proper" name + protected abstract char[] getPrefix(); + /** * Checks that the target for the ITD is not an annotation. If it is, an error message * is signaled. We return true if it is annotation so the caller knows to stop processing. diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeFieldDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeFieldDeclaration.java index cc325269d..2b48a8c35 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeFieldDeclaration.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeFieldDeclaration.java @@ -48,6 +48,9 @@ public class InterTypeFieldDeclaration extends InterTypeDeclaration { //we don't have a body to parse } + protected char[] getPrefix() { + return (NameMangler.ITD_PREFIX + "interField$").toCharArray(); + } public void resolveOnType(ClassScope classScope) { super.resolveOnType(classScope); diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeMethodDeclaration.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeMethodDeclaration.java index 98de6d00c..46a2eb5a3 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeMethodDeclaration.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/InterTypeMethodDeclaration.java @@ -20,6 +20,7 @@ import org.aspectj.ajdt.internal.compiler.lookup.EclipseTypeMunger; import org.aspectj.weaver.AjAttribute; import org.aspectj.weaver.AjcMemberMaker; import org.aspectj.weaver.Member; +import org.aspectj.weaver.NameMangler; import org.aspectj.weaver.NewMethodTypeMunger; import org.aspectj.weaver.ResolvedMember; import org.aspectj.weaver.ResolvedTypeX; @@ -56,6 +57,9 @@ public class InterTypeMethodDeclaration extends InterTypeDeclaration { } } + protected char[] getPrefix() { + return (NameMangler.ITD_PREFIX + "interMethod$").toCharArray(); + } public void analyseCode( ClassScope currentScope, diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/ThisJoinPointVisitor.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/ThisJoinPointVisitor.java index f5d5c2e1a..5f51a4564 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/ThisJoinPointVisitor.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/ThisJoinPointVisitor.java @@ -179,7 +179,7 @@ public class ThisJoinPointVisitor extends ASTVisitor { private MethodBinding getEquivalentStaticBinding(MethodBinding template) { ReferenceBinding b = (ReferenceBinding)thisJoinPointStaticPartDec.type; - return b.getExactMethod(template.selector, template.parameters); + return b.getExactMethod(template.selector, template.parameters,null); } public int removeUnusedExtraArguments() { diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/ValidateAtAspectJAnnotationsVisitor.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/ValidateAtAspectJAnnotationsVisitor.java index 8dd82a467..2ad4edfb4 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/ValidateAtAspectJAnnotationsVisitor.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/ValidateAtAspectJAnnotationsVisitor.java @@ -66,6 +66,7 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor { private CompilationUnitDeclaration unit; private Stack typeStack = new Stack(); + private AspectJAnnotations ajAnnotations; public ValidateAtAspectJAnnotationsVisitor(CompilationUnitDeclaration unit) { this.unit = unit; @@ -73,6 +74,7 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor { public boolean visit(TypeDeclaration localTypeDeclaration, BlockScope scope) { typeStack.push(localTypeDeclaration); + ajAnnotations = new AspectJAnnotations(localTypeDeclaration.annotations); checkTypeDeclaration(localTypeDeclaration); return true; } @@ -83,6 +85,7 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor { public boolean visit(TypeDeclaration memberTypeDeclaration,ClassScope scope) { typeStack.push(memberTypeDeclaration); + ajAnnotations = new AspectJAnnotations(memberTypeDeclaration.annotations); checkTypeDeclaration(memberTypeDeclaration); return true; } @@ -93,6 +96,7 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor { public boolean visit(TypeDeclaration typeDeclaration, CompilationUnitScope scope) { typeStack.push(typeDeclaration); + ajAnnotations = new AspectJAnnotations(typeDeclaration.annotations); checkTypeDeclaration(typeDeclaration); return true; } @@ -103,7 +107,7 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor { private void checkTypeDeclaration(TypeDeclaration typeDecl) { if (!(typeDecl instanceof AspectDeclaration)) { - if (insideAspect()) { + if (ajAnnotations.hasAspectAnnotation) { validateAspectDeclaration(typeDecl); } else { // check that class doesn't extend aspect @@ -122,65 +126,42 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor { } } } else { - // check that aspect doesn't have @Aspect annotation - boolean foundAspectAnnotation = false; - for (int i = 0; i < typeDecl.annotations.length; i++) { - if (typeDecl.annotations[i].resolvedType == null) continue; - char[] sig = typeDecl.annotations[i].resolvedType.signature(); - if (CharOperation.equals(aspectSig,sig)) { - if (!foundAspectAnnotation) { - foundAspectAnnotation = true; // this is the one we added in the first visitor pass - } else { - //a second @Aspect annotation, user must have declared one... - typeDecl.scope.problemReporter().signalError( - typeDecl.sourceStart, - typeDecl.sourceEnd, - "aspects cannot have @Aspect annotation" - ); - } - } + // check that aspect doesn't have @Aspect annotation, we've already added on ourselves. + if (ajAnnotations.hasMultipleAspectAnnotations) { + typeDecl.scope.problemReporter().signalError( + typeDecl.sourceStart, + typeDecl.sourceEnd, + "aspects cannot have @Aspect annotation" + ); } } } public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) { + ajAnnotations = new AspectJAnnotations(methodDeclaration.annotations); if (!methodDeclaration.getClass().equals(AjMethodDeclaration.class)) { // simply test for innapropriate use of annotations on code-style members - if (!hasAspectJAnnotation(methodDeclaration)) return false; - int numPointcutAnnotations = 0; - int numAdviceAnnotations = 0; - int numAdviceNameAnnotations = 0; - for (int i=0; i < methodDeclaration.annotations.length; i++) { - if (isAspectJAnnotation(methodDeclaration.annotations[i])) { - if (CharOperation.equals(adviceNameSig,methodDeclaration.annotations[i].resolvedType.signature())) { - numAdviceNameAnnotations++; - } else if (CharOperation.equals(pointcutSig,methodDeclaration.annotations[i].resolvedType.signature())) { - numPointcutAnnotations++; - } else { - for (int j = 0; j < adviceSigs.length; j++) { - if (CharOperation.equals(adviceSigs[j],methodDeclaration.annotations[i].resolvedType.signature())) { - numAdviceAnnotations++; - } - } - } - } - } if (methodDeclaration instanceof PointcutDeclaration) { - if (numPointcutAnnotations > 1 || numAdviceAnnotations > 0 || numAdviceNameAnnotations > 0) { + if (ajAnnotations.hasMultiplePointcutAnnotations || + ajAnnotations.hasAdviceAnnotation || + ajAnnotations.hasAspectAnnotation || + ajAnnotations.hasAdviceNameAnnotation) { methodDeclaration.scope.problemReporter().signalError( methodDeclaration.sourceStart, methodDeclaration.sourceEnd, "@AspectJ annotations cannot be declared on this aspect member"); } } else if (methodDeclaration instanceof AdviceDeclaration) { - if (numPointcutAnnotations > 0 || numAdviceAnnotations > 1) { + if (ajAnnotations.hasMultipleAdviceAnnotations || + ajAnnotations.hasAspectAnnotation || + ajAnnotations.hasPointcutAnnotation) { methodDeclaration.scope.problemReporter().signalError( methodDeclaration.sourceStart, methodDeclaration.sourceEnd, "Only @AdviceName AspectJ annotation allowed on advice"); } } else { - if (numPointcutAnnotations > 0 || numAdviceAnnotations > 0 || numAdviceNameAnnotations > 0) { + if (ajAnnotations.hasAspectJAnnotations()) { methodDeclaration.scope.problemReporter().signalError( methodDeclaration.sourceStart, methodDeclaration.sourceEnd, @@ -189,52 +170,15 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor { } return false; } - if (isAnnotationStyleAdvice(methodDeclaration.annotations)) { + + if (ajAnnotations.hasAdviceAnnotation) { validateAdvice(methodDeclaration); - } else if (isAnnotationStylePointcut(methodDeclaration.annotations)) { + } else if (ajAnnotations.hasPointcutAnnotation) { convertToPointcutDeclaration(methodDeclaration,scope); } return false; } - - - private boolean isAnnotationStyleAdvice(Annotation[] annotations) { - if (annotations == null) return false; - for (int i = 0; i < annotations.length; i++) { - if (annotations[i].resolvedType == null) continue; - char[] sig = annotations[i].resolvedType.signature(); - if (CharOperation.equals(beforeAdviceSig,sig) || - CharOperation.equals(afterAdviceSig,sig) || - CharOperation.equals(afterReturningAdviceSig,sig) || - CharOperation.equals(aroundAdviceSig,sig) || - CharOperation.equals(afterThrowingAdviceSig,sig)) { - return true; - } - } - return false; - } - - private boolean isAnnotationStylePointcut(Annotation[] annotations) { - if (annotations == null) return false; - for (int i = 0; i < annotations.length; i++) { - if (annotations[i].resolvedType == null) continue; - char[] sig = annotations[i].resolvedType.signature(); - if (CharOperation.equals(pointcutSig,sig)) { - return true; - } - } - return false; - } - - private boolean hasAspectJAnnotation(MethodDeclaration methodDecl) { - if (methodDecl.annotations == null) return false; - for (int i=0; i < methodDecl.annotations.length; i++) { - if (isAspectJAnnotation(methodDecl.annotations[i])) return true; - } - return false; - } - private boolean isAspectJAnnotation(Annotation ann) { if (ann.resolvedType == null) return false; char[] sig = ann.resolvedType.signature(); @@ -249,19 +193,7 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor { private boolean isAspect(TypeDeclaration typeDecl) { if (typeDecl instanceof AspectDeclaration) return true; - return hasAspectAnnotation(typeDecl); - } - - private boolean hasAspectAnnotation(TypeDeclaration typeDecl) { - if (typeDecl.annotations == null) return false; - for (int i = 0; i < typeDecl.annotations.length; i++) { - if (typeDecl.annotations[i].resolvedType == null) continue; - char[] sig = typeDecl.annotations[i].resolvedType.signature(); - if (CharOperation.equals(aspectSig,sig)) { - return true; - } - } - return false; + return new AspectJAnnotations(typeDecl.annotations).hasAspectAnnotation; } /** @@ -297,15 +229,7 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor { } } - Annotation aspectAnnotation = null; - for (int i = 0; i < typeDecl.annotations.length; i++) { - if (typeDecl.annotations[i].resolvedType == null) continue; - char[] sig = typeDecl.annotations[i].resolvedType.signature(); - if (CharOperation.equals(aspectSig,sig)) { - aspectAnnotation = typeDecl.annotations[i]; - break; - } - } + Annotation aspectAnnotation = ajAnnotations.aspectAnnotation; int[] pcLoc = new int[2]; String perClause = getStringLiteralFor("value", aspectAnnotation, pcLoc); @@ -347,47 +271,24 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor { .signalError(methodDeclaration.sourceStart,methodDeclaration.sourceEnd,"advice must be public"); } - AdviceKind kind = null; - Annotation adviceAnn = null; - Annotation duplicateAnn = null; - for(int i = 0; i < methodDeclaration.annotations.length; i++) { - Annotation ann = methodDeclaration.annotations[i]; - if (isAspectJAnnotation(ann)) { - if (adviceAnn != null) { - duplicateAnn = ann; - break; - } - if (CharOperation.equals(afterAdviceSig,ann.resolvedType.signature())) { - kind = AdviceKind.After; - adviceAnn = ann; - } else if (CharOperation.equals(afterReturningAdviceSig,ann.resolvedType.signature())) { - kind = AdviceKind.AfterReturning; - adviceAnn = ann; - } else if (CharOperation.equals(afterThrowingAdviceSig,ann.resolvedType.signature())) { - kind = AdviceKind.AfterThrowing; - adviceAnn = ann; - } else if (CharOperation.equals(beforeAdviceSig,ann.resolvedType.signature())) { - kind = AdviceKind.Before; - adviceAnn = ann; - } else if (CharOperation.equals(aroundAdviceSig,ann.resolvedType.signature())) { - kind = AdviceKind.Around; - adviceAnn = ann; - } else if (CharOperation.equals(adviceNameSig,ann.resolvedType.signature())) { - methodDeclaration.scope.problemReporter().signalError( - ann.sourceStart,ann.sourceEnd, "AdviceName annotation cannot be used for advice defined using annotation style"); - } - } + if (ajAnnotations.hasMultipleAdviceAnnotations) { + methodDeclaration.scope.problemReporter().disallowedTargetForAnnotation(ajAnnotations.duplicateAdviceAnnotation); } - - if (duplicateAnn != null) { - methodDeclaration.scope.problemReporter().disallowedTargetForAnnotation(duplicateAnn); + if (ajAnnotations.hasPointcutAnnotation) { + methodDeclaration.scope.problemReporter().disallowedTargetForAnnotation(ajAnnotations.pointcutAnnotation); + } + if (ajAnnotations.hasAspectAnnotation) { + methodDeclaration.scope.problemReporter().disallowedTargetForAnnotation(ajAnnotations.aspectAnnotation); + } + if (ajAnnotations.hasAdviceNameAnnotation) { + methodDeclaration.scope.problemReporter().disallowedTargetForAnnotation(ajAnnotations.adviceNameAnnotation); } - if (kind != AdviceKind.Around) { + if (ajAnnotations.adviceKind != AdviceKind.Around) { ensureVoidReturnType(methodDeclaration); } - resolveAndSetPointcut(methodDeclaration, adviceAnn); + resolveAndSetPointcut(methodDeclaration, ajAnnotations.adviceAnnotation); } @@ -505,25 +406,16 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor { PointcutDeclaration pcDecl = new PointcutDeclaration(unit.compilationResult); copyAllFields(methodDeclaration,pcDecl); - Annotation pcutAnn = null; - Annotation duplicateAnn = null; - for(int i = 0; i < methodDeclaration.annotations.length; i++) { - Annotation ann = methodDeclaration.annotations[i]; - if (isAspectJAnnotation(ann)) { - if (pcutAnn != null) { - duplicateAnn = ann; - break; - } - if (CharOperation.equals(pointcutSig,ann.resolvedType.signature())) { - pcutAnn = ann; - } - } + if (ajAnnotations.hasAdviceAnnotation) { + methodDeclaration.scope.problemReporter().disallowedTargetForAnnotation(ajAnnotations.adviceAnnotation); } - - if (duplicateAnn != null && !CharOperation.equals(pointcutSig,duplicateAnn.resolvedType.signature())) { - // (duplicate annotations of same type are already reported) - methodDeclaration.scope.problemReporter().disallowedTargetForAnnotation(duplicateAnn); + if (ajAnnotations.hasAspectAnnotation) { + methodDeclaration.scope.problemReporter().disallowedTargetForAnnotation(ajAnnotations.aspectAnnotation); } + if (ajAnnotations.hasAdviceNameAnnotation) { + methodDeclaration.scope.problemReporter().disallowedTargetForAnnotation(ajAnnotations.adviceNameAnnotation); + } + boolean returnsVoid = true; if ((methodDeclaration.returnType instanceof SingleTypeReference)) { @@ -547,7 +439,7 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor { } int[] pcLocation = new int[2]; - String pointcutExpression = getStringLiteralFor("value",pcutAnn,pcLocation); + String pointcutExpression = getStringLiteralFor("value",ajAnnotations.pointcutAnnotation,pcLocation); try { ISourceContext context = new EclipseSourceContext(unit.compilationResult,pcLocation[0]); Pointcut pc = new PatternParser(pointcutExpression,context).parsePointcut(); @@ -610,4 +502,83 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor { } } } + + private static class AspectJAnnotations { + boolean hasAdviceAnnotation = false; + boolean hasPointcutAnnotation = false; + boolean hasAspectAnnotation = false; + boolean hasAdviceNameAnnotation = false; + + boolean hasMultipleAdviceAnnotations = false; + boolean hasMultiplePointcutAnnotations = false; + boolean hasMultipleAspectAnnotations = false; + + AdviceKind adviceKind = null; + Annotation adviceAnnotation = null; + Annotation pointcutAnnotation = null; + Annotation aspectAnnotation = null; + Annotation adviceNameAnnotation = null; + + Annotation duplicateAdviceAnnotation = null; + Annotation duplicatePointcutAnnotation = null; + Annotation duplicateAspectAnnotation = null; + + public AspectJAnnotations(Annotation[] annotations) { + if (annotations == null) return; + for (int i = 0; i < annotations.length; i++) { + if (annotations[i].resolvedType == null) continue; // user messed up annotation declaration + char[] sig = annotations[i].resolvedType.signature(); + if (CharOperation.equals(afterAdviceSig,sig)) { + adviceKind = AdviceKind.After; + addAdviceAnnotation(annotations[i]); + } else if (CharOperation.equals(afterReturningAdviceSig,sig)) { + adviceKind = AdviceKind.AfterReturning; + addAdviceAnnotation(annotations[i]); + } else if (CharOperation.equals(afterThrowingAdviceSig,sig)) { + adviceKind = AdviceKind.AfterThrowing; + addAdviceAnnotation(annotations[i]); + } else if (CharOperation.equals(beforeAdviceSig,sig)) { + adviceKind = AdviceKind.Before; + addAdviceAnnotation(annotations[i]); + } else if (CharOperation.equals(aroundAdviceSig,sig)) { + adviceKind = AdviceKind.Around; + addAdviceAnnotation(annotations[i]); + } else if (CharOperation.equals(adviceNameSig,sig)) { + hasAdviceNameAnnotation = true; + adviceNameAnnotation = annotations[i]; + } else if (CharOperation.equals(aspectSig,sig)) { + if (hasAspectAnnotation) { + hasMultipleAspectAnnotations = true; + duplicateAspectAnnotation = annotations[i]; + } else { + hasAspectAnnotation = true; + aspectAnnotation = annotations[i]; + } + } else if (CharOperation.equals(pointcutSig,sig)) { + if (hasPointcutAnnotation) { + hasMultiplePointcutAnnotations = true; + duplicatePointcutAnnotation = annotations[i]; + } else { + hasPointcutAnnotation = true; + pointcutAnnotation = annotations[i]; + } + + } + } + } + + public boolean hasAspectJAnnotations() { + return hasAdviceAnnotation || hasPointcutAnnotation || hasAdviceNameAnnotation || hasAspectAnnotation; + } + + private void addAdviceAnnotation(Annotation annotation) { + if (!hasAdviceAnnotation) { + hasAdviceAnnotation = true; + adviceAnnotation = annotation; + } else { + hasMultipleAdviceAnnotations = true; + duplicateAdviceAnnotation = annotation; + } + } + } } diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AjLookupEnvironment.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AjLookupEnvironment.java index 197fa3376..9629edf4f 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AjLookupEnvironment.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AjLookupEnvironment.java @@ -13,6 +13,7 @@ package org.aspectj.ajdt.internal.compiler.lookup; +import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -534,8 +535,12 @@ public class AjLookupEnvironment extends LookupEnvironment { onType + ": " + dangerousInterfaces.get(parent), onType.getSourceLocation(), null); } - AsmRelationshipProvider.getDefault().addDeclareParentsRelationship(declareParents.getSourceLocation(),factory.fromEclipse(sourceType), newParents); - addParent(sourceType, parent); + if (Modifier.isFinal(parent.getModifiers())) { + factory.showMessage(IMessage.ERROR,"cannot extend final class " + parent.getClassName(),declareParents.getSourceLocation(),null); + } else { + AsmRelationshipProvider.getDefault().addDeclareParentsRelationship(declareParents.getSourceLocation(),factory.fromEclipse(sourceType), newParents); + addParent(sourceType, parent); + } } return true; } diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/problem/AjProblemReporter.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/problem/AjProblemReporter.java index 34831fd82..0e9f8f2e7 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/problem/AjProblemReporter.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/problem/AjProblemReporter.java @@ -231,7 +231,7 @@ public class AjProblemReporter extends ProblemReporter { long metaTagBits = annotation.resolvedType.getAnnotationTagBits(); // could be forward reference if (name.indexOf("interField") != -1) { if ((metaTagBits & TagBits.AnnotationForField) != 0) return; - } else if (name.indexOf("InterConstructor") != -1) { // ??? Should that be Upper case 'I'? + } else if (name.indexOf("interConstructor") != -1) { if ((metaTagBits & TagBits.AnnotationForConstructor) != 0) return; } else if (name.indexOf("interMethod") != -1) { if ((metaTagBits & TagBits.AnnotationForMethod) != 0) return; @@ -242,6 +242,8 @@ public class AjProblemReporter extends ProblemReporter { if ((metaTagBits & TagBits.AnnotationForField)!=0) return; } else if (name.indexOf("declare_"+DeclareAnnotation.AT_CONSTRUCTOR+"_")!=-1) { if ((metaTagBits & TagBits.AnnotationForConstructor)!=0) return; + } else if (name.indexOf("declare_eow") != -1) { + if ((metaTagBits & TagBits.AnnotationForField) != 0) return; } } } diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjCompilerOptions.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjCompilerOptions.java index 0eeb1797f..3fc7138d5 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjCompilerOptions.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjCompilerOptions.java @@ -15,6 +15,7 @@ package org.aspectj.ajdt.internal.core.builder; import java.util.Map; +import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.aspectj.org.eclipse.jdt.internal.compiler.impl.CompilerOptions; @@ -49,15 +50,15 @@ public class AjCompilerOptions extends CompilerOptions { public static final String OPTION_Emacssym = "org.aspectj.ajdt.core.compiler.model.Emacssym"; // constants for irritant levels - public static final long InvalidAbsoluteTypeName = 0x20000000000L; - public static final long InvalidWildCardTypeName = 0x40000000000L; - public static final long UnresolvableMember = 0x80000000000L; - public static final long TypeNotExposedToWeaver = 0x100000000000L; - public static final long ShadowNotInStructure = 0x200000000000L; - public static final long UnmatchedSuperTypeInCall = 0x400000000000L; - public static final long CannotImplementLazyTJP = 0x800000000000L; - public static final long NeedSerialVersionUIDField = 0x1000000000000L; - public static final long IncompatibleSerialVersion = 0x2000000000000L; + public static final long InvalidAbsoluteTypeName = ASTNode.Bit45L; + public static final long InvalidWildCardTypeName = ASTNode.Bit46L; + public static final long UnresolvableMember = ASTNode.Bit47L; + public static final long TypeNotExposedToWeaver = ASTNode.Bit48L; + public static final long ShadowNotInStructure = ASTNode.Bit49L; + public static final long UnmatchedSuperTypeInCall = ASTNode.Bit50L; + public static final long CannotImplementLazyTJP = ASTNode.Bit51L; + public static final long NeedSerialVersionUIDField = ASTNode.Bit52L; + public static final long IncompatibleSerialVersion = ASTNode.Bit53L; public boolean noWeave = false; public boolean xSerializableAspects = false; |