Example usage for org.eclipse.jdt.core.dom Initializer getBody

List of usage examples for org.eclipse.jdt.core.dom Initializer getBody

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom Initializer getBody.

Prototype

public Block getBody() 

Source Link

Document

Returns the body of this initializer declaration.

Usage

From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java

License:Open Source License

@Override
public boolean visit(Initializer node) {
    if (node.getJavadoc() != null) {
        node.getJavadoc().accept(this);
    }//from  ww w  .ja va  2 s.c om
    if (node.getAST().apiLevel() >= JLS3) {
        printModifiers(node.modifiers());
    }
    node.getBody().accept(this);
    return false;
}

From source file:boa.datagen.util.Java7Visitor.java

License:Apache License

@Override
public boolean visit(Initializer node) {
    List<boa.types.Ast.Method> list = methods.peek();
    Method.Builder b = Method.newBuilder();
    //      b.setPosition(pos.build());
    b.setName("<clinit>");
    for (Object m : node.modifiers()) {
        if (((IExtendedModifier) m).isAnnotation())
            ((Annotation) m).accept(this);
        else//from   ww w  .java 2  s  . c o  m
            ((org.eclipse.jdt.core.dom.Modifier) m).accept(this);
        b.addModifiers(modifiers.pop());
    }
    boa.types.Ast.Type.Builder tb = boa.types.Ast.Type.newBuilder();
    tb.setName(getIndex("void"));
    tb.setKind(boa.types.Ast.TypeKind.OTHER);
    b.setReturnType(tb.build());
    if (node.getBody() != null) {
        statements.push(new ArrayList<boa.types.Ast.Statement>());
        node.getBody().accept(this);
        for (boa.types.Ast.Statement s : statements.pop())
            b.addStatements(s);
    }
    list.add(b.build());
    return false;
}

From source file:br.uff.ic.gems.resources.ast.Visitor.java

@Override
public boolean visit(Initializer node) {

    int beginLine = beginLine(node);
    int endLine = cu.getLineNumber(node.getStartPosition() + node.getLength());
    int beginColumn = beginColunm(node);
    int endColumn = cu.getColumnNumber(node.getStartPosition() + node.getLength());

    Block body = node.getBody();

    if (body != null) {

        int beginLineBody = cu.getLineNumber(body.getStartPosition());
        int endLineBody = cu.getLineNumber(body.getStartPosition() + body.getLength());
        int beginColumnBody = cu.getColumnNumber(body.getStartPosition());
        int endColumnBody = cu.getColumnNumber(body.getStartPosition() + body.getLength());

        languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine,
                beginColumn, endColumn, beginLineBody, endLineBody, beginColumnBody, endColumnBody, null));
    } else {/* www .  j  a v a  2  s  . c o m*/
        languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine,
                beginColumn, endColumn));
    }

    return true;
}

From source file:coloredide.utils.CopiedNaiveASTFlattener.java

License:Open Source License

public boolean visit(Initializer node) {
    if (node.getJavadoc() != null) {
        node.getJavadoc().accept(this);
    }//from w w  w  .  j  a v a2 s  . c  o m
    if (node.getAST().apiLevel() >= AST.JLS3) {
        printModifiers(node.modifiers());
    }
    node.getBody().accept(this);
    return false;
}

From source file:com.google.devtools.j2cpp.translate.InitializationNormalizer.java

License:Open Source License

/**
 * Add a static or instance init block's statements to the appropriate list
 * of initialization statements./* w w  w . ja v a2 s.  c om*/
 */
private void addInitializer(BodyDeclaration member, List<Statement> initStatements,
        List<Statement> classInitStatements) {
    Initializer initializer = (Initializer) member;
    List<Statement> l = Modifier.isStatic(initializer.getModifiers()) ? classInitStatements : initStatements;
    @SuppressWarnings("unchecked")
    List<Statement> stmts = initializer.getBody().statements(); // safe by specification
    l.addAll(stmts);
}

From source file:com.google.devtools.j2objc.ast.DebugASTPrinter.java

License:Apache License

@Override
public boolean visit(Initializer node) {
    printModifiers(node.getModifiers());
    node.getBody().accept(this);
    return false;
}

From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java

License:Apache License

/** Visitor method for {@link Initializer}s. */
@Override/*from w  w  w.jav  a  2 s.co m*/
public boolean visit(Initializer node) {
    sync(node);
    visitAndBreakModifiers(node.modifiers(), Direction.VERTICAL, Optional.<BreakTag>absent());
    node.getBody().accept(this);
    builder.guessToken(";");
    return false;
}

From source file:com.j2swift.ast.DebugASTPrinter.java

License:Apache License

@Override
public boolean visit(Initializer node) {
    printAnnotations(node.getAnnotations());
    printModifiers(node.getModifiers());
    node.getBody().accept(this);
    return false;
}

From source file:de.fkoeberle.autocommit.message.java.helper.DeclarationListDeltaTest.java

License:Open Source License

@Test
public void testReplacedInitializer() {
    DeclarationListDelta delta = createClassDelta("static int i; { i = 0; }\n",
            "static int i; { i = 1; i++;}\n");

    assertEquals(1, delta.getAddedDeclarations().size());
    assertEquals(0, delta.getChangedDeclarations().size());
    assertEquals(1, delta.getRemovedDeclarations().size());

    BodyDeclaration removedDeclaration = delta.getRemovedDeclarations().get(0);
    assertTrue(removedDeclaration instanceof Initializer);
    Initializer removedInitializer = (Initializer) removedDeclaration;
    assertEquals(1, removedInitializer.getBody().statements().size());

    BodyDeclaration addedDeclaration = delta.getAddedDeclarations().get(0);
    assertTrue(addedDeclaration instanceof Initializer);
    Initializer addedInitializer = (Initializer) addedDeclaration;
    assertEquals(2, addedInitializer.getBody().statements().size());
}

From source file:edu.uci.ics.sourcerer.tools.java.extractor.eclipse.ReferenceExtractorVisitor.java

License:Open Source License

/**
 * This method writes:/*ww w. ja  va  2s .com*/
 * <ul>
 *   <li>Initializer entity to <code>IEntityWriter</code>
 *   <ul>
 *     <li>Inside relation to <code>IRelationWriter</code></li>
 *   </ul></li>
 * </ul>
 * 
 * Enum constant fully qualified names (FQNs) adhere to the following format:<br> 
 * parent fqn + . + simple name
 */
@Override
public boolean visit(Initializer node) {
    // Get the fqn
    String fqn = fqnStack.peek(EnclosingDeclaredType.class).getInitializerFqn();

    String parentFqn = fqnStack.getFqn();

    // Visit the children
    fqnStack.push(fqn, Entity.INITIALIZER);
    accept(node.getJavadoc());
    accept(node.modifiers());
    accept(node.getBody());

    // Write the entity
    entityWriter.writeEntity(Entity.INITIALIZER, fqn, node.getModifiers(), createMetrics(node),
            createLocation(node));

    // Write the contains relation
    relationWriter.writeRelation(Relation.CONTAINS, parentFqn, fqn, createUnknownLocation());

    fqnStack.pop();

    return false;
}