Example usage for org.eclipse.jdt.core.dom VariableDeclarationStatement getLength

List of usage examples for org.eclipse.jdt.core.dom VariableDeclarationStatement getLength

Introduction

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

Prototype

public final int getLength() 

Source Link

Document

Returns the length in characters of the original source file indicating where the source fragment corresponding to this node ends.

Usage

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

@Override
public boolean visit(VariableDeclarationStatement node) {

    List<VariableDeclarationFragment> fragments = node.fragments();

    for (VariableDeclarationFragment fragment : fragments) {
        String identifier = fragment.getName().getIdentifier();
        int beginLine = cu.getLineNumber(fragment.getStartPosition());
        int endLine = cu.getLineNumber(fragment.getStartPosition() + fragment.getLength());
        int beginColumn = cu.getColumnNumber(node.getStartPosition());
        int endColumn = cu.getColumnNumber(node.getStartPosition() + node.getLength());

        SimpleName name = fragment.getName();

        if (name != null) {
            endLine = cu.getLineNumber(name.getStartPosition() + name.getLength());
            endColumn = cu.getColumnNumber(name.getStartPosition() + name.getLength());
        }/*from  w ww.  j ava  2 s.com*/

        languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine,
                beginColumn, endColumn, identifier));

    }

    return true;
}

From source file:br.uff.ic.mergeguider.javaparser.DepVisitor.java

@Override
public boolean visit(VariableDeclarationStatement node) {

    Location location;//  w w  w . j  av a 2s  .  co m

    List<VariableDeclarationFragment> fragments = node.fragments();

    for (VariableDeclarationFragment fragment : fragments) {

        int elementLineBegin = cu.getLineNumber(fragment.getStartPosition());
        int elementLineEnd = cu.getLineNumber(fragment.getStartPosition() + node.getLength());
        int elementColumnBegin = cu.getColumnNumber(fragment.getStartPosition());
        int elementColumnEnd = cu.getColumnNumber(fragment.getStartPosition() + node.getLength());

        location = new Location(elementLineBegin, elementLineEnd, elementColumnBegin, elementColumnEnd);

        MyVariableDeclaration myVariableDeclaration = new MyVariableDeclaration(fragment, location);

        if (!classLanguageConstructsList.isEmpty()) {
            classLanguageConstructsList.get(classLanguageConstructsList.size() - 1).getVariableDeclarations()
                    .add(myVariableDeclaration);
        }

    }

    return true;

}