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;
}
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;
}
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);
}
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());
}
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());
}
Aggregations