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()));
}
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();
}
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()));
}
Aggregations