From 05eccb2300e5d159fdf7fb5aa9eedb416941ad06 Mon Sep 17 00:00:00 2001 From: acolyer Date: Wed, 4 May 2005 22:46:50 +0000 Subject: [PATCH] enable compilation of @AfterReturning(pointcut="...") --- .../internal/compiler/AjCompilerAdapter.java | 96 ++++++++++++------- .../ValidateAtAspectJAnnotationsVisitor.java | 15 ++- .../internal/core/builder/AjBuildManager.java | 6 +- .../internal/core/builder/AspectJBuilder.java | 12 +-- .../systemtest/ajc150/ataspectj/syntax.xml | 10 +- 5 files changed, 87 insertions(+), 52 deletions(-) diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/AjCompilerAdapter.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/AjCompilerAdapter.java index 8085a51f4..9369f4bb7 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/AjCompilerAdapter.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/AjCompilerAdapter.java @@ -22,14 +22,12 @@ import java.util.Map; import org.aspectj.ajdt.internal.compiler.ast.AddAtAspectJAnnotationsVisitor; import org.aspectj.ajdt.internal.compiler.ast.ValidateAtAspectJAnnotationsVisitor; import org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory; -import org.aspectj.ajdt.internal.core.builder.AjCompilerOptions; import org.aspectj.bridge.IMessage; import org.aspectj.bridge.IMessageHandler; import org.aspectj.bridge.IProgressListener; import org.aspectj.org.eclipse.jdt.core.compiler.IProblem; import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult; import org.aspectj.org.eclipse.jdt.internal.compiler.Compiler; -import org.aspectj.org.eclipse.jdt.internal.compiler.ICompilerAdapter; import org.aspectj.org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; import org.aspectj.org.eclipse.jdt.internal.compiler.env.ICompilationUnit; import org.aspectj.org.eclipse.jdt.internal.compiler.impl.CompilerOptions; @@ -114,12 +112,50 @@ public class AjCompilerAdapter implements ICompilerAdapter { weaverMessageHandler = new WeaverMessageHandler(msgHandler, compiler); world.setMessageHandler(weaverMessageHandler); } + + // the compilation lifecycle methods below are called in order as compilation progresses... public void beforeCompiling(ICompilationUnit[] sourceUnits) { resultsPendingWeave = new ArrayList(); reportedErrors = false; } + public void beforeProcessing(CompilationUnitDeclaration unit) { + eWorld.showMessage(IMessage.INFO, "compiling " + new String(unit.getFileName()), null, null); + if (inJava5Mode && !noAtAspectJAnnotationProcessing) { + AddAtAspectJAnnotationsVisitor atAspectJVisitor = new AddAtAspectJAnnotationsVisitor(unit); + unit.traverse(atAspectJVisitor, unit.scope); + } + } + + public void beforeResolving(CompilationUnitDeclaration unit) { + // no-op + } + + public void afterResolving(CompilationUnitDeclaration unit) { + // no-op + + } + + public void beforeAnalysing(CompilationUnitDeclaration unit) { + if (inJava5Mode && !noAtAspectJAnnotationProcessing) { + ValidateAtAspectJAnnotationsVisitor atAspectJVisitor = new ValidateAtAspectJAnnotationsVisitor(unit); + unit.traverse(atAspectJVisitor, unit.scope); + } + } + + public void afterAnalysing(CompilationUnitDeclaration unit) { + // no-op + } + + public void beforeGenerating(CompilationUnitDeclaration unit) { + // no-op + } + + public void afterGenerating(CompilationUnitDeclaration unit) { + // no-op + } + public void afterCompiling(CompilationUnitDeclaration[] units) { try { if (isXNoWeave || (reportedErrors && !proceedOnError)) { @@ -141,21 +177,6 @@ public class AjCompilerAdapter implements ICompilerAdapter { } } - public void beforeProcessing(CompilationUnitDeclaration unit) { - eWorld.showMessage(IMessage.INFO, "compiling " + new String(unit.getFileName()), null, null); - if (inJava5Mode && !noAtAspectJAnnotationProcessing) { - AddAtAspectJAnnotationsVisitor atAspectJVisitor = new AddAtAspectJAnnotationsVisitor(unit); - unit.traverse(atAspectJVisitor, unit.scope); - } - } - - public void beforeAnalysing(CompilationUnitDeclaration unit) { - if (inJava5Mode && !noAtAspectJAnnotationProcessing) { - ValidateAtAspectJAnnotationsVisitor atAspectJVisitor = new ValidateAtAspectJAnnotationsVisitor(unit); - unit.traverse(atAspectJVisitor, unit.scope); - } - } - public void afterProcessing(CompilationUnitDeclaration unit, int unitIndex) { eWorld.finishedCompilationUnit(unit); InterimCompilationResult intRes = new InterimCompilationResult(unit.compilationResult,outputFileNameProvider); @@ -172,26 +193,26 @@ public class AjCompilerAdapter implements ICompilerAdapter { } } - public void beforeResolving(CompilationUnitDeclaration unit, ICompilationUnit sourceUnit, boolean verifyMethods, boolean analyzeCode, boolean generateCode) { - resultsPendingWeave = new ArrayList(); - reportedErrors = false; - } - - public void afterResolving(CompilationUnitDeclaration unit, ICompilationUnit sourceUnit, boolean verifyMethods, boolean analyzeCode, boolean generateCode) { - InterimCompilationResult intRes = new InterimCompilationResult(unit.compilationResult,outputFileNameProvider); - if (unit.compilationResult.hasErrors()) reportedErrors = true; - if (isXNoWeave || !generateCode) { - acceptResult(unit.compilationResult); - } else if (generateCode){ - resultsPendingWeave.add(intRes); - try { - weave(); - } catch (IOException ex) { - AbortCompilation ac = new AbortCompilation(null,ex); - throw ac; - } - } - } +// public void beforeResolving(CompilationUnitDeclaration unit, ICompilationUnit sourceUnit, boolean verifyMethods, boolean analyzeCode, boolean generateCode) { +// resultsPendingWeave = new ArrayList(); +// reportedErrors = false; +// } +// +// public void afterResolving(CompilationUnitDeclaration unit, ICompilationUnit sourceUnit, boolean verifyMethods, boolean analyzeCode, boolean generateCode) { +// InterimCompilationResult intRes = new InterimCompilationResult(unit.compilationResult,outputFileNameProvider); +// if (unit.compilationResult.hasErrors()) reportedErrors = true; +// if (isXNoWeave || !generateCode) { +// acceptResult(unit.compilationResult); +// } else if (generateCode){ +// resultsPendingWeave.add(intRes); +// try { +// weave(); +// } catch (IOException ex) { +// AbortCompilation ac = new AbortCompilation(null,ex); +// throw ac; +// } +// } +// } // helper methods... // ================================================================================== @@ -288,4 +309,5 @@ public class AjCompilerAdapter implements ICompilerAdapter { } } } + } 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 2ad4edfb4..16473a40c 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 @@ -344,6 +344,8 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor { private FormalBinding[] buildFormalAdviceBindingsFrom(MethodDeclaration mDecl) { if (mDecl.arguments == null) return new FormalBinding[0]; + String extraArgName = maybeGetExtraArgName(); + if (extraArgName == null) extraArgName = ""; FormalBinding[] ret = new FormalBinding[mDecl.arguments.length]; for (int i = 0; i < mDecl.arguments.length; i++) { Argument arg = mDecl.arguments[i]; @@ -353,7 +355,8 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor { if (CharOperation.equals(joinPoint,argTypeBinding.signature()) || CharOperation.equals(joinPointStaticPart,argTypeBinding.signature()) || CharOperation.equals(joinPointEnclosingStaticPart,argTypeBinding.signature()) || - CharOperation.equals(proceedingJoinPoint,argTypeBinding.signature())) { + CharOperation.equals(proceedingJoinPoint,argTypeBinding.signature()) || + name.equals(extraArgName)) { ret[i] = new FormalBinding.ImplicitFormalBinding(type,name,i); } else { ret[i] = new FormalBinding(type, name, i, arg.sourceStart, arg.sourceEnd, "unknown"); @@ -361,6 +364,16 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor { } return ret; } + + private String maybeGetExtraArgName() { + String argName = null; + if (ajAnnotations.adviceKind == AdviceKind.AfterReturning) { + argName = getStringLiteralFor("returning",ajAnnotations.adviceAnnotation,new int[2]); + } else if (ajAnnotations.adviceKind == AdviceKind.AfterThrowing) { + argName = getStringLiteralFor("throwing",ajAnnotations.adviceAnnotation,new int[2]); + } + return argName; + } private String getStringLiteralFor(String memberName, Annotation inAnnotation, int[] location) { if (inAnnotation instanceof SingleMemberAnnotation && memberName.equals("value")) { diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java index ce7fa3c5b..c4475d47b 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java @@ -35,6 +35,8 @@ import java.util.zip.ZipEntry; import org.aspectj.ajdt.internal.compiler.AjCompilerAdapter; import org.aspectj.ajdt.internal.compiler.IBinarySourceProvider; +import org.aspectj.ajdt.internal.compiler.ICompilerAdapter; +import org.aspectj.ajdt.internal.compiler.ICompilerAdapterFactory; import org.aspectj.ajdt.internal.compiler.IIntermediateResultsRequestor; import org.aspectj.ajdt.internal.compiler.IOutputClassFileNameProvider; import org.aspectj.ajdt.internal.compiler.InterimCompilationResult; @@ -59,8 +61,6 @@ import org.aspectj.org.eclipse.jdt.core.compiler.IProblem; 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.DefaultErrorHandlingPolicies; -import org.aspectj.org.eclipse.jdt.internal.compiler.ICompilerAdapter; -import org.aspectj.org.eclipse.jdt.internal.compiler.ICompilerAdapterFactory; import org.aspectj.org.eclipse.jdt.internal.compiler.ICompilerRequestor; import org.aspectj.org.eclipse.jdt.internal.compiler.IProblemFactory; import org.aspectj.org.eclipse.jdt.internal.compiler.batch.ClasspathDirectory; @@ -711,7 +711,7 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc environment = new StatefulNameEnvironment(environment, state.classesFromName); } - org.aspectj.org.eclipse.jdt.internal.compiler.Compiler.setCompilerAdapterFactory(this); + org.aspectj.ajdt.internal.compiler.CompilerAdapter.setCompilerAdapterFactory(this); org.aspectj.org.eclipse.jdt.internal.compiler.Compiler compiler = new org.aspectj.org.eclipse.jdt.internal.compiler.Compiler(environment, DefaultErrorHandlingPolicies.proceedWithAllProblems(), diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AspectJBuilder.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AspectJBuilder.java index 471770f7b..5ee6e0138 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AspectJBuilder.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AspectJBuilder.java @@ -20,12 +20,15 @@ import java.util.Properties; import org.aspectj.ajdt.core.AspectJCore; import org.aspectj.ajdt.internal.compiler.AjCompilerAdapter; import org.aspectj.ajdt.internal.compiler.IBinarySourceProvider; +import org.aspectj.ajdt.internal.compiler.ICompilerAdapter; +import org.aspectj.ajdt.internal.compiler.ICompilerAdapterFactory; import org.aspectj.ajdt.internal.compiler.IIntermediateResultsRequestor; import org.aspectj.ajdt.internal.compiler.IOutputClassFileNameProvider; import org.aspectj.ajdt.internal.compiler.InterimCompilationResult; import org.aspectj.ajdt.internal.compiler.lookup.AjLookupEnvironment; import org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory; import org.aspectj.ajdt.internal.compiler.problem.AjProblemReporter; +import org.aspectj.ajdt.internal.compiler.CompilerAdapter; import org.aspectj.bridge.AbortException; import org.aspectj.bridge.IMessage; import org.aspectj.bridge.IMessageHandler; @@ -45,8 +48,6 @@ import org.aspectj.org.eclipse.jdt.core.JavaModelException; import org.aspectj.org.eclipse.jdt.internal.compiler.CompilationResult; import org.aspectj.org.eclipse.jdt.internal.compiler.Compiler; import org.aspectj.org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies; -import org.aspectj.org.eclipse.jdt.internal.compiler.ICompilerAdapter; -import org.aspectj.org.eclipse.jdt.internal.compiler.ICompilerAdapterFactory; import org.aspectj.org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; import org.aspectj.org.eclipse.jdt.internal.core.builder.BatchImageBuilder; import org.aspectj.org.eclipse.jdt.internal.core.builder.BuildNotifier; @@ -80,7 +81,7 @@ public class AspectJBuilder extends JavaBuilder implements ICompilerAdapterFacto // super method always causes construction of a new XXXImageBuilder, which // causes construction of a new Compiler, so we will be detected as the // adapter. - Compiler.setCompilerAdapterFactory(this); + CompilerAdapter.setCompilerAdapterFactory(this); return super.build(kind, ignored, monitor); } @@ -228,7 +229,7 @@ public class AspectJBuilder extends JavaBuilder implements ICompilerAdapterFacto if (kind == IMessage.DEBUG || kind == IMessage.INFO) return true; return false; } - + /** * No-op * @see org.aspectj.bridge.IMessageHandler#isIgnoring(org.aspectj.bridge.IMessage.Kind) @@ -236,10 +237,9 @@ public class AspectJBuilder extends JavaBuilder implements ICompilerAdapterFacto */ public void dontIgnore(IMessage.Kind kind) { ; - } - } + } private static class OutputFileNameProvider implements IOutputClassFileNameProvider { diff --git a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/syntax.xml b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/syntax.xml index 89981e4fa..d839dda28 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/syntax.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/syntax.xml @@ -58,11 +58,11 @@ - - - - - + + + + + -- 2.39.5