Search in sources :

Example 16 with SwitchStmt

use of com.github.javaparser.ast.stmt.SwitchStmt in project drools by kiegroup.

the class AccessibleMethod method setterSwitchStatement.

private Statement setterSwitchStatement() {
    SwitchStmt switchStmt = switchOnFieldName();
    NodeList<SwitchEntry> entries = switchStmt.getEntries();
    for (DescrFieldDefinition field : fields) {
        if (!field.isOverride()) {
            entries.add(setValueFromField(field));
        }
    }
    Optional<Class<?>> abstractResolvedClass = descrTypeDefinition.getAbstractResolvedClass();
    if (abstractResolvedClass.isPresent()) {
        entries.addAll(superClassSetterEntries(abstractResolvedClass.get()).collect(toList()));
    } else if (descrTypeDefinition.getDeclaredAbstractClass().isPresent()) {
        entries.add(switchEntry(SUPER_SET_VALUE));
    }
    return new BlockStmt(nodeList(switchStmt));
}
Also used : SwitchStmt(com.github.javaparser.ast.stmt.SwitchStmt) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) SwitchEntry(com.github.javaparser.ast.stmt.SwitchEntry)

Example 17 with SwitchStmt

use of com.github.javaparser.ast.stmt.SwitchStmt in project drools by kiegroup.

the class FEELPropertyAccessibleImplementation method setFeelPropertyDefinition.

private MethodDefinition setFeelPropertyDefinition() {
    MethodDeclaration setFEELProperty = cloneMethodTemplate("setFEELProperty");
    SwitchStmt firstSwitch = setFEELProperty.findFirst(SwitchStmt.class).orElseThrow(() -> new InvalidTemplateException("Missing switch statement in setFEELProperty"));
    firstSwitch.setComment(null);
    List<SwitchEntry> collect = fields.stream().map(this::toSetPropertySwitchEntry).collect(Collectors.toList());
    firstSwitch.setEntries(nodeList(collect));
    BlockStmt body = setFEELProperty.getBody().orElseThrow(() -> new InvalidTemplateException("Empty body in setFEELProperty"));
    if (typeDefinition instanceof AbstractDMNSetType) {
        body.addStatement(0, new ExpressionStmt(StaticJavaParser.parseExpression("definedKeySet.add(property)")));
    }
    MethodWithStringBody setFeelPropertyDefinition = new MethodWithStringBody("setFEELProperty", "void", body.toString()).addParameter(String.class.getCanonicalName(), "property").addParameter(Object.class.getCanonicalName(), "value");
    addOverrideAnnotation(setFeelPropertyDefinition);
    return setFeelPropertyDefinition;
}
Also used : SwitchStmt(com.github.javaparser.ast.stmt.SwitchStmt) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) MethodWithStringBody(org.drools.modelcompiler.builder.generator.declaredtype.api.MethodWithStringBody) SwitchEntry(com.github.javaparser.ast.stmt.SwitchEntry) ExpressionStmt(com.github.javaparser.ast.stmt.ExpressionStmt)

Aggregations

SwitchStmt (com.github.javaparser.ast.stmt.SwitchStmt)17 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)9 ExpressionStmt (com.github.javaparser.ast.stmt.ExpressionStmt)6 SwitchEntry (com.github.javaparser.ast.stmt.SwitchEntry)6 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)4 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)4 NameExpr (com.github.javaparser.ast.expr.NameExpr)4 Statement (com.github.javaparser.ast.stmt.Statement)4 CompilationUnit (com.github.javaparser.ast.CompilationUnit)3 NodeList (com.github.javaparser.ast.NodeList)3 Expression (com.github.javaparser.ast.expr.Expression)3 ReturnStmt (com.github.javaparser.ast.stmt.ReturnStmt)3 StaticJavaParser.parseStatement (com.github.javaparser.StaticJavaParser.parseStatement)2 Node (com.github.javaparser.ast.Node)2 IntegerLiteralExpr (com.github.javaparser.ast.expr.IntegerLiteralExpr)2 ForEachStmt (com.github.javaparser.ast.stmt.ForEachStmt)2 IfStmt (com.github.javaparser.ast.stmt.IfStmt)2 SwitchEntryStmt (com.github.javaparser.ast.stmt.SwitchEntryStmt)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2