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

The following examples show how to use com.github.javaparser.ast.expr.BooleanLiteralExpr. 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: CompositeContextNodeVisitor.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
@Override
public void visitNode(String factoryField, T node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) {
    body.addStatement(getAssignedFactoryMethod(factoryField, factoryClass(), getNodeId(node), factoryMethod(), new LongLiteralExpr(node.getId())))
            .addStatement(getNameMethod(node, getDefaultName()));
    visitMetaData(node.getMetaData(), body, getNodeId(node));
    VariableScope variableScopeNode = (VariableScope) node.getDefaultContext(VariableScope.VARIABLE_SCOPE);

    if (variableScope != null) {
        visitVariableScope(getNodeId(node), variableScopeNode, body, new HashSet<>());
    }

    visitCustomFields(node, variableScope).forEach(body::addStatement);

    // composite context node might not have variable scope
    // in that case inherit it from parent
    VariableScope scope = variableScope;
    if (node.getDefaultContext(VariableScope.VARIABLE_SCOPE) != null && !((VariableScope) node.getDefaultContext(VariableScope.VARIABLE_SCOPE)).getVariables().isEmpty()) {
        scope = (VariableScope) node.getDefaultContext(VariableScope.VARIABLE_SCOPE);
    }
    body.addStatement(getFactoryMethod(getNodeId(node), CompositeContextNodeFactory.METHOD_AUTO_COMPLETE, new BooleanLiteralExpr(node.isAutoComplete())));
    visitNodes(getNodeId(node), node.getNodes(), body, scope, metadata);
    visitConnections(getNodeId(node), node.getNodes(), body);
    body.addStatement(getDoneMethod(getNodeId(node)));
}
 
Example #2
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 #3
Source File: CDIDependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Override
public Expression getMultiInstance(String fieldName) {
    return new MethodCallExpr(
            new MethodCallExpr(new NameExpr("java.util.stream.StreamSupport"), "stream", NodeList.nodeList(
                    new MethodCallExpr(new NameExpr(fieldName), "spliterator"),
                    new BooleanLiteralExpr(false)
            )),
            "collect",
            NodeList.nodeList(
                    new MethodCallExpr(new NameExpr("java.util.stream.Collectors"), "toList")
            )
    );
}
 
Example #4
Source File: KieModuleModelMethod.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
private void sessionDefault() {
    if (kieSessionModel.isDefault()) {
        if (kieSessionModel.getType() == KieSessionModel.KieSessionType.STATELESS) {
            defaultKieStatelessSessionName = kieSessionModel.getName();
        } else {
            defaultKieSessionName = kieSessionModel.getName();
        }
        stmt.addStatement(new MethodCallExpr(nameExpr, "setDefault", nodeList(new BooleanLiteralExpr(true))));
    }
}
 
Example #5
Source File: EventSubProcessNodeVisitor.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Override
public Stream<MethodCallExpr> visitCustomFields(EventSubProcessNode node, VariableScope variableScope) {
    Collection<MethodCallExpr> methods = new ArrayList<>();
    methods.add(getFactoryMethod(getNodeId(node), METHOD_KEEP_ACTIVE, new BooleanLiteralExpr(node.isKeepActive())));
    node.getEvents()
            .forEach(e -> methods.add(getFactoryMethod(getNodeId(node), METHOD_EVENT, new StringLiteralExpr(e))));
    return methods.stream();
}
 
Example #6
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 #7
Source File: CDIDependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public Expression optionalInstanceExists(String fieldName) {
    MethodCallExpr condition = new MethodCallExpr(new NameExpr(fieldName), "isUnsatisfied");
    return new BinaryExpr(condition, new BooleanLiteralExpr(false), BinaryExpr.Operator.EQUALS);
}
 
Example #8
Source File: SpringDependencyInjectionAnnotator.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends NodeWithAnnotations<?>> T withOptionalInjection(T node) {
    node.addAnnotation(new NormalAnnotationExpr(new Name("org.springframework.beans.factory.annotation.Autowired"), NodeList.nodeList(new MemberValuePair("required", new BooleanLiteralExpr(false)))));
    return node;
}
 
Example #9
Source File: KieModuleModelMethod.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
private void kieBaseModelDefault() {
    if (kieBaseModel.isDefault()) {
        defaultKieBaseName = kieBaseModel.getName();
        stmt.addStatement(new MethodCallExpr(kieBaseModelNameExpr, "setDefault", nodeList(new BooleanLiteralExpr(true))));
    }
}
 
Example #10
Source File: LambdaSubProcessNodeVisitor.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Override
public void visitNode(String factoryField, SubProcessNode node, BlockStmt body, VariableScope variableScope, ProcessMetaData metadata) {
    InputStream resourceAsStream = this.getClass().getResourceAsStream("/class-templates/SubProcessFactoryTemplate.java");
    Optional<Expression> retValue = parse(resourceAsStream).findFirst(Expression.class);
    String name = node.getName();
    String subProcessId = node.getProcessId();

    NodeValidator.of(getNodeKey(), name)
            .notEmpty("subProcessId", subProcessId)
            .validate();


    body.addStatement(getAssignedFactoryMethod(factoryField, SubProcessNodeFactory.class, getNodeId(node), getNodeKey(), new LongLiteralExpr(node.getId())))
            .addStatement(getNameMethod(node, "Call Activity"))
            .addStatement(getFactoryMethod(getNodeId(node), METHOD_PROCESS_ID, new StringLiteralExpr(subProcessId)))
            .addStatement(getFactoryMethod(getNodeId(node), METHOD_PROCESS_NAME, new StringLiteralExpr(getOrDefault(node.getProcessName(), ""))))
            .addStatement(getFactoryMethod(getNodeId(node), METHOD_WAIT_FOR_COMPLETION, new BooleanLiteralExpr(node.isWaitForCompletion())))
            .addStatement(getFactoryMethod(getNodeId(node), METHOD_INDEPENDENT, new BooleanLiteralExpr(node.isIndependent())));

    Map<String, String> inputTypes = (Map<String, String>) node.getMetaData("BPMN.InputTypes");

    String subProcessModelClassName = ProcessToExecModelGenerator.extractModelClassName(subProcessId);
    ModelMetaData subProcessModel = new ModelMetaData(subProcessId,
            metadata.getPackageName(),
            subProcessModelClassName,
            WorkflowProcess.PRIVATE_VISIBILITY,
            VariableDeclarations.ofRawInfo(inputTypes),
            false);

    retValue.ifPresent(retValueExpression -> {
        retValueExpression.findAll(ClassOrInterfaceType.class)
                .stream()
                .filter(t -> t.getNameAsString().equals("$Type$"))
                .forEach(t -> t.setName(subProcessModelClassName));

        retValueExpression.findFirst(MethodDeclaration.class, m -> m.getNameAsString().equals("bind"))
                .ifPresent(m -> m.setBody(bind(variableScope, node, subProcessModel)));
        retValueExpression.findFirst(MethodDeclaration.class, m -> m.getNameAsString().equals("createInstance"))
                .ifPresent(m -> m.setBody(createInstance(node, metadata)));
        retValueExpression.findFirst(MethodDeclaration.class, m -> m.getNameAsString().equals("unbind"))
                .ifPresent(m -> m.setBody(unbind(variableScope, node)));
    });

    if (retValue.isPresent()) {
        body.addStatement(getFactoryMethod(getNodeId(node), getNodeKey(), retValue.get()));
    } else {
        body.addStatement(getFactoryMethod(getNodeId(node), getNodeKey()));
    }

    visitMetaData(node.getMetaData(), body, getNodeId(node));
    body.addStatement(getDoneMethod(getNodeId(node)));
}
 
Example #11
Source File: ProcessVisitor.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
public void visitProcess(WorkflowProcess process, MethodDeclaration processMethod, ProcessMetaData metadata) {
    BlockStmt body = new BlockStmt();

    ClassOrInterfaceType processFactoryType = new ClassOrInterfaceType(null, RuleFlowProcessFactory.class.getSimpleName());

    // create local variable factory and assign new fluent process to it
    VariableDeclarationExpr factoryField = new VariableDeclarationExpr(processFactoryType, FACTORY_FIELD_NAME);
    MethodCallExpr assignFactoryMethod = new MethodCallExpr(new NameExpr(processFactoryType.getName().asString()), "createProcess");
    assignFactoryMethod.addArgument(new StringLiteralExpr(process.getId()));
    body.addStatement(new AssignExpr(factoryField, assignFactoryMethod, AssignExpr.Operator.ASSIGN));

    // item definitions
    Set<String> visitedVariables = new HashSet<>();
    VariableScope variableScope = (VariableScope) ((org.jbpm.process.core.Process) process).getDefaultContext(VariableScope.VARIABLE_SCOPE);

    visitVariableScope(variableScope, body, visitedVariables);
    visitSubVariableScopes(process.getNodes(), body, visitedVariables);

    visitInterfaces(process.getNodes(), body);

    // the process itself
    body.addStatement(getFactoryMethod(FACTORY_FIELD_NAME, METHOD_NAME, new StringLiteralExpr(process.getName())))
            .addStatement(getFactoryMethod(FACTORY_FIELD_NAME, METHOD_PACKAGE_NAME, new StringLiteralExpr(process.getPackageName())))
            .addStatement(getFactoryMethod(FACTORY_FIELD_NAME, METHOD_DYNAMIC, new BooleanLiteralExpr(((org.jbpm.workflow.core.WorkflowProcess) process).isDynamic())))
            .addStatement(getFactoryMethod(FACTORY_FIELD_NAME, METHOD_VERSION, new StringLiteralExpr(getOrDefault(process.getVersion(), DEFAULT_VERSION))))
            .addStatement(getFactoryMethod(FACTORY_FIELD_NAME, METHOD_VISIBILITY, new StringLiteralExpr(getOrDefault(process.getVisibility(), WorkflowProcess.PUBLIC_VISIBILITY))));

    visitMetaData(process.getMetaData(), body, FACTORY_FIELD_NAME);

    visitHeader(process, body);

    List<Node> processNodes = new ArrayList<>();
    for (org.kie.api.definition.process.Node procNode : process.getNodes()) {
        processNodes.add((org.jbpm.workflow.core.Node) procNode);
    }
    visitNodes(processNodes, body, variableScope, metadata);
    visitConnections(process.getNodes(), body);

    body.addStatement(getFactoryMethod(FACTORY_FIELD_NAME, METHOD_VALIDATE));

    MethodCallExpr getProcessMethod = new MethodCallExpr(new NameExpr(FACTORY_FIELD_NAME), "getProcess");
    body.addStatement(new ReturnStmt(getProcessMethod));
    processMethod.setBody(body);
}
 
