use of org.structr.javaparser.entity.Package in project structr by structr.
the class JavaParserModule method handlePackageFolder.
private void handlePackageFolder(final Folder folder, final Folder parentFolder) {
// Folder contains a package-info.java so it must be a package
String[] parts = folder.getPath().split("src/main/java/");
if (parts.length > 1) {
final PropertyMap identifyingProperties = new PropertyMap();
final PropertyMap allProperties = new PropertyMap();
// Convert path to package path
String path = StringUtils.replaceAll(parts[1], "/", ".");
identifyingProperties.put(Package.name, path);
allProperties.putAll(identifyingProperties);
allProperties.put(Package.folder, folder);
// Check if we are contained in a module:
// Find the closest ancestor folder which has a module
Module mod = null;
Package pkg = null;
Folder possibleModuleParentFolder = parentFolder;
// Continue until root folder or a module was found
while (possibleModuleParentFolder != null && mod == null) {
try {
mod = app.nodeQuery(Module.class).and(Module.folder, possibleModuleParentFolder).getFirst();
pkg = app.nodeQuery(Package.class).and(Module.folder, possibleModuleParentFolder).getFirst();
} catch (FrameworkException ignore) {
}
if (pkg != null) {
// Parent folder contains a package
allProperties.put(Package.parent, pkg);
} else if (mod != null) {
// Parent folder contains a module
allProperties.put(Package.module, mod);
break;
}
// Continue while loop
possibleModuleParentFolder = possibleModuleParentFolder.getParent();
}
getOrCreate(Package.class, identifyingProperties, allProperties);
logger.info("Created or found package '" + path + "' in folder " + folder.getPath());
}
}
use of org.structr.javaparser.entity.Package in project structr by structr.
the class JavaParserModule method parseJavaFilesAndSolveTypes.
private void parseJavaFilesAndSolveTypes(final Folder folder) {
if (ignoreTests && "test".equals(folder.getName())) {
return;
}
for (final File file : folder.getFiles()) {
if (file.getContentType().equals("text/x-java")) {
final String javaFileName = file.getName();
if (javaFileName.equals("package-info.java") || javaFileName.equals("testPackage-info.java")) {
} else {
final String javaContent = file.getFavoriteContent();
ClassOrInterface clsOrIface = null;
CompilationUnit cu = null;
try {
cu = JavaParser.parse(javaContent);
for (final TypeDeclaration type : cu.findAll(TypeDeclaration.class)) {
SymbolReference<? extends ResolvedValueDeclaration> decl = facade.solve(type.getName());
if (type.isClassOrInterfaceDeclaration()) {
org.structr.javaparser.entity.Package pkg = null;
if (cu.getPackageDeclaration().isPresent()) {
pkg = handlePackage(cu.getPackageDeclaration().get());
}
clsOrIface = handleClassOrInterface(type, pkg);
}
}
for (final BodyDeclaration t : cu.findAll(BodyDeclaration.class)) {
if (t instanceof CallableDeclaration) {
final CallableDeclaration callable = t.asCallableDeclaration();
if (t instanceof ConstructorDeclaration) {
// final ConstructorDeclaration cd = t.asConstructorDeclaration();
// logger.info("Constructor found: " + cd.getNameAsString());
//
// final SymbolReference<ResolvedReferenceTypeDeclaration> constructorRef = typeSolver.tryToSolveType(cd.getNameAsString());
// if (constructorRef.isSolved()) {
//
// logger.info("Solved constructor: " + cd.getNameAsString());
// //final ResolvedReferenceTypeDeclaration decl = constructorRef.getCorrespondingDeclaration();
// }
} else if (t instanceof MethodDeclaration) {
final MethodDeclaration md = t.asMethodDeclaration();
final String methodName = md.getNameAsString();
logger.info("Method found: " + methodName);
// Create methods and link to class
final PropertyMap identifyingMethodProperties = new PropertyMap();
identifyingMethodProperties.put(Method.name, methodName);
final PropertyMap methodProperties = new PropertyMap();
methodProperties.putAll(identifyingMethodProperties);
methodProperties.put(Method.classOrInterface, clsOrIface);
methodProperties.put(Method.declaration, md.getDeclarationAsString());
final Optional<BlockStmt> block = md.getBody();
if (block.isPresent()) {
methodProperties.put(Method.body, block.get().toString());
}
final String symbolName = StringUtils.substringAfterLast(clsOrIface.getName(), ".") + "." + md.getNameAsString();
try {
final SymbolReference<? extends ResolvedValueDeclaration> methodRef = facade.solve(md.getName());
if (methodRef.isSolved()) {
final ResolvedValueDeclaration decl = methodRef.getCorrespondingDeclaration();
if (decl.isMethod()) {
final String mName = decl.asMethod().getName();
final String signature = decl.asMethod().getSignature();
logger.info("Solved method: " + methodRef.toString() + ", signature: " + signature);
methodProperties.put(Method.resolved, true);
}
}
} catch (final UnsolvedSymbolException ignore) {
}
getOrCreate(Method.class, identifyingMethodProperties, methodProperties);
logger.info("Created (or found) method " + symbolName);
}
// final NodeList<Parameter> parameters = callable.getParameters();
//
// List<JsonResult> parameterList = new ArrayList<>();
//
// parameters.forEach((p) -> {
//
// JsonResult param = new JsonResult();
//
// param.addName(p);
// param.addType(p.getType());
// param.addModifiers(p);
//
// parameterList.add(param);
// });
}
}
} catch (Throwable ignore) {
}
}
}
}
}
Aggregations