I want to extract the local data flow of a Java method. So far I have this query to extract wherever a variable is accessed, declared, or assigned within the function:
/**
* @name Empty block
* @kind problem
* @problem.severity warning
* @id java/example/empty-block
*/
import java
import semmle.code.java.dataflow.DataFlow
from File fl, LocalVariableDeclExpr ld, VarAccess va, Assignment asn
where
fl.getBaseName() = "Calculator.java"
and
ld.getEnclosingCallable().getName()= "calc"
and va.getEnclosingCallable().getName() = "calc"
and asn.getEnclosingCallable().getName() = "calc"
and ld.getLocation().getFile() = fl
and va.getLocation().getFile() = fl
and asn.getLocation().getFile() = fl
and va.getLocation().getStartLine() = ld.getLocation().getStartLine()
select ld, "\"" + va.getVariable().getName()+"\"" + "->" + "\"" +ld.getVariable().getName()+"\"" + "\n" + "\"" +asn.getDest()+"\"" + "->" + "\"" +asn.getSource()+"\"" + "\n"
The problem is it takes so long in the SELECT phase.
I am using this repository as a database. The file name is Calculator.Java
and this is the method:
public double calc(double x, String input, char opt) {
inText.setFont(inText.getFont().deriveFont(Font.PLAIN));
double y = Double.parseDouble(input);
switch (opt) {
case '+':
return x + y;
case '-':
return x - y;
case '*':
return x * y;
case '/':
return x / y;
case '%':
return x % y;
case '^':
return Math.pow(x, y);
default:
inText.setFont(inText.getFont().deriveFont(Font.PLAIN));
return y;
}
}
Thanks.