aboutsummaryrefslogtreecommitdiffstats
path: root/weaver
diff options
context:
space:
mode:
authoraclement <aclement>2006-05-31 11:51:21 +0000
committeraclement <aclement>2006-05-31 11:51:21 +0000
commitd072fd16eccdca9df642585297804902f68e16cc (patch)
tree2b2b61ee6bc53a420c7ffc1ccd3371252b9b07f3 /weaver
parent7e86ccf44daa9140a6576e03583c7be7aaa094ff (diff)
downloadaspectj-d072fd16eccdca9df642585297804902f68e16cc.tar.gz
aspectj-d072fd16eccdca9df642585297804902f68e16cc.zip
test and fix for 129282
Diffstat (limited to 'weaver')
-rw-r--r--weaver/src/org/aspectj/weaver/IEclipseSourceContext.java16
-rw-r--r--weaver/src/org/aspectj/weaver/World.java28
-rw-r--r--weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java39
3 files changed, 83 insertions, 0 deletions
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) {