Package com.tonic.analysis.similarity
Class MethodSignature
- java.lang.Object
-
- com.tonic.analysis.similarity.MethodSignature
-
public class MethodSignature extends Object
A method's comparison fingerprints: bytecode hash, opcode sequence, and structural counters.
-
-
Constructor Summary
Constructors Constructor Description MethodSignature(String className, String methodName, String descriptor)Creates an empty signature identifying a method; fingerprints are filled by fromMethod.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description doublecompareExactBytecode(MethodSignature other)Compares bytecode hashes for an exact match.doublecompareOpcodeSequence(MethodSignature other)Compares opcode sequences using longest common subsequence length.doublecompareStructural(MethodSignature other)Compares structural metrics: instruction, branch, and call count ratios.static MethodSignaturefromMethod(MethodEntry method, String className)Builds a signature from a method entry, analyzing its bytecode when present.intgetBranchCount()byte[]getBytecodeHash()intgetCallCount()StringgetClassName()StringgetDescriptor()StringgetDisplayName()intgetFieldAccessCount()StringgetFullReference()intgetInstructionCount()intgetLoopCount()intgetMaxLocals()intgetMaxStack()StringgetMethodName()int[]getOpcodeSequence()StringtoString()
-
-
-
Method Detail
-
fromMethod
public static MethodSignature fromMethod(MethodEntry method, String className)
Builds a signature from a method entry, analyzing its bytecode when present.- Parameters:
method- the method to fingerprintclassName- the owning class name- Returns:
- the populated signature
-
compareExactBytecode
public double compareExactBytecode(MethodSignature other)
Compares bytecode hashes for an exact match.- Parameters:
other- the signature to compare against- Returns:
- 1.0 on equal hashes, otherwise 0.0
-
compareOpcodeSequence
public double compareOpcodeSequence(MethodSignature other)
Compares opcode sequences using longest common subsequence length.- Parameters:
other- the signature to compare against- Returns:
- the LCS length over the longer sequence, in [0, 1]
-
compareStructural
public double compareStructural(MethodSignature other)
Compares structural metrics: instruction, branch, and call count ratios.- Parameters:
other- the signature to compare against- Returns:
- the average ratio in [0, 1], 0 if no metrics are comparable
-
getClassName
public String getClassName()
- Returns:
- the class name
-
getMethodName
public String getMethodName()
- Returns:
- the method name
-
getDescriptor
public String getDescriptor()
- Returns:
- the descriptor
-
getBytecodeHash
public byte[] getBytecodeHash()
- Returns:
- the bytecode hash
-
getOpcodeSequence
public int[] getOpcodeSequence()
- Returns:
- the opcode sequence
-
getInstructionCount
public int getInstructionCount()
- Returns:
- the instruction count
-
getMaxStack
public int getMaxStack()
- Returns:
- the max stack
-
getMaxLocals
public int getMaxLocals()
- Returns:
- the max locals
-
getLoopCount
public int getLoopCount()
- Returns:
- the loop count
-
getBranchCount
public int getBranchCount()
- Returns:
- the branch count
-
getCallCount
public int getCallCount()
- Returns:
- the call count
-
getFieldAccessCount
public int getFieldAccessCount()
- Returns:
- the field access count
-
getDisplayName
public String getDisplayName()
- Returns:
- a short display string of simple class name and method name
-
getFullReference
public String getFullReference()
- Returns:
- the full reference in class.name+descriptor form
-
-