]> source.dussan.org Git - aspectj.git/commitdiff
test and fix for 129282
authoraclement <aclement>
Wed, 31 May 2006 11:51:21 +0000 (11:51 +0000)
committeraclement <aclement>
Wed, 31 May 2006 11:51:21 +0000 (11:51 +0000)
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EclipseSourceContext.java
tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java
weaver/src/org/aspectj/weaver/IEclipseSourceContext.java [new file with mode: 0644]
weaver/src/org/aspectj/weaver/World.java
weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java

index 3d49c7e77f2a074ca3d363e51ed87d8c7b3da92f..c4d5fd333fba812629adcb590807a78e42d1e242 100644 (file)
@@ -672,6 +672,7 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc
                bcelWorld.setXlazyTjp(buildConfig.isXlazyTjp());
                bcelWorld.setXHasMemberSupportEnabled(buildConfig.isXHasMemberEnabled());
                bcelWorld.setPinpointMode(buildConfig.isXdevPinpoint());
+               bcelWorld.setErrorAndWarningThreshold(buildConfig.getOptions().errorThreshold,buildConfig.getOptions().warningThreshold);
                BcelWeaver bcelWeaver = new BcelWeaver(bcelWorld);
                state.setWorld(bcelWorld);
                state.setWeaver(bcelWeaver);
index 5485397a08a8062fbcc98d9b7bd994e8dd413c27..6c6e362f20afc409c08dc5fcca40e972da5fbc5d 100644 (file)
@@ -18,13 +18,16 @@ import java.io.File;
 import org.aspectj.ajdt.internal.compiler.lookup.EclipseSourceLocation;
 import org.aspectj.bridge.ISourceLocation;
 import org.aspectj.bridge.SourceLocation;
-import org.aspectj.weaver.IHasPosition;
-import org.aspectj.weaver.ISourceContext;
+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.CompilationResult.ProblemsForRemovalFilter;
+import org.aspectj.weaver.IEclipseSourceContext;
+import org.aspectj.weaver.IHasPosition;
+import org.aspectj.weaver.Member;
 
 
 
