OSDN Git Service

daily commit
authortama3 <tama3@acee48c3-7b26-0410-bdac-b3d0e5314bbc>
Thu, 27 Nov 2008 11:02:01 +0000 (11:02 +0000)
committertama3 <tama3@acee48c3-7b26-0410-bdac-b3d0e5314bbc>
Thu, 27 Nov 2008 11:02:01 +0000 (11:02 +0000)
git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/stigmata/plugins/trunk@324 acee48c3-7b26-0410-bdac-b3d0e5314bbc

wsp/pom.xml
wsp/src/main/java/jp/sourceforge/stigmata/birthmarks/wsp/CurrentDepth.java [new file with mode: 0644]
wsp/src/main/java/jp/sourceforge/stigmata/birthmarks/wsp/StackPattern.java [new file with mode: 0644]
wsp/src/main/java/jp/sourceforge/stigmata/birthmarks/wsp/StackPatternBasedBirthmarkElement.java [new file with mode: 0644]
wsp/src/main/java/jp/sourceforge/stigmata/birthmarks/wsp/StackPatternBasedBirthmarkExtractor.java

index 48846ee..224b92f 100644 (file)
@@ -17,7 +17,7 @@
       <groupId>jp.sourceforge</groupId>
       <artifactId>stigmata</artifactId>
       <version>2.0.0-SNAPSHOT</version>
-      <scope>compile</scope>
+      <scope>provided</scope>
     </dependency>
   </dependencies>
 </project>
