[Fb-contrib-commit] fb-contrib/src/com/mebigfatguy/fbcontrib/detect ClassEnvy.java,1.5,1.6
Brought to you by:
dbrosius
|
From: Dave B. <dbr...@us...> - 2005-10-10 06:36:23
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9906/src/com/mebigfatguy/fbcontrib/detect Modified Files: ClassEnvy.java Log Message: more restrictive tests for class envy. Subtract out ALOAD calls, and don't report on <clinit> Index: ClassEnvy.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- ClassEnvy.java 1 Oct 2005 07:38:02 -0000 1.5 +++ ClassEnvy.java 10 Oct 2005 06:36:14 -0000 1.6 @@ -25,6 +25,7 @@ import org.apache.bcel.Repository; import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.JavaClass; +import org.apache.bcel.classfile.Method; import org.apache.bcel.generic.Type; import edu.umd.cs.findbugs.BugInstance; @@ -44,6 +45,8 @@ private String clsName; private Map<String, Integer> clsAccessCount; private int thisClsAccessCount; + private String methodName; + private boolean methodIsStatic; private double envyPercent = 0.90; public ClassEnvy(final BugReporter bugReporter) { @@ -72,11 +75,18 @@ super.visitClassContext(classContext); } + public void visitMethod(final Method obj) { + methodName = obj.getName(); + methodIsStatic = (obj.getAccessFlags() & ACC_STATIC) != 0; + } @Override public void visitCode(final Code obj) { stack.resetForMethodEntry(this); clsAccessCount = new HashMap<String, Integer>(); thisClsAccessCount = 0; + if ("<clinit>".equals(methodName)) + return; + super.visitCode(obj); String bestEnvy = null; @@ -129,6 +139,8 @@ countClassAccess(1); } else if (seen == GETFIELD) { countClassAccess(0); + } else if ((seen == ALOAD_0) && (!methodIsStatic)) { + countClassAccess(clsName); } } finally { stack.sawOpcode(this, seen); |