-public class EclipseSourceContext implements ISourceContext {
+public class EclipseSourceContext implements IEclipseSourceContext {
        
        CompilationResult result;
        int offset = 0;
@@ -73,4 +76,36 @@ public class EclipseSourceContext implements ISourceContext {
          result=null;
     }
 
+       public void removeUnnecessaryProblems(Member member, int problemLineNumber) {
+               if (result == null) return; 
+               IProblem[] probs = result.getProblems();
+               for (int i = 0; i < probs.length; i++) {
+                       IProblem problem = probs[i];
+                       if (problem == null) continue;
+                       if (problem.getID() == IProblem.UnusedMethodDeclaredThrownException 
+                                       || problem.getID() == IProblem.UnusedConstructorDeclaredThrownException) {
+                               if (problem.getSourceLineNumber() == problemLineNumber) {
+                                       UnusedDeclaredThrownExceptionFilter filter = 
+                                               new UnusedDeclaredThrownExceptionFilter(problem);
+                                       result.removeProblems(filter);  
+                               }
+                       }
+               }
+       }
+
+       private class UnusedDeclaredThrownExceptionFilter implements ProblemsForRemovalFilter { 
+               private IProblem problemToRemove;
+
+               public UnusedDeclaredThrownExceptionFilter(IProblem p) {
+                       problemToRemove = p;
+               }
+
+               public boolean accept(IProblem p) {
+                       if (p.equals(problemToRemove)) {
+                               return true;
+                       }
+                       return false;
+               }
+
+       }
 }
index 87c00def2c9e817fdc2c026a274666da93fa2607..c73079d7947e99f9b031fe404c28d6fab3511b66 100644 (file)
@@ -24,6 +24,16 @@ import org.aspectj.testing.XMLBasedAjcTestCase;
 
 public class Ajc152Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
 
+  public void testNoUnnecessaryDeclarationOfThrownExcp_pr129282_1() {runTest("no unnecessary declaration of thrown exception warning - 1");}
+  public void testNoUnnecessaryDeclarationOfThrownExcp_pr129282_2() {runTest("no unnecessary declaration of thrown exception warning - 2");}
+  public void testNoUnnecessaryDeclarationOfThrownExcp_pr129282_3() {runTest("no unnecessary declaration of thrown exception warning - 3");}
+  public void testNoUnnecessaryDeclarationOfThrownExcp_pr129282_4() {runTest("no unnecessary declaration of thrown exception warning - 4");}
+  public void testNoUnnecessaryDeclarationOfThrownExcp_pr129282_5() {runTest("no unnecessary declaration of thrown exception warning - 5");}
+  public void testNoUnnecessaryDeclarationOfThrownExcp_pr129282_6() {runTest("no unnecessary declaration of thrown exception warning - 6");}
+  public void testNoUnnecessaryDeclarationOfThrownExcp_pr129282_7() {runTest("no unnecessary declaration of thrown exception warning - 7");}
+  public void testNoUnnecessaryDeclarationOfThrownExcp_pr129282_8() {runTest("no unnecessary declaration of thrown exception warning - 8");}
+  public void testNoUnnecessaryDeclarationOfThrownExcp_pr129282_9() {runTest("no unnecessary declaration of thrown exception warning - 9");}
+  public void testNoUnnecessaryDeclarationOfThrownExcp_pr129282_10() {runTest("no unnecessary declaration of thrown exception warning - 10");}  
   public void testAtAJVerificationError_pr144602() { runTest("atAJ perthis aspect verification error");}
   public void testLTWAndGeneratingSUID_pr144465() { runTest("ltw with serialversionUID creation"); }
   public void testAspects14PerSingleton_pr122253() { runTest("aspects14 - persingleton");}
diff --git a/weaver/src/org/aspectj/weaver/IEclipseSourceContext.java b/weaver/src/org/aspectj/weaver/IEclipseSourceContext.java
new file mode 100644 (file)
index 0000000..10d0258
--- /dev/null
@@ -0,0 +1,16 @@
+/********************************************************************
+ * Copyright (c) 2006 Contributors. All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Eclipse Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://eclipse.org/legal/epl-v10.html 
+ *  
+ * Contributors: IBM Corporation - initial API and implementation 
+ *                              Helen Hawkins   - iniital version
+ *******************************************************************/
+package org.aspectj.weaver;
+
+
+public interface IEclipseSourceContext extends ISourceContext {
+       public void removeUnnecessaryProblems(Member method, int problemLineNumber);
+}
index 90f7aa74c5558436684a382444805ff67500d88c..1ad205845ab4c1c279587e7baf32e6bdf1660f72 100644 (file)
@@ -112,6 +112,9 @@ public abstract class World implements Dump.INode {
     // Records whether ASM is around ... so we might use it for delegates
     protected static boolean isASMAround;
     
+       private long errorThreshold;
+       private long warningThreshold;
+    
     static {
        try {
                Class c = Class.forName("org.aspectj.org.objectweb.asm.ClassVisitor");
@@ -688,6 +691,31 @@ public abstract class World implements Dump.INode {
        behaveInJava5Way = b;
     }
        
+       /**
+        * Set the error and warning threashold which can be taken from 
+        * CompilerOptions (see bug 129282)
+        * 
+        * @param errorThreshold
+        * @param warningThreshold
+        */
+       public void setErrorAndWarningThreshold(long errorThreshold, long warningThreshold) {
+               this.errorThreshold = errorThreshold;
+               this.warningThreshold = warningThreshold;
+       }
+       
+       /**
+        * @return true if ignoring the UnusedDeclaredThrownException and false if
+        *         this compiler option is set to error or warning
+        */
+       public boolean isIgnoringUnusedDeclaredThrownException() {
+               // the 0x800000 is CompilerOptions.UnusedDeclaredThrownException
+               // which is ASTNode.bit24
+               if((this.errorThreshold & 0x800000) != 0 
+                               || (this.warningThreshold & 0x800000) != 0)
+                       return false;
+               return true;
+       }
+       
        public void performExtraConfiguration(String config) {
                if (config==null) return;
                // Bunch of name value pairs to split
index 6823e3339b14261868ef3de508a4b88f15c13016..f849996a3bd591d50ec8fdbb2cbb9dda2bf4f0ab 100644 (file)
@@ -28,6 +28,7 @@ import org.aspectj.weaver.Advice;
 import org.aspectj.weaver.AdviceKind;
 import org.aspectj.weaver.AjAttribute;
 import org.aspectj.weaver.BCException;
+import org.aspectj.weaver.IEclipseSourceContext;
 import org.aspectj.weaver.ISourceContext;
 import org.aspectj.weaver.Member;
 import org.aspectj.weaver.ResolvedMember;
@@ -186,6 +187,34 @@ public class BcelAdvice extends Advice {
     public void implementOn(Shadow s) {
         hasMatchedAtLeastOnce=true;
         BcelShadow shadow = (BcelShadow) s;
+        
+        // remove any unnecessary exceptions if the compiler option is set to
+        // error or warning and if this piece of advice throws exceptions
+        // (bug 129282). This may be expanded to include other compiler warnings
+        // at the moment it only deals with 'declared exception is not thrown'
+        if (!shadow.getWorld().isIgnoringUnusedDeclaredThrownException() 
+                       && !thrownExceptions.isEmpty()) {
+               Member member = shadow.getSignature();
+               if (member instanceof BcelMethod) {
+                       removeUnnecessaryProblems((BcelMethod)member, 
+                                       ((BcelMethod)member).getDeclarationLineNumber());
+                       } else {
+                               // we're in a call shadow therefore need the line number of the
+                               // declared method (which may be in a different type). However,
+                       // we want to remove the problems from the CompilationResult
+                               // held within the current type's EclipseSourceContext so need
+                               // the enclosing shadow too
+                               ResolvedMember resolvedMember = shadow.getSignature().resolve(shadow.getWorld());
+                               if (resolvedMember instanceof BcelMethod 
+                                               && shadow.getEnclosingShadow() instanceof BcelShadow) { 
+                                       Member enclosingMember = shadow.getEnclosingShadow().getSignature();
+                                       if (enclosingMember instanceof BcelMethod) {
+                                               removeUnnecessaryProblems((BcelMethod)enclosingMember,
+                                                               ((BcelMethod)resolvedMember).getDeclarationLineNumber());
+                                       }
+                               }
+                       }
+               }
 
         //FIXME AV - see #75442, this logic is not enough so for now comment it out until we fix the bug
 //        // callback for perObject AJC MightHaveAspect postMunge (#75442)
@@ -250,6 +279,16 @@ public class BcelAdvice extends Advice {
         }
     }
 
+    private void removeUnnecessaryProblems(BcelMethod method, int problemLineNumber) {
+               ISourceContext sourceContext = method.getSourceContext();
+               if (sourceContext instanceof IEclipseSourceContext) {
+                       if (sourceContext != null 
+                               && sourceContext instanceof IEclipseSourceContext) {
+                               ((IEclipseSourceContext)sourceContext).removeUnnecessaryProblems(method, problemLineNumber);                                            
+                       }
+               }
+    }
+    
     // ---- implementations
        
        private Collection collectCheckedExceptions(UnresolvedType[] excs) {