[Fb-contrib-commit] SF.net SVN: fb-contrib: [521] trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/det
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-05-09 07:09:11
|
Revision: 521 Author: dbrosius Date: 2006-05-09 00:08:59 -0700 (Tue, 09 May 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=521&view=rev Log Message: ----------- collect srcline annotations for creations of sync'ed 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-09 06:48:21 UTC (rev 520) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java 2006-05-09 07:08:59 UTC (rev 521) @@ -32,6 +32,7 @@ import edu.umd.cs.findbugs.BytecodeScanningDetector; import edu.umd.cs.findbugs.FieldAnnotation; import edu.umd.cs.findbugs.OpcodeStack; +import edu.umd.cs.findbugs.SourceLineAnnotation; import edu.umd.cs.findbugs.ba.ClassContext; /** @@ -64,6 +65,7 @@ private Map<Integer, String> instanceAliases; private OpcodeStack stack; private int state; + private String className; /** * constructs a NMCS detector given the reporter to report bugs on @@ -82,6 +84,8 @@ staticAliases = new HashMap<Integer, String>(); instanceAliases = new HashMap<Integer, String>(); stack = new OpcodeStack(); + JavaClass cls = classContext.getJavaClass(); + className = cls.getClassName(); super.visitClassContext(classContext); } } finally { @@ -152,6 +156,9 @@ try { stack.mergeJumps(this); isSyncCollection = isSyncCollectionCreation(seen); + if (seen == PUTFIELD) { + processCollectionStore(PUTSTATIC, seen); + } } finally { stack.sawOpcode(this, seen); if (isSyncCollection) { @@ -168,6 +175,8 @@ try { stack.mergeJumps(this); isSyncCollection = isSyncCollectionCreation(seen); + processCollectionStore(PUTFIELD, seen); + } finally { stack.sawOpcode(this, seen); if (isSyncCollection) { @@ -203,4 +212,28 @@ } return false; } + + private void processCollectionStore(int fieldOp, int seen) { + if (seen == fieldOp) { + String fieldClassName = getClassConstantOperand(); + String fieldName = getNameConstantOperand(); + if (fieldClassName.equals(className)) { + 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); + 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. |