use of com.github.javaparser.ast.body.BodyDeclaration in project checker-framework by typetools.
the class ToIndexFileConverter method visit.
@Override
public Void visit(ObjectCreationExpr expr, AElement elem) {
ClassOrInterfaceType type = expr.getType();
AClass clazz = scene.classes.vivify(type.getNameAsString());
Expression scope = expr.getScope().orElse(null);
List<Type> typeArgs = expr.getTypeArguments().orElse(null);
List<Expression> args = expr.getArguments();
NodeList<BodyDeclaration<?>> bodyDecls = expr.getAnonymousClassBody().orElse(null);
if (scope != null) {
scope.accept(this, elem);
}
if (args != null) {
for (Expression arg : args) {
arg.accept(this, elem);
}
}
if (typeArgs != null) {
for (Type typeArg : typeArgs) {
typeArg.accept(this, elem);
}
}
type.accept(this, clazz);
if (bodyDecls != null) {
for (BodyDeclaration<?> decl : bodyDecls) {
decl.accept(this, clazz);
}
}
return null;
}
use of com.github.javaparser.ast.body.BodyDeclaration in project javaparser by javaparser.
the class DumpVisitor method printMembers.
private void printMembers(final List<BodyDeclaration> members, final Object arg) {
for (final BodyDeclaration member : members) {
printer.printLn();
member.accept(this, arg);
printer.printLn();
}
}
use of com.github.javaparser.ast.body.BodyDeclaration in project javaparser by javaparser.
the class CloneVisitor method visit.
@Override
public Node visit(AnnotationDeclaration _n, Object _arg) {
JavadocComment javaDoc = cloneNodes(_n.getJavaDoc(), _arg);
List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg);
List<BodyDeclaration> members = visit(_n.getMembers(), _arg);
Comment comment = cloneNodes(_n.getComment(), _arg);
AnnotationDeclaration r = new AnnotationDeclaration(_n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), _n.getModifiers(), annotations, _n.getName(), 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(EnumConstantDeclaration _n, Object _arg) {
JavadocComment javaDoc = cloneNodes(_n.getJavaDoc(), _arg);
List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg);
List<Expression> args = visit(_n.getArgs(), _arg);
List<BodyDeclaration> classBody = visit(_n.getClassBody(), _arg);
Comment comment = cloneNodes(_n.getComment(), _arg);
EnumConstantDeclaration r = new EnumConstantDeclaration(_n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), annotations, _n.getName(), args, classBody);
r.setComment(comment);
return r;
}
use of com.github.javaparser.ast.body.BodyDeclaration in project javaparser by javaparser.
the class TokenKindGenerator method generate.
@Override
public void generate() {
Log.info("Running %s", getClass().getSimpleName());
final CompilationUnit javaTokenCu = sourceRoot.parse("com.github.javaparser", "JavaToken.java");
final ClassOrInterfaceDeclaration javaToken = javaTokenCu.getClassByName("JavaToken").orElseThrow(() -> new AssertionError("Can't find class in java file."));
final EnumDeclaration kindEnum = javaToken.findFirst(EnumDeclaration.class, e -> e.getNameAsString().equals("Kind")).orElseThrow(() -> new AssertionError("Can't find class in java file."));
kindEnum.getEntries().clear();
annotateGenerated(kindEnum);
final SwitchStmt valueOfSwitch = kindEnum.findFirst(SwitchStmt.class).orElseThrow(() -> new AssertionError("Can't find valueOf switch."));
valueOfSwitch.findAll(SwitchEntryStmt.class).stream().filter(e -> e.getLabel().isPresent()).forEach(Node::remove);
final CompilationUnit constantsCu = generatedJavaCcSourceRoot.parse("com.github.javaparser", "GeneratedJavaParserConstants.java");
final ClassOrInterfaceDeclaration constants = constantsCu.getInterfaceByName("GeneratedJavaParserConstants").orElseThrow(() -> new AssertionError("Can't find class in java file."));
for (BodyDeclaration<?> member : constants.getMembers()) {
member.toFieldDeclaration().filter(field -> {
String javadoc = field.getJavadocComment().get().getContent();
return javadoc.contains("RegularExpression Id") || javadoc.contains("End of File");
}).map(field -> field.getVariable(0)).ifPresent(var -> {
final String name = var.getNameAsString();
final IntegerLiteralExpr kind = var.getInitializer().get().asIntegerLiteralExpr();
generateEnumEntry(kindEnum, name, kind);
generateValueOfEntry(valueOfSwitch, name, kind);
});
}
}
Aggregations