Example #12
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 BooleanLiteralExpr n, final Void arg) {
    printJavaComment(n.getComment(), arg);
    printer.print(String.valueOf(n.getValue()));
}
 
Example #13
Source File: RedundantAssertion.java    From TestSmellDetector with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void visit(MethodCallExpr n, Void arg) {
    String argumentValue = null;

    super.visit(n, arg);
    if (currentMethod != null) {
        switch (n.getNameAsString()) {
            case "assertTrue":
            case "assertFalse":
                if (n.getArguments().size() == 1 && n.getArgument(0) instanceof BooleanLiteralExpr) { // assertTrue(boolean condition) or assertFalse(boolean condition)
                    argumentValue = Boolean.toString(((BooleanLiteralExpr) n.getArgument(0)).getValue());
                } else if (n.getArguments().size() == 2 && n.getArgument(1) instanceof BooleanLiteralExpr) { // assertTrue(java.lang.String message, boolean condition)  or assertFalse(java.lang.String message, boolean condition)
                    argumentValue = Boolean.toString(((BooleanLiteralExpr) n.getArgument(1)).getValue());
                }

                if (argumentValue != null && (argumentValue.toLowerCase().equals("true") || argumentValue.toLowerCase().equals("false"))) {
                    redundantCount++;
                }
                break;

            case "assertNotNull":
            case "assertNull":
                if (n.getArguments().size() == 1 && n.getArgument(0) instanceof NullLiteralExpr) { // assertNotNull(java.lang.Object object) or assertNull(java.lang.Object object)
                    argumentValue = (((NullLiteralExpr) n.getArgument(0)).toString());
                } else if (n.getArguments().size() == 2 && n.getArgument(1) instanceof NullLiteralExpr) { // assertNotNull(java.lang.String message, java.lang.Object object) or assertNull(java.lang.String message, java.lang.Object object)
                    argumentValue = (((NullLiteralExpr) n.getArgument(1)).toString());
                }

                if (argumentValue != null && (argumentValue.toLowerCase().equals("null"))) {
                    redundantCount++;
                }
                break;

            default:
                if (n.getNameAsString().startsWith("assert")) {
                    if (n.getArguments().size() == 2) { //e.g. assertArrayEquals(byte[] expecteds, byte[] actuals); assertEquals(long expected, long actual);
                        if (n.getArgument(0).equals(n.getArgument(1))) {
                            redundantCount++;
                        }
                    }
                    if (n.getArguments().size() == 3) { //e.g. assertArrayEquals(java.lang.String message, byte[] expecteds, byte[] actuals); assertEquals(java.lang.String message, long expected, long actual)
                        if (n.getArgument(1).equals(n.getArgument(2))) {
                            redundantCount++;
                        }
                    }
                }
                break;
        }
    }
}
 
Example #14
Source File: TraceVisitor.java    From JCTools with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(BooleanLiteralExpr n, Void arg) {
    out.println("BooleanLiteralExpr: " + (extended ? n : n.getValue()));
    super.visit(n, arg);
}
 
Example #15
Source File: BooleanLiteralExprMerger.java    From dolphin with Apache License 2.0 3 votes vote down vote up
@Override public BooleanLiteralExpr doMerge(BooleanLiteralExpr first, BooleanLiteralExpr second) {
  BooleanLiteralExpr ble = new BooleanLiteralExpr();

  ble.setValue(first.getValue());

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

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

    return true;
  }