use of com.github.javaparser.ast.body.TypeDeclaration in project peass by DaGeRe.
the class TraceReadUtils method getNamedClasses.
public static Map<String, TypeDeclaration<?>> getNamedClasses(final Node parent, final String alreadyReadPrefix) {
final Map<String, TypeDeclaration<?>> foundDeclaredClasses = new HashMap<>();
for (final Node child : parent.getChildNodes()) {
LOG.trace(child.getClass());
if (child instanceof ClassOrInterfaceDeclaration) {
final String ownName = ((ClassOrInterfaceDeclaration) child).getNameAsString();
if (alreadyReadPrefix.equals("")) {
foundDeclaredClasses.put(ownName, (ClassOrInterfaceDeclaration) child);
foundDeclaredClasses.putAll(getNamedClasses(child, ownName));
} else {
foundDeclaredClasses.put(alreadyReadPrefix + "$" + ownName, (ClassOrInterfaceDeclaration) child);
foundDeclaredClasses.putAll(getNamedClasses(child, alreadyReadPrefix + "$" + ownName));
}
} else if (child instanceof EnumDeclaration) {
final String ownName = ((EnumDeclaration) child).getNameAsString();
if (alreadyReadPrefix.equals("")) {
foundDeclaredClasses.put(ownName, (ClassOrInterfaceDeclaration) child);
foundDeclaredClasses.putAll(getNamedClasses(child, ownName));
} else {
foundDeclaredClasses.put(alreadyReadPrefix + "$" + ownName, (EnumDeclaration) child);
foundDeclaredClasses.putAll(getNamedClasses(child, alreadyReadPrefix + "$" + ownName));
}
} else {
foundDeclaredClasses.putAll(getNamedClasses(child, alreadyReadPrefix));
}
}
return foundDeclaredClasses;
}
use of com.github.javaparser.ast.body.TypeDeclaration in project peass by DaGeRe.
the class ClazzFinder method getContainingClazz.
public static String getContainingClazz(final Node statement) {
String clazz = "";
Node current = statement;
while (current.getParentNode().isPresent()) {
if (current instanceof ClassOrInterfaceDeclaration || current instanceof EnumDeclaration || current instanceof AnnotationDeclaration) {
TypeDeclaration<?> declaration = (TypeDeclaration<?>) current;
String name = declaration.getNameAsString();
if (!clazz.isEmpty()) {
clazz = name + "$" + clazz;
} else {
clazz = name;
}
}
current = current.getParentNode().get();
}
return clazz;
}
use of com.github.javaparser.ast.body.TypeDeclaration in project peass by DaGeRe.
the class ClazzFinder method findClazz.
public static TypeDeclaration<?> findClazz(final ChangedEntity entity, final List<Node> nodes) {
TypeDeclaration<?> declaration = null;
for (final Node node : nodes) {
if (node instanceof TypeDeclaration<?>) {
final TypeDeclaration<?> temp = (TypeDeclaration<?>) node;
final String nameAsString = temp.getNameAsString();
if (nameAsString.equals(entity.getSimpleClazzName())) {
declaration = (ClassOrInterfaceDeclaration) node;
break;
} else {
if (entity.getSimpleClazzName().startsWith(nameAsString + ChangedEntity.CLAZZ_SEPARATOR)) {
ChangedEntity inner = new ChangedEntity(entity.getSimpleClazzName().substring(nameAsString.length() + 1), entity.getModule());
declaration = findClazz(inner, node.getChildNodes());
}
}
}
}
return declaration;
}
use of com.github.javaparser.ast.body.TypeDeclaration in project butterknife by JakeWharton.
the class FinalRClassBuilder method brewJava.
public static void brewJava(File rFile, File outputDir, String packageName, String className) throws Exception {
CompilationUnit compilationUnit = JavaParser.parse(rFile);
TypeDeclaration resourceClass = compilationUnit.getTypes().get(0);
TypeSpec.Builder result = TypeSpec.classBuilder(className).addModifiers(PUBLIC).addModifiers(FINAL);
for (Node node : resourceClass.getChildNodes()) {
if (node instanceof ClassOrInterfaceDeclaration) {
addResourceType(Arrays.asList(SUPPORTED_TYPES), result, (ClassOrInterfaceDeclaration) node);
}
}
JavaFile finalR = JavaFile.builder(packageName, result.build()).addFileComment("Generated code from Butter Knife gradle plugin. Do not modify!").build();
finalR.writeTo(outputDir);
}
use of com.github.javaparser.ast.body.TypeDeclaration in project checker-framework by typetools.
the class ToIndexFileConverter method extractScene.
/**
* Entry point of recursive-descent IndexUnit to AScene transformer. It operates by visiting the
* stub and scene in parallel, descending into them in the same way. It augments the existing
* scene (it does not create a new scene).
*
* @param iu {@link StubUnit} representing stubfile
*/
private static void extractScene(StubUnit iu, AScene scene) {
for (CompilationUnit cu : iu.getCompilationUnits()) {
NodeList<TypeDeclaration<?>> typeDecls = cu.getTypes();
if (typeDecls != null && cu.getPackageDeclaration().isPresent()) {
List<ImportDeclaration> impDecls = cu.getImports();
PackageDeclaration pkgDecl = cu.getPackageDeclaration().get();
for (TypeDeclaration<?> typeDecl : typeDecls) {
ToIndexFileConverter converter = new ToIndexFileConverter(pkgDecl, impDecls, scene);
String pkgName = converter.pkgName;
String name = typeDecl.getNameAsString();
if (pkgName != null) {
name = pkgName + "." + name;
}
typeDecl.accept(converter, scene.classes.getVivify(name));
}
}
}
}
Aggregations