[Fb-contrib-commit] SF.net SVN: fb-contrib: [527] trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/det
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-05-10 03:24:59
|
Revision: 527 Author: dbrosius Date: 2006-05-09 20:24:54 -0700 (Tue, 09 May 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=527&view=rev Log Message: ----------- no need to differentiate static from instance collections Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java 2006-05-10 03:12:34 UTC (rev 526) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java 2006-05-10 03:24:54 UTC (rev 527) @@ -53,8 +53,8 @@ } private static Set<String> syncCollections = new HashSet<String>(); static { - syncCollections.add("java/util/Vector"); - syncCollections.add("java/util/Hashtable"); + syncCollections.add("java.util.Vector"); + syncCollections.add("java.util.Hashtable"); } private static Set<String> modifyingMethods = new HashSet<String>(); static { @@ -84,10 +84,8 @@ private static final int IN_INIT = 2; private BugReporter bugReporter; - private Map<String, FieldAnnotation> staticCollectionFields; - private Map<String, FieldAnnotation> instanceCollectionFields; - private Map<Integer, String> staticAliases; - private Map<Integer, String> instanceAliases; + private Map<String, FieldAnnotation> collectionFields; + private Map<Integer, String> aliases; private OpcodeStack stack; private int state; private String className; @@ -104,35 +102,23 @@ public void visitClassContext(ClassContext classContext) { try { if (collectionClass != null) { - staticCollectionFields = new HashMap<String, FieldAnnotation>(); - instanceCollectionFields = new HashMap<String, FieldAnnotation>(); - staticAliases = new HashMap<Integer, String>(); - instanceAliases = new HashMap<Integer, String>(); + collectionFields = new HashMap<String, FieldAnnotation>(); + aliases = new HashMap<Integer, String>(); stack = new OpcodeStack(); JavaClass cls = classContext.getJavaClass(); className = cls.getClassName(); super.visitClassContext(classContext); - for (FieldAnnotation fa : staticCollectionFields.values()) { + for (FieldAnnotation fa : collectionFields.values()) { if (fa.getSourceLines() != null) { bugReporter.reportBug(new BugInstance(this, "NMCS_NEEDLESS_MEMBER_COLLECTION_SYNCHRONIZATION", NORMAL_PRIORITY) .addClass(this) .addField(fa)); } } - for (FieldAnnotation fa : instanceCollectionFields.values()) { - if (fa.getSourceLines() != null) { - bugReporter.reportBug(new BugInstance(this, "NMCS_NEEDLESS_MEMBER_COLLECTION_SYNCHRONIZATION", NORMAL_PRIORITY) - .addClass(this) - .addField(fa)); - } - } - } } finally { - staticCollectionFields = null; - instanceCollectionFields = null; - staticAliases = null; - instanceAliases = null; + collectionFields = null; + aliases = null; stack = null; } } @@ -146,10 +132,7 @@ JavaClass cls = Repository.lookupClass(signature.substring(1, signature.length() - 1)); if (cls.implementationOf(collectionClass)) { FieldAnnotation fa = FieldAnnotation.fromVisitedField(this); - if (obj.isStatic()) - staticCollectionFields.put(fa.getFieldName(), fa); - else - instanceCollectionFields.put(fa.getFieldName(), fa); + collectionFields.put(fa.getFieldName(), fa); } } catch (ClassNotFoundException cnfe) { bugReporter.reportMissingClass(cnfe); @@ -160,9 +143,8 @@ @Override public void visitCode(Code obj) { - if ((staticCollectionFields.size() + instanceCollectionFields.size()) > 0) { - staticAliases.clear(); - instanceAliases.clear(); + if (collectionFields.size() > 0) { + aliases.clear(); String methodName = getMethodName(); if ("<clinit>".equals(methodName)) state = IN_CLINIT; @@ -240,24 +222,15 @@ OpcodeStack.Item item = stack.getStackItem(parmCount); FieldAnnotation fa = item.getField(); if (fa != null) { - if (fa.isStatic()) - staticCollectionFields.remove(fa.getFieldName()); - else - instanceCollectionFields.remove(fa.getFieldName()); + collectionFields.remove(fa.getFieldName()); } else { int reg = item.getRegisterNumber(); if (reg >= 0) { Integer register = new Integer(reg); - String fName = staticAliases.get(register); + String fName = aliases.get(register); if (fName != null) { - staticCollectionFields.remove(fName); - staticAliases.remove(register); - } else { - fName = instanceAliases.get(register); - if (fName != null) { - instanceCollectionFields.remove(fName); - instanceAliases.remove(register); - } + collectionFields.remove(fName); + aliases.remove(register); } } } @@ -270,10 +243,7 @@ OpcodeStack.Item item = stack.getStackItem(0); FieldAnnotation fa = item.getField(); if (fa != null) { - if (fa.isStatic()) - staticCollectionFields.remove(fa.getFieldName()); - else - instanceCollectionFields.remove(fa.getFieldName()); + collectionFields.remove(fa.getFieldName()); } } break; @@ -308,13 +278,7 @@ if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); if (item.getUserValue() != null) { - Map<String, FieldAnnotation> fields; - if (fieldOp == PUTFIELD) - fields = instanceCollectionFields; - else - fields = staticCollectionFields; - - FieldAnnotation fa = fields.get(fieldName); + FieldAnnotation fa = collectionFields.get(fieldName); if (fa != null) { fa.setSourceLines(SourceLineAnnotation.fromVisitedInstruction(this)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |