Search in sources :

Example 1 with BreakStmt

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

the class PropagatorCompilerHandler method extractMethod.

private void extractMethod(SwitchEntry switchEntry) {
    String label = switchEntry.getLabels().stream().map(Node::toString).collect(Collectors.joining());
    SwitchStmt switchStatement = switchEntry.findAncestor(SwitchStmt.class).orElseThrow(() -> new CouldNotCreateAlphaNetworkCompilerException("SwitchEntry without SwitchStatement"));
    int index = switchStatement.getEntries().indexOf(switchEntry);
    String selectorString = switchStatement.getSelector().toString();
    String newMethodName = String.format("extractedPropagated_%s_%d", md5Hash(selectorString), index);
    // First statement is actual block, second statement is break
    BlockStmt switchEntryStatements = (BlockStmt) switchEntry.getStatements().get(0);
    MethodDeclaration extractedMethod = new MethodDeclaration().setModifiers(nodeList(Modifier.publicModifier())).setName(newMethodName).setParameters(methodParameters()).setType(new VoidType()).setBody(switchEntryStatements);
    extractedMethod.setComment(new LineComment(selectorString + " " + label));
    MethodCallExpr callExtractedMethod = new MethodCallExpr().setName(newMethodName).setArguments(arguments());
    switchEntry.setStatements(nodeList(new ExpressionStmt(callExtractedMethod), new BreakStmt()));
    extractedMethods.add(extractedMethod);
}
Also used : VoidType(com.github.javaparser.ast.type.VoidType) SwitchStmt(com.github.javaparser.ast.stmt.SwitchStmt) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) BreakStmt(com.github.javaparser.ast.stmt.BreakStmt) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) LineComment(com.github.javaparser.ast.comments.LineComment) IndexableConstraint(org.drools.core.rule.IndexableConstraint) ExpressionStmt(com.github.javaparser.ast.stmt.ExpressionStmt) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Example 2 with BreakStmt

use of com.github.javaparser.ast.stmt.BreakStmt in project checker-framework by typetools.

the class JointJavacJavaParserVisitor method visitBreak.

@Override
public Void visitBreak(BreakTree javacTree, Node javaParserNode) {
    BreakStmt node = castNode(BreakStmt.class, javaParserNode, javacTree);
    processBreak(javacTree, node);
    return null;
}
Also used : BreakStmt(com.github.javaparser.ast.stmt.BreakStmt)

Example 3 with BreakStmt

use of com.github.javaparser.ast.stmt.BreakStmt in project checker-framework by typetools.

the class DoubleJavaParserVisitor method visit.

@Override
public void visit(final BreakStmt node1, final Node other) {
    BreakStmt node2 = (BreakStmt) other;
    defaultAction(node1, node2);
    node1.getLabel().ifPresent(l -> l.accept(this, node2.getLabel().get()));
}
Also used : BreakStmt(com.github.javaparser.ast.stmt.BreakStmt)

Aggregations

BreakStmt (com.github.javaparser.ast.stmt.BreakStmt)3 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)1 LineComment (com.github.javaparser.ast.comments.LineComment)1 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)1 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)1 ExpressionStmt (com.github.javaparser.ast.stmt.ExpressionStmt)1 SwitchStmt (com.github.javaparser.ast.stmt.SwitchStmt)1 VoidType (com.github.javaparser.ast.type.VoidType)1 IndexableConstraint (org.drools.core.rule.IndexableConstraint)1