package click.kamil.springstatemachineexporter.ast.common;

import org.eclipse.jdt.core.dom.Expression;
import click.kamil.springstatemachineexporter.analysis.service.VariableTracer;
import java.util.List;

public class LegacyDataFlowModel implements DataFlowModel {
    private final VariableTracer variableTracer;

    public LegacyDataFlowModel(VariableTracer variableTracer) {
        this.variableTracer = variableTracer;
    }

    @Override
    public List<Expression> getReachingDefinitions(Expression expr) {
        if (variableTracer == null || expr == null) {
            return expr != null ? List.of(expr) : List.of();
        }
        return variableTracer.traceVariableAll(expr);
    }

    @Override
    public String resolveValue(Expression expr, CodebaseContext context) {
        if (expr == null) return null;
        if (variableTracer == null) {
            return context.resolveExpression(expr);
        }
        Expression traced = variableTracer.traceVariable(expr);
        return context.resolveExpression(traced);
    }
}
