[Fb-contrib-commit] SF.net SVN: fb-contrib: [577] trunk/fb-contrib/src/com/mebigfatguy/fbcontrib
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-08-02 01:05:37
|
Revision: 577 Author: dbrosius Date: 2006-08-01 18:05:27 -0700 (Tue, 01 Aug 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=577&view=rev Log Message: ----------- Initial attempt at a first pass collector/not working yet Added Paths: ----------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectStatistics.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/Statistics.java Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectStatistics.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectStatistics.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/CollectStatistics.java 2006-08-02 01:05:27 UTC (rev 577) @@ -0,0 +1,75 @@ +package com.mebigfatguy.fbcontrib.collect; + +import org.apache.bcel.classfile.Method; + +import edu.umd.cs.findbugs.BugReporter; +import edu.umd.cs.findbugs.BytecodeScanningDetector; +import edu.umd.cs.findbugs.ba.ClassContext; + +public class CollectStatistics extends BytecodeScanningDetector +{ + private static final int SG_INVALID = -1; + private static final int SG_SAW_NOTHING = 0; + private static final int SG_SAW_ALOAD_0 = 1; + private static final int SG_SAW_GETFIELD = 2; + private static final int SG_SAW_RETURN = 3; + + private Statistics statistics = Statistics.getStatistics(); + private int sgState; + + public CollectStatistics(BugReporter bugReporter) { + + } + + @Override + public void visitClassContext(ClassContext classContext) { + + } + + @Override + public void visitMethod(Method obj) { + String methodName = obj.getName(); + String signature = obj.getSignature(); + if (methodName.startsWith("get") + && (signature.indexOf("()") >= 0) + && (signature.indexOf(")V") < 0)) + { + sgState = SG_SAW_NOTHING; + } + else + { + sgState = SG_INVALID; + } + } + + @Override + public void sawOpcode(int seen) { + if (sgState != SG_INVALID) + sawSimpleGetter(seen); + } + + private void sawSimpleGetter(int seen) { + switch (sgState) { + case SG_SAW_NOTHING: + if (seen == ALOAD_0) + sgState = SG_SAW_ALOAD_0; + else + sgState = SG_INVALID; + break; + + case SG_SAW_ALOAD_0: + if (seen == GETFIELD) + sgState = SG_SAW_GETFIELD; + else + sgState = SG_INVALID; + break; + + case SG_SAW_GETFIELD: + if ((seen >= IRETURN) && (seen <= ARETURN)) { + statistics.addSimpleGetter(getMethodName(), getMethodSig()); + } + sgState = SG_INVALID; + break; + } + } +} Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/Statistics.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/Statistics.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/collect/Statistics.java 2006-08-02 01:05:27 UTC (rev 577) @@ -0,0 +1,29 @@ +package com.mebigfatguy.fbcontrib.collect; + +import java.util.HashSet; +import java.util.Set; + +public class Statistics { + + private static Statistics statistics = new Statistics(); + + private Set<String> simpleGetters = new HashSet<String>(); + + + public static Statistics getStatistics() + { + return statistics; + } + + public void clear() { + simpleGetters.clear(); + } + + public void addSimpleGetter(String methodName, String signature) { + simpleGetters.add(methodName + ":" + signature); + } + + public boolean isSimpleGetter(String methodName, String signature) { + return simpleGetters.contains(methodName + ":" + signature); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |