]> source.dussan.org Git - aspectj.git/commitdiff
enable compilation of @AfterReturning(pointcut="...")
authoracolyer <acolyer>
Wed, 4 May 2005 22:46:50 +0000 (22:46 +0000)
committeracolyer <acolyer>
Wed, 4 May 2005 22:46:50 +0000 (22:46 +0000)
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/AjCompilerAdapter.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/ValidateAtAspectJAnnotationsVisitor.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/AspectJBuilder.java
tests/src/org/aspectj/systemtest/ajc150/ataspectj/syntax.xml

index 8085a51f41fce8082df63379931da058af494179..9369f4bb71a499ecd85afc02976609c18d26c8c2 100644 (file)
@@ -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 {
                        }                       
                }
        }
+
 }
index 2ad4edfb4413b4516723316c16425096b0073d78..16473a40c2f7f5dca055c722aac39ba666be26be 100644 (file)
@@ -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")) {
index ce7fa3c5bdae0b8dc5d3b8ae4a66756a59590d92..c4475d47b7647b0fb89a455f9ac383da3e1997d7 100644 (file)
@@ -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(),
index 471770f7b06ecb9beb06c36f5aef9dde95d0e018..5ee6e0138418f9209fa84d9032dbc7af84ea5932 100644 (file)
@@ -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 {
 
index 89981e4fa196e255098966c7d705a55521ee37d5..d839dda28212d311281d03ccb56ab077e163c956 100644 (file)
         <run class="ataspectj.PrecedenceTest"/>
     </ajc-test>
 
-<!--    <comment>FIXME AV when JDT of M6 is in</comment>-->
-<!--    <ajc-test dir="java5/ataspectj" title="AfterXTest">-->
-<!--        <compile files="ataspectj/AfterXTest.java,ataspectj/TestHelper.java" options="-1.5"/>-->
-<!--        <run class="ataspectj.AfterXTest"/>-->
-<!--    </ajc-test>-->
+<!--    <comment>FIXME AV when JDT of M6 is in</comment> -->
+    <ajc-test dir="java5/ataspectj" title="AfterXTest">
+        <compile files="ataspectj/AfterXTest.java,ataspectj/TestHelper.java" options="-1.5"/>
+        <run class="ataspectj.AfterXTest"/>
+    </ajc-test>
 
 <!--    <comment>FIXME AV when we impl if support in pointcut parser and weaver</comment>-->
 <!--    <ajc-test dir="java5/ataspectj" title="IfPointcutTest">-->