stage 1 update loop
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package click.kamil.springstatemachineexporter.ast.common;
|
package click.kamil.springstatemachineexporter.ast.common;
|
||||||
|
|
||||||
import org.eclipse.jdt.core.dom.*;
|
import org.eclipse.jdt.core.dom.*;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public final class BindingResolver {
|
public final class BindingResolver {
|
||||||
|
|
||||||
@@ -72,12 +73,18 @@ public final class BindingResolver {
|
|||||||
return binding.getErasure().getQualifiedName();
|
return binding.getErasure().getQualifiedName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if childBinding is compatible with (extends or implements) targetFqn.
|
|
||||||
*/
|
|
||||||
public static boolean isSubtypeOf(ITypeBinding childBinding, String targetFqn) {
|
public static boolean isSubtypeOf(ITypeBinding childBinding, String targetFqn) {
|
||||||
|
return isSubtypeOf(childBinding, targetFqn, new java.util.HashSet<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isSubtypeOf(ITypeBinding childBinding, String targetFqn, Set<String> visited) {
|
||||||
if (childBinding == null || targetFqn == null) return false;
|
if (childBinding == null || targetFqn == null) return false;
|
||||||
|
|
||||||
|
String key = childBinding.getKey();
|
||||||
|
if (key != null && !visited.add(key)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Direct match
|
// Direct match
|
||||||
if (targetFqn.equals(childBinding.getErasure().getQualifiedName())) {
|
if (targetFqn.equals(childBinding.getErasure().getQualifiedName())) {
|
||||||
return true;
|
return true;
|
||||||
@@ -85,7 +92,7 @@ public final class BindingResolver {
|
|||||||
|
|
||||||
// Check interfaces
|
// Check interfaces
|
||||||
for (ITypeBinding intf : childBinding.getInterfaces()) {
|
for (ITypeBinding intf : childBinding.getInterfaces()) {
|
||||||
if (isSubtypeOf(intf, targetFqn)) {
|
if (isSubtypeOf(intf, targetFqn, visited)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,7 +100,7 @@ public final class BindingResolver {
|
|||||||
// Check superclass
|
// Check superclass
|
||||||
ITypeBinding superclass = childBinding.getSuperclass();
|
ITypeBinding superclass = childBinding.getSuperclass();
|
||||||
if (superclass != null) {
|
if (superclass != null) {
|
||||||
return isSubtypeOf(superclass, targetFqn);
|
return isSubtypeOf(superclass, targetFqn, visited);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -492,6 +492,16 @@ public class CodebaseContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private IMethodBinding findMethodBinding(ITypeBinding typeBinding, String methodName) {
|
private IMethodBinding findMethodBinding(ITypeBinding typeBinding, String methodName) {
|
||||||
|
return findMethodBinding(typeBinding, methodName, new java.util.HashSet<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
private IMethodBinding findMethodBinding(ITypeBinding typeBinding, String methodName, Set<String> visited) {
|
||||||
|
if (typeBinding == null) return null;
|
||||||
|
String key = typeBinding.getKey();
|
||||||
|
if (key != null && !visited.add(key)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
for (IMethodBinding mb : typeBinding.getDeclaredMethods()) {
|
for (IMethodBinding mb : typeBinding.getDeclaredMethods()) {
|
||||||
if (mb.getName().equals(methodName)) {
|
if (mb.getName().equals(methodName)) {
|
||||||
return mb;
|
return mb;
|
||||||
@@ -500,12 +510,12 @@ public class CodebaseContext {
|
|||||||
|
|
||||||
ITypeBinding superclass = typeBinding.getSuperclass();
|
ITypeBinding superclass = typeBinding.getSuperclass();
|
||||||
if (superclass != null) {
|
if (superclass != null) {
|
||||||
IMethodBinding mb = findMethodBinding(superclass, methodName);
|
IMethodBinding mb = findMethodBinding(superclass, methodName, visited);
|
||||||
if (mb != null) return mb;
|
if (mb != null) return mb;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ITypeBinding intf : typeBinding.getInterfaces()) {
|
for (ITypeBinding intf : typeBinding.getInterfaces()) {
|
||||||
IMethodBinding mb = findMethodBinding(intf, methodName);
|
IMethodBinding mb = findMethodBinding(intf, methodName, visited);
|
||||||
if (mb != null) return mb;
|
if (mb != null) return mb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user