OSDN Git Service

cflib は plugins プロジェクトから,Stigmata直下のプロジェクトに移行したため,このリポジトリからは削除した.
[stigmata/stigmata-plugins.git] / wsp / src / main / java / jp / sourceforge / stigmata / birthmarks / wsp / StackPatternBasedBirthmarkExtractor.java
index db88032..5e12f4b 100644 (file)
@@ -1,9 +1,5 @@
 package jp.sourceforge.stigmata.birthmarks.wsp;
 
-/*
- * $Id$
- */
-
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -14,12 +10,12 @@ import jp.sourceforge.stigmata.BirthmarkContext;
 import jp.sourceforge.stigmata.BirthmarkElement;
 import jp.sourceforge.stigmata.ExtractionUnit;
 import jp.sourceforge.stigmata.birthmarks.ASMBirthmarkExtractor;
-import jp.sourceforge.stigmata.birthmarks.BirthmarkElementBuilder;
 import jp.sourceforge.stigmata.birthmarks.BirthmarkExtractVisitor;
-import jp.sourceforge.stigmata.birthmarks.LabelOpcode;
-import jp.sourceforge.stigmata.birthmarks.Opcode;
-import jp.sourceforge.stigmata.birthmarks.OpcodeExtractVisitor;
-import jp.sourceforge.stigmata.spi.BirthmarkSpi;
+import jp.sourceforge.stigmata.cflib.BirthmarkElementBuilder;
+import jp.sourceforge.stigmata.cflib.LabelOpcode;
+import jp.sourceforge.stigmata.cflib.Opcode;
+import jp.sourceforge.stigmata.cflib.OpcodeExtractVisitor;
+import jp.sourceforge.stigmata.spi.BirthmarkService;
 
 import org.objectweb.asm.ClassWriter;
 import org.objectweb.asm.Label;
@@ -27,16 +23,21 @@ import org.objectweb.asm.Label;
 /**
  *
  * @author Haruaki Tamada
- * @version $Revision$
  */
-public class StackPatternBasedBirthmarkExtractor extends ASMBirthmarkExtractor{
-    public StackPatternBasedBirthmarkExtractor(BirthmarkSpi service){
+public class StackPatternBasedBirthmarkExtractor
+        extends ASMBirthmarkExtractor{
+    public StackPatternBasedBirthmarkExtractor(BirthmarkService service){
         super(service);
     }
 
     @Override
-    public BirthmarkExtractVisitor createExtractVisitor(ClassWriter writer, Birthmark birthmark, BirthmarkContext context){
-        return new OpcodeExtractVisitor(writer, birthmark, context, new WSPBirthmarkElementBuilder());
+    public BirthmarkExtractVisitor createExtractVisitor(
+            ClassWriter writer, Birthmark birthmark,
+           BirthmarkContext context){
+
+        return new OpcodeExtractVisitor(
+            writer, birthmark, context, new WSPBirthmarkElementBuilder()
+        );
     }
 
     @Override
@@ -46,38 +47,59 @@ public class StackPatternBasedBirthmarkExtractor extends ASMBirthmarkExtractor{
         };
     }
 
-    private static class WSPBirthmarkElementBuilder implements BirthmarkElementBuilder{
-        public BirthmarkElement[] buildElements(List<Opcode> opcodes, BirthmarkContext context){
+    private static class WSPBirthmarkElementBuilder
+            implements BirthmarkElementBuilder{
+        @Override
+        public BirthmarkElement[] buildElements(List<Opcode> opcodes,
+                                                BirthmarkContext context){
             List<CurrentDepth> pattern = buildStackPattern(opcodes, context);
-            List<BirthmarkElement> elements = new ArrayList<BirthmarkElement>();
+            List<BirthmarkElement> elements =
+                new ArrayList<BirthmarkElement>();
 
             List<CurrentDepth> subPattern = new ArrayList<CurrentDepth>();
             for(CurrentDepth depth: pattern){
                 subPattern.add(depth);
                 if(depth.getDepth() == 0){
-                    elements.add(new StackPatternBasedBirthmarkElement(subPattern.toArray(new CurrentDepth[subPattern.size()])));
+                    elements.add(
+                        new StackPatternBasedBirthmarkElement(
+                            subPattern.toArray(
+                                new CurrentDepth[subPattern.size()]
+                            )
+                        )
+                    );
                     subPattern.clear();
                 }
             }
-            elements.add(new StackPatternBasedBirthmarkElement(subPattern.toArray(new CurrentDepth[subPattern.size()])));
+            elements.add(
+                new StackPatternBasedBirthmarkElement(
+                    subPattern.toArray(new CurrentDepth[subPattern.size()])
+                )
+            );
 
             return elements.toArray(new BirthmarkElement[elements.size()]);
         }
 
         @SuppressWarnings("unchecked")
-        private List<CurrentDepth> buildStackPattern(List<Opcode> opcodes, BirthmarkContext context){
+        private List<CurrentDepth> buildStackPattern(List<Opcode> opcodes,
+                BirthmarkContext context){
             Map<Label, Integer> tableMap = new HashMap<Label, Integer>();
             List<CurrentDepth> pattern = new ArrayList<CurrentDepth>();
-            Map<Integer, Integer> weights = (Map<Integer, Integer>)context.getProperty("birthmarks.wsp.weights");
+            Map<Integer, Integer> weights =
+                (Map<Integer, Integer>)context.getProperty(
+                    "birthmarks.wsp.weights"
+                );
 
             int currentDepth = 0;
             Integer forwardedStatus = null;
             for(Opcode opcode: opcodes){
                 if(opcode.getCategory() == Opcode.Category.TARGETER){
-                    forwardedStatus = tableMap.get(((LabelOpcode)opcode).getLabel());
+                    forwardedStatus =
+                        tableMap.get(((LabelOpcode)opcode).getLabel());
                 }
                 else{
-                    WSPOpcode wspOpcode = new WSPOpcode(opcode, weights.get(opcode.getOpcode()));
+                    WSPOpcode wspOpcode = new WSPOpcode(
+                        opcode, weights.get(opcode.getOpcode())
+                    );
                     if(forwardedStatus == null){
                         currentDepth += opcode.getAct();
                     }
@@ -96,5 +118,10 @@ public class StackPatternBasedBirthmarkExtractor extends ASMBirthmarkExtractor{
             }
             return pattern;
         }
+    }
+
+    @Override
+    public BirthmarkElement buildElement(String value){
+        return new StackPatternBasedBirthmarkElement(value);
     };
 }