OSDN Git Service

cflib は plugins プロジェクトから,Stigmata直下のプロジェクトに移行したため,このリポジトリからは削除した.
[stigmata/stigmata-plugins.git] / kgram / src / main / java / jp / sourceforge / stigmata / birthmarks / kgram / KGramBasedBirthmarkExtractor.java
1 package jp.sourceforge.stigmata.birthmarks.kgram;
2
3 import jp.sourceforge.stigmata.Birthmark;
4 import jp.sourceforge.stigmata.BirthmarkContext;
5 import jp.sourceforge.stigmata.BirthmarkElement;
6 import jp.sourceforge.stigmata.ExtractionUnit;
7 import jp.sourceforge.stigmata.birthmarks.ASMBirthmarkExtractor;
8 import jp.sourceforge.stigmata.birthmarks.BirthmarkExtractVisitor;
9 import jp.sourceforge.stigmata.spi.BirthmarkService;
10
11 import org.objectweb.asm.ClassWriter;
12
13 /**
14  * @author Haruaki TAMADA
15  */
16 public class KGramBasedBirthmarkExtractor extends ASMBirthmarkExtractor{
17     private int kvalue = 4;
18
19     public KGramBasedBirthmarkExtractor(BirthmarkService spi){
20         super(spi);
21     }
22
23     public KGramBasedBirthmarkExtractor(){
24         super();
25     }
26
27     public void setKValue(int kvalue){
28         this.kvalue = kvalue;
29     }
30
31     public int getKValue(){
32         return kvalue;
33     }
34
35     @Override
36     public BirthmarkExtractVisitor createExtractVisitor(ClassWriter writer, 
37             Birthmark birthmark, BirthmarkContext context){
38         KGramBasedBirthmarkExtractVisitor extractor = 
39             new KGramBasedBirthmarkExtractVisitor(writer, birthmark, context);
40         extractor.setKValue(getKValue());
41         return extractor;
42     }
43
44     @Override
45     public ExtractionUnit[] getAcceptableUnits(){
46         return new ExtractionUnit[] {
47             ExtractionUnit.CLASS, ExtractionUnit.PACKAGE,
48             ExtractionUnit.ARCHIVE, 
49         };
50     }
51
52
53     @Override
54     public BirthmarkElement buildElement(String value) {
55         value = value.trim();
56         if(value.startsWith("{") && value.endsWith("}")){
57             String[] param = 
58                 value.substring(1, value.length() - 1).split(", *");
59             KGram<Integer> kgram = new KGram<Integer>(param.length);
60             for(int i = 0; i < param.length; i++){
61                 kgram.set(i, new Integer(param[i].trim()));
62             }
63             return new KGramBasedBirthmarkElement<Integer>(kgram);
64         }
65         return null;
66     }
67 }