我有这样的方法:
public static int calc(int a, int b) {
if (a >= b)
return a - b;
return 0;
}
我想知道在已知行号上使用的条件。在这种情况下,我的预期结果是条件的名称,类似于"> ="。
我知道如何解析给定CompilationUnit
的{{1}}。但我怎样才能得到条件?
答案 0 :(得分:0)
为此你必须创建一个ASTVisitor,它将访问所有的中缀表达式。在访问者类中,访问方法将具有以下内容:
Error activating IMetrics using binding from IMetrics to Metrics
A cyclical dependency was detected between the constructors of two services.
Activation path:
3) Injection of dependency IMetrics into parameter metrics of constructor of type Metrics
2) Injection of dependency IMetrics into property metrics of type _Default
1) Request for default_aspx
Suggestions:
1) Ensure that you have not declared a dependency for IMetrics on any implementations of the service.
2) Consider combining the services into a single one to remove the cycle.
3) Use property injection instead of constructor injection, and implement IInitializable
if you need initialization logic to be run after property values have been injected.
在@Override
public boolean visit(InfixExpression node) {
Operator op= node.getOperator();
if(op.equals(Operator.GREATER) || op.equals(Operator.EQUALS) || ....)
conditionalInfixExpressionList.add(node);
return super.visit(node);
}
方法的if语句中,你必须检查,如果中缀表达式是一个条件变量,并相应地将它添加到列表中。