use of org.drools.javaparser.ast.type.Type in project drools by kiegroup.
the class ModelGenerator method addUnitData.
private static void addUnitData(String unitVar, Class<?> type, BlockStmt ruleBlock) {
Type declType = classToReferenceType(type);
ClassOrInterfaceType varType = JavaParser.parseClassOrInterfaceType(UnitData.class.getCanonicalName());
varType.setTypeArguments(declType);
VariableDeclarationExpr var_ = new VariableDeclarationExpr(varType, toVar(unitVar), Modifier.FINAL);
MethodCallExpr unitDataCall = new MethodCallExpr(null, UNIT_DATA_CALL);
unitDataCall.addArgument(new ClassExpr(declType));
unitDataCall.addArgument(new StringLiteralExpr(unitVar));
AssignExpr var_assign = new AssignExpr(var_, unitDataCall, AssignExpr.Operator.ASSIGN);
ruleBlock.addStatement(var_assign);
}
use of org.drools.javaparser.ast.type.Type in project drools by kiegroup.
the class ModelGenerator method addVariable.
private static void addVariable(KnowledgeBuilderImpl kbuilder, BlockStmt ruleBlock, DeclarationSpec decl) {
if (decl.getDeclarationClass() == null) {
kbuilder.addBuilderResult(new UnknownDeclarationError(decl.getBindingId()));
return;
}
Type declType = classToReferenceType(decl.getDeclarationClass());
ClassOrInterfaceType varType = JavaParser.parseClassOrInterfaceType(Variable.class.getCanonicalName());
varType.setTypeArguments(declType);
VariableDeclarationExpr var_ = new VariableDeclarationExpr(varType, toVar(decl.getBindingId()), Modifier.FINAL);
MethodCallExpr declarationOfCall = new MethodCallExpr(null, DECLARATION_OF_CALL);
declarationOfCall.addArgument(new ClassExpr(decl.getType()));
declarationOfCall.addArgument(new StringLiteralExpr(decl.getVariableName().orElse(decl.getBindingId())));
decl.getDeclarationSource().ifPresent(declarationOfCall::addArgument);
decl.getEntryPoint().ifPresent(ep -> {
MethodCallExpr entryPointCall = new MethodCallExpr(null, "entryPoint");
entryPointCall.addArgument(new StringLiteralExpr(ep));
declarationOfCall.addArgument(entryPointCall);
});
for (BehaviorDescr behaviorDescr : decl.getBehaviors()) {
MethodCallExpr windowCall = new MethodCallExpr(null, "window");
if (Behavior.BehaviorType.TIME_WINDOW.matches(behaviorDescr.getSubType())) {
windowCall.addArgument("Window.Type.TIME");
windowCall.addArgument("" + TimeUtils.parseTimeString(behaviorDescr.getParameters().get(0)));
}
if (Behavior.BehaviorType.LENGTH_WINDOW.matches(behaviorDescr.getSubType())) {
windowCall.addArgument("Window.Type.LENGTH");
windowCall.addArgument("" + Integer.valueOf(behaviorDescr.getParameters().get(0)));
}
declarationOfCall.addArgument(windowCall);
}
AssignExpr var_assign = new AssignExpr(var_, declarationOfCall, AssignExpr.Operator.ASSIGN);
ruleBlock.addStatement(var_assign);
}
use of org.drools.javaparser.ast.type.Type in project drools by kiegroup.
the class POJOGenerator method generateHashCodeMethod.
private static MethodDeclaration generateHashCodeMethod(List<Statement> hashCodeFieldStatement) {
final Statement header = parseStatement("int result = super.hashCode();");
NodeList<Statement> hashCodeStatements = nodeList(header);
hashCodeStatements.addAll(hashCodeFieldStatement);
hashCodeStatements.add(parseStatement("return result;"));
final Type returnType = JavaParser.parseType(int.class.getSimpleName());
final MethodDeclaration equals = new MethodDeclaration(EnumSet.of(Modifier.PUBLIC), returnType, HASH_CODE);
equals.addAnnotation("Override");
equals.setBody(new BlockStmt(hashCodeStatements));
return equals;
}
use of org.drools.javaparser.ast.type.Type in project drools by kiegroup.
the class POJOGenerator method generateEqualsMethod.
private static MethodDeclaration generateEqualsMethod(String generatedClassName, List<Statement> equalsFieldStatement) {
NodeList<Statement> equalsStatements = nodeList(referenceEquals, classCheckEquals);
equalsStatements.add(classCastStatement(generatedClassName));
equalsStatements.add(parseStatement("if ( !super.equals( o ) ) return false;"));
equalsStatements.addAll(equalsFieldStatement);
equalsStatements.add(parseStatement("return true;"));
final Type returnType = JavaParser.parseType(boolean.class.getSimpleName());
final MethodDeclaration equals = new MethodDeclaration(EnumSet.of(Modifier.PUBLIC), returnType, EQUALS);
equals.addParameter(Object.class, "o");
equals.addAnnotation("Override");
equals.setBody(new BlockStmt(equalsStatements));
return equals;
}
use of org.drools.javaparser.ast.type.Type in project drools by kiegroup.
the class QueryGenerator method getQueryType.
private static ClassOrInterfaceType getQueryType(List<QueryParameter> queryParameters) {
Class<?> res = QueryDef.getQueryClassByArity(queryParameters.size());
ClassOrInterfaceType queryType = JavaParser.parseClassOrInterfaceType(res.getCanonicalName());
Type[] genericType = queryParameters.stream().map(e -> e.type).map(DrlxParseUtil::classToReferenceType).toArray(Type[]::new);
if (genericType.length > 0) {
queryType.setTypeArguments(genericType);
}
return queryType;
}
Aggregations