Search in sources :

Example 26 with ClassOrInterfaceType

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

the class KiePMMLModelFactoryUtils method addGetCreatedKiePMMLOutputFieldsMethod.

public static void addGetCreatedKiePMMLOutputFieldsMethod(final ClassOrInterfaceDeclaration modelTemplate, final List<org.dmg.pmml.OutputField> outputFields) {
    final MethodDeclaration methodDeclaration = modelTemplate.addMethod(GET_CREATED_KIEPMMLOUTPUTFIELDS, Modifier.Keyword.PRIVATE);
    final ClassOrInterfaceType returnedType = getTypedClassOrInterfaceTypeByTypeNames(List.class.getSimpleName(), Collections.singletonList(KiePMMLOutputField.class.getSimpleName()));
    methodDeclaration.setType(returnedType);
    commonPopulateGetCreatedKiePMMLOutputFieldsMethod(methodDeclaration, outputFields);
}
Also used : MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) NodeList(com.github.javaparser.ast.NodeList) List(java.util.List) CommonCodegenUtils.createArraysAsListFromList(org.kie.pmml.compiler.commons.utils.CommonCodegenUtils.createArraysAsListFromList) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType)

Example 27 with ClassOrInterfaceType

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

the class KiePMMLModelFactoryUtils method addGetCreatedKiePMMLMiningFieldsMethod.

/**
 * Add the <code>getCreatedKiePMMLMiningFields</code> method to the given <code>ClassOrInterfaceDeclaration</code>
 * @param modelTemplate
 * @param miningFields
 * @param fields
 */
public static void addGetCreatedKiePMMLMiningFieldsMethod(final ClassOrInterfaceDeclaration modelTemplate, final List<org.dmg.pmml.MiningField> miningFields, final List<org.dmg.pmml.Field<?>> fields) {
    final MethodDeclaration methodDeclaration = modelTemplate.addMethod(GET_CREATED_KIEPMMLMININGFIELDS, Modifier.Keyword.PRIVATE);
    final ClassOrInterfaceType returnedType = getTypedClassOrInterfaceTypeByTypeNames(List.class.getSimpleName(), Collections.singletonList(KiePMMLMiningField.class.getSimpleName()));
    methodDeclaration.setType(returnedType);
    commonPopulateGetCreatedKiePMMLMiningFieldsMethod(methodDeclaration, miningFields, fields);
}
Also used : MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) NodeList(com.github.javaparser.ast.NodeList) List(java.util.List) CommonCodegenUtils.createArraysAsListFromList(org.kie.pmml.compiler.commons.utils.CommonCodegenUtils.createArraysAsListFromList) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType)

Example 28 with ClassOrInterfaceType

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

the class KiePMMLClusteringModelFactory method comparisonMeasureCreationExprFrom.

private static ObjectCreationExpr comparisonMeasureCreationExprFrom(ComparisonMeasure comparisonMeasure) {
    NodeList<Expression> arguments = new NodeList<>();
    arguments.add(literalExprFrom(comparisonMeasureKindFrom(comparisonMeasure.getKind())));
    arguments.add(literalExprFrom(aggregateFunctionFrom(comparisonMeasure.getMeasure())));
    arguments.add(literalExprFrom(compareFunctionFrom(comparisonMeasure.getCompareFunction())));
    return new ObjectCreationExpr(null, new ClassOrInterfaceType(null, KiePMMLComparisonMeasure.class.getCanonicalName()), arguments);
}
Also used : ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) Expression(com.github.javaparser.ast.expr.Expression) NodeList(com.github.javaparser.ast.NodeList) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType)

Example 29 with ClassOrInterfaceType

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

the class KiePMMLNodeFactory method getKiePMMLScoreDistribution.

static ObjectCreationExpr getKiePMMLScoreDistribution(final String variableName, final ScoreDistribution scoreDistribution) {
    final NodeList<Expression> scoreDistributionsArguments = new NodeList<>();
    scoreDistributionsArguments.add(getExpressionForObject(variableName));
    scoreDistributionsArguments.add(new NullLiteralExpr());
    scoreDistributionsArguments.add(getExpressionForObject(scoreDistribution.getValue().toString()));
    scoreDistributionsArguments.add(getExpressionForObject(scoreDistribution.getRecordCount().intValue()));
    Expression confidenceExpression = scoreDistribution.getConfidence() != null ? getExpressionForObject(scoreDistribution.getConfidence().doubleValue()) : new NullLiteralExpr();
    scoreDistributionsArguments.add(confidenceExpression);
    Expression probabilityExpression = scoreDistribution.getProbability() != null ? getExpressionForObject(scoreDistribution.getProbability().doubleValue()) : new NullLiteralExpr();
    scoreDistributionsArguments.add(probabilityExpression);
    return new ObjectCreationExpr(null, new ClassOrInterfaceType(null, KiePMMLScoreDistribution.class.getCanonicalName()), scoreDistributionsArguments);
}
Also used : NullLiteralExpr(com.github.javaparser.ast.expr.NullLiteralExpr) ObjectCreationExpr(com.github.javaparser.ast.expr.ObjectCreationExpr) Expression(com.github.javaparser.ast.expr.Expression) NodeList(com.github.javaparser.ast.NodeList) StaticJavaParser.parseClassOrInterfaceType(com.github.javaparser.StaticJavaParser.parseClassOrInterfaceType) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType)

Example 30 with ClassOrInterfaceType

use of com.github.javaparser.ast.type.ClassOrInterfaceType in project checker-framework by typetools.

the class AnnotationFileParser method sameType.

/**
 * Returns true if the two types are the same.
 *
 * @param javacType type in javac form
 * @param javaParserType type in JavaParser form
 * @return true if the two types are the same
 */
private boolean sameType(TypeMirror javacType, Type javaParserType) {
    switch(javacType.getKind()) {
        case BOOLEAN:
            return javaParserType.equals(PrimitiveType.booleanType());
        case BYTE:
            return javaParserType.equals(PrimitiveType.byteType());
        case CHAR:
            return javaParserType.equals(PrimitiveType.charType());
        case DOUBLE:
            return javaParserType.equals(PrimitiveType.doubleType());
        case FLOAT:
            return javaParserType.equals(PrimitiveType.floatType());
        case INT:
            return javaParserType.equals(PrimitiveType.intType());
        case LONG:
            return javaParserType.equals(PrimitiveType.longType());
        case SHORT:
            return javaParserType.equals(PrimitiveType.shortType());
        case DECLARED:
        case TYPEVAR:
            if (!(javaParserType instanceof ClassOrInterfaceType)) {
                return false;
            }
            com.sun.tools.javac.code.Type javacTypeInternal = (com.sun.tools.javac.code.Type) javacType;
            ClassOrInterfaceType javaParserClassType = (ClassOrInterfaceType) javaParserType;
            // Use asString() because toString() includes annotations.
            String javaParserString = javaParserClassType.asString();
            Element javacElement = javacTypeInternal.asElement();
            // Check both fully-qualified name and simple name.
            return javacElement.toString().equals(javaParserString) || javacElement.getSimpleName().contentEquals(javaParserString);
        case ARRAY:
            return javaParserType.isArrayType() && sameType(((ArrayType) javacType).getComponentType(), javaParserType.asArrayType().getComponentType());
        default:
            throw new BugInCF("Unhandled type %s of kind %s", javacType, javacType.getKind());
    }
}
Also used : AnnotatedArrayType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedArrayType) ArrayType(javax.lang.model.type.ArrayType) AnnotatedArrayType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedArrayType) Type(com.github.javaparser.ast.type.Type) ArrayType(javax.lang.model.type.ArrayType) AnnotatedExecutableType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType) AnnotatedWildcardType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedWildcardType) AnnotationFileType(org.checkerframework.framework.stub.AnnotationFileUtil.AnnotationFileType) DeclaredType(javax.lang.model.type.DeclaredType) WildcardType(com.github.javaparser.ast.type.WildcardType) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) ReferenceType(com.github.javaparser.ast.type.ReferenceType) AnnotatedDeclaredType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType) PrimitiveType(com.github.javaparser.ast.type.PrimitiveType) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) PackageElement(javax.lang.model.element.PackageElement) VariableElement(javax.lang.model.element.VariableElement) ExecutableElement(javax.lang.model.element.ExecutableElement) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) BugInCF(org.checkerframework.javacutil.BugInCF)

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