Search in sources :

Example 6 with ClassOrInterfaceType

use of com.github.javaparser.ast.type.ClassOrInterfaceType in project cas by apereo.

the class ConfigurationMetadataFieldVisitor method processNestedClassOrInterfaceTypeIfNeeded.

private void processNestedClassOrInterfaceTypeIfNeeded(final FieldDeclaration n, final ConfigurationMetadataProperty prop) {
    if (n.getElementType() instanceof ClassOrInterfaceType) {
        val type = (ClassOrInterfaceType) n.getElementType();
        if (!shouldTypeBeExcluded(type)) {
            val instance = ConfigurationMetadataClassSourceLocator.getInstance();
            val clz = instance.locatePropertiesClassForType(type);
            if (clz != null && !clz.isMemberClass()) {
                val typePath = ConfigurationMetadataClassSourceLocator.buildTypeSourcePath(this.sourcePath, clz.getName());
                val parser = new ConfigurationMetadataUnitParser(this.sourcePath);
                parser.parseCompilationUnit(properties, groups, prop, typePath, clz.getName(), false);
            }
        }
    }
}
Also used : lombok.val(lombok.val) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType)

Example 7 with ClassOrInterfaceType

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

the class ExpressionTyper method mapCreationLiteral.

private Optional<TypedExpressionCursor> mapCreationLiteral(MapCreationLiteralExpression mapCreationLiteralExpression, java.lang.reflect.Type originalTypeCursor) {
    ClassOrInterfaceType hashMapType = (ClassOrInterfaceType) parseType(HashMap.class.getCanonicalName());
    BlockStmt initializationStmt = new BlockStmt();
    InitializerDeclaration body = new InitializerDeclaration(false, initializationStmt);
    ObjectCreationExpr newHashMapExpr = new ObjectCreationExpr(null, hashMapType, nodeList(), nodeList(), nodeList(body));
    for (Expression e : mapCreationLiteralExpression.getExpressions()) {
        MapCreationLiteralExpressionKeyValuePair expr = (MapCreationLiteralExpressionKeyValuePair) e;
        Expression key = resolveCreationLiteralNameExpr(originalTypeCursor, expr.getKey());
        Expression value = resolveCreationLiteralNameExpr(originalTypeCursor, expr.getValue());
        initializationStmt.addStatement(new MethodCallExpr(null, "put", nodeList(key, value)));
    }
    return of(new TypedExpressionCursor(newHashMapExpr, HashMap.class));
}
Also used : ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) InitializerDeclaration(com.github.javaparser.ast.body.InitializerDeclaration) Expression(com.github.javaparser.ast.expr.Expression) UnificationTypedExpression(org.drools.modelcompiler.builder.generator.UnificationTypedExpression) MapCreationLiteralExpression(org.drools.mvel.parser.ast.expr.MapCreationLiteralExpression) DrlxParseUtil.isThisExpression(org.drools.modelcompiler.builder.generator.DrlxParseUtil.isThisExpression) ListCreationLiteralExpression(org.drools.mvel.parser.ast.expr.ListCreationLiteralExpression) TypedExpression(org.drools.modelcompiler.builder.generator.TypedExpression) HashMap(java.util.HashMap) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) MapCreationLiteralExpressionKeyValuePair(org.drools.mvel.parser.ast.expr.MapCreationLiteralExpressionKeyValuePair) DrlxParseUtil.toClassOrInterfaceType(org.drools.modelcompiler.builder.generator.DrlxParseUtil.toClassOrInterfaceType) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) NullSafeMethodCallExpr(org.drools.mvel.parser.ast.expr.NullSafeMethodCallExpr) DrlxParseUtil.nameExprToMethodCallExpr(org.drools.modelcompiler.builder.generator.DrlxParseUtil.nameExprToMethodCallExpr)

Example 8 with ClassOrInterfaceType

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

the class FlowDSLQueryGenerator method queryNameClassArg.

private void queryNameClassArg(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 = queryDefImpl();
    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 = stringWithIndexInside(i);
        typeArguments.add(parseType(genericTypeName));
        arguments.add(new NameExpr(type));
        arguments.add(new NameExpr(name));
        String classGenericType = genericType(genericTypeName);
        Type genericType = parseType(classGenericType);
        query1.addParameter(genericType, type);
        query1.addParameter(stringType(), name);
        typeParameters.add(new TypeParameter(genericTypeName));
    });
    query1.setTypeParameters(typeParameters);
    query1.setBody(stmts);
    ClassOrInterfaceType type = queryDef();
    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) DrlxParseUtil.toClassOrInterfaceType(org.drools.modelcompiler.builder.generator.DrlxParseUtil.toClassOrInterfaceType) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) DrlxParseUtil.toClassOrInterfaceType(org.drools.modelcompiler.builder.generator.DrlxParseUtil.toClassOrInterfaceType) 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 9 with ClassOrInterfaceType

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

the class FlowDSLQueryGenerator method queryPkgNameClassArg.

private void queryPkgNameClassArg(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 = queryDefImpl();
    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 = stringWithIndexInside(i);
        typeArguments.add(parseType(genericTypeName));
        arguments.add(new NameExpr(type));
        arguments.add(new NameExpr(name));
        String classGenericType = genericType(genericTypeName);
        Type genericType = parseType(classGenericType);
        query1.addParameter(genericType, type);
        query1.addParameter(stringType(), name);
        typeParameters.add(new TypeParameter(genericTypeName));
    });
    query1.setTypeParameters(typeParameters);
    query1.setBody(stmts);
    ClassOrInterfaceType type = queryDef();
    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) DrlxParseUtil.toClassOrInterfaceType(org.drools.modelcompiler.builder.generator.DrlxParseUtil.toClassOrInterfaceType) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) DrlxParseUtil.toClassOrInterfaceType(org.drools.modelcompiler.builder.generator.DrlxParseUtil.toClassOrInterfaceType) 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 10 with ClassOrInterfaceType

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

the class QueryDefImplGenerator method callMethod.

private void callMethod(ClassOrInterfaceDeclaration clazz) {
    MethodDeclaration method = clazz.addMethod("call", Modifier.Keyword.PUBLIC);
    addOverride(method);
    method.addParameter("boolean", "open");
    method.setType(toClassOrInterfaceType(QueryCallViewItem.class));
    BlockStmt statements = new BlockStmt();
    NodeList<Expression> arguments = nodeList();
    ClassOrInterfaceType queryCallViewItemImpl = toClassOrInterfaceType(QueryCallViewItemImpl.class);
    ObjectCreationExpr objCreationExpr = new ObjectCreationExpr(null, queryCallViewItemImpl, arguments);
    statements.addStatement(new ReturnStmt(objCreationExpr));
    objCreationExpr.addArgument("this");
    objCreationExpr.addArgument("open");
    rangeArity().forEach(i -> {
        String varWithIndex = stringWithIndex("var", i);
        String genericTypeName = genericTypeName(i);
        method.addParameter(genericType("Argument", genericTypeName), varWithIndex);
        objCreationExpr.addArgument(varWithIndex);
    });
    method.setBody(statements);
}
Also used : ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) Expression(com.github.javaparser.ast.expr.Expression) StaticJavaParser.parseExpression(com.github.javaparser.StaticJavaParser.parseExpression) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) QueryCallViewItem(org.drools.model.view.QueryCallViewItem) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) DrlxParseUtil.toClassOrInterfaceType(org.drools.modelcompiler.builder.generator.DrlxParseUtil.toClassOrInterfaceType) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt)

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