Search in sources :

Example 36 with ClassOrInterfaceDeclaration

use of com.github.javaparser.ast.body.ClassOrInterfaceDeclaration in project drools by kiegroup.

the class KiePMMLScorecardModelFactory method getKiePMMLScorecardModelSourcesMap.

public static Map<String, String> getKiePMMLScorecardModelSourcesMap(final DroolsCompilationDTO<Scorecard> compilationDTO) {
    logger.trace("getKiePMMLScorecardModelSourcesMap {} {} {}", compilationDTO.getFields(), compilationDTO.getModel(), compilationDTO.getPackageName());
    CompilationUnit cloneCU = getKiePMMLModelCompilationUnit(compilationDTO, KIE_PMML_SCORECARD_MODEL_TEMPLATE_JAVA, KIE_PMML_SCORECARD_MODEL_TEMPLATE);
    String className = compilationDTO.getSimpleClassName();
    ClassOrInterfaceDeclaration modelTemplate = cloneCU.getClassByName(className).orElseThrow(() -> new KiePMMLException(MAIN_CLASS_NOT_FOUND + ": " + className));
    setConstructor(compilationDTO, modelTemplate);
    Map<String, String> toReturn = new HashMap<>();
    String fullClassName = compilationDTO.getPackageCanonicalClassName();
    toReturn.put(fullClassName, cloneCU.toString());
    return toReturn;
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) KiePMMLDroolsModelFactoryUtils.getKiePMMLModelCompilationUnit(org.kie.pmml.models.drools.utils.KiePMMLDroolsModelFactoryUtils.getKiePMMLModelCompilationUnit) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) HashMap(java.util.HashMap) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException)

Example 37 with ClassOrInterfaceDeclaration

use of com.github.javaparser.ast.body.ClassOrInterfaceDeclaration in project drools by kiegroup.

the class KiePMMLTreeModelFactory method getKiePMMLTreeModelSourcesMap.

public static Map<String, String> getKiePMMLTreeModelSourcesMap(final TreeCompilationDTO compilationDTO) {
    logger.trace("getKiePMMLTreeModelSourcesMap {} {} {}", compilationDTO.getFields(), compilationDTO.getModel(), compilationDTO.getPackageName());
    String className = compilationDTO.getSimpleClassName();
    String packageName = compilationDTO.getPackageName();
    CompilationUnit cloneCU = JavaParserUtils.getKiePMMLModelCompilationUnit(className, packageName, KIE_PMML_TREE_MODEL_TEMPLATE_JAVA, KIE_PMML_TREE_MODEL_TEMPLATE);
    ClassOrInterfaceDeclaration modelTemplate = cloneCU.getClassByName(className).orElseThrow(() -> new KiePMMLException(MAIN_CLASS_NOT_FOUND + ": " + className));
    final Double missingValuePenalty = compilationDTO.getMissingValuePenalty();
    final KiePMMLNodeFactory.NodeNamesDTO nodeNamesDTO = new KiePMMLNodeFactory.NodeNamesDTO(compilationDTO.getNode(), createNodeClassName(), null, missingValuePenalty);
    String fullNodeClassName = packageName + "." + nodeNamesDTO.nodeClassName;
    Map<String, String> toReturn = getKiePMMLNodeSourcesMap(nodeNamesDTO, compilationDTO.getFields(), packageName);
    setConstructor(compilationDTO, modelTemplate, fullNodeClassName);
    String fullClassName = packageName + "." + className;
    toReturn.put(fullClassName, cloneCU.toString());
    return toReturn;
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) KiePMMLException(org.kie.pmml.api.exceptions.KiePMMLException)

Example 38 with ClassOrInterfaceDeclaration

use of com.github.javaparser.ast.body.ClassOrInterfaceDeclaration in project controller by opendaylight.

the class SieASTVisitor method visit.

