Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3621/src/com/mebigfatguy/fbcontrib/detect
Modified Files:
OverlyConcreteParameter.java
Log Message:
don't report on parameters of methods that implement interfaces.
Index: OverlyConcreteParameter.java
===================================================================
RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- OverlyConcreteParameter.java 3 Nov 2005 03:20:12 -0000 1.23
+++ OverlyConcreteParameter.java 11 Nov 2005 02:51:11 -0000 1.24
@@ -40,15 +40,18 @@
import edu.umd.cs.findbugs.BytecodeScanningDetector;
import edu.umd.cs.findbugs.OpcodeStack;
import edu.umd.cs.findbugs.StatelessDetector;
+import edu.umd.cs.findbugs.ba.ClassContext;
public class OverlyConcreteParameter extends BytecodeScanningDetector implements StatelessDetector
{
private BugReporter bugReporter;
+ private JavaClass[] interfaces = null;
private Map<Integer, Map<JavaClass, List<String>>> parameterDefiners = new HashMap<Integer, Map<JavaClass, List<String>>>();
private Set<Integer> usedParameters = new HashSet<Integer>();
private JavaClass objectClass;
private OpcodeStack stack = new OpcodeStack();
private int parmCount;
+ private boolean methodImplementsInterface;
private boolean methodIsStatic;
public OverlyConcreteParameter(final BugReporter bugReporter) {
@@ -67,8 +70,47 @@
}
@Override
+ public void visitClassContext(ClassContext classContext) {
+ try {
+ interfaces = classContext.getJavaClass().getAllInterfaces();
+ super.visitClassContext(classContext);
+ interfaces = null;
+ } catch (ClassNotFoundException cnfe) {
+ bugReporter.reportMissingClass(cnfe);
+ }
+ }
+
+ @Override
+ public void visitMethod(Method obj) {
+ methodImplementsInterface = false;
+ String methodName = obj.getName();
+
+ if (!"<init>".equals(methodName)
+ && !"<clinit>".equals(methodName)) {
+ String methodSig = obj.getSignature();
+
+ outer:for (JavaClass inf : interfaces) {
+ Method[] methods = inf.getMethods();
+ for (Method m : methods) {
+ if (methodName.equals(m.getName())) {
+ if (methodSig.equals(m.getSignature())) {
+ methodImplementsInterface = true;
+ break outer;
+ }
+ }
+ }
+ }
+ }
+
+ super.visitMethod(obj);
+ }
+
+ @Override
public void visitCode(final Code obj) {
try {
+ if (methodImplementsInterface)
+ return;
+
parameterDefiners.clear();
usedParameters.clear();
stack.resetForMethodEntry(this);
@@ -82,6 +124,9 @@
methodIsStatic = m.isStatic();
parmCount = m.getArgumentTypes().length;
+ if (parmCount == 0)
+ return;
+
if (buildParameterDefiners()) {
super.visitCode(obj);
reportBugs();
|