@Override
 public Node visit(MethodCallExpr call, List<Statement> preStates) {
   // Look for a call to a machine property getter
   final Expression scope = call.getScope();
   if (!(scope instanceof NameExpr)) {
     return super.visit(call, preStates);
   }
   final NameExpr nameExpr = (NameExpr) scope;
   if (!nameExpr.getName().equals(VariableToGetter.SCOPE.getName())) {
     return super.visit(call, preStates);
   }
   // Create variable declaration in pre with the init value set to the call we found
   final String callName = call.getName();
   final int argCount = call.getArgs() == null ? 0 : call.getArgs().size();
   final String varName = methodToVarName(callName);
   final VariableDeclarationExpr preState =
       new VariableDeclarationExpr(
           ModifierSet.FINAL,
           getReturnType(callName, argCount),
           Collections.singletonList(
               new VariableDeclarator(new VariableDeclaratorId(varName), call)));
   preStates.add(new ExpressionStmt(preState));
   // Replace the call by a reference to the variable
   return new NameExpr(varName);
 }
Ejemplo n.º 2
0
  @Override
  public Boolean visit(final NameExpr n1, final Node arg) {
    final NameExpr n2 = (NameExpr) arg;

    if (!objEquals(n1.getName(), n2.getName())) {
      return Boolean.FALSE;
    }

    return Boolean.TRUE;
  }
 @Override
 public Node visit(NameExpr name, Object arg) {
   return new MethodCallExpr(SCOPE, "get" + capitalize(name.getName()));
 }
 @Override
 public void visit(final NameExpr n, final A arg) {
   visitComment(n.getComment(), arg);
 }