1
This commit is contained in:
BIN
TestHeuristic.class
Normal file
BIN
TestHeuristic.class
Normal file
Binary file not shown.
17
TestHeuristic.java
Normal file
17
TestHeuristic.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class TestHeuristic {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println(isFullyQualifiedMethod("TransformerImpl.transform"));
|
||||||
|
System.out.println(isFullyQualifiedMethod("Transformer.transform"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isFullyQualifiedMethod(String methodFqn) {
|
||||||
|
if (methodFqn == null || !methodFqn.contains(".")) return false;
|
||||||
|
int lastDot = methodFqn.lastIndexOf('.');
|
||||||
|
String classPart = methodFqn.substring(0, lastDot);
|
||||||
|
if (classPart.contains(".")) return true;
|
||||||
|
if (!classPart.isEmpty() && Character.isUpperCase(classPart.charAt(0))) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -179,6 +179,7 @@ public class CallGraphPathFinder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean calculateHeuristicMatch(String neighbor, String target) {
|
private boolean calculateHeuristicMatch(String neighbor, String target) {
|
||||||
|
System.out.println("calculateHeuristicMatch: neighbor=" + neighbor + ", target=" + target);
|
||||||
if (neighbor.equals(target)) return true;
|
if (neighbor.equals(target)) return true;
|
||||||
|
|
||||||
if (isFullyQualifiedMethod(neighbor) && isFullyQualifiedMethod(target)) {
|
if (isFullyQualifiedMethod(neighbor) && isFullyQualifiedMethod(target)) {
|
||||||
@@ -202,7 +203,6 @@ public class CallGraphPathFinder {
|
|||||||
String simpleClassTarget = classTarget.contains(".") ? classTarget.substring(classTarget.lastIndexOf('.') + 1) : classTarget;
|
String simpleClassTarget = classTarget.contains(".") ? classTarget.substring(classTarget.lastIndexOf('.') + 1) : classTarget;
|
||||||
|
|
||||||
if (simpleClassNeighbor.equals(simpleClassTarget)) return true;
|
if (simpleClassNeighbor.equals(simpleClassTarget)) return true;
|
||||||
if (simpleClassNeighbor.contains(simpleClassTarget) || simpleClassTarget.contains(simpleClassNeighbor)) return true;
|
|
||||||
|
|
||||||
List<String> impls = context.getImplementations(classTarget);
|
List<String> impls = context.getImplementations(classTarget);
|
||||||
if (impls != null) {
|
if (impls != null) {
|
||||||
@@ -222,7 +222,21 @@ public class CallGraphPathFinder {
|
|||||||
|
|
||||||
String simpleTarget = target.contains(".") ? target.substring(target.lastIndexOf('.') + 1) : target;
|
String simpleTarget = target.contains(".") ? target.substring(target.lastIndexOf('.') + 1) : target;
|
||||||
String simpleNeighbor = neighbor.contains(".") ? neighbor.substring(neighbor.lastIndexOf('.') + 1) : neighbor;
|
String simpleNeighbor = neighbor.contains(".") ? neighbor.substring(neighbor.lastIndexOf('.') + 1) : neighbor;
|
||||||
return simpleNeighbor.equals(simpleTarget);
|
if (!simpleNeighbor.equals(simpleTarget)) return false;
|
||||||
|
|
||||||
|
String classNeighbor = neighbor.contains(".") ? neighbor.substring(0, neighbor.lastIndexOf('.')) : null;
|
||||||
|
String classTarget = target.contains(".") ? target.substring(0, target.lastIndexOf('.')) : null;
|
||||||
|
String simpleClassTarget = classTarget != null && classTarget.contains(".") ? classTarget.substring(classTarget.lastIndexOf('.') + 1) : classTarget;
|
||||||
|
String simpleClassNeighbor = classNeighbor != null && classNeighbor.contains(".") ? classNeighbor.substring(classNeighbor.lastIndexOf('.') + 1) : classNeighbor;
|
||||||
|
|
||||||
|
if (simpleClassNeighbor != null && simpleClassTarget != null) {
|
||||||
|
if (simpleClassNeighbor.equalsIgnoreCase(simpleClassTarget)) return true;
|
||||||
|
// e.g. "this" vs "com.example.Machine"
|
||||||
|
if (simpleClassNeighbor.equals("this") || simpleClassNeighbor.equals("super")) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isFullyQualifiedMethod(String methodFqn) {
|
private boolean isFullyQualifiedMethod(String methodFqn) {
|
||||||
|
|||||||
@@ -525,14 +525,39 @@ public class VariableTracer {
|
|||||||
if (simpleClassNeighbor.equals(simpleClassTarget)) return true;
|
if (simpleClassNeighbor.equals(simpleClassTarget)) return true;
|
||||||
|
|
||||||
List<String> impls = context.getImplementations(classTarget);
|
List<String> impls = context.getImplementations(classTarget);
|
||||||
if (impls != null && impls.contains(classNeighbor)) return true;
|
if (impls != null) {
|
||||||
|
for (String impl : impls) {
|
||||||
|
if (impl.equals(classNeighbor) || impl.endsWith("." + classNeighbor)) return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
List<String> implsN = context.getImplementations(classNeighbor);
|
List<String> implsN = context.getImplementations(classNeighbor);
|
||||||
if (implsN != null && implsN.contains(classTarget)) return true;
|
if (implsN != null) {
|
||||||
|
for (String impl : implsN) {
|
||||||
|
if (impl.equals(classTarget) || impl.endsWith("." + classTarget)) return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String simpleTarget = target.contains(".") ? target.substring(target.lastIndexOf('.') + 1) : target;
|
||||||
|
String simpleNeighbor = neighbor.contains(".") ? neighbor.substring(neighbor.lastIndexOf('.') + 1) : neighbor;
|
||||||
|
if (!simpleNeighbor.equals(simpleTarget)) return false;
|
||||||
|
|
||||||
|
String classNeighbor = neighbor.contains(".") ? neighbor.substring(0, neighbor.lastIndexOf('.')) : null;
|
||||||
|
String classTarget = target.contains(".") ? target.substring(0, target.lastIndexOf('.')) : null;
|
||||||
|
String simpleClassTarget = classTarget != null && classTarget.contains(".") ? classTarget.substring(classTarget.lastIndexOf('.') + 1) : classTarget;
|
||||||
|
String simpleClassNeighbor = classNeighbor != null && classNeighbor.contains(".") ? classNeighbor.substring(classNeighbor.lastIndexOf('.') + 1) : classNeighbor;
|
||||||
|
|
||||||
|
if (simpleClassNeighbor != null && simpleClassTarget != null) {
|
||||||
|
if (simpleClassNeighbor.equalsIgnoreCase(simpleClassTarget)) return true;
|
||||||
|
if (simpleClassNeighbor.equals("this") || simpleClassNeighbor.equals("super")) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private MethodDeclaration findEnclosingMethod(ASTNode node) {
|
private MethodDeclaration findEnclosingMethod(ASTNode node) {
|
||||||
ASTNode parent = node.getParent();
|
ASTNode parent = node.getParent();
|
||||||
while (parent != null && !(parent instanceof MethodDeclaration)) {
|
while (parent != null && !(parent instanceof MethodDeclaration)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user