[Fb-contrib-commit] fb-contrib/src/com/mebigfatguy/fbcontrib/detect FieldCouldBeLocal.java,1.4,1.5
Brought to you by:
dbrosius
From: Dave B. <dbr...@us...> - 2006-03-28 02:38:57
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31169/src/com/mebigfatguy/fbcontrib/detect Modified Files: FieldCouldBeLocal.java Log Message: add SourceLineAnnotations for fields that are only accessed in ctors or static initializers Index: FieldCouldBeLocal.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- FieldCouldBeLocal.java 28 Mar 2006 02:19:55 -0000 1.4 +++ FieldCouldBeLocal.java 28 Mar 2006 02:38:53 -0000 1.5 @@ -143,12 +143,35 @@ } /** - * implements the visitor to do nothing + * 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. * * @param obj the context object of the currently parsed code attribute */ @Override public void visitCode(Code obj) { + String methodName = getMethodName(); + if ("<clinit".equals(methodName) || "<init>".equals(methodName)) + super.visitCode(obj); + } + + + /** + * implements the visitor to add SourceLineAnnotations for fields in constructors and static + * initializers. + * + * @param seen the opcode of the currently visited instruction + */ + public void sawOpcode(int seen) { + if ((seen == GETFIELD) || (seen == PUTFIELD)) { + String fieldName = getNameConstantOperand(); + FieldInfo fi = localizableFields.get(fieldName); + if (fi != null) { + SourceLineAnnotation sla = SourceLineAnnotation.fromVisitedInstruction(this); + fi.setSrcLineAnnotation(sla); + } + } } /** |