[Fb-contrib-commit] fb-contrib/src/com/mebigfatguy/fbcontrib/detect FieldCouldBeLocal.java,1.1,1.2
Brought to you by:
dbrosius
|
From: Dave B. <dbr...@us...> - 2006-03-27 06:22:06
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27585/src/com/mebigfatguy/fbcontrib/detect Modified Files: FieldCouldBeLocal.java Log Message: FieldAnnotation's don't play nice with hashsets, so use a String keyed HashMap Index: FieldCouldBeLocal.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- FieldCouldBeLocal.java 27 Mar 2006 05:56:54 -0000 1.1 +++ FieldCouldBeLocal.java 27 Mar 2006 06:21:56 -0000 1.2 @@ -20,8 +20,10 @@ package com.mebigfatguy.fbcontrib.detect; import java.util.BitSet; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.Map; import java.util.Set; import org.apache.bcel.classfile.Code; @@ -53,7 +55,7 @@ private BugReporter bugReporter; private ClassContext clsContext; - private Set<FieldAnnotation> localizableFields = new HashSet<FieldAnnotation>(); + private Map<String, FieldAnnotation> localizableFields = new HashMap<String, FieldAnnotation>(); private CFG cfg; private ConstantPoolGen cpg; private BitSet visitedBlocks = new BitSet(); @@ -94,13 +96,13 @@ for (Field f : fields) { if ((!f.isStatic()) && (f.isPrivate() || (clsIsFinal && f.isProtected()))) { FieldAnnotation fa = new FieldAnnotation(cls.getClassName(), f.getName(), f.getSignature(), false); - localizableFields.add(fa); + localizableFields.put(f.getName(), fa); } } if (localizableFields.size() > 0) { super.visitClassContext(classContext); - for (FieldAnnotation fa : localizableFields) { + for (FieldAnnotation fa : localizableFields.values()) { bugReporter.reportBug(new BugInstance(this, "FCBL_FIELD_COULD_BE_LOCAL", NORMAL_PRIORITY) .addClass(this) .addField(fa)); @@ -125,7 +127,7 @@ cpg = new ConstantPoolGen(getConstantPool()); cfg = clsContext.getCFG(obj); BasicBlock bb = cfg.getEntry(); - Set<FieldAnnotation> uncheckedFields = new HashSet<FieldAnnotation>(localizableFields); + Set<String> uncheckedFields = new HashSet<String>(localizableFields.keySet()); visitedBlocks.clear(); checkBlock(bb, uncheckedFields); } @@ -139,6 +141,7 @@ * * @param obj the context object of the currently parsed code attribute */ + @Override public void visitCode(Code obj) { } @@ -151,7 +154,7 @@ * @param bb this basic block * @param uncheckedFields the list of fields to look for */ - private void checkBlock(BasicBlock bb, Set<FieldAnnotation> uncheckedFields) { + private void checkBlock(BasicBlock bb, Set<String> uncheckedFields) { visitedBlocks.set(bb.getId()); InstructionIterator ii = bb.instructionIterator(); while (ii.hasNext()) { @@ -159,10 +162,15 @@ Instruction ins = ih.getInstruction(); if (ins instanceof FieldInstruction) { FieldInstruction fi = (FieldInstruction) ins; - FieldAnnotation fa = new FieldAnnotation(getClassName(), fi.getFieldName(cpg), fi.getSignature(cpg), false); - uncheckedFields.remove(fa); - if (ins instanceof GETFIELD) - localizableFields.remove(fa); + String fieldName = fi.getFieldName(cpg); + uncheckedFields.remove(fieldName); + if (uncheckedFields.size() == 0) + return; + if (ins instanceof GETFIELD) { + localizableFields.remove(fieldName); + if (localizableFields.size() == 0) + return; + } } } @@ -172,7 +180,7 @@ Edge e = oei.next(); BasicBlock cb = e.getTarget(); if (!visitedBlocks.get(cb.getId())) { - Set<FieldAnnotation> subCheckedFields = new HashSet<FieldAnnotation>(uncheckedFields); + Set<String> subCheckedFields = new HashSet<String>(uncheckedFields); checkBlock(cb, subCheckedFields); if (localizableFields.size() == 0) return; |