Example usage for org.eclipse.jdt.core.dom Name setSourceRange

List of usage examples for org.eclipse.jdt.core.dom Name setSourceRange

Introduction

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

Prototype

public final void setSourceRange(int startPosition, int length) 

Source Link

Document

Sets the source range of the original source file where the source fragment corresponding to this node was found.

Usage

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

protected void retrieveIdentifierAndSetPositions(int start, int end, Name name) {
    this.scanner.resetTo(start, end);
    int token;//from  w ww  .  j  a  va2  s .co  m
    try {
        while ((token = this.scanner.getNextToken()) != TerminalTokens.TokenNameEOF) {
            if (token == TerminalTokens.TokenNameIdentifier) {
                int startName = this.scanner.startPosition;
                int endName = this.scanner.currentPosition - 1;
                name.setSourceRange(startName, endName - startName + 1);
                return;
            }
        }
    } catch (InvalidInputException e) {
        // ignore
    }
}

From source file:org.eclipse.wb.internal.core.utils.ast.AstParser.java

License:Open Source License

/**
 * @return the {@link QualifiedName} for given name.
 *//*from w  ww  .  ja v  a  2  s  .  c om*/
public QualifiedName parseQualifiedName(int startPosition, String src) {
    String parts[] = StringUtils.split(src, '.');
    Assert.isTrue(parts.length >= 2);
    // build QualifiedName
    Name result = null;
    {
        int currentPosition = startPosition;
        for (int i = 0; i < parts.length; i++) {
            String part = parts[i];
            //
            if (result == null) {
                result = parseSimpleName(currentPosition, part);
            } else {
                currentPosition++;
                result = getAst().newQualifiedName(result, parseSimpleName(currentPosition, part));
            }
            //
            currentPosition += part.length();
            result.setSourceRange(startPosition, currentPosition - startPosition);
        }
    }
    // return result
    return (QualifiedName) result;
}