more fixes 3
This commit is contained in:
@@ -123,17 +123,19 @@ public class TransitionLinkerEnricher implements AnalysisEnricher {
|
||||
result.setMetadata(updatedMetadata);
|
||||
}
|
||||
|
||||
|
||||
private boolean isRoutedToCorrectMachine(CallChain chain, String currentMachineName) {
|
||||
// If the chain's target expression or qualifier indicates a specific machine name, verify it
|
||||
// First, check explicit variable targeting (like contextMachineId)
|
||||
String targetVar = chain.getContextMachineId();
|
||||
if (targetVar == null && chain.getTriggerPoint() != null) {
|
||||
targetVar = chain.getTriggerPoint().getStateMachineId();
|
||||
}
|
||||
|
||||
String simplifiedMachineName = currentMachineName != null ? currentMachineName.substring(currentMachineName.lastIndexOf('.') + 1).toLowerCase() : "";
|
||||
|
||||
if (targetVar != null && !targetVar.isEmpty()) {
|
||||
targetVar = targetVar.toLowerCase();
|
||||
// E.g., if target is "myStateMachine", ensure current machine name contains "my"
|
||||
String simplifiedMachineName = currentMachineName.substring(currentMachineName.lastIndexOf('.') + 1).toLowerCase();
|
||||
// If the variable name ends with StateMachine, we extract the prefix
|
||||
if (targetVar.endsWith("statemachine")) {
|
||||
String prefix = targetVar.substring(0, targetVar.length() - "statemachine".length());
|
||||
@@ -142,6 +144,44 @@ public class TransitionLinkerEnricher implements AnalysisEnricher {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Second, filter by vertical routing based on Service class name
|
||||
if (chain.getMethodChain() != null) {
|
||||
boolean hasElectronicsService = false;
|
||||
boolean hasComputerStoreService = false;
|
||||
|
||||
for (String method : chain.getMethodChain()) {
|
||||
String className = method;
|
||||
if (method.contains(".")) {
|
||||
className = method.substring(0, method.lastIndexOf('.'));
|
||||
if (className.contains(".")) {
|
||||
className = className.substring(className.lastIndexOf('.') + 1);
|
||||
}
|
||||
}
|
||||
|
||||
String lowerClass = className.toLowerCase();
|
||||
if (lowerClass.contains("electronics")) {
|
||||
hasElectronicsService = true;
|
||||
} else if (lowerClass.contains("computerstore")) {
|
||||
hasComputerStoreService = true;
|
||||
}
|
||||
}
|
||||
|
||||
String lowerMachine = currentMachineName != null ? currentMachineName.toLowerCase() : "";
|
||||
boolean isElectronicsMachine = lowerMachine.contains("electronics");
|
||||
// If the machine is an electronics machine, it must NOT be triggered by computer store
|
||||
if (isElectronicsMachine && hasComputerStoreService && !hasElectronicsService) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the machine is NOT an electronics machine (e.g. standard computer store SM),
|
||||
// it must NOT be triggered by electronics services
|
||||
if (!isElectronicsMachine && hasElectronicsService && !hasComputerStoreService) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -188,8 +188,12 @@ public class CallGraphBuilder {
|
||||
if (declaredType != null) {
|
||||
System.out.println("DEEP TRACE: " + sourceMethod + " " + (varName != null ? varName : "inline") + " -> " + declaredType);
|
||||
List<String> typesToInspect = new ArrayList<>();
|
||||
typesToInspect.add(declaredType);
|
||||
typesToInspect.addAll(context.getImplementations(declaredType));
|
||||
if ("inline-instantiation".equals(sourceMethod)) {
|
||||
typesToInspect.add(declaredType);
|
||||
} else {
|
||||
typesToInspect.add(declaredType);
|
||||
typesToInspect.addAll(context.getImplementations(declaredType));
|
||||
}
|
||||
System.out.println("DEEP TRACE IMPLS: " + typesToInspect);
|
||||
|
||||
for (String type : typesToInspect) {
|
||||
@@ -340,7 +344,12 @@ public class CallGraphBuilder {
|
||||
} else if (retExpr instanceof QualifiedName qn) {
|
||||
constants.add(qn.toString());
|
||||
} else if (retExpr instanceof SimpleName sn) {
|
||||
constants.add(sn.toString());
|
||||
List<String> consts = traceFieldInConstructors(td, sn.getIdentifier(), context, visited);
|
||||
if (!consts.isEmpty()) {
|
||||
constants.addAll(consts);
|
||||
} else {
|
||||
constants.add(sn.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -803,4 +812,43 @@ public class CallGraphBuilder {
|
||||
}
|
||||
return expr;
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> traceFieldInConstructors(TypeDeclaration td, String fieldName, CodebaseContext context, Set<String> visited) {
|
||||
List<String> results = new ArrayList<>();
|
||||
for (MethodDeclaration md : td.getMethods()) {
|
||||
if (md.isConstructor() && md.getBody() != null) {
|
||||
md.getBody().accept(new ASTVisitor() {
|
||||
@Override
|
||||
public boolean visit(Assignment node) {
|
||||
Expression left = node.getLeftHandSide();
|
||||
if ((left instanceof SimpleName && ((SimpleName) left).getIdentifier().equals(fieldName)) ||
|
||||
(left instanceof FieldAccess && ((FieldAccess) left).getName().getIdentifier().equals(fieldName))) {
|
||||
String val = constantResolver.resolve(node.getRightHandSide(), context);
|
||||
if (val != null) results.add(val);
|
||||
}
|
||||
return super.visit(node);
|
||||
}
|
||||
@Override
|
||||
public boolean visit(SuperConstructorInvocation node) {
|
||||
for (Object argObj : node.arguments()) {
|
||||
Expression arg = (Expression) argObj;
|
||||
String val = constantResolver.resolve(arg, context);
|
||||
if (val != null) {
|
||||
if (val.startsWith("ENUM_SET:")) {
|
||||
for (String eVal : val.substring(9).split(",")) {
|
||||
results.add(eVal.substring(eVal.lastIndexOf('.') + 1));
|
||||
}
|
||||
} else {
|
||||
results.add(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.visit(node);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user