Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22422/src/com/mebigfatguy/fbcontrib/detect
Added Files:
StaticMethodInstanceInvocation.java
Log Message:
new SMII detector, intial checkin
--- NEW FILE: StaticMethodInstanceInvocation.java ---
/*
* fb-contrib - Auxilliary detectors for Java programs
* Copyright (C) 2005 Dave Brosius
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.mebigfatguy.fbcontrib.detect;
import org.apache.bcel.classfile.Method;
import org.apache.bcel.generic.Type;
import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.BugReporter;
import edu.umd.cs.findbugs.BytecodeScanningDetector;
import edu.umd.cs.findbugs.OpcodeStack;
public class StaticMethodInstanceInvocation extends BytecodeScanningDetector {
private static final int SEEN_NOTHING = 0;
private static final int SEEN_ALOAD = 1;
private static final int SEEN_POP = 2;
private BugReporter bugReporter;
private OpcodeStack stack = new OpcodeStack();
private int state;
public StaticMethodInstanceInvocation(BugReporter bugReporter) {
this.bugReporter = bugReporter;
}
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
@Override
public void visitMethod(Method obj) {
state = SEEN_NOTHING;
stack.resetForMethodEntry(this);
super.visitMethod(obj);
}
@Override
public void sawOpcode(int seen) {
try {
switch (state) {
case SEEN_NOTHING:
if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3)))
state = SEEN_ALOAD;
break;
case SEEN_ALOAD:
if (seen == POP)
state = SEEN_POP;
else
state = SEEN_NOTHING;
break;
case SEEN_POP:
if (seen == INVOKESTATIC) {
String sig = getSigConstantOperand();
Type[] args = Type.getArgumentTypes(getSigConstantOperand());
if (args.length <= stack.getStackDepth()) {
bugReporter.reportBug(new BugInstance(this, "SMII_STATIC_METHOD_INSTANCE_INVOCATION", NORMAL_PRIORITY)
.addClass(this)
.addMethod(this)
.addSourceLine(this));
state = SEEN_NOTHING;
} else {
Type result = Type.getReturnType(sig);
if ("V".equals(result.getSignature()))
state = SEEN_NOTHING;
}
} else if ((seen == ASTORE)
|| ((seen >= ASTORE_0) && (seen <= ASTORE_3))
|| (seen == PUTFIELD)
|| (seen == ATHROW)
|| (seen == GOTO)) {
state = SEEN_NOTHING;
} else if ((seen == INVOKESPECIAL)
|| (seen == INVOKEINTERFACE)
|| (seen == INVOKEVIRTUAL)) {
Type result = Type.getReturnType(getSigConstantOperand());
if ("V".equals(result.getSignature()))
state = SEEN_NOTHING;
}
break;
}
} finally {
stack.sawOpcode(this, seen);
}
}
}
|