Browse Source

test and fix for 129282

tags/V1_5_2rc1
aclement 18 years ago
parent
commit
d072fd16ec

+ 1
- 0
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java View 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);

+ 38
- 3
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EclipseSourceContext.java View 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;
}

}
}

+ 10
- 0
tests/src/org/aspectj/systemtest/ajc152/Ajc152Tests.java View 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");}

+ 16
- 0
weaver/src/org/aspectj/weaver/IEclipseSourceContext.java View File

@@ -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);
}

+ 28
- 0
weaver/src/org/aspectj/weaver/World.java View 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

+ 39
- 0
weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java View 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) {

Loading…
Cancel
Save