<modelVersion>4.0.0</modelVersion>
<groupId>jp.naist.se</groupId>
<artifactId>stigmata</artifactId>
- <version>1.0.1</version>
+ <version>1.1.0</version>
<name>stigmata</name>
<description>Java birthmark toolkit</description>
<url>http://stigmata.sourceforge.jp/</url>
/**
* collections for elements.
*/
- private List<BirthmarkElement> elements = new ArrayList<BirthmarkElement>();
+ protected List<BirthmarkElement> elements = new ArrayList<BirthmarkElement>();
public void addElement(BirthmarkElement element){
elements.add(element);
* to string.
*/
public String toString(){
- return value;
+ return String.valueOf(getValue());
}
/**
createExtractVisitor(ClassWriter writer, Birthmark birthmark, BirthmarkContext context);\r
\r
@Override\r
- public Birthmark extract(InputStream in,\r
+ public Birthmark extract(Birthmark birthmark, InputStream in,\r
BirthmarkContext context) throws BirthmarkExtractionException{\r
BirthmarkExtractionException bee = new BirthmarkExtractionException();\r
\r
try{\r
- Birthmark birthmark = new PlainBirthmark(getProvider().getType());\r
-\r
ClassReader reader = new ClassReader(in);\r
ClassWriter writer = new ClassWriter(false);\r
BirthmarkExtractVisitor visitor = createExtractVisitor(writer, birthmark, context);\r
*/\r
\r
import jp.naist.se.stigmata.AbstractBirthmark;\r
+import jp.naist.se.stigmata.BirthmarkElement;\r
\r
/**\r
* Implementation of plain birthmark.\r
public PlainBirthmark(){\r
}\r
\r
+ public void addElement(int index, BirthmarkElement element){\r
+ elements.add(index, element);\r
+ }\r
+\r
+ public BirthmarkElement getElement(int index){\r
+ return elements.get(index);\r
+ }\r
+\r
public void setType(String type){\r
this.type = type;\r
}\r
--- /dev/null
+package jp.naist.se.stigmata.birthmarks;\r
+\r
+/*\r
+ * $Id$\r
+ */\r
+\r
+/**\r
+ * This interface represents that the implemented class have name and its count.\r
+ * \r
+ * @author Haruaki Tamada\r
+ * @version $Revision$ $Date$\r
+ */\r
+public interface ValueCountable{\r
+ public int getValueCount();\r
+\r
+ public String getValueName();\r
+}\r
--- /dev/null
+package jp.naist.se.stigmata.birthmarks.comparators;\r
+\r
+/*\r
+ * $Id$\r
+ */\r
+\r
+import jp.naist.se.stigmata.Birthmark;\r
+import jp.naist.se.stigmata.BirthmarkComparator;\r
+import jp.naist.se.stigmata.spi.BirthmarkSpi;\r
+\r
+/**\r
+ * abstract birthmark comparator.\r
+ *\r
+ * @author Haruaki Tamada\r
+ * @version $Revision$ $Date$\r
+ */\r
+public abstract class AbstractBirthmarkComparator implements BirthmarkComparator{\r
+ private BirthmarkSpi spi;\r
+\r
+ @Deprecated\r
+ public AbstractBirthmarkComparator(){\r
+ }\r
+\r
+ public AbstractBirthmarkComparator(BirthmarkSpi spi){\r
+ this.spi = spi;\r
+ }\r
+\r
+ public BirthmarkSpi getProvider(){\r
+ return spi;\r
+ }\r
+\r
+ public String getType(){\r
+ return spi.getType();\r
+ }\r
+\r
+ public abstract double compare(Birthmark b1, Birthmark b2);\r
+\r
+ public int getCompareCount(Birthmark b1, Birthmark b2){\r
+ return b1.getElementCount() + b2.getElementCount();\r
+ }\r
+}\r
--- /dev/null
+package jp.naist.se.stigmata.birthmarks.comparators;\r
+\r
+/*\r
+ * $Id$\r
+ */\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import jp.naist.se.stigmata.Birthmark;\r
+import jp.naist.se.stigmata.BirthmarkElement;\r
+import jp.naist.se.stigmata.birthmarks.ValueCountable;\r
+import jp.naist.se.stigmata.spi.BirthmarkSpi;\r
+\r
+/**\r
+ * Comparing birthmarks by cosine similarity algorithm. This class compares\r
+ * birthmarks which must be implemented\r
+ * {@link ValueCountable <code>ValueCountable</code>} interface.\r
+ * \r
+ * @author Haruaki Tamada\r
+ * @version $Revision$ $Date$\r
+ */\r
+public class CosineSimilarityBirthmarkComparator extends\r
+ AbstractBirthmarkComparator{\r
+\r
+ public CosineSimilarityBirthmarkComparator(BirthmarkSpi spi){\r
+ super(spi);\r
+ }\r
+\r
+ public double compare(Birthmark b1, Birthmark b2){\r
+ if(!b1.getType().equals(b2.getType())){\r
+ return Double.NaN;\r
+ }\r
+ if(b1.getElementCount() == 0 && b2.getElementCount() == 0){\r
+ return 1d;\r
+ }\r
+ else if(b1.getElementCount() == 0 || b2.getElementCount() == 0){\r
+ return 0d;\r
+ }\r
+\r
+ Map<String, CountPair> pairs = new HashMap<String, CountPair>();\r
+ addCount(pairs, b1, true);\r
+ addCount(pairs, b2, false);\r
+\r
+ double norm1 = norm(pairs, true);\r
+ double norm2 = norm(pairs, false);\r
+ double product = innerproduct(pairs);\r
+\r
+ return product / (norm1 * norm2);\r
+ }\r
+\r
+ private double innerproduct(Map<String, CountPair> pairs){\r
+ double sum = 0;\r
+ for(CountPair pair: pairs.values()){\r
+ sum += pair.get(true) * pair.get(false);\r
+ }\r
+ return sum;\r
+ }\r
+\r
+ private double norm(Map<String, CountPair> pairs, boolean first){\r
+ double sum = 0;\r
+ for(CountPair pair: pairs.values()){\r
+ sum += pair.get(first) * pair.get(first);\r
+ }\r
+ return Math.sqrt(sum);\r
+ }\r
+\r
+ private void addCount(Map<String, CountPair> pairs, Birthmark birthmark, boolean first){\r
+ for(BirthmarkElement element: birthmark){\r
+ ValueCountable vc = (ValueCountable)element;\r
+ CountPair cp = pairs.get(vc.getValueName());\r
+ if(cp == null){\r
+ cp = new CountPair();\r
+ pairs.put(vc.getValueName(), cp);\r
+ }\r
+ cp.set(first, vc.getValueCount());\r
+ }\r
+ }\r
+\r
+ private class CountPair{\r
+ private int c1 = 0;\r
+ private int c2 = 0;\r
+\r
+ public int get(boolean first){\r
+ if(first){\r
+ return c1;\r
+ }\r
+ else{\r
+ return c2;\r
+ }\r
+ }\r
+\r
+ public void set(boolean first, int count){\r
+ if(first){\r
+ c1 = count;\r
+ }\r
+ else{\r
+ c2 = count;\r
+ }\r
+ }\r
+ }\r
+}\r
--- /dev/null
+package jp.naist.se.stigmata.birthmarks.comparators;\r
+\r
+/*\r
+ * $Id: DPMatchingBirthmarkComparatorService.java 130 2007-06-13 10:08:01Z tama3 $\r
+ */\r
+\r
+import jp.naist.se.stigmata.BirthmarkComparator;\r
+import jp.naist.se.stigmata.spi.BirthmarkSpi;\r
+\r
+/**\r
+ * SPI of {@link BirthmarkComparator <code>BirthmarkComparator</code>}.\r
+ * Comparing birthmarks by cosine similarity algorithm.\r
+ *\r
+ * @author Haruaki TAMADA\r
+ * @version $Revision: 130 $ $Date: 2007-06-13 19:08:01 +0900 (Wed, 13 Jun 2007) $\r
+ */\r
+public class CosineSimilarityBirthmarkComparatorService extends AbstractBirthmarkComparatorService{\r
+ /**\r
+ * returns a type of the birthmark this service provides.\r
+ */\r
+ public String getType(){\r
+ return "cosine";\r
+ }\r
+\r
+ public String getComparatorClassName(){\r
+ return "jp.naist.se.stigmata.birthmarks.comparators.CosineSimilarityBirthmarkComparator";\r
+ }\r
+\r
+ /**\r
+ * returns a extractor for the birthmark of this service.\r
+ */\r
+ public BirthmarkComparator getComparator(BirthmarkSpi service){\r
+ return new CosineSimilarityBirthmarkComparator(service);\r
+ }\r
+}\r
+\r
*/
import jp.naist.se.stigmata.Birthmark;
-import jp.naist.se.stigmata.BirthmarkComparator;
import jp.naist.se.stigmata.BirthmarkElement;
import jp.naist.se.stigmata.spi.BirthmarkSpi;
* @author Haruaki TAMADA
* @version $Revision$ $Date$
*/
-public class DPMatchingBirthmarkComparator implements BirthmarkComparator{
- private BirthmarkSpi spi;
+public class DPMatchingBirthmarkComparator extends AbstractBirthmarkComparator{
private int mismatchPenalty = 5;
private int shiftPenalty = 1;
- public DPMatchingBirthmarkComparator(){
- }
-
public DPMatchingBirthmarkComparator(BirthmarkSpi spi){
- this.spi = spi;
- }
-
- public BirthmarkSpi getProvider(){
- return spi;
- }
-
- public String getType(){
- return spi.getType();
+ super(spi);
}
public int getMismatchPenalty(){
*/
import jp.naist.se.stigmata.Birthmark;
-import jp.naist.se.stigmata.BirthmarkComparator;
import jp.naist.se.stigmata.BirthmarkElement;
import jp.naist.se.stigmata.spi.BirthmarkSpi;
* @author Haruaki TAMADA
* @version $Revision$ $Date$
*/
-public class EditDistanceBirthmarkComparator implements BirthmarkComparator{
- private BirthmarkSpi spi;
-
- public EditDistanceBirthmarkComparator(){
- }
-
+public class EditDistanceBirthmarkComparator extends AbstractBirthmarkComparator{
public EditDistanceBirthmarkComparator(BirthmarkSpi spi){
- this.spi = spi;
- }
-
- public BirthmarkSpi getProvider(){
- return spi;
- }
-
- public String getType(){
- return spi.getType();
+ super(spi);
}
public double compare(Birthmark b1, Birthmark b2) {
return (double)(length - d) / length;
}
- public int getCompareCount(Birthmark b1, Birthmark b2){
- return b1.getElementCount() + b2.getElementCount();
- }
-
protected int[][] createDistanceMatrics(BirthmarkElement[] element1,
BirthmarkElement[] element2){
int[][] distance = new int[element1.length + 1][element2.length + 1];
* @version $Revision$ $Date$
*/
public class ExtendedEditDistanceBirthmarkComparator extends EditDistanceBirthmarkComparator{
- public ExtendedEditDistanceBirthmarkComparator(){
- }
-
public ExtendedEditDistanceBirthmarkComparator(BirthmarkSpi spi){
super(spi);
}
* $Id$
*/
-import java.util.Set;
import java.util.HashSet;
+import java.util.Set;
import jp.naist.se.stigmata.Birthmark;
-import jp.naist.se.stigmata.BirthmarkComparator;
import jp.naist.se.stigmata.BirthmarkElement;
import jp.naist.se.stigmata.spi.BirthmarkSpi;
* @author Haruaki TAMADA
* @version $Revision$ $Date$
*/
-public class LogicalAndBirthmarkComparator implements BirthmarkComparator{
- private BirthmarkSpi spi;
-
- public LogicalAndBirthmarkComparator(){
- }
-
+public class LogicalAndBirthmarkComparator extends AbstractBirthmarkComparator{
public LogicalAndBirthmarkComparator(BirthmarkSpi spi){
- this.spi = spi;
- }
-
- public BirthmarkSpi getProvider(){
- return spi;
- }
-
- public String getType(){
- return spi.getType();
+ super(spi);
}
public double compare(Birthmark b1, Birthmark b2) {
return Double.NaN;
}
-
BirthmarkElement[] element1 = b1.getElements();
BirthmarkElement[] element2 = b2.getElements();
Set<BirthmarkElement> set1 = new HashSet<BirthmarkElement>();
* @author Haruaki TAMADA
* @version $Revision$ $Date$
*/
-public class PlainBirthmarkComparator implements BirthmarkComparator{
- private BirthmarkSpi spi;
-
- public PlainBirthmarkComparator(){
- }
-
+public class PlainBirthmarkComparator extends AbstractBirthmarkComparator{
public PlainBirthmarkComparator(BirthmarkSpi spi){
- this.spi = spi;
- }
-
- public BirthmarkSpi getProvider(){
- return spi;
- }
-
- public String getType(){
- return spi.getType();
+ super(spi);
}
public double compare(Birthmark b1, Birthmark b2) {
import jp.naist.se.stigmata.Birthmark;
import jp.naist.se.stigmata.BirthmarkContext;
+import jp.naist.se.stigmata.ExtractionUnit;
import jp.naist.se.stigmata.birthmarks.ASMBirthmarkExtractor;
import jp.naist.se.stigmata.birthmarks.BirthmarkExtractVisitor;
import jp.naist.se.stigmata.spi.BirthmarkSpi;
public BirthmarkExtractVisitor createExtractVisitor(ClassWriter writer, Birthmark birthmark, BirthmarkContext context) {
return new ConstantValueOfFieldVariableBirthmarkExtractVisitor(writer, birthmark, context);
}
+
+ public ExtractionUnit[] getAcceptableUnits(){
+ return new ExtractionUnit[] {
+ ExtractionUnit.CLASS, ExtractionUnit.PACKAGE, ExtractionUnit.ARCHIVE,
+ };
+ }
}
--- /dev/null
+package jp.naist.se.stigmata.birthmarks.fmc;\r
+\r
+/*\r
+ * $Id$\r
+ */\r
+\r
+import java.util.Arrays;\r
+import java.util.Comparator;\r
+import java.util.HashMap;\r
+import java.util.Iterator;\r
+import java.util.Map;\r
+\r
+import jp.naist.se.stigmata.AbstractBirthmark;\r
+import jp.naist.se.stigmata.BirthmarkElement;\r
+import jp.naist.se.stigmata.utils.ArrayIterator;\r
+\r
+/**\r
+ * \r
+ * @author Haruaki Tamada\r
+ * @version $Revision$ $Date$\r
+ */\r
+public class FrequencyMethodCallBirthmark extends AbstractBirthmark{\r
+ private static final long serialVersionUID = 1905526895627693908L;\r
+\r
+ private Map<String, FrequencyOfMethodBirthmarkElement> counts = new HashMap<String, FrequencyOfMethodBirthmarkElement>();\r
+ private String type;\r
+\r
+ public FrequencyMethodCallBirthmark(String type){\r
+ this.type = type;\r
+ }\r
+\r
+ @Override\r
+ public int getElementCount(){\r
+ return counts.size();\r
+ }\r
+\r
+ @Override\r
+ public synchronized BirthmarkElement[] getElements(){\r
+ FrequencyOfMethodBirthmarkElement[] elements = new FrequencyOfMethodBirthmarkElement[counts.size()];\r
+ int index = 0;\r
+ for(Map.Entry<String, FrequencyOfMethodBirthmarkElement> entry: counts.entrySet()){\r
+ elements[index] = entry.getValue();\r
+ index++;\r
+ }\r
+ Arrays.sort(elements, new Comparator<FrequencyOfMethodBirthmarkElement>(){\r
+ public int compare(FrequencyOfMethodBirthmarkElement o1, FrequencyOfMethodBirthmarkElement o2){\r
+ return o1.getValueName().compareTo(o2.getValueName());\r
+ }\r
+ });\r
+ \r
+ return elements;\r
+ }\r
+\r
+ @Override\r
+ public Iterator<BirthmarkElement> iterator(){\r
+ return new ArrayIterator<BirthmarkElement>(getElements());\r
+ }\r
+\r
+ public void addElement(BirthmarkElement element){\r
+ if(element instanceof FrequencyOfMethodBirthmarkElement){\r
+ FrequencyOfMethodBirthmarkElement e = (FrequencyOfMethodBirthmarkElement)element;\r
+ FrequencyOfMethodBirthmarkElement foundElement = counts.get(e.getValueName());\r
+ if(foundElement != null){\r
+ foundElement.incrementValueCount();\r
+ }\r
+ else{\r
+ foundElement = e;\r
+ }\r
+ counts.put(e.getValueName(), foundElement);\r
+ } \r
+ }\r
+\r
+ @Override\r
+ public String getType(){\r
+ return type;\r
+ }\r
+}\r
--- /dev/null
+package jp.naist.se.stigmata.birthmarks.fmc;\r
+\r
+/*\r
+ * $Id: SequentialMethodCallBirthmarkExtractVisitor.java 130 2007-06-13 10:08:01Z tama3 $\r
+ */\r
+\r
+import jp.naist.se.stigmata.Birthmark;\r
+import jp.naist.se.stigmata.BirthmarkContext;\r
+import jp.naist.se.stigmata.birthmarks.BirthmarkExtractVisitor;\r
+\r
+import org.objectweb.asm.ClassVisitor;\r
+import org.objectweb.asm.MethodAdapter;\r
+import org.objectweb.asm.MethodVisitor;\r
+\r
+/**\r
+ * \r
+ * \r
+ *\r
+ * @author Haruaki TAMADA\r
+ * @version $Revision: 130 $ $Date: 2007-06-13 19:08:01 +0900 (Wed, 13 Jun 2007) $\r
+ */\r
+public class FrequencyMethodCallBirthmarkExtractVisitor extends BirthmarkExtractVisitor{\r
+ public FrequencyMethodCallBirthmarkExtractVisitor(ClassVisitor visitor, Birthmark birthmark, BirthmarkContext context){\r
+ super(visitor, birthmark, context);\r
+ }\r
+\r
+ public MethodVisitor visitMethod(int access, String name, String desc,\r
+ String signature, String[] exceptions){\r
+\r
+ MethodVisitor visitor = super.visitMethod(access, name, desc, signature, exceptions);\r
+\r
+ return new MethodAdapter(visitor){\r
+ public void visitMethodInsn(int opcode, String owner, String name, String desc){\r
+ String className = owner.replace('/', '.');\r
+ if(getContext().getWellknownClassManager().isWellKnownClass(className)){\r
+ addElement(new FrequencyOfMethodBirthmarkElement(className, name, desc));\r
+ }\r
+ super.visitMethodInsn(opcode, owner, name, desc);\r
+ }\r
+ };\r
+ }\r
+}\r
--- /dev/null
+package jp.naist.se.stigmata.birthmarks.fmc;
+
+/*
+ * $Id: SequentialMethodCallBirthmarkExtractor.java 130 2007-06-13 10:08:01Z tama3 $
+ */
+
+import jp.naist.se.stigmata.Birthmark;
+import jp.naist.se.stigmata.BirthmarkContext;
+import jp.naist.se.stigmata.ExtractionUnit;
+import jp.naist.se.stigmata.birthmarks.ASMBirthmarkExtractor;
+import jp.naist.se.stigmata.birthmarks.BirthmarkExtractVisitor;
+import jp.naist.se.stigmata.spi.BirthmarkSpi;
+
+import org.objectweb.asm.ClassWriter;
+
+/**
+ * @author Haruaki TAMADA
+ * @version $Revision: 130 $ $Date: 2007-06-13 19:08:01 +0900 (Wed, 13 Jun 2007) $
+ */
+public class FrequencyMethodCallBirthmarkExtractor extends ASMBirthmarkExtractor{
+ public FrequencyMethodCallBirthmarkExtractor(BirthmarkSpi spi){
+ super(spi);
+ }
+
+ public FrequencyMethodCallBirthmarkExtractor(){
+ super();
+ }
+
+ @Override
+ public BirthmarkExtractVisitor createExtractVisitor(ClassWriter writer, Birthmark birthmark, BirthmarkContext context){
+ return new FrequencyMethodCallBirthmarkExtractVisitor(writer, birthmark, context);
+ }
+
+ public ExtractionUnit[] getAcceptableUnits(){
+ return new ExtractionUnit[] {
+ ExtractionUnit.CLASS, ExtractionUnit.PACKAGE, ExtractionUnit.ARCHIVE,
+ };
+ }
+
+ @Override
+ public Birthmark createBirthmark(){
+ return new FrequencyMethodCallBirthmark(getProvider().getType());
+ }
+}
--- /dev/null
+package jp.naist.se.stigmata.birthmarks.fmc;\r
+\r
+/*\r
+ * $Id: SequentialMethodCallBirthmarkService.java 130 2007-06-13 10:08:01Z tama3 $\r
+ */\r
+\r
+import jp.naist.se.stigmata.BirthmarkComparator;\r
+import jp.naist.se.stigmata.BirthmarkExtractor;\r
+import jp.naist.se.stigmata.birthmarks.AbstractBirthmarkService;\r
+import jp.naist.se.stigmata.birthmarks.comparators.CosineSimilarityBirthmarkComparator;\r
+import jp.naist.se.stigmata.spi.BirthmarkSpi;\r
+\r
+/**\r
+ * \r
+ * \r
+ * \r
+ * @author Haruaki TAMADA\r
+ * @version $Revision: 130 $ $Date: 2007-06-13 19:08:01 +0900 (Wed, 13 Jun 2007) $\r
+ */\r
+public class FrequencyMethodCallBirthmarkService extends AbstractBirthmarkService implements BirthmarkSpi{\r
+ private BirthmarkComparator comparator = new CosineSimilarityBirthmarkComparator(this);\r
+ private BirthmarkExtractor extractor = new FrequencyMethodCallBirthmarkExtractor(this);\r
+\r
+ public String getType(){\r
+ return "fmc";\r
+ }\r
+\r
+ public String getDefaultDescription(){\r
+ return "Frequency of method call which order is appeared in method definition.";\r
+ }\r
+\r
+ public BirthmarkExtractor getExtractor(){\r
+ return extractor;\r
+ }\r
+\r
+ public BirthmarkComparator getComparator(){\r
+ return comparator;\r
+ }\r
+\r
+ public boolean isExpert(){\r
+ return false;\r
+ }\r
+\r
+ public boolean isUserDefined(){\r
+ return false;\r
+ }\r
+}\r
--- /dev/null
+package jp.naist.se.stigmata.birthmarks.fmc;\r
+\r
+import jp.naist.se.stigmata.birthmarks.ValueCountable;\r
+import jp.naist.se.stigmata.birthmarks.smc.MethodCallBirthmarkElement;\r
+\r
+public class FrequencyOfMethodBirthmarkElement extends MethodCallBirthmarkElement implements ValueCountable{\r
+ private static final long serialVersionUID = 4454345943098520436L;\r
+\r
+ private int count = 1;\r
+\r
+ public FrequencyOfMethodBirthmarkElement(String className, String methodName, String signature){\r
+ super(className, methodName, signature);\r
+ }\r
+\r
+ void incrementValueCount(){\r
+ count++;\r
+ }\r
+\r
+ @Override\r
+ public boolean equals(Object o){\r
+ boolean flag = false;\r
+ if(o instanceof FrequencyOfMethodBirthmarkElement){\r
+ FrequencyOfMethodBirthmarkElement fmbe = (FrequencyOfMethodBirthmarkElement)o;\r
+ flag = super.equals(fmbe) && getValueCount() == fmbe.getValueCount();\r
+ }\r
+ return flag;\r
+ }\r
+\r
+ @Override\r
+ public Object getValue(){\r
+ return getValueCount() + ": " + getValueName();\r
+ }\r
+\r
+ @Override\r
+ public int hashCode(){\r
+ return System.identityHashCode(this);\r
+ }\r
+\r
+ public String getValueName(){\r
+ return getClassName() + "#" + getMethodName() + "!" + getSignature();\r
+ }\r
+\r
+ public int getValueCount(){\r
+ return count;\r
+ }\r
+}\r
import jp.naist.se.stigmata.BirthmarkContext;
import jp.naist.se.stigmata.BirthmarkElementClassNotFoundException;
import jp.naist.se.stigmata.BirthmarkExtractionException;
+import jp.naist.se.stigmata.ExtractionUnit;
import jp.naist.se.stigmata.birthmarks.BirthmarkExtractVisitor;
-import jp.naist.se.stigmata.birthmarks.PlainBirthmark;
import jp.naist.se.stigmata.spi.BirthmarkSpi;
import org.objectweb.asm.ClassReader;
}
@Override
- public Birthmark extract(InputStream in, BirthmarkContext context) throws BirthmarkExtractionException{
+ public Birthmark extract(Birthmark birthmark, InputStream in, BirthmarkContext context) throws BirthmarkExtractionException{
BirthmarkElementClassNotFoundException e = new BirthmarkElementClassNotFoundException();
- Birthmark birthmark = new PlainBirthmark(getProvider().getType());
try{
ClassReader reader = new ClassReader(in);
ClassWriter writer = new ClassWriter(false);
}
return birthmark;
}
+
+ public ExtractionUnit[] getAcceptableUnits(){
+ return new ExtractionUnit[] { ExtractionUnit.CLASS, };
+ }
}
import jp.naist.se.stigmata.Birthmark;
import jp.naist.se.stigmata.BirthmarkContext;
+import jp.naist.se.stigmata.ExtractionUnit;
import jp.naist.se.stigmata.birthmarks.ASMBirthmarkExtractor;
import jp.naist.se.stigmata.birthmarks.BirthmarkExtractVisitor;
import jp.naist.se.stigmata.spi.BirthmarkSpi;
extractor.setKValue(getKValue());
return extractor;
}
+
+ public ExtractionUnit[] getAcceptableUnits(){
+ return new ExtractionUnit[] {
+ ExtractionUnit.CLASS, ExtractionUnit.PACKAGE, ExtractionUnit.ARCHIVE,
+ };
+ }
}
}
public Object getValue(){
- return getClassName() + "#" + getMethodName();
+ return getClassName() + "#" + getMethodName() + "!" + getSignature();
}
public int hashCode(){
import jp.naist.se.stigmata.Birthmark;
import jp.naist.se.stigmata.BirthmarkContext;
+import jp.naist.se.stigmata.ExtractionUnit;
import jp.naist.se.stigmata.birthmarks.ASMBirthmarkExtractor;
import jp.naist.se.stigmata.birthmarks.BirthmarkExtractVisitor;
import jp.naist.se.stigmata.spi.BirthmarkSpi;
public BirthmarkExtractVisitor createExtractVisitor(ClassWriter writer, Birthmark birthmark, BirthmarkContext context){
return new SequentialMethodCallBirthmarkExtractVisitor(writer, birthmark, context);
}
+
+ @Override
+ public ExtractionUnit[] getAcceptableUnits(){
+ return new ExtractionUnit[] { ExtractionUnit.CLASS, ExtractionUnit.ARCHIVE, ExtractionUnit.PACKAGE, };
+ }
}
--- /dev/null
+package jp.naist.se.stigmata.birthmarks.uc;\r
+\r
+/*\r
+ * $Id$\r
+ */\r
+\r
+import jp.naist.se.stigmata.BirthmarkElement;\r
+import jp.naist.se.stigmata.birthmarks.PlainBirthmark;\r
+\r
+/**\r
+ * \r
+ * @author Haruaki Tamada\r
+ * @version $Revision$ $Date$\r
+ */\r
+class UsedClassesBirthmark extends PlainBirthmark{\r
+ private static final long serialVersionUID = -1043130948373105655L;\r
+\r
+ public UsedClassesBirthmark(String type){\r
+ super(type);\r
+ }\r
+\r
+ @Override\r
+ public synchronized void addElement(BirthmarkElement element){\r
+ int c = getElementCount();\r
+ String s = (String)element.getValue();\r
+ boolean addFlag = false;\r
+ for(int i = 0; i < c; i++){\r
+ BirthmarkElement e = getElement(i);\r
+ String v = (String)e.getValue();\r
+ if(s.equals(v)){\r
+ addFlag = true;\r
+ break;\r
+ }\r
+ }\r
+ if(!addFlag){\r
+ for(int i = 0; i < c; i++){\r
+ if(s.compareTo((String)getElement(i).getValue()) < 0){\r
+ super.addElement(i, element);\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ if(!addFlag && c == getElementCount()){\r
+ super.addElement(element);\r
+ }\r
+ }\r
+}\r
* $Id$\r
*/\r
\r
-import java.util.Arrays;\r
-import java.util.HashSet;\r
-import java.util.Set;\r
-\r
import jp.naist.se.stigmata.Birthmark;\r
import jp.naist.se.stigmata.BirthmarkContext;\r
import jp.naist.se.stigmata.BirthmarkElement;\r
* @version $Revision$ $Date$\r
*/\r
public class UsedClassesBirthmarkExtractVisitor extends BirthmarkExtractVisitor{\r
- private Set<String> set = new HashSet<String>();\r
-\r
public UsedClassesBirthmarkExtractVisitor(ClassVisitor visitor, Birthmark birthmark,\r
BirthmarkContext context){\r
super(visitor, birthmark, context);\r
}\r
\r
- public void visitEnd(){\r
- String[] classNames = set.toArray(new String[set.size()]);\r
- Arrays.sort(classNames);\r
- for(String className: classNames){\r
- addElement(new BirthmarkElement(className));\r
- }\r
- }\r
-\r
public void visit(int version, int access, String name, String signature,\r
String superName, String[] interfaces){\r
addSignatureClass(signature);\r
\r
if(getContext().getWellknownClassManager().isWellKnownClass(superName)){\r
- set.add(superName);\r
+ add(superName);\r
}\r
for(String i: interfaces){\r
if(getContext().getWellknownClassManager().isWellKnownClass(i)){\r
- set.add(i);\r
+ add(i);\r
}\r
}\r
}\r
if(exceptions != null){\r
for(String exception: exceptions){\r
if(getContext().getWellknownClassManager().isWellKnownClass(exception)){\r
- set.add(exception);\r
+ add(exception);\r
}\r
}\r
}\r
public void visitTypeInsn(int opcode, String desc){\r
Type type = Type.getType("L" + desc + ";");\r
if(checkType(type)){\r
- set.add(normalize(desc));\r
+ add(normalize(desc));\r
}\r
super.visitTypeInsn(opcode, desc);\r
}\r
public void visitTryCatchBlock(Label start, Label end, Label handle, String desc){\r
Type type = Type.getType("L" + desc + ";");\r
if(checkType(type)){\r
- set.add(getType(type));\r
+ add(getType(type));\r
}\r
super.visitTryCatchBlock(start, end, handle, desc);\r
}\r
public void visitMultiANewArrayInsn(String desc, int dims){\r
Type type = Type.getType(desc);\r
if(checkType(type)){\r
- set.add(getType(type));\r
+ add(getType(type));\r
}\r
super.visitMultiANewArrayInsn(desc, dims);\r
}\r
public void visitLocalVariable(String name, String desc, String signature,\r
Label start, Label end, int index){\r
if(checkType(Type.getType(desc))){\r
- set.add(normalize(desc));\r
+ add(normalize(desc));\r
}\r
addSignatureClass(signature);\r
\r
\r
public void visitFieldInsn(int opcode, String owner, String name, String desc){\r
if(getContext().getWellknownClassManager().isWellKnownClass(owner)){\r
- set.add(normalize(owner));\r
+ add(normalize(owner));\r
}\r
addDescriptor(desc);\r
super.visitFieldInsn(opcode, owner, name, desc);\r
public void visitMethodInsn(int opcode, String owner, String name, String desc){\r
String className = normalize(owner);\r
if(getContext().getWellknownClassManager().isWellKnownClass(className)){\r
- set.add(className);\r
+ add(className);\r
}\r
addMethodDescriptor(desc);\r
super.visitMethodInsn(opcode, owner, name, desc);\r
SignatureWriter writer = new SignatureWriter(){\r
public void visitClassType(String classType){\r
if(getContext().getWellknownClassManager().isWellKnownClass(classType)){\r
- set.add(normalize(classType));\r
+ add(normalize(classType));\r
}\r
}\r
};\r
Type returnType = Type.getReturnType(desc);\r
Type[] args = Type.getArgumentTypes(desc);\r
if(checkType(returnType)){\r
- set.add(getType(returnType));\r
+ add(getType(returnType));\r
}\r
for(Type arg: args){\r
if(checkType(arg)){\r
- set.add(getType(arg));\r
+ add(getType(arg));\r
}\r
}\r
}\r
private void addDescriptor(String desc){\r
Type type = Type.getType(desc);\r
if(checkType(type)){\r
- set.add(normalize(desc));\r
+ add(normalize(desc));\r
}\r
}\r
\r
\r
return name;\r
}\r
+\r
+ private void add(String name){\r
+ addElement(new BirthmarkElement(name));\r
+ }\r
}\r
import jp.naist.se.stigmata.Birthmark;
import jp.naist.se.stigmata.BirthmarkContext;
+import jp.naist.se.stigmata.ExtractionUnit;
import jp.naist.se.stigmata.birthmarks.ASMBirthmarkExtractor;
import jp.naist.se.stigmata.birthmarks.BirthmarkExtractVisitor;
import jp.naist.se.stigmata.spi.BirthmarkSpi;
public BirthmarkExtractVisitor createExtractVisitor(ClassWriter writer, Birthmark birthmark, BirthmarkContext context){
return new UsedClassesBirthmarkExtractVisitor(writer, birthmark, context);
}
+
+ public ExtractionUnit[] getAcceptableUnits(){
+ return new ExtractionUnit[] {
+ ExtractionUnit.CLASS, ExtractionUnit.PACKAGE, ExtractionUnit.ARCHIVE,
+ };
+ }
+
+ @Override
+ public Birthmark createBirthmark(){
+ return new UsedClassesBirthmark(getProvider().getType());
+ }
}
--- /dev/null
+package jp.naist.se.stigmata.utils;\r
+\r
+/*\r
+ * $Id$\r
+ */\r
+\r
+import java.util.Iterator;\r
+\r
+/**\r
+ * \r
+ * @author Haruaki Tamada\r
+ * @version $Revission$ $Date$\r
+ */\r
+public class ArrayIterator<T> implements Iterator<T>{\r
+ private T[] values;\r
+ private int length;\r
+ private int currentIndex = 0;\r
+\r
+ public ArrayIterator(T[] values){\r
+ this.values = values;\r
+ if(values != null){\r
+ length = values.length;\r
+ }\r
+ else{\r
+ length = 0;\r
+ }\r
+ }\r
+\r
+ public boolean hasNext(){\r
+ return currentIndex < length;\r
+ }\r
+\r
+ public T next(){\r
+ T value = values[currentIndex];\r
+ currentIndex++;\r
+ return value;\r
+ }\r
+\r
+ public void remove(){\r
+ }\r
+}\r
jp.naist.se.stigmata.birthmarks.comparators.DPMatchingBirthmarkComparatorService\r
jp.naist.se.stigmata.birthmarks.comparators.EditDistanceBirthmarkComparatorService\r
jp.naist.se.stigmata.birthmarks.comparators.ExtendedEditDistanceBirthmarkComparatorService\r
+jp.naist.se.stigmata.birthmarks.comparators.CosineSimilarityBirthmarkComparatorService\r
jp.naist.se.stigmata.birthmarks.is.InheritanceStructureBirthmarkService\r
jp.naist.se.stigmata.birthmarks.uc.UsedClassesBirthmarkService\r
jp.naist.se.stigmata.birthmarks.kgram.KGramBasedBirthmarkService\r
+jp.naist.se.stigmata.birthmarks.fmc.FrequencyMethodCallBirthmarkService\r
birthmark.cvfv.display.type=Constant Value of Field Variable\r
birthmark.cvfv.description=Field type and its initial value.\r
-birthmark.smc.display.type=Sequence of Method Call\r
-birthmark.smc.description=Sequence of method call which order is appeared in method definition.\r
+birthmark.smc.display.type=Sequence of Method Calls\r
+birthmark.smc.description=Sequence of method calls which order is appeared in method definition.\r
birthmark.uc.display.type=Used Classes\r
birthmark.uc.description=Set of used classes in target class.\r
birthmark.is.display.type=Inheritance Structure\r
birthmark.is.description=Inheritance sequence to root class and user classes is replaced to <null>.\r
birthmark.kgram.display.type=k-gram\r
birthmark.kgram.description=Set of extracted k-gram from opcode sequence.\r
+birthmark.fmc.display.type=Frequency of Method Calls\r
+birthmark.fmc.description=Frequency of method calls.\r
\r
comparator.dpmatching.description=\r
comparator.editdistance.description=\r
extractor.uc.description=\r
extractor.is.description=\r
extractor.kgram.description=\r
+extractor.fmc.description=\r
\r
formatter.xml.description=\r
formatter.csv.description=\r
birthmark.is.description=\8cp\8f³\8aÖ\8cW\82ð\83\8b\81[\83g\82Ü\82Å\92H\82Á\82Ä\93¾\82ç\82ê\82é\83N\83\89\83X\82Ì\8cn\97ñ\r
birthmark.kgram.display.type=k-gram\r
birthmark.kgram.description=opcode\82Ì\95À\82Ñ\82©\82çk-gram\82ð\8eæ\82è\8fo\82µ\82½\8fW\8d\87\r
+birthmark.fmc.display.type=\83\81\83\\83b\83h\8fo\8c»\95p\93x\r
+birthmark.fmc.description=\83\81\83\\83b\83h\8cÄ\8fo\82µ\82Ì\8fo\8c»\95p\93x\r
\r
filter.similarity.display.type=\97Þ\8e\97\93x\82Å\82Ì\83t\83B\83\8b\83^\83\8a\83\93\83O\r
filter.name.display.type=\83N\83\89\83X\96¼\82Å\82Ì\83t\83B\83\8b\83^\83\8a\83\93\83O\r
\r
Birthmark birthmark = array[0].getBirthmark("uc");\r
Assert.assertEquals("uc", birthmark.getType());\r
- Assert.assertEquals(21, birthmark.getElementCount());\r
+ Assert.assertEquals(23, birthmark.getElementCount());\r
\r
BirthmarkElement[] elements = birthmark.getElements();\r
- Assert.assertEquals("java.io.ByteArrayInputStream", elements[ 0].getValue());\r
- Assert.assertEquals("java.io.ByteArrayOutputStream", elements[ 1].getValue());\r
- Assert.assertEquals("java.io.File", elements[ 2].getValue());\r
- Assert.assertEquals("java.io.FileInputStream", elements[ 3].getValue());\r
- Assert.assertEquals("java.io.InputStream", elements[ 4].getValue());\r
- Assert.assertEquals("java.lang.Class", elements[ 5].getValue());\r
- Assert.assertEquals("java.lang.Double", elements[ 6].getValue());\r
- Assert.assertEquals("java.lang.Object", elements[ 7].getValue());\r
- Assert.assertEquals("java.lang.String", elements[ 8].getValue());\r
- Assert.assertEquals("java.lang.StringBuilder", elements[ 9].getValue());\r
- Assert.assertEquals("java.lang.System", elements[10].getValue());\r
- Assert.assertEquals("java.net.URI", elements[11].getValue());\r
- Assert.assertEquals("java.net.URL", elements[12].getValue());\r
- Assert.assertEquals("java.util.ArrayList", elements[13].getValue());\r
- Assert.assertEquals("java.util.Iterator", elements[14].getValue());\r
- Assert.assertEquals("java.util.List", elements[15].getValue());\r
- Assert.assertEquals("java.util.Map", elements[16].getValue());\r
- Assert.assertEquals("java.util.Set", elements[17].getValue());\r
- Assert.assertEquals("java.util.logging.Logger", elements[18].getValue());\r
- Assert.assertEquals("javax.imageio.spi.ServiceRegistry", elements[19].getValue());\r
- Assert.assertEquals("org.apache.commons.beanutils.BeanUtils", elements[20].getValue());\r
+ int index = 0;\r
+ Assert.assertEquals("java.io.ByteArrayInputStream", elements[index++].getValue());\r
+ Assert.assertEquals("java.io.ByteArrayOutputStream", elements[index++].getValue());\r
+ Assert.assertEquals("java.io.File", elements[index++].getValue());\r
+ Assert.assertEquals("java.io.FileInputStream", elements[index++].getValue());\r
+ Assert.assertEquals("java.io.InputStream", elements[index++].getValue());\r
+ Assert.assertEquals("java.lang.Class", elements[index++].getValue());\r
+ Assert.assertEquals("java.lang.Double", elements[index++].getValue());\r
+ Assert.assertEquals("java.lang.Object", elements[index++].getValue());\r
+ Assert.assertEquals("java.lang.String", elements[index++].getValue());\r
+ Assert.assertEquals("java.lang.StringBuilder", elements[index++].getValue());\r
+ Assert.assertEquals("java.lang.System", elements[index++].getValue());\r
+ Assert.assertEquals("java.net.URI", elements[index++].getValue());\r
+ Assert.assertEquals("java.net.URL", elements[index++].getValue());\r
+ Assert.assertEquals("java.util.ArrayList", elements[index++].getValue());\r
+ Assert.assertEquals("java.util.Collection", elements[index++].getValue());\r
+ Assert.assertEquals("java.util.HashMap", elements[index++].getValue());\r
+ Assert.assertEquals("java.util.Iterator", elements[index++].getValue());\r
+ Assert.assertEquals("java.util.List", elements[index++].getValue());\r
+ Assert.assertEquals("java.util.Map", elements[index++].getValue());\r
+ Assert.assertEquals("java.util.Set", elements[index++].getValue());\r
+ Assert.assertEquals("java.util.logging.Logger", elements[index++].getValue());\r
+ Assert.assertEquals("javax.imageio.spi.ServiceRegistry", elements[index++].getValue());\r
+ Assert.assertEquals("org.apache.commons.beanutils.BeanUtils", elements[index++].getValue());\r
}\r
\r
@Test\r