@Test public void getKiePMMLModelCompilationUnitWithPackage() { String className = "ClassName"; String packageName = "apackage"; CompilationUnit retrieved = JavaParserUtils.getKiePMMLModelCompilationUnit(className, packageName, TEMPLATE_FILE, TEMPLATE_CLASS); assertNotNull(retrieved); assertTrue(retrieved.getPackageDeclaration().isPresent()); assertEquals(packageName, retrieved.getPackageDeclaration().get().getName().asString()); assertFalse(retrieved.getClassByName(TEMPLATE_CLASS).isPresent()); assertTrue(retrieved.getClassByName(className).isPresent()); }
public static CompilationUnit getKiePMMLModelCompilationUnit(final String className, final String packageName, final String javaTemplate, final String modelClassName) { logger.trace("getKiePMMLModelCompilationUnit {} {}", className, packageName); CompilationUnit templateCU = getFromFileName(javaTemplate); CompilationUnit toReturn = templateCU.clone(); if (packageName != null && !packageName.isEmpty()) { toReturn.setPackageDeclaration(packageName); } ClassOrInterfaceDeclaration modelTemplate = toReturn.getClassByName(modelClassName) .orElseThrow(() -> new KiePMMLException(MAIN_CLASS_NOT_FOUND + ": " + modelClassName)); modelTemplate.setName(className); return toReturn; }
JavaParserUtils { public static CompilationUnit getKiePMMLModelCompilationUnit(final String className, final String packageName, final String javaTemplate, final String modelClassName) { logger.trace("getKiePMMLModelCompilationUnit {} {}", className, packageName); CompilationUnit templateCU = getFromFileName(javaTemplate); CompilationUnit toReturn = templateCU.clone(); if (packageName != null && !packageName.isEmpty()) { toReturn.setPackageDeclaration(packageName); } ClassOrInterfaceDeclaration modelTemplate = toReturn.getClassByName(modelClassName) .orElseThrow(() -> new KiePMMLException(MAIN_CLASS_NOT_FOUND + ": " + modelClassName)); modelTemplate.setName(className); return toReturn; } }
JavaParserUtils { public static CompilationUnit getKiePMMLModelCompilationUnit(final String className, final String packageName, final String javaTemplate, final String modelClassName) { logger.trace("getKiePMMLModelCompilationUnit {} {}", className, packageName); CompilationUnit templateCU = getFromFileName(javaTemplate); CompilationUnit toReturn = templateCU.clone(); if (packageName != null && !packageName.isEmpty()) { toReturn.setPackageDeclaration(packageName); } ClassOrInterfaceDeclaration modelTemplate = toReturn.getClassByName(modelClassName) .orElseThrow(() -> new KiePMMLException(MAIN_CLASS_NOT_FOUND + ": " + modelClassName)); modelTemplate.setName(className); return toReturn; } private  JavaParserUtils(); }
JavaParserUtils { public static CompilationUnit getKiePMMLModelCompilationUnit(final String className, final String packageName, final String javaTemplate, final String modelClassName) { logger.trace("getKiePMMLModelCompilationUnit {} {}", className, packageName); CompilationUnit templateCU = getFromFileName(javaTemplate); CompilationUnit toReturn = templateCU.clone(); if (packageName != null && !packageName.isEmpty()) { toReturn.setPackageDeclaration(packageName); } ClassOrInterfaceDeclaration modelTemplate = toReturn.getClassByName(modelClassName) .orElseThrow(() -> new KiePMMLException(MAIN_CLASS_NOT_FOUND + ": " + modelClassName)); modelTemplate.setName(className); return toReturn; } private  JavaParserUtils(); static CompilationUnit getFromFileName(String fileName); static CompilationUnit getKiePMMLModelCompilationUnit(final String className,
                                                                 final String packageName,
                                                                 final String javaTemplate,
                                                                 final String modelClassName); static String getFullClassName(final CompilationUnit cu); }
JavaParserUtils { public static CompilationUnit getKiePMMLModelCompilationUnit(final String className, final String packageName, final String javaTemplate, final String modelClassName) { logger.trace("getKiePMMLModelCompilationUnit {} {}", className, packageName); CompilationUnit templateCU = getFromFileName(javaTemplate); CompilationUnit toReturn = templateCU.clone(); if (packageName != null && !packageName.isEmpty()) { toReturn.setPackageDeclaration(packageName); } ClassOrInterfaceDeclaration modelTemplate = toReturn.getClassByName(modelClassName) .orElseThrow(() -> new KiePMMLException(MAIN_CLASS_NOT_FOUND + ": " + modelClassName)); modelTemplate.setName(className); return toReturn; } private  JavaParserUtils(); static CompilationUnit getFromFileName(String fileName); static CompilationUnit getKiePMMLModelCompilationUnit(final String className,
                                                                 final String packageName,
                                                                 final String javaTemplate,
                                                                 final String modelClassName); static String getFullClassName(final CompilationUnit cu); static final String MAIN_CLASS_NOT_FOUND; }