[Fb-contrib-commit] SF.net SVN: fb-contrib: [435] trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/det
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-04-09 23:17:57
|
Revision: 435 Author: dbrosius Date: 2006-04-09 16:17:52 -0700 (Sun, 09 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=435&view=rev Log Message: ----------- prescreen for PUTFIELD and GETFIELD Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java 2006-04-09 23:13:10 UTC (rev 434) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java 2006-04-09 23:17:52 UTC (rev 435) @@ -27,6 +27,7 @@ import java.util.Map; import java.util.Set; +import org.apache.bcel.Constants; import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.Field; import org.apache.bcel.classfile.JavaClass; @@ -37,6 +38,8 @@ import org.apache.bcel.generic.Instruction; import org.apache.bcel.generic.InstructionHandle; +import com.mebigfatguy.fbcontrib.utils.VersionTransition; + import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; @@ -143,6 +146,17 @@ } /** + * looks for methods that contain a GETFIELD or PUTFIELD opcodes + * + * @param method the context object of the current method + * @return if the class uses synchronization + */ + public boolean prescreen(Method method) { + BitSet bytecodeSet = VersionTransition.getBytecodeSet(getClassContext(), method); + return (bytecodeSet != null) && (bytecodeSet.get(Constants.PUTFIELD) || bytecodeSet.get(Constants.GETFIELD)); + } + + /** * implements the visitor to pass through constructors and static initializers to the * byte code scanning code. These methods are not reported, but are used to build * SourceLineAnnotations for fields, if accessed. @@ -151,12 +165,14 @@ */ @Override public void visitCode(Code obj) { - String methodName = getMethodName(); - if ("<clinit".equals(methodName) || "<init>".equals(methodName)) - super.visitCode(obj); + Method m = getMethod(); + if (prescreen(m)) { + String methodName = m.getName(); + if ("<clinit".equals(methodName) || "<init>".equals(methodName)) + super.visitCode(obj); + } } - /** * implements the visitor to add SourceLineAnnotations for fields in constructors and static * initializers. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |