use of com.github.javaparser.ast.CompilationUnit in project cas by apereo.
the class ConfigurationMetadataGenerator method parseCompilationUnit.
@SneakyThrows
private void parseCompilationUnit(final Set<ConfigurationMetadataProperty> collectedProps, final Set<ConfigurationMetadataProperty> collectedGroups, final ConfigurationMetadataProperty p, final String typePath, final String typeName, final boolean indexNameWithBrackets) {
try (InputStream is = new FileInputStream(typePath)) {
final CompilationUnit cu = JavaParser.parse(is);
new FieldVisitor(collectedProps, collectedGroups, indexNameWithBrackets, typeName).visit(cu, p);
if (cu.getTypes().size() > 0) {
final ClassOrInterfaceDeclaration decl = ClassOrInterfaceDeclaration.class.cast(cu.getType(0));
for (int i = 0; i < decl.getExtendedTypes().size(); i++) {
final ClassOrInterfaceType parentType = decl.getExtendedTypes().get(i);
final Class parentClazz = locatePropertiesClassForType(parentType);
final String parentTypePath = buildTypeSourcePath(parentClazz.getName());
parseCompilationUnit(collectedProps, collectedGroups, p, parentTypePath, parentClazz.getName(), indexNameWithBrackets);
}
}
}
}
use of com.github.javaparser.ast.CompilationUnit in project Gargoyle by callakrsos.
the class FileUtil method consumeJavaParser.
/********************************
* 작성일 : 2016. 7. 14. 작성자 : KYJ
*
* JavaParser
*
* @param javaFile
* @param converter
* @param errorHandler
********************************/
public static void consumeJavaParser(File javaFile, Consumer<CompilationUnit> converter, Consumer<Exception> errorHandler) {
try {
if (javaFile != null && javaFile.exists()) {
CompilationUnit cu = GargoyleJavaParser.getCompileUnit(javaFile);
converter.accept(cu);
}
} catch (Exception e) {
errorHandler.accept(e);
}
}
use of com.github.javaparser.ast.CompilationUnit in project Gargoyle by callakrsos.
the class VoEditorController method setFromFile.
/********************************
* 작성일 : 2016. 7. 4. 작성자 : KYJ
*
*
* @param voFile
* @throws IOException
* @throws FileNotFoundException
********************************/
public void setFromFile(File voFile) {
if (voFile == null || !voFile.exists())
return;
if (voFile.isFile()) {
CompilationUnit cu;
try (FileInputStream in = new FileInputStream(voFile)) {
// parse the file
cu = JavaParser.parse(in);
PackageDeclaration packageDeclaration = cu.getPackage();
txtPackageName.setText(packageDeclaration.getName().toString());
txtClassName.setText(voFile.getName().substring(0, voFile.getName().indexOf('.')));
txtLocation.setText(voFile.getAbsolutePath());
MethodVisitor methodVisitor = new MethodVisitor();
methodVisitor.visit(cu, null);
List<TableModelDVO> valideFieldMeta = methodVisitor.getValideFieldMeta(t -> {
TableModelDVO tableModelDVO = new TableModelDVO();
tableModelDVO.setName(t.getName());
tableModelDVO.setType(t.getFieldType().getSimpleName());
return tableModelDVO;
});
this.tbVoEditor.getItems().addAll(valideFieldMeta);
} catch (IOException | ParseException e) {
LOGGER.error(ValueUtil.toString(e));
}
} else {
txtLocation.setText(voFile.getAbsolutePath());
}
}
use of com.github.javaparser.ast.CompilationUnit in project Gargoyle by callakrsos.
the class GargoyleJavaParser method getPackageName.
/********************************
* 작성일 : 2016. 7. 14. 작성자 : KYJ
*
*
* @param javaFile
* @param converter
* @return
* @throws FileNotFoundException
* @throws IOException
* @throws ParseException
********************************/
public static String getPackageName(File javaFile, FileCheckHandler<String> converter) throws FileNotFoundException, IOException, ParseException {
String packageName = null;
if (javaFile == null) {
packageName = converter.ifNull();
} else if (!javaFile.exists())
packageName = converter.notExists();
else if (javaFile.isFile()) {
CompilationUnit cu = getCompileUnit(javaFile);
packageName = getPackageName(cu);
}
return packageName;
}
use of com.github.javaparser.ast.CompilationUnit in project Gargoyle by callakrsos.
the class VOEditorParser method parse.
public void parse() throws ParseException {
// FileInputStream in = new FileInputStream(fileName);
CompilationUnit cu = JavaParser.parse(is);
PackageDeclaration package1 = cu.getPackage();
LOGGER.debug(package1.getName().toString());
LOGGER.debug(String.format("package name : %s", package1.getName().getName()));
// prints the resulting compilation unit to default system output
LOGGER.debug(cu.toString());
new MethodVisitor().visit(cu, null);
}
Aggregations