use of com.github.javaparser.ast.body.BodyDeclaration in project javaparser by javaparser.
the class CloneVisitor method visit.
@Override
public Node visit(EnumDeclaration _n, Object _arg) {
JavadocComment javaDoc = cloneNodes(_n.getJavaDoc(), _arg);
List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg);
List<ClassOrInterfaceType> implementsList = visit(_n.getImplements(), _arg);
List<EnumConstantDeclaration> entries = visit(_n.getEntries(), _arg);
List<BodyDeclaration> members = visit(_n.getMembers(), _arg);
Comment comment = cloneNodes(_n.getComment(), _arg);
EnumDeclaration r = new EnumDeclaration(_n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), _n.getModifiers(), annotations, _n.getName(), implementsList, entries, members);
r.setComment(comment);
return r;
}
use of com.github.javaparser.ast.body.BodyDeclaration in project javaparser by javaparser.
the class CloneVisitor method visit.
@Override
public Node visit(ClassOrInterfaceDeclaration _n, Object _arg) {
JavadocComment javaDoc = cloneNodes(_n.getJavaDoc(), _arg);
List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg);
List<TypeParameter> typeParameters = visit(_n.getTypeParameters(), _arg);
List<ClassOrInterfaceType> extendsList = visit(_n.getExtends(), _arg);
List<ClassOrInterfaceType> implementsList = visit(_n.getImplements(), _arg);
List<BodyDeclaration> members = visit(_n.getMembers(), _arg);
Comment comment = cloneNodes(_n.getComment(), _arg);
ClassOrInterfaceDeclaration r = new ClassOrInterfaceDeclaration(_n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), _n.getModifiers(), annotations, _n.isInterface(), _n.getName(), typeParameters, extendsList, implementsList, members);
r.setComment(comment);
return r;
}
use of com.github.javaparser.ast.body.BodyDeclaration in project javaparser by javaparser.
the class JavaParser method parseBodyDeclaration.
/**
* Parses the Java body declaration(e.g fields or methods) contained in a
* {@link String} and returns a {@link BodyDeclaration} that represents it.
*
* @param body
* {@link String} containing Java body declaration
* @return BodyDeclaration representing the Java annotation
* @throws ParseException
* if the source code has parser errors
*/
public static BodyDeclaration parseBodyDeclaration(final String body) {
StringReader sr = new StringReader(body);
BodyDeclaration bd = new ASTParser(sr).AnnotationBodyDeclaration();
sr.close();
return bd;
}
use of com.github.javaparser.ast.body.BodyDeclaration in project javaparser by javaparser.
the class MethodChanger_2 method changeMethods.
private static void changeMethods(CompilationUnit cu) {
// Go through all the types in the file
NodeList<TypeDeclaration<?>> types = cu.getTypes();
for (TypeDeclaration<?> type : types) {
// Go through all fields, methods, etc. in this type
NodeList<BodyDeclaration<?>> members = type.getMembers();
for (BodyDeclaration<?> member : members) {
if (member instanceof MethodDeclaration) {
MethodDeclaration method = (MethodDeclaration) member;
changeMethod(method);
}
}
}
}
use of com.github.javaparser.ast.body.BodyDeclaration in project AndroidLife by CaMnter.
the class R2ClassBuilder method addResourceType.
/**
* 复制资源 内部 class 到 R2 class 中
*
* 这里是给 R2 的 TypeSpec 添加生成局域
*
* @param supportedTypes 支持的类型( "array", "attr", "bool", "color", "dimen", "drawable", "id",
* "integer", "string" )
* @param result R2 的 TypeSpec
* @param node R 的 接口或者类 ClassOrInterfaceDeclaration
*/
private static void addResourceType(List<String> supportedTypes, TypeSpec.Builder result, ClassOrInterfaceDeclaration node) {
// 判断是否是资源内部类( "array", "attr", "bool", "color", "dimen", "drawable", "id", "integer", "string" )
if (!supportedTypes.contains(node.getNameAsString())) {
return;
}
// 创建 R2 的内部类 TypeSpec,为了进行资源复制
String type = node.getNameAsString();
TypeSpec.Builder resourceType = TypeSpec.classBuilder(type).addModifiers(PUBLIC, STATIC, FINAL);
/*
* 遍历 R 内部类的每个资源 field
* 然后给 R2 的内部类 TypeSpec 添加 field 生成语句
*/
for (BodyDeclaration field : node.getMembers()) {
if (field instanceof FieldDeclaration) {
addResourceField(resourceType, ((FieldDeclaration) field).getVariables().get(0), getSupportAnnotationClass(type));
}
}
// R2 的内部类 TypeSpec 添加到 R2 TypeSpec 内
result.addType(resourceType.build());
}
Aggregations