diff --git a/wsp/src/main/java/jp/sourceforge/stigmata/birthmarks/wsp/CurrentDepth.java b/wsp/src/main/java/jp/sourceforge/stigmata/birthmarks/wsp/CurrentDepth.java
new file mode 100644 (file)
index 0000000..b23fc17
--- /dev/null
@@ -0,0 +1,19 @@
+package jp.sourceforge.stigmata.birthmarks.wsp;
+
+public class CurrentDepth{
+    private Opcode opcode;
+    private int depth;
+
+    public CurrentDepth(int depth, Opcode opcode){
+        this.depth = depth;
+        this.opcode = opcode;
+    }
+
+    public int getDepth(){
+        return depth;
+    }
+
+    public Opcode getOpcode(){
+        return opcode;
+    }
+}
diff --git a/wsp/src/main/java/jp/sourceforge/stigmata/birthmarks/wsp/StackPattern.java b/wsp/src/main/java/jp/sourceforge/stigmata/birthmarks/wsp/StackPattern.java
new file mode 100644 (file)
index 0000000..e120ff6
--- /dev/null
@@ -0,0 +1,29 @@
+package jp.sourceforge.stigmata.birthmarks.wsp;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+public class StackPattern implements Iterable<CurrentDepth>{
+    private List<CurrentDepth> depthList = new ArrayList<CurrentDepth>();
+
+    public StackPattern(){
+    }
+
+    public int getLength(){
+        return depthList.size();
+    }
+
+    public void update(int depth, Opcode opcode){
+        update(new CurrentDepth(depth, opcode));
+    }
+
+    public void update(CurrentDepth depth){
+        depthList.add(depth);
+    }
+
+    public Iterator<CurrentDepth> iterator(){
+        return Collections.unmodifiableList(depthList).iterator();
+    }
+}
diff --git a/wsp/src/main/java/jp/sourceforge/stigmata/birthmarks/wsp/StackPatternBasedBirthmarkElement.java b/wsp/src/main/java/jp/sourceforge/stigmata/birthmarks/wsp/StackPatternBasedBirthmarkElement.java
new file mode 100644 (file)
index 0000000..5ace5f5
--- /dev/null
@@ -0,0 +1,27 @@
+package jp.sourceforge.stigmata.birthmarks.wsp;
+
+/*
+ * $Id$
+ */
+
+import jp.sourceforge.stigmata.BirthmarkElement;
+
+/**
+ * 
+ * @author Haruaki TAMADA
+ * @version $Revision$ 
+ */
+public class StackPatternBasedBirthmarkElement extends BirthmarkElement{
+    private static final long serialVersionUID = 7965456413167854L;
+
+    private StackPattern pattern;
+
+    public StackPatternBasedBirthmarkElement(StackPattern pattern){
+        super(pattern.toString());
+        this.pattern = pattern;
+    }
+
+    public StackPattern getPattern(){
+        return pattern;
+    }
+}
index 8cb1f43..183306f 100644 (file)
@@ -29,16 +29,15 @@ import org.objectweb.asm.MethodVisitor;
  * @version $Revision$
  */
 public class StackPatternBasedBirthmarkExtractor extends ASMBirthmarkExtractor{
+    public StackPatternBasedBirthmarkExtractor(BirthmarkSpi service){
+        super(service);
+    }
 
     @Override
     public BirthmarkExtractVisitor createExtractVisitor(ClassWriter writer, Birthmark birthmark, BirthmarkEnvironment environment){
         return new Visitor(writer, birthmark, environment);
     }
 
-    public StackPatternBasedBirthmarkExtractor(BirthmarkSpi service){
-        super(service);
-    }
-
     @Override
     public ExtractionUnit[] getAcceptableUnits(){
         return new ExtractionUnit[] {
@@ -47,54 +46,71 @@ public class StackPatternBasedBirthmarkExtractor extends ASMBirthmarkExtractor{
     }
 
     private BirthmarkElement[] buildElement(List<Opcode> opcodes){
+        StackPattern pattern = buildStackPattern(opcodes);
         List<BirthmarkElement> elements = new ArrayList<BirthmarkElement>();
+
+        StackPattern subpattern = new StackPattern();
+        for(CurrentDepth depth: pattern){
+            subpattern.update(depth);
+            if(depth.getDepth() == 0){
+                elements.add(new StackPatternBasedBirthmarkElement(subpattern));
+                subpattern = new StackPattern();
+            }
+        }
+        elements.add(new StackPatternBasedBirthmarkElement(subpattern));
+
+        return elements.toArray(new BirthmarkElement[elements.size()]);
+    }
+
+    private StackPattern buildStackPattern(List<Opcode> opcodes){ 
         Map<Label, Integer> tableMap = new HashMap<Label, Integer>();
+        StackPattern pattern = new StackPattern();
 
         int currentDepth = 0;
+        Integer forwardedStatus = null;
         for(Opcode opcode: opcodes){
-            Integer forwardedStatus = null;
-            if(opcode.getCategory() != Opcode.Category.TARGETER){
+            if(opcode.getCategory() == Opcode.Category.TARGETER){
                 forwardedStatus = tableMap.get(((LabelOpcode)opcode).getLabel());
             }
-            if(forwardedStatus == null){
-                currentDepth += opcode.getAct();
-            }
             else{
-                currentDepth = forwardedStatus + opcode.getAct(); 
-            }
-            if(opcode.getCategory() == Opcode.Category.BRANCH){
-                for(Iterator<Label> i = opcode.labels(); i.hasNext(); ){
-                    Label label = i.next();
-                    tableMap.put(label, currentDepth);
+                if(forwardedStatus == null){
+                    currentDepth += opcode.getAct();
+                }
+                else{
+                    currentDepth = forwardedStatus + opcode.getAct(); 
+                }
+                forwardedStatus = null;
+
+                pattern.update(currentDepth, opcode);
+                if(opcode.getCategory() == Opcode.Category.BRANCH){
+                    for(Iterator<Label> i = opcode.labels(); i.hasNext(); ){
+                        Label label = i.next();
+                        tableMap.put(label, currentDepth);
+                    }
                 }
             }
         }
-
-        return elements.toArray(new BirthmarkElement[elements.size()]);
+        return pattern;
     }
 
     private class Visitor extends BirthmarkExtractVisitor{
+        private List<Opcode> opcodeList = new ArrayList<Opcode>();
+
         public Visitor(ClassVisitor visitor, Birthmark birthmark, BirthmarkEnvironment environment){
             super(visitor, birthmark, environment);
         }
 
         public void visitEnd(){
+            BirthmarkElement[] elements = buildElement(opcodeList);
+            for(BirthmarkElement element: elements){
+                addElement(element);
+            }
         }
 
         @Override
         public MethodVisitor visitMethod(int arg0, String arg1, String arg2, String arg3, String[] arg4){
             MethodVisitor visitor = super.visitMethod(arg0, arg1, arg2, arg3, arg4);
-            OpcodeExtractionMethodVisitor opcodeVisitor = new OpcodeExtractionMethodVisitor(visitor);
-            opcodeVisitor.addOpcodeExtractionFinishListener(new OpcodeExtractionFinishListener(){
-                @Override
-                public void finishExtractionOpcodes(List<Opcode> opcodes){
-                    BirthmarkElement[] elements = buildElement(opcodes);
-
-                    for(BirthmarkElement be: elements){
-                        addElement(be);
-                    }
-                }
-            });
+            OpcodeExtractionMethodVisitor opcodeVisitor = new OpcodeExtractionMethodVisitor(visitor, opcodeList);
 
             return opcodeVisitor;
         }