diff options
author | aclement <aclement> | 2006-05-31 11:51:21 +0000 |
---|---|---|
committer | aclement <aclement> | 2006-05-31 11:51:21 +0000 |
commit | d072fd16eccdca9df642585297804902f68e16cc (patch) | |
tree | 2b2b61ee6bc53a420c7ffc1ccd3371252b9b07f3 | |
parent | 7e86ccf44daa9140a6576e03583c7be7aaa094ff (diff) | |
download | aspectj-d072fd16eccdca9df642585297804902f68e16cc.tar.gz aspectj-d072fd16eccdca9df642585297804902f68e16cc.zip |
test and fix for 129282
6 files changed, 132 insertions, 3 deletions
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 3d49c7e77..c4d5fd333 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 @@ -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); diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EclipseSourceContext.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EclipseSourceContext.java index 5485397a0..6c6e362f2 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EclipseSourceContext.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EclipseSourceContext.java @@ -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; + } + + } } diff --git a/tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java b/tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java index 87c00def2..c73079d79 100644 --- a/tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java @@ -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 index 000000000..10d02582d --- /dev/null +++ b/weaver/src/org/aspectj/weaver/IEclipseSourceContext.java @@ -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); +} diff --git a/weaver/src/org/aspectj/weaver/World.java b/weaver/src/org/aspectj/weaver/World.java index 90f7aa74c..1ad205845 100644 --- a/weaver/src/org/aspectj/weaver/World.java +++ b/weaver/src/org/aspectj/weaver/World.java @@ -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 diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java b/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java index 6823e3339..f849996a3 100644 --- a/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java +++ b/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java @@ -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) { |