Search in sources :

Example 1 with MethodParameter

use of org.drools.modelcompiler.builder.generator.declaredtype.api.MethodParameter in project drools by kiegroup.

the class GeneratedClassDeclaration method addMethod.

private void addMethod(MethodDefinition methodDefinition) {
    List<Modifier.Keyword> modifiers = new ArrayList<>();
    if (methodDefinition.isStatic()) {
        modifiers.add(Modifier.Keyword.STATIC);
    }
    if (methodDefinition.isPublic()) {
        modifiers.add(Modifier.Keyword.PUBLIC);
    }
    MethodDeclaration methodDeclaration = generatedClass.addMethod(methodDefinition.getMethodName(), modifiers.toArray(new Modifier.Keyword[0]));
    methodDeclaration.setType(methodDefinition.getReturnType());
    for (MethodParameter mp : methodDefinition.parameters()) {
        methodDeclaration.addParameter(mp.getType(), mp.getName());
    }
    for (AnnotationDefinition a : methodDefinition.getAnnotations()) {
        methodDeclaration.addAnnotation(createSimpleAnnotation(a.getName()));
    }
    methodDeclaration.setBody(StaticJavaParser.parseBlock(methodDefinition.getBody()));
}
Also used : AnnotationDefinition(org.drools.modelcompiler.builder.generator.declaredtype.api.AnnotationDefinition) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) ArrayList(java.util.ArrayList) MethodParameter(org.drools.modelcompiler.builder.generator.declaredtype.api.MethodParameter)

Aggregations

MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)1 ArrayList (java.util.ArrayList)1 AnnotationDefinition (org.drools.modelcompiler.builder.generator.declaredtype.api.AnnotationDefinition)1 MethodParameter (org.drools.modelcompiler.builder.generator.declaredtype.api.MethodParameter)1