use of org.structr.javaparser.entity.ClassOrInterface in project structr by structr.
the class JavaParserModule method handleClassOrInterface.
private ClassOrInterface handleClassOrInterface(final TypeDeclaration type, final org.structr.javaparser.entity.Package pkg) {
final String name = (pkg != null ? pkg.getName() + "." : "") + type.getNameAsString();
logger.info("Parsing class or interface " + name);
final PropertyMap identifyingProperties = new PropertyMap();
identifyingProperties.put(ClassOrInterface.name, name);
if (pkg != null) {
identifyingProperties.put(ClassOrInterface.packageProp, pkg);
}
ClassOrInterface clsOrIface = null;
boolean isInterface = type.asClassOrInterfaceDeclaration().isInterface();
if (isInterface) {
// Create Java interface
clsOrIface = (JavaInterface) getOrCreate(JavaInterface.class, identifyingProperties, identifyingProperties);
logger.info("Created (or found) interface " + clsOrIface.getName());
} else {
// Create Java class
clsOrIface = (JavaClass) getOrCreate(JavaClass.class, identifyingProperties, identifyingProperties);
logger.info("Created (or found) class " + clsOrIface.getName());
}
return clsOrIface;
}
use of org.structr.javaparser.entity.ClassOrInterface 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