Java Code Examples for com.sun.source.tree.LineMap#getColumnNumber()

The following examples show how to use com.sun.source.tree.LineMap#getColumnNumber() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: T4994049.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public boolean run(DocletEnvironment root) {
    DocTrees trees = root.getDocTrees();

    SourcePositions sourcePositions = trees.getSourcePositions();
    for (TypeElement klass : ElementFilter.typesIn(root.getIncludedElements())) {
        for (ExecutableElement method : getMethods(klass)) {
            if (method.getSimpleName().toString().equals("tabbedMethod")) {
                TreePath path = trees.getPath(method);
                CompilationUnitTree cu = path.getCompilationUnit();
                long pos = sourcePositions.getStartPosition(cu, path.getLeaf());
                LineMap lineMap = cu.getLineMap();
                long columnNumber = lineMap.getColumnNumber(pos);
                if (columnNumber == 9) {
                    System.out.println(columnNumber + ": OK!");
                    return true;
                } else {
                    System.err.println(columnNumber + ": wrong tab expansion");
                    return false;
                }
            }
        }
    }
    return false;
}
 
Example 2
Source File: CompletenessStressTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private boolean testStatement(StringWriter writer, SourcePositions sp, String text, CompilationUnitTree cut, Tree statement) {
    if (statement == null) {
        return true;
    }
    int start = (int) sp.getStartPosition(cut, statement);
    int end = (int) sp.getEndPosition(cut, statement);
    char ch = text.charAt(end - 1);
    SourceCodeAnalysis.Completeness expected = COMPLETE;
    LineMap lineMap = cut.getLineMap();
    int row = (int) lineMap.getLineNumber(start);
    int column = (int) lineMap.getColumnNumber(start);
    switch (ch) {
        case ',':
        case ';':
            expected = (statement instanceof ExpressionStatementTree)
                    ? COMPLETE
                    : COMPLETE_WITH_SEMI;
            --end;
            break;
        case '}':
            break;
        default:
            writer.write(String.format("Unexpected end: row %d, column %d: '%c' -- %s\n",
                    row, column, ch, text.substring(start, end)));
            return true;
    }
    String unit = text.substring(start, end);
    SourceCodeAnalysis.CompletionInfo ci = getAnalysis().analyzeCompletion(unit);
    if (ci.completeness() != expected) {
        if (expected == COMPLETE_WITH_SEMI && (ci.completeness() == CONSIDERED_INCOMPLETE || ci.completeness() == EMPTY)) {
            writer.write(String.format("Empty statement: row %d, column %d: -- %s\n",
                    start, end, unit));
        } else {
            writer.write(String.format("Expected %s got %s: '%s'  row %d, column %d: -- %s\n",
                    expected, ci.completeness(), unit, row, column, unit));
            return false;
        }
    }
    return true;
}
 
Example 3
Source File: TextDocumentServiceImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static Position createPosition(LineMap lm, int offset) {
    return new Position((int) lm.getLineNumber(offset) - 1,
                        (int) lm.getColumnNumber(offset) - 1);
}