com.github.javaparser.ast.expr.EnclosedExpr Java Examples

The following examples show how to use com.github.javaparser.ast.expr.EnclosedExpr. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractNodeVisitor.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
protected static LambdaExpr createLambdaExpr(String consequence, VariableScope scope) {
    BlockStmt conditionBody = new BlockStmt();
    List<Variable> variables = scope.getVariables();
    variables.stream()
            .map(ActionNodeVisitor::makeAssignment)
            .forEach(conditionBody::addStatement);

    conditionBody.addStatement(new ReturnStmt(new EnclosedExpr(new NameExpr(consequence))));

    return new LambdaExpr(
            new Parameter(new UnknownType(), KCONTEXT_VAR), // (kcontext) ->
            conditionBody
    );
}
 
Example #2
Source File: ModelMetaData.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public MethodCallExpr callSetter(String targetVar, String destField, Expression value) {
    String name = variableScope.getTypes().get(destField).getSanitizedName();
    String type = variableScope.getType(destField);
    String setter = "set" + StringUtils.capitalize(name); // todo cache FieldDeclarations in compilationUnit()
    return new MethodCallExpr(new NameExpr(targetVar), setter).addArgument(
            new CastExpr(
                    new ClassOrInterfaceType(null, type),
                    new EnclosedExpr(value)));
}
 
Example #3
Source File: ProcessContextMetaModel.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public Expression getVariable(String procVar) {
    String interpolatedVar = extractVariableFromExpression(procVar);
    Variable v = variableScope.findVariable(interpolatedVar);
    if (v == null) {
        throw new IllegalArgumentException("No such variable " + procVar);
    }
    MethodCallExpr getter = new MethodCallExpr().setScope(new NameExpr(kcontext))
            .setName("getVariable")
            .addArgument(new StringLiteralExpr(interpolatedVar));
    CastExpr castExpr = new CastExpr()
            .setExpression(new EnclosedExpr(getter))
            .setType(v.getType().getStringType());
    return castExpr;
}
 
Example #4
Source File: PrettyPrintVisitor.java    From stategen with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void visit(final EnclosedExpr n, final Void arg) {
    printJavaComment(n.getComment(), arg);
    printer.print("(");
    if (n.getInner().isPresent()) {
        n.getInner().get().accept(this, arg);
    }
    printer.print(")");
}
 
Example #5
Source File: TraceVisitor.java    From JCTools with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(EnclosedExpr n, Void arg) {
    out.println("EnclosedExpr: " + (extended ? n : ""));
    super.visit(n, arg);
}
 
Example #6
Source File: MigrateJCas.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/** 
 * visitor for method calls
 */
@Override
public void visit(MethodCallExpr n, Object ignore) {
  Optional<Node> p1, p2, p3 = null; 
  Node updatedNode = null;
  NodeList<Expression> args;
  
  do {
    if (get_set_method == null) break;
   
    /** remove checkArraybounds statement **/
    if (n.getNameAsString().equals("checkArrayBounds") &&
        ((p1 = n.getParentNode()).isPresent() && p1.get() instanceof ExpressionStmt) &&
        ((p2 = p1.get().getParentNode()).isPresent() && p2.get() instanceof BlockStmt) &&
        ((p3 = p2.get().getParentNode()).isPresent() && p3.get() == get_set_method)) {
      NodeList<Statement> stmts = ((BlockStmt)p2.get()).getStatements();
      stmts.set(stmts.indexOf(p1.get()), new EmptyStmt());
      return;
    }
         
    // convert simpleCore expression ll_get/setRangeValue
    boolean useGetter = isGetter || isArraySetter;
    if (n.getNameAsString().startsWith("ll_" + (useGetter ? "get" : "set") + rangeNameV2Part + "Value")) {
      args = n.getArguments();
      if (args.size() != (useGetter ? 2 : 3)) break;
      String suffix = useGetter ? "Nc" : rangeNamePart.equals("Feature") ? "NcWj" : "Nfc";
      String methodName = "_" + (useGetter ? "get" : "set") + rangeNamePart + "Value" + suffix; 
      args.remove(0);    // remove the old addr arg
      // arg 0 converted when visiting args FieldAccessExpr 
      n.setScope(null);
      n.setName(methodName);
    }
    
    // convert array sets/gets
    String z = "ll_" + (isGetter ? "get" : "set");
    String nname = n.getNameAsString();
    if (nname.startsWith(z) &&
        nname.endsWith("ArrayValue")) {
      
      String s = nname.substring(z.length());
      s = s.substring(0,  s.length() - "Value".length()); // s = "ShortArray",  etc.
      if (s.equals("RefArray")) s = "FSArray";
      if (s.equals("IntArray")) s = "IntegerArray";
      EnclosedExpr ee = new EnclosedExpr(
          new CastExpr(new ClassOrInterfaceType(s), n.getArguments().get(0)));
      
      n.setScope(ee);    // the getter for the array fs
      n.setName(isGetter ? "get" : "set");
      n.getArguments().remove(0);
    }
    
    /** remove ll_getFSForRef **/
    /** remove ll_getFSRef **/
    if (n.getNameAsString().equals("ll_getFSForRef") ||
        n.getNameAsString().equals("ll_getFSRef")) {
      updatedNode = replaceInParent(n, n.getArguments().get(0));        
    }
    
    
    
  } while (false);
      
  if (updatedNode != null) {
    updatedNode.accept(this,  null);
  } else {
    super.visit(n, null);
  }
}
 
Example #7
Source File: MigrateJCas.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
private Expression getUnenclosedExpr(Expression e) {
  while (e instanceof EnclosedExpr) {
    e = ((EnclosedExpr)e).getInner().get();
  }
  return e;
}
 
Example #8
Source File: EnclosedExprMerger.java    From dolphin with Apache License 2.0 3 votes vote down vote up
@Override public EnclosedExpr doMerge(EnclosedExpr first, EnclosedExpr second) {
  EnclosedExpr ee = new EnclosedExpr();

  ee.setInner(mergeSingle(first.getInner(),second.getInner()));

  return ee;
}
 
Example #9
Source File: EnclosedExprMerger.java    From dolphin with Apache License 2.0 2 votes vote down vote up
@Override public boolean doIsEquals(EnclosedExpr first, EnclosedExpr second) {

    if(!isEqualsUseMerger(first.getInner(),second.getInner())) return false;

    return true;
  }