Search in sources :

Example 56 with ClassOrInterfaceType

use of com.github.javaparser.ast.type.ClassOrInterfaceType in project drools by kiegroup.

the class PatternDSLQueryGenerator method queryFirstMethod.

private void queryFirstMethod(ClassOrInterfaceDeclaration clazz) {
    MethodDeclaration query1 = clazz.addMethod(QUERY, Modifier.Keyword.PUBLIC, Modifier.Keyword.STATIC);
    query1.addParameter(STRINGLITERAL, "name");
    BlockStmt stmts = new BlockStmt();
    NodeList<Type> typeArguments = nodeList();
    NodeList<TypeParameter> typeParameters = nodeList();
    NodeList<Expression> arguments = nodeList();
    ClassOrInterfaceType queryCallViewItemImpl = queryDefImplType();
    ObjectCreationExpr objCreationExpr = new ObjectCreationExpr(null, queryCallViewItemImpl, arguments);
    objCreationExpr.setDiamondOperator();
    stmts.addStatement(new ReturnStmt(objCreationExpr));
    objCreationExpr.addArgument(new NameExpr(VIEWBUILDER));
    objCreationExpr.addArgument("name");
    rangeArity().forEach(i -> {
        String genericTypeName = stringWithIndex("T", i);
        String type = stringWithIndex("type", i);
        String name = argNameWithIndex(i);
        typeArguments.add(parseType(genericTypeName));
        arguments.add(new NameExpr(type));
        arguments.add(new NameExpr(name));
        String classGenericType = genericType("Class", genericTypeName);
        Type genericType = parseType(classGenericType);
        query1.addParameter(genericType, type);
        query1.addParameter(parseType(STRINGLITERAL), name);
        typeParameters.add(new TypeParameter(genericTypeName));
    });
    query1.setTypeParameters(typeParameters);
    query1.setBody(stmts);
    ClassOrInterfaceType type = queryDefType();
    type.setTypeArguments(typeArguments);
    query1.setType(type);
}
Also used : ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) TypeParameter(com.github.javaparser.ast.type.TypeParameter) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) NameExpr(com.github.javaparser.ast.expr.NameExpr) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) Type(com.github.javaparser.ast.type.Type) StaticJavaParser.parseType(com.github.javaparser.StaticJavaParser.parseType) Expression(com.github.javaparser.ast.expr.Expression) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt)

Example 57 with ClassOrInterfaceType

use of com.github.javaparser.ast.type.ClassOrInterfaceType in project drools by kiegroup.

the class PatternDSLQueryGenerator method querySecondMethod.

private void querySecondMethod(ClassOrInterfaceDeclaration clazz) {
    MethodDeclaration query1 = clazz.addMethod(QUERY, Modifier.Keyword.PUBLIC, Modifier.Keyword.STATIC);
    query1.addParameter(STRINGLITERAL, "pkg");
    query1.addParameter(STRINGLITERAL, "name");
    BlockStmt stmts = new BlockStmt();
    NodeList<Type> typeArguments = nodeList();
    NodeList<TypeParameter> typeParameters = nodeList();
    NodeList<Expression> arguments = nodeList();
    ClassOrInterfaceType queryCallViewItemImpl = queryDefImplType();
    ObjectCreationExpr objCreationExpr = new ObjectCreationExpr(null, queryCallViewItemImpl, arguments);
    objCreationExpr.setDiamondOperator();
    stmts.addStatement(new ReturnStmt(objCreationExpr));
    objCreationExpr.addArgument(new NameExpr(VIEWBUILDER));
    objCreationExpr.addArgument("pkg");
    objCreationExpr.addArgument("name");
    rangeArity().forEach(i -> {
        String genericTypeName = stringWithIndex("T", i);
        String type = stringWithIndex("type", i);
        String name = argNameWithIndex(i);
        typeArguments.add(parseType(genericTypeName));
        arguments.add(new NameExpr(type));
        arguments.add(new NameExpr(name));
        String classGenericType = genericType("Class", genericTypeName);
        Type genericType = parseType(classGenericType);
        query1.addParameter(genericType, type);
        query1.addParameter(parseType(STRINGLITERAL), name);
        typeParameters.add(new TypeParameter(genericTypeName));
    });
    query1.setTypeParameters(typeParameters);
    query1.setBody(stmts);
    ClassOrInterfaceType type = queryDefType();
    type.setTypeArguments(typeArguments);
    query1.setType(type);
}
Also used : ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) TypeParameter(com.github.javaparser.ast.type.TypeParameter) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) NameExpr(com.github.javaparser.ast.expr.NameExpr) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) Type(com.github.javaparser.ast.type.Type) StaticJavaParser.parseType(com.github.javaparser.StaticJavaParser.parseType) Expression(com.github.javaparser.ast.expr.Expression) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt)

