Search in sources :

Example 16 with ExplicitConstructorInvocationStmt

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

the class KiePMMLScorecardModelFactory method setConstructor.

static void setConstructor(final ScorecardCompilationDTO compilationDTO, final ClassOrInterfaceDeclaration modelTemplate, final String fullCharacteristicsClassName) {
    KiePMMLModelFactoryUtils.init(compilationDTO, modelTemplate);
    final ConstructorDeclaration constructorDeclaration = modelTemplate.getDefaultConstructor().orElseThrow(() -> new KiePMMLInternalException(String.format(MISSING_DEFAULT_CONSTRUCTOR, modelTemplate.getName())));
    final BlockStmt body = constructorDeclaration.getBody();
    final ExplicitConstructorInvocationStmt superStatement = CommonCodegenUtils.getExplicitConstructorInvocationStmt(body).orElseThrow(() -> new KiePMMLException(String.format(MISSING_CONSTRUCTOR_IN_BODY, body)));
    ClassOrInterfaceType characteristicsClass = parseClassOrInterfaceType(fullCharacteristicsClassName);
    ObjectCreationExpr characteristicsReference = new ObjectCreationExpr();
    characteristicsReference.setType(characteristicsClass);
    superStatement.setArgument(2, characteristicsReference);
    superStatement.setArgument(3, getExpressionForObject(compilationDTO.getInitialScore()));
    superStatement.setArgument(4, getExpressionForObject(compilationDTO.isUseReasonCodes()));
    REASONCODE_ALGORITHM reasoncodeAlgorithm = compilationDTO.getREASONCODE_ALGORITHM();
    NameExpr reasonCodeExpr = new NameExpr(REASONCODE_ALGORITHM.class.getName() + "." + reasoncodeAlgorithm.name());
    superStatement.setArgument(5, reasonCodeExpr);
    superStatement.setArgument(6, getExpressionForObject(compilationDTO.getBaselineScore()));
}
Also used : ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) ConstructorDeclaration(com.github.javaparser.ast.body.ConstructorDeclaration) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) REASONCODE_ALGORITHM(org.kie.pmml.api.enums.REASONCODE_ALGORITHM) NameExpr(com.github.javaparser.ast.expr.NameExpr) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException) KiePMMLInternalException(org.kie.pmml.api.exceptions.KiePMMLInternalException) ExplicitConstructorInvocationStmt(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt) StaticJavaParser.parseClassOrInterfaceType(com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType)

Example 17 with ExplicitConstructorInvocationStmt

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

the class JointJavacJavaParserVisitor method isDefaultSuperConstructorCall.

/**
 * Returns whether a JavaParser statement represents a method call {@code super()}.
 *
 * @param statement the JavaParser statement to check
 * @return true if statement is an explicit super constructor invocation with no arguments
 */
private boolean isDefaultSuperConstructorCall(Statement statement) {
    if (!statement.isExplicitConstructorInvocationStmt()) {
        return false;
    }
    ExplicitConstructorInvocationStmt invocation = statement.asExplicitConstructorInvocationStmt();
    boolean isSuper = !invocation.isThis();
    return isSuper && invocation.getArguments().isEmpty();
}
Also used : ExplicitConstructorInvocationStmt(com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt)

Example 18 with ExplicitConstructorInvocationStmt

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

the class DoubleJavaParserVisitor method visit.

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

Aggregations

ExplicitConstructorInvocationStmt (com.github.javaparser.ast.stmt.ExplicitConstructorInvocationStmt)18 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)10 KiePMMLException (org.kie.pmml.api.exceptions.KiePMMLException)9 NameExpr (com.github.javaparser.ast.expr.NameExpr)6 Test (org.junit.Test)5 ConstructorDeclaration (com.github.javaparser.ast.body.ConstructorDeclaration)4 KiePMMLInternalException (org.kie.pmml.api.exceptions.KiePMMLInternalException)4 Expression (com.github.javaparser.ast.expr.Expression)3 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)3 StaticJavaParser.parseClassOrInterfaceType (com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType)2 NullLiteralExpr (com.github.javaparser.ast.expr.NullLiteralExpr)2 ObjectCreationExpr (com.github.javaparser.ast.expr.ObjectCreationExpr)2 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)2 ExpressionStmt (com.github.javaparser.ast.stmt.ExpressionStmt)2 ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)2 CompilationUnit (com.github.javaparser.ast.CompilationUnit)1 NodeList (com.github.javaparser.ast.NodeList)1 AssignExpr (com.github.javaparser.ast.expr.AssignExpr)1 DoubleLiteralExpr (com.github.javaparser.ast.expr.DoubleLiteralExpr)1 MethodReferenceExpr (com.github.javaparser.ast.expr.MethodReferenceExpr)1