use of com.github.javaparser.ast.type.ClassOrInterfaceType in project drools by kiegroup.
the class PackageModel method buildRulesField.
private MethodCallExpr buildRulesField(ClassOrInterfaceDeclaration rulesClass) {
MethodCallExpr rulesInit = new MethodCallExpr(null, "java.util.Arrays.asList");
ClassOrInterfaceType rulesType = new ClassOrInterfaceType(null, new SimpleName("java.util.List"), new NodeList<Type>(toClassOrInterfaceType(Rule.class)));
MethodDeclaration rulesGetter = new MethodDeclaration(NodeList.nodeList(publicModifier()), rulesType, "getRulesList");
rulesGetter.createBody().addStatement(new ReturnStmt(rulesInit));
rulesClass.addMember(rulesGetter);
return rulesInit;
}
use of com.github.javaparser.ast.type.ClassOrInterfaceType in project drools by kiegroup.
the class PackageModel method addGlobalField.
private static void addGlobalField(ClassOrInterfaceDeclaration classDeclaration, String packageName, String globalName, Class<?> globalClass) {
ClassOrInterfaceType varType = toClassOrInterfaceType(Global.class);
varType.setTypeArguments(DrlxParseUtil.classToReferenceType(globalClass));
Type declType = DrlxParseUtil.classToReferenceType(globalClass);
MethodCallExpr declarationOfCall = createDslTopLevelMethod(GLOBAL_OF_CALL);
declarationOfCall.addArgument(new ClassExpr(declType));
declarationOfCall.addArgument(toStringLiteral(packageName));
declarationOfCall.addArgument(toStringLiteral(globalName));
FieldDeclaration field = classDeclaration.addField(varType, toVar(globalName), publicModifier().getKeyword(), staticModifier().getKeyword(), finalModifier().getKeyword());
field.getVariables().get(0).setInitializer(declarationOfCall);
}
use of com.github.javaparser.ast.type.ClassOrInterfaceType in project drools by kiegroup.
the class ExecModelLambdaPostProcessor method replaceLambda.
private void replaceLambda(LambdaExpr lambdaExpr, Function<Optional<String>, MaterializedLambda> lambdaExtractor, Optional<String> exprId) {
try {
CreatedClass aClass = lambdaExtractor.apply(exprId).create(lambdaExpr.clone(), imports, staticImports);
lambdaClasses.put(aClass.getClassNameWithPackage(), aClass);
ClassOrInterfaceType type = toClassOrInterfaceType(aClass.getClassNameWithPackage());
FieldAccessExpr lambdaInstance = lambdaInstance(type);
toBeReplacedLambdas.add(() -> lambdaExpr.replace(lambdaInstance));
} catch (DoNotConvertLambdaException e) {
logger.debug("Cannot externalize lambdas {}", e.getMessage());
}
}
use of com.github.javaparser.ast.type.ClassOrInterfaceType in project drools by kiegroup.
the class MaterializedLambdaExtractor method createImplementedTypes.
@Override
protected NodeList<ClassOrInterfaceType> createImplementedTypes() {
ClassOrInterfaceType functionType = functionType();
NodeList<Type> typeArguments = lambdaParametersToTypeArguments();
typeArguments.add(returnType);
functionType.setTypeArguments(typeArguments);
return nodeList(functionType, lambdaExtractorType());
}
use of com.github.javaparser.ast.type.ClassOrInterfaceType in project drools by kiegroup.
the class PreprocessPhase method addTypeToInitialization.
private Optional<Expression> addTypeToInitialization(WithStatement withStatement, Deque<Statement> allNewStatements) {
if (withStatement.getWithObject().isAssignExpr()) {
AssignExpr assignExpr = withStatement.getWithObject().asAssignExpr();
Expression assignExprValue = assignExpr.getValue();
Expression assignExprTarget = assignExpr.getTarget();
if (assignExprValue.isObjectCreationExpr() && assignExprTarget instanceof DrlNameExpr) {
ObjectCreationExpr constructor = assignExprValue.asObjectCreationExpr();
ClassOrInterfaceType ctorType = constructor.getType();
String targetVariableName = ((DrlNameExpr) assignExprTarget).getNameAsString();
VariableDeclarationExpr variableDeclarationExpr = new VariableDeclarationExpr(ctorType, targetVariableName);
AssignExpr withTypeAssignmentExpr = new AssignExpr(variableDeclarationExpr, assignExprValue, assignExpr.getOperator());
allNewStatements.add(new ExpressionStmt(withTypeAssignmentExpr));
return of(new DrlNameExpr(targetVariableName));
}
}
return empty();
}
Aggregations