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

The following examples show how to use com.github.javaparser.ast.expr.IntegerLiteralExpr. 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: StateNodeVisitor.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Override
public Stream<MethodCallExpr> visitCustomFields(StateNode node, VariableScope variableScope) {
    if (node.getConstraints() == null) {
        return Stream.empty();
    }
    return node.getConstraints()
            .entrySet()
            .stream()
            .map((e -> getFactoryMethod(getNodeId(node), METHOD_CONSTRAINT,
                    getOrNullExpr(e.getKey().getConnectionId()),
                    new LongLiteralExpr(e.getKey().getNodeId()),
                    new StringLiteralExpr(e.getKey().getToType()),
                    new StringLiteralExpr(e.getValue().getDialect()),
                    new StringLiteralExpr(StringEscapeUtils.escapeJava(e.getValue().getConstraint())),
                    new IntegerLiteralExpr(e.getValue().getPriority()))));
}
 
Example #2
Source File: TimerNodeVisitor.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Override
public void visitNode(String factoryField, TimerNode node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) {
    body.addStatement(getAssignedFactoryMethod(factoryField, TimerNodeFactory.class, getNodeId(node), getNodeKey(), new LongLiteralExpr(node.getId())))
    .addStatement(getNameMethod(node,"Timer"));

    Timer timer = node.getTimer();
    body.addStatement(getFactoryMethod(getNodeId(node), METHOD_TYPE, new IntegerLiteralExpr(timer.getTimeType())));

    if (timer.getTimeType() == Timer.TIME_CYCLE) {
        body.addStatement(getFactoryMethod(getNodeId(node), METHOD_DELAY, new StringLiteralExpr(timer.getDelay())));
        if (timer.getPeriod() != null && !timer.getPeriod().isEmpty()) {
            body.addStatement(getFactoryMethod(getNodeId(node), METHOD_PERIOD, new StringLiteralExpr(timer.getPeriod())));
        }
    } else if (timer.getTimeType() == Timer.TIME_DURATION) {
        body.addStatement(getFactoryMethod(getNodeId(node), METHOD_DELAY, new StringLiteralExpr(timer.getDelay())));
    } else if (timer.getTimeType() == Timer.TIME_DATE) {
        body.addStatement(getFactoryMethod(getNodeId(node), METHOD_DATE, new StringLiteralExpr(timer.getDate())));
    }

    visitMetaData(node.getMetaData(), body, getNodeId(node));
    body.addStatement(getDoneMethod(getNodeId(node)));
}
 
Example #3
Source File: WorkItemNodeVisitor.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
private Expression getParameterExpr(String type, String value) {
    ParamType pType = ParamType.fromString(type);
    if (pType == null) {
        return new StringLiteralExpr(value);
    }
    switch (pType) {
        case BOOLEAN:
            return new BooleanLiteralExpr(Boolean.parseBoolean(value));
        case FLOAT:
            return new MethodCallExpr()
                    .setScope(new NameExpr(Float.class.getName()))
                    .setName("parseFloat")
                    .addArgument(new StringLiteralExpr(value));
        case INTEGER:
            return new IntegerLiteralExpr(Integer.parseInt(value));
        default:
            return new StringLiteralExpr(value);
    }
}
 
Example #4
Source File: AnnotatedMember.java    From jeddict with Apache License 2.0 6 votes vote down vote up
static Optional<String> getStringAttribute(AnnotationExpr annotationExpr, String attributeName) {
    Optional<Expression> expressionOpt = getAttribute(annotationExpr, attributeName);
    if (expressionOpt.isPresent()) {
        Expression expression = expressionOpt.get();
        if (expression.isStringLiteralExpr()) {
            return expression.toStringLiteralExpr()
                    .map(StringLiteralExpr::getValue);
        } else if (expression.isNameExpr()) {
            return expression.toNameExpr()
                    .map(NameExpr::getNameAsString);
        } else if (expression.isIntegerLiteralExpr()) {
            return expression.toIntegerLiteralExpr()
                    .map(IntegerLiteralExpr::asInt)
                    .map(String::valueOf);
        } else if (expression.isFieldAccessExpr() || expression.isBinaryExpr()) {
            return expressionOpt
                    .map(Expression::toString);
        } else {
            throw new UnsupportedOperationException();
        }
    }
    return Optional.empty();
}
 
Example #5
Source File: KieModuleModelMethod.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
private void kieBaseSessionsPool() {
    if (kieBaseModel.getSessionsPool() != SessionsPoolOption.NO) {
        int poolSize = kieBaseModel.getSessionsPool().getSize();
        MethodCallExpr poolExpr = new MethodCallExpr(new NameExpr(SessionsPoolOption.class.getCanonicalName()), "get", nodeList(new IntegerLiteralExpr(poolSize)));
        stmt.addStatement(new MethodCallExpr(kieBaseModelNameExpr, "setSessionsPool", nodeList(poolExpr)));
    }
}
 
Example #6
Source File: SplitNodeVisitor.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Override
public void visitNode(String factoryField, Split node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) {
    body.addStatement(getAssignedFactoryMethod(factoryField, SplitFactory.class, getNodeId(node), getNodeKey(), new LongLiteralExpr(node.getId())))
            .addStatement(getNameMethod(node, "Split"))
            .addStatement(getFactoryMethod(getNodeId(node), METHOD_TYPE, new IntegerLiteralExpr(node.getType())));

    visitMetaData(node.getMetaData(), body, getNodeId(node));

    if (node.getType() == Split.TYPE_OR || node.getType() == Split.TYPE_XOR) {
        for (Entry<ConnectionRef, Constraint> entry : node.getConstraints().entrySet()) {
            if (entry.getValue() != null) {
                BlockStmt actionBody = new BlockStmt();
                LambdaExpr lambda = new LambdaExpr(
                        new Parameter(new UnknownType(), KCONTEXT_VAR), // (kcontext) ->
                        actionBody
                );

                for (Variable v : variableScope.getVariables()) {
                    actionBody.addStatement(makeAssignment(v));
                }
                BlockStmt constraintBody = new BlockStmt();
                constraintBody.addStatement(entry.getValue().getConstraint());

                actionBody.addStatement(constraintBody);

                body.addStatement(getFactoryMethod(getNodeId(node), METHOD_CONSTRAINT,
                        new LongLiteralExpr(entry.getKey().getNodeId()),
                        new StringLiteralExpr(getOrDefault(entry.getKey().getConnectionId(), "")),
                        new StringLiteralExpr(entry.getKey().getToType()),
                        new StringLiteralExpr(entry.getValue().getDialect()),
                        lambda,
                        new IntegerLiteralExpr(entry.getValue().getPriority())));
            }
        }
    }
    body.addStatement(getDoneMethod(getNodeId(node)));
}
 
Example #7
Source File: StartNodeVisitor.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Override
public void visitNode(String factoryField, StartNode node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) {
    body.addStatement(getAssignedFactoryMethod(factoryField, StartNodeFactory.class, getNodeId(node), getNodeKey(), new LongLiteralExpr(node.getId())))
            .addStatement(getNameMethod(node, "Start"))
            .addStatement(getFactoryMethod(getNodeId(node), METHOD_INTERRUPTING, new BooleanLiteralExpr(node.isInterrupting())));

    visitMetaData(node.getMetaData(), body, getNodeId(node));
    body.addStatement(getDoneMethod(getNodeId(node)));
    if (node.getTimer() != null) {
        Timer timer = node.getTimer();
        body.addStatement(getFactoryMethod(getNodeId(node), METHOD_TIMER, getOrNullExpr(timer.getDelay()),
                getOrNullExpr(timer.getPeriod()),
                getOrNullExpr(timer.getDate()),
                new IntegerLiteralExpr(node.getTimer().getTimeType())));

    } else if (node.getTriggers() != null && !node.getTriggers().isEmpty()) {
        Map<String, Object> nodeMetaData = node.getMetaData();
        metadata.getTriggers().add(new TriggerMetaData((String) nodeMetaData.get(TRIGGER_REF),
                (String) nodeMetaData.get(TRIGGER_TYPE),
                (String) nodeMetaData.get(MESSAGE_TYPE),
                (String) nodeMetaData.get(TRIGGER_MAPPING),
                String.valueOf(node.getId())).validate());

        handleSignal(node, nodeMetaData, body, variableScope, metadata);
    } else {
        // since there is start node without trigger then make sure it is startable
        metadata.setStartable(true);
    }

}
 
Example #8
Source File: JoinNodeVisitor.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Override
public void visitNode(String factoryField, Join node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) {
    body.addStatement(getAssignedFactoryMethod(factoryField, JoinFactory.class, getNodeId(node), getNodeKey(), new LongLiteralExpr(node.getId())));
    body.addStatement(getNameMethod(node, "Join"));
    body.addStatement(getFactoryMethod(getNodeId(node), METHOD_TYPE, new IntegerLiteralExpr(node.getType())));

    visitMetaData(node.getMetaData(), body, getNodeId(node));
    body.addStatement(getDoneMethod(getNodeId(node)));
}
 
Example #9
Source File: PrettyPrintVisitor.java    From stategen with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void visit(final IntegerLiteralExpr n, final Void arg) {
    printJavaComment(n.getComment(), arg);
    printer.print(n.getValue());
}
 
Example #10
Source File: TraceVisitor.java    From JCTools with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(IntegerLiteralExpr n, Void arg) {
    out.println("IntegerLiteralExpr: " + (extended ? n : n));
    super.visit(n, arg);
}
 
Example #11
Source File: IntegerLiteralExprMerger.java    From dolphin with Apache License 2.0 3 votes vote down vote up
@Override public IntegerLiteralExpr doMerge(IntegerLiteralExpr first, IntegerLiteralExpr second) {
  IntegerLiteralExpr ile = new IntegerLiteralExpr();

  ile.setValue(first.getValue());

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

    if(!first.getValue().equals(second.getValue())) return false;

    return true;
  }