Search in sources :

Example 1 with InitializerDeclaration

use of com.github.javaparser.ast.body.InitializerDeclaration in project javaparser by javaparser.

the class CloneVisitor method visit.

@Override
public Node visit(InitializerDeclaration _n, Object _arg) {
    JavadocComment javaDoc = cloneNodes(_n.getJavaDoc(), _arg);
    BlockStmt block = cloneNodes(_n.getBlock(), _arg);
    Comment comment = cloneNodes(_n.getComment(), _arg);
    InitializerDeclaration r = new InitializerDeclaration(_n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), _n.isStatic(), block);
    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) InitializerDeclaration(com.github.javaparser.ast.body.InitializerDeclaration)

Example 2 with InitializerDeclaration

use of com.github.javaparser.ast.body.InitializerDeclaration in project javaparser by javaparser.

the class NodeWithMembers method addInitializer.

default BlockStmt addInitializer() {
    BlockStmt block = new BlockStmt();
    InitializerDeclaration initializerDeclaration = new InitializerDeclaration(false, block);
    getMembers().add(initializerDeclaration);
    initializerDeclaration.setParentNode((Node) this);
    return block;
}
Also used : InitializerDeclaration(com.github.javaparser.ast.body.InitializerDeclaration) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt)

Example 3 with InitializerDeclaration

use of com.github.javaparser.ast.body.InitializerDeclaration in project javaparser by javaparser.

the class NodeWithMembers method addStaticInitializer.

default BlockStmt addStaticInitializer() {
    BlockStmt block = new BlockStmt();
    InitializerDeclaration initializerDeclaration = new InitializerDeclaration(true, block);
    getMembers().add(initializerDeclaration);
    initializerDeclaration.setParentNode((Node) this);
    return block;
}
Also used : InitializerDeclaration(com.github.javaparser.ast.body.InitializerDeclaration) BlockStmt(com.github.javaparser.ast.stmt.BlockStmt)

Example 4 with InitializerDeclaration

use of com.github.javaparser.ast.body.InitializerDeclaration in project javaparser by javaparser.

the class InitializerDeclarationTransformationsTest method instanceToStatic.

// JavaDoc
// Body
// IsStatic
@Test
public void instanceToStatic() throws IOException {
    InitializerDeclaration it = consider("{ /*some comment*/ }");
    it.setStatic(true);
    assertTransformedToString("static { /*some comment*/ }", it);
}
Also used : InitializerDeclaration(com.github.javaparser.ast.body.InitializerDeclaration) Test(org.junit.Test) AbstractLexicalPreservingTest(com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)

Example 5 with InitializerDeclaration

use of com.github.javaparser.ast.body.InitializerDeclaration in project javaparser by javaparser.

the class InitializerDeclarationTransformationsTest method staticToInstance.

@Test
public void staticToInstance() throws IOException {
    InitializerDeclaration it = consider("static { /*some comment*/ }");
    it.setStatic(false);
    assertTransformedToString("{ /*some comment*/ }", it);
}
Also used : InitializerDeclaration(com.github.javaparser.ast.body.InitializerDeclaration) Test(org.junit.Test) AbstractLexicalPreservingTest(com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)

Aggregations

InitializerDeclaration (com.github.javaparser.ast.body.InitializerDeclaration)5 BlockStmt (com.github.javaparser.ast.stmt.BlockStmt)2 AbstractLexicalPreservingTest (com.github.javaparser.printer.lexicalpreservation.AbstractLexicalPreservingTest)2 Test (org.junit.Test)2 BlockComment (com.github.javaparser.ast.comments.BlockComment)1 Comment (com.github.javaparser.ast.comments.Comment)1 JavadocComment (com.github.javaparser.ast.comments.JavadocComment)1 LineComment (com.github.javaparser.ast.comments.LineComment)1