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

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

Introduction

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

Prototype

public final int getStartPosition() 

Source Link

Document

Returns the character index into the original source file indicating where the source fragment corresponding to this node begins.

Usage

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();//from www. j av a 2 s .  c  om

    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 {
        languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine,
                beginColumn, endColumn));
    }

    return true;
}

From source file:net.sf.j2s.core.astvisitors.ASTJ2SDocVisitor.java

License:Open Source License

private int getPreviousStartPosition(Block node) {
    int previousStart = 0;
    ASTNode blockParent = node.getParent();
    if (blockParent != null) {
        if (blockParent instanceof Statement) {
            Statement sttmt = (Statement) blockParent;
            previousStart = sttmt.getStartPosition();
            if (sttmt instanceof Block) {
                Block parentBlock = (Block) sttmt;
                for (Iterator iter = parentBlock.statements().iterator(); iter.hasNext();) {
                    Statement element = (Statement) iter.next();
                    if (element == node) {
                        break;
                    }/*from   w  w w .j a  v  a 2s. c o m*/
                    previousStart = element.getStartPosition() + element.getLength();
                }
            } else if (sttmt instanceof IfStatement) {
                IfStatement ifSttmt = (IfStatement) sttmt;
                if (ifSttmt.getElseStatement() == node) {
                    Statement thenSttmt = ifSttmt.getThenStatement();
                    previousStart = thenSttmt.getStartPosition() + thenSttmt.getLength();
                }
            }
        } else if (blockParent instanceof MethodDeclaration) {
            MethodDeclaration method = (MethodDeclaration) blockParent;
            previousStart = method.getStartPosition();
        } else if (blockParent instanceof Initializer) {
            Initializer initializer = (Initializer) blockParent;
            previousStart = initializer.getStartPosition();
        } else if (blockParent instanceof CatchClause) {
            CatchClause catchClause = (CatchClause) blockParent;
            previousStart = catchClause.getStartPosition();
        }
    }
    return previousStart;
}