[Fb-contrib-commit] fb-contrib/src/com/mebigfatguy/fbcontrib/detect ClassEnvy.java,1.16,1.17
Brought to you by:
dbrosius
|
From: Dave B. <dbr...@us...> - 2005-12-05 05:43:52
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23618/src/com/mebigfatguy/fbcontrib/detect Modified Files: ClassEnvy.java Log Message: javadoc Index: ClassEnvy.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- ClassEnvy.java 5 Dec 2005 05:21:15 -0000 1.16 +++ ClassEnvy.java 5 Dec 2005 05:43:44 -0000 1.17 @@ -39,7 +39,10 @@ import edu.umd.cs.findbugs.StatelessDetector; import edu.umd.cs.findbugs.ba.ClassContext; - +/** + * finds methods that excessively use methods from another class. This probably means + * these methods should be defined in that other class. + */ public class ClassEnvy extends BytecodeScanningDetector implements StatelessDetector { private static final String ENVY_PERCENT_PROPERTY = "fb-contrib.ce.percent"; @@ -91,6 +94,11 @@ return super.clone(); } + /** + * overrides the visitor to collect package and class names + * + * @param classContext the context object that holds the JavaClass being parsed + */ @Override public void visitClassContext(final ClassContext classContext) { JavaClass cls = classContext.getJavaClass(); @@ -99,10 +107,23 @@ super.visitClassContext(classContext); } + /** + * overrides the visitor to check whether the method is static + * + * @param obj the method currently being parsed + */ + @Override public void visitMethod(final Method obj) { methodName = obj.getName(); methodIsStatic = (obj.getAccessFlags() & ACC_STATIC) != 0; } + + /** + * overrides the visitor to look for the method that uses another class the most, and + * if it exceeds the threshold reports it + * + * @param obj the code that is currently being parsed + */ @Override public void visitCode(final Code obj) { stack.resetForMethodEntry(this); @@ -143,6 +164,12 @@ } } + /** + * overrides the visitor to look for method calls, and populate a class access count map + * based on the owning class of methods called. + * + * @param seen the opcode currently being parsed + */ @Override public void sawOpcode(final int seen) { try { @@ -171,6 +198,13 @@ } } + /** + * return whether or not a class implements a common or marker interface + * + * @param name the class name to check + * + * @return if this class implements a common or marker interface + */ private boolean implementsCommonInterface(String name) { try { JavaClass cls = Repository.lookupClass(name); @@ -191,6 +225,13 @@ } } + /** + * increment the count of class access of the class on the stack + * + * @param classAtStackIndex the position on the stack of the class in question + * + * @return true if the class is counted + */ private boolean countClassAccess(final int classAtStackIndex) { String calledClass = null; @@ -213,6 +254,12 @@ return true; } + /** + * increment the count of class access of the specified class if it is in a similar + * package to the caller, and is not general purpose + * + * @param calledClass the class to check + */ private void countClassAccess(final String calledClass) { if (calledClass.equals(clsName)) thisClsAccessCount++; @@ -231,6 +278,11 @@ } } + /** + * add the current line number to a set of line numbers + * + * @param lineNumbers the current set of line numbers + */ private void addLineNumber(Set<Integer> lineNumbers) { LineNumberTable lnt = getCode().getLineNumberTable(); if (lnt == null) @@ -244,6 +296,14 @@ } } } + + /** + * checks to see if the specified class is a built in class, or implements a simple interface + * + * @param className the class in question + * + * @return whether or not the class is general purpose + */ private boolean generalPurpose(final String className) { if (className.startsWith("java.") || className.startsWith("javax.")) @@ -283,6 +343,13 @@ return false; } + /** + * parses the package name from a fully qualified class name + * + * @param className the class in question + * + * @return the package of the class + */ private String getPackageName(final String className) { int dotPos = className.lastIndexOf("."); if (dotPos < 0) @@ -290,6 +357,15 @@ return className.substring(0, dotPos); } + /** + * returns whether or not the two packages have the same first 'depth' parts, if they exist + * + * @param packName1 the first package to check + * @param packName2 the second package to check + * @param depth the number of package parts to check + * + * @return if they are similar + */ private boolean similarPackages(final String packName1, final String packName2, int depth) { if (depth == 0) return true; |