Example 58 with ClassOrInterfaceType

use of com.github.javaparser.ast.type.ClassOrInterfaceType in project drools by kiegroup.

the class PatternDSLQueryGenerator method queryFirstMethodOnlyClass.

private void queryFirstMethodOnlyClass(ClassOrInterfaceDeclaration clazz) {
    MethodDeclaration query1 = clazz.addMethod(QUERY, Modifier.Keyword.PUBLIC, Modifier.Keyword.STATIC);
    addNameParameter(query1);
    BlockStmt stmts = new BlockStmt();
    NodeList<Type> typeArguments = nodeList();
    NodeList<TypeParameter> typeParameters = nodeList();
    NodeList<Expression> arguments = nodeList();
    ClassOrInterfaceType queryCallViewItemImpl = queryDefImplType();
    ObjectCreationExpr objCreationExpr = new ObjectCreationExpr(null, queryCallViewItemImpl, arguments);
    objCreationExpr.setDiamondOperator();
    stmts.addStatement(new ReturnStmt(objCreationExpr));
    objCreationExpr.addArgument(new NameExpr(VIEWBUILDER));
    objCreationExpr.addArgument("name");
    rangeArity().forEach(i -> {
        String genericTypeName = stringWithIndex("T", i);
        String type = stringWithIndex("type", i);
        typeArguments.add(parseType(genericTypeName));
        arguments.add(new NameExpr(type));
        String classGenericType = genericType(CLASS, genericTypeName);
        Type genericType = parseType(classGenericType);
        query1.addParameter(genericType, type);
        typeParameters.add(new TypeParameter(genericTypeName));
    });
    query1.setTypeParameters(typeParameters);
    query1.setBody(stmts);
    ClassOrInterfaceType type = queryDefType();
    type.setTypeArguments(typeArguments);
    query1.setType(type);
}
Also used : ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) TypeParameter(com.github.javaparser.ast.type.TypeParameter) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) NameExpr(com.github.javaparser.ast.expr.NameExpr) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) Type(com.github.javaparser.ast.type.Type) StaticJavaParser.parseType(com.github.javaparser.StaticJavaParser.parseType) Expression(com.github.javaparser.ast.expr.Expression) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt)

Example 59 with ClassOrInterfaceType

use of com.github.javaparser.ast.type.ClassOrInterfaceType in project drools by kiegroup.

the class PatternDSLQueryGenerator method querySecondMethodOnlyClass.

private void querySecondMethodOnlyClass(ClassOrInterfaceDeclaration clazz) {
    MethodDeclaration query1 = clazz.addMethod(QUERY, Modifier.Keyword.PUBLIC, Modifier.Keyword.STATIC);
    query1.addParameter(STRINGLITERAL, "pkg");
    query1.addParameter(STRINGLITERAL, "name");
    BlockStmt stmts = new BlockStmt();
    NodeList<Type> typeArguments = nodeList();
    NodeList<TypeParameter> typeParameters = nodeList();
    NodeList<Expression> arguments = nodeList();
    ClassOrInterfaceType queryCallViewItemImpl = queryDefImplType();
    ObjectCreationExpr objCreationExpr = new ObjectCreationExpr(null, queryCallViewItemImpl, arguments);
    objCreationExpr.setDiamondOperator();
    stmts.addStatement(new ReturnStmt(objCreationExpr));
    objCreationExpr.addArgument(new NameExpr(VIEWBUILDER));
    objCreationExpr.addArgument("pkg");
    objCreationExpr.addArgument("name");
    rangeArity().forEach(i -> {
        String genericTypeName = stringWithIndex("T", i);
        String type = stringWithIndex("type", i);
        typeArguments.add(parseType(genericTypeName));
        arguments.add(new NameExpr(type));
        String classGenericType = genericType(CLASS, genericTypeName);
        Type genericType = parseType(classGenericType);
        query1.addParameter(genericType, type);
        typeParameters.add(new TypeParameter(genericTypeName));
    });
    query1.setTypeParameters(typeParameters);
    query1.setBody(stmts);
    ClassOrInterfaceType type = queryDefType();
    type.setTypeArguments(typeArguments);
    query1.setType(type);
}
Also used : ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) TypeParameter(com.github.javaparser.ast.type.TypeParameter) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) NameExpr(com.github.javaparser.ast.expr.NameExpr) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) Type(com.github.javaparser.ast.type.Type) StaticJavaParser.parseType(com.github.javaparser.StaticJavaParser.parseType) Expression(com.github.javaparser.ast.expr.Expression) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt)

Example 60 with ClassOrInterfaceType

use of com.github.javaparser.ast.type.ClassOrInterfaceType in project drools by kiegroup.

the class MaterializedLambdaPredicate method createPredicateInformationMethod.

private void createPredicateInformationMethod(EnumDeclaration classDeclaration) {
    MethodDeclaration methodDeclaration = classDeclaration.addMethod("predicateInformation", Modifier.Keyword.PUBLIC);
    methodDeclaration.addAnnotation("Override");
    ClassOrInterfaceType predicateInformationType = toClassOrInterfaceType(PredicateInformation.class);
    methodDeclaration.setType(predicateInformationType);
    BlockStmt block = new BlockStmt();
    NameExpr infoExpr = new NameExpr("info");
    VariableDeclarationExpr infoVar = new VariableDeclarationExpr(toClassOrInterfaceType(PredicateInformation.class), "info");
    NodeList<Expression> newPredicateInformationArguments = NodeList.nodeList(toStringLiteral(StringEscapeUtils.escapeJava(predicateInformation.getStringConstraint())));
    ObjectCreationExpr newPredicateInformation = new ObjectCreationExpr(null, predicateInformationType, newPredicateInformationArguments);
    block.addStatement(new AssignExpr(infoVar, newPredicateInformation, AssignExpr.Operator.ASSIGN));
    int i = 0;
    NodeList<Expression> addRuleNamesArguments = null;
    for (PredicateInformation.RuleDef ruleDef : predicateInformation.getRuleDefs()) {
        if (i++ % 125 == 0) {
            addRuleNamesArguments = NodeList.nodeList();
            block.addStatement(new MethodCallExpr(infoExpr, "addRuleNames", addRuleNamesArguments));
        }
        addRuleNamesArguments.add(toStringLiteral(ruleDef.getRuleName()));
        addRuleNamesArguments.add(toStringLiteral(ruleDef.getFileName()));
    }
    if (predicateInformation.isMoreThanMaxRuleDefs()) {
        block.addStatement(new MethodCallExpr(infoExpr, "setMoreThanMaxRuleDefs", NodeList.nodeList(new BooleanLiteralExpr(true))));
    }
    block.addStatement(new ReturnStmt(infoExpr));
    methodDeclaration.setBody(block);
}
Also used : ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) VariableDeclarationExpr(com.github.javaparser.ast.expr.VariableDeclarationExpr) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) NameExpr(com.github.javaparser.ast.expr.NameExpr) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) DrlxParseUtil.toClassOrInterfaceType(org.drools.modelcompiler.builder.generator.DrlxParseUtil.toClassOrInterfaceType) AssignExpr(com.github.javaparser.ast.expr.AssignExpr) Expression(com.github.javaparser.ast.expr.Expression) BooleanLiteralExpr(com.github.javaparser.ast.expr.BooleanLiteralExpr) PredicateInformation(org.drools.model.functions.PredicateInformation) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Aggregations

ClassOrInterfaceType (com.github.javaparser.ast.type.ClassOrInterfaceType)76 Expression (com.github.javaparser.ast.expr.Expression)33 ObjectCreationExpr (com.github.javaparser.ast.expr.ObjectCreationExpr)29 Type (com.github.javaparser.ast.type.Type)24 NameExpr (com.github.javaparser.ast.expr.NameExpr)23 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)21 DrlxParseUtil.toClassOrInterfaceType (org.drools.modelcompiler.builder.generator.DrlxParseUtil.toClassOrInterfaceType)21 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)17 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)17 NodeList (com.github.javaparser.ast.NodeList)14 ReturnStmt (com.github.javaparser.ast.stmt.ReturnStmt)13 TypeParameter (com.github.javaparser.ast.type.TypeParameter)13 StaticJavaParser.parseClassOrInterfaceType (com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType)12 Test (org.junit.Test)11 StaticJavaParser.parseType (com.github.javaparser.StaticJavaParser.parseType)9 List (java.util.List)9 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)8 StringLiteralExpr (com.github.javaparser.ast.expr.StringLiteralExpr)7 ExpressionStmt (com.github.javaparser.ast.stmt.ExpressionStmt)7 HashMap (java.util.HashMap)7