@Override
public void visit(final NormalAnnotationExpr expr, final Void arg) {
    final String fqcn = expr.getName().toString();
    if (fqcn.equals(Description.class.getCanonicalName())) {
        final Node parent = expr.getParentNode();
        final String value = expr.getPairs().get(0).toString();
        if (parent instanceof ClassOrInterfaceDeclaration) {
            descriptionAnotValue = value;
        } else if (parent instanceof MethodDeclaration) {
            methodDescriptions.put(((MethodDeclaration) parent).getName(), value);
        }
    } else if (fqcn.equals(ServiceInterfaceAnnotation.class.getCanonicalName())) {
        String text1 = expr.getPairs().get(0).toString();
        String text2 = expr.getPairs().get(1).toString();
        if (text1.contains("value")) {
            sieAnnotValue = text1;
            sieAnnotOsgiRegistrationType = text2;
        } else {
            sieAnnotValue = text2;
            sieAnnotOsgiRegistrationType = text1;
        }
    }
    super.visit(expr, arg);
}
Also used : Description(org.opendaylight.controller.config.api.annotations.Description) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) Node(com.github.javaparser.ast.Node)

Example 39 with ClassOrInterfaceDeclaration

use of com.github.javaparser.ast.body.ClassOrInterfaceDeclaration in project javaparser by javaparser.

the class DifferentiateDotExpressionTest method staticMethodCallsFromInnerClasses.

@Test
public void staticMethodCallsFromInnerClasses() {
    ClassOrInterfaceDeclaration clazz = ((JavaParserClassDeclaration) typeSolver.solveType("InnerClassDotExpressions")).getWrappedNode();
    MethodDeclaration mainMethod = Navigator.demandMethod(clazz, "main");
    JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
    MethodCallExpr methodCall = Navigator.findMethodCall(mainMethod, "methodCall").get();
    MethodCallExpr innerMethodCall = Navigator.findMethodCall(mainMethod, "innerMethodCall").get();
    MethodCallExpr innerInnerMethodCall = Navigator.findMethodCall(mainMethod, "innerInnerMethodCall").get();
    assertEquals(true, javaParserFacade.solve(methodCall).isSolved());
    assertEquals(true, javaParserFacade.solve(innerMethodCall).isSolved());
    assertEquals(true, javaParserFacade.solve(innerInnerMethodCall).isSolved());
}
Also used : JavaParserClassDeclaration(com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Example 40 with ClassOrInterfaceDeclaration

use of com.github.javaparser.ast.body.ClassOrInterfaceDeclaration in project javaparser by javaparser.

the class DifferentiateDotExpressionTest method staticFieldCallsFromInnerClasses.

@Test
public void staticFieldCallsFromInnerClasses() {
    ClassOrInterfaceDeclaration clazz = ((JavaParserClassDeclaration) typeSolver.solveType("InnerStaticClassFieldDotExpressions")).getWrappedNode();
    MethodDeclaration mainMethod = Navigator.demandMethod(clazz, "main");
    JavaParserFacade javaParserFacade = JavaParserFacade.get(typeSolver);
    MethodCallExpr methodCallWithNestedStaticFieldParam = Navigator.findMethodCall(mainMethod, "parseInt").get();
    assertEquals(true, javaParserFacade.solve(methodCallWithNestedStaticFieldParam).isSolved());
}
Also used : JavaParserClassDeclaration(com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) MethodDeclaration(com.github.javaparser.ast.body.MethodDeclaration) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) AbstractResolutionTest(com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest) Test(org.junit.Test)

Aggregations

ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)261 Test (org.junit.Test)174 CompilationUnit (com.github.javaparser.ast.CompilationUnit)164 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)84 ReflectionTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver)79 AbstractResolutionTest (com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest)71 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)52 Context (com.github.javaparser.symbolsolver.core.resolution.Context)39 ClassOrInterfaceDeclarationContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.ClassOrInterfaceDeclarationContext)38 CompilationUnitContext (com.github.javaparser.symbolsolver.javaparsermodel.contexts.CompilationUnitContext)37 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)36 Expression (com.github.javaparser.ast.expr.Expression)33 TypeSolver (com.github.javaparser.symbolsolver.model.resolution.TypeSolver)28 JavaParserFacade (com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade)27 MemoryTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.MemoryTypeSolver)24 HashMap (java.util.HashMap)21 VariableDeclarator (com.github.javaparser.ast.body.VariableDeclarator)20 ResolvedMethodDeclaration (com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration)20 KiePMMLException (org.kie.pmml.api.exceptions.KiePMMLException)20 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)19