Search in sources :

Example 1 with BodyDeclaration

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;
}
Also used : ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) Type(com.github.javaparser.ast.type.Type) ReferenceType(com.github.javaparser.ast.type.ReferenceType) VoidType(com.github.javaparser.ast.type.VoidType) ArrayType(com.github.javaparser.ast.type.ArrayType) PrimitiveType(com.github.javaparser.ast.type.PrimitiveType) WildcardType(com.github.javaparser.ast.type.WildcardType) Expression(com.github.javaparser.ast.expr.Expression) AClass(scenelib.annotations.el.AClass) BodyDeclaration(com.github.javaparser.ast.body.BodyDeclaration) ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType)

Example 2 with BodyDeclaration

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();
    }
}
Also used : BodyDeclaration(com.github.javaparser.ast.body.BodyDeclaration)

Example 3 with BodyDeclaration

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;
}
Also used : JavadocComment(com.github.javaparser.ast.comments.JavadocComment) BlockComment(com.github.javaparser.ast.comments.BlockComment) LineComment(com.github.javaparser.ast.comments.LineComment) Comment(com.github.javaparser.ast.comments.Comment) JavadocComment(com.github.javaparser.ast.comments.JavadocComment) AnnotationDeclaration(com.github.javaparser.ast.body.AnnotationDeclaration) BodyDeclaration(com.github.javaparser.ast.body.BodyDeclaration)

Example 4 with BodyDeclaration

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;
}
Also used : JavadocComment(com.github.javaparser.ast.comments.JavadocComment) BlockComment(com.github.javaparser.ast.comments.BlockComment) LineComment(com.github.javaparser.ast.comments.LineComment) Comment(com.github.javaparser.ast.comments.Comment) EnumConstantDeclaration(com.github.javaparser.ast.body.EnumConstantDeclaration) JavadocComment(com.github.javaparser.ast.comments.JavadocComment) BodyDeclaration(com.github.javaparser.ast.body.BodyDeclaration)

Example 5 with BodyDeclaration

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);
        });
    }
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) NodeList(com.github.javaparser.ast.NodeList) Generator(com.github.javaparser.generator.Generator) SourceRoot(com.github.javaparser.utils.SourceRoot) ReturnStmt(com.github.javaparser.ast.stmt.ReturnStmt) EnumConstantDeclaration(com.github.javaparser.ast.body.EnumConstantDeclaration) BodyDeclaration(com.github.javaparser.ast.body.BodyDeclaration) EnumDeclaration(com.github.javaparser.ast.body.EnumDeclaration) Log(com.github.javaparser.utils.Log) SwitchEntryStmt(com.github.javaparser.ast.stmt.SwitchEntryStmt) SwitchStmt(com.github.javaparser.ast.stmt.SwitchStmt) CompilationUnit(com.github.javaparser.ast.CompilationUnit) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) Node(com.github.javaparser.ast.Node) IntegerLiteralExpr(com.github.javaparser.ast.expr.IntegerLiteralExpr) IntegerLiteralExpr(com.github.javaparser.ast.expr.IntegerLiteralExpr) SwitchStmt(com.github.javaparser.ast.stmt.SwitchStmt) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) Node(com.github.javaparser.ast.Node) SwitchEntryStmt(com.github.javaparser.ast.stmt.SwitchEntryStmt) EnumDeclaration(com.github.javaparser.ast.body.EnumDeclaration)

Aggregations

BodyDeclaration (com.github.javaparser.ast.body.BodyDeclaration)21 FieldDeclaration (com.github.javaparser.ast.body.FieldDeclaration)6 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)6 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)5 BlockComment (com.github.javaparser.ast.comments.BlockComment)5 Comment (com.github.javaparser.ast.comments.Comment)5 JavadocComment (com.github.javaparser.ast.comments.JavadocComment)5 LineComment (com.github.javaparser.ast.comments.LineComment)5 CompilationUnit (com.github.javaparser.ast.CompilationUnit)4 ConstructorDeclaration (com.github.javaparser.ast.body.ConstructorDeclaration)4 EnumDeclaration (com.github.javaparser.ast.body.EnumDeclaration)4 TypeDeclaration (com.github.javaparser.ast.body.TypeDeclaration)4 EnumConstantDeclaration (com.github.javaparser.ast.body.EnumConstantDeclaration)3 TypeSpec (com.squareup.javapoet.TypeSpec)3 Optional (java.util.Optional)3 NodeList (com.github.javaparser.ast.NodeList)2 CallableDeclaration (com.github.javaparser.ast.body.CallableDeclaration)2 Parameter (com.github.javaparser.ast.body.Parameter)2 SimpleName (com.github.javaparser.ast.expr.SimpleName)2 Type (com.github.javaparser.ast.type.Type)2