public class CodeFootstamp extends java.lang.Object
Represents a single 'footprint' of some piece of ASM code. Is used to detect if two code pieces are (nearly) the same or different.
During duplicate-detection we create CodeFootstamp
for every block found starting with LINENUMBER directive.
We appends to the CodeFootstamp
all found 'jvm asm' instructions. When we found the end of the block (start of next line) we need to
call finalize()
. After that we are allowed to use hashCode()
, equals(Object)
and isMeaningful()
methods
to compare two blocks and decide if they are duplicates or not.
CodeFootstamp
as duplicates not only when they are completely identical, but also if:
trimableIfFirst(String)
)trimableIfLast(String)
) You should also use isMeaningful()
method to avoid comparing two CodeFootstamp
that are two short (for example empty).
They would be probably found this snapshot as 'equal', but in fact the snapshoots are too short to proof anything.
At the implementation level we encode all found instructions into list of String events
and we are comparing those string list.
It's not beautiful design - but its simple and works.
This class implements equals(Object)
and hashCode()
so might be used as key in maps
Modifier and Type | Field and Description |
---|---|
private java.util.LinkedList<java.lang.String> |
events |
private boolean |
finalized |
Constructor and Description |
---|
CodeFootstamp() |
Modifier and Type | Method and Description |
---|---|
private void |
appendIfNotFinal(java.lang.String string) |
private void |
assertNotFinal() |
boolean |
equals(java.lang.Object obj) |
void |
finalize() |
int |
hashCode() |
boolean |
isMeaningful()
Some signatures are to simple (empty) and generates false positive duplicates.
|
java.lang.String |
toString() |
private boolean |
trimableIfFirst(java.lang.String e) |
private boolean |
trimableIfLast(java.lang.String e) |
void |
visitFieldInsn(int access,
java.lang.String name,
java.lang.String description,
java.lang.String signature) |
void |
visitIintInsn(int opCode,
int variable) |
void |
visitInsn(int opCode) |
(package private) void |
visitIntInsn(int opCode,
int variable) |
void |
visitJumpInsn(int opCode,
org.objectweb.asm.Label label) |
void |
visitLabel(org.objectweb.asm.Label label) |
void |
visitLdcInsn(java.lang.Object obj) |
void |
visitLookupSwitchInsn(org.objectweb.asm.Label arg0,
int[] arg1,
org.objectweb.asm.Label[] arg2) |
void |
visitMethodInsn(int opCode,
java.lang.String className,
java.lang.String methodName,
java.lang.String description) |
void |
visitMultiANewArrayInsn(java.lang.String type,
int arg1) |
void |
visitTableSwitchInsn(int arg0,
int arg1,
org.objectweb.asm.Label arg2,
org.objectweb.asm.Label[] arg3) |
private final java.util.LinkedList<java.lang.String> events
private boolean finalized
public CodeFootstamp()
public void visitLabel(org.objectweb.asm.Label label)
private void appendIfNotFinal(java.lang.String string)
private void assertNotFinal()
public void visitFieldInsn(int access, java.lang.String name, java.lang.String description, java.lang.String signature)
public void visitInsn(int opCode)
void visitIntInsn(int opCode, int variable)
public void visitIintInsn(int opCode, int variable)
public void visitLdcInsn(java.lang.Object obj)
public void visitJumpInsn(int opCode, org.objectweb.asm.Label label)
public void visitMethodInsn(int opCode, java.lang.String className, java.lang.String methodName, java.lang.String description)
public void visitMultiANewArrayInsn(java.lang.String type, int arg1)
public void visitLookupSwitchInsn(org.objectweb.asm.Label arg0, int[] arg1, org.objectweb.asm.Label[] arg2)
public void visitTableSwitchInsn(int arg0, int arg1, org.objectweb.asm.Label arg2, org.objectweb.asm.Label[] arg3)
public void finalize()
finalize
in class java.lang.Object
private boolean trimableIfFirst(java.lang.String e)
private boolean trimableIfLast(java.lang.String e)
public java.lang.String toString()
toString
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public boolean isMeaningful()