本文整理匯總了Java中com.sun.source.tree.CompilationUnitTree.getLineMap方法的典型用法代碼示例。如果您正苦於以下問題:Java CompilationUnitTree.getLineMap方法的具體用法?Java CompilationUnitTree.getLineMap怎麽用?Java CompilationUnitTree.getLineMap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.sun.source.tree.CompilationUnitTree
的用法示例。
在下文中一共展示了CompilationUnitTree.getLineMap方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: run
import com.sun.source.tree.CompilationUnitTree; //導入方法依賴的package包/類
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;
}
示例2: MethodArgumentsScanner
import com.sun.source.tree.CompilationUnitTree; //導入方法依賴的package包/類
/** Creates a new instance of MethodArgumentsScanner */
public MethodArgumentsScanner(int offset, CompilationUnitTree tree,
SourcePositions positions, boolean methodInvocation,
ASTOperationCreationDelegate positionDelegate) {
this.offset = offset;
this.tree = tree;
this.positions = positions;
this.lineMap = tree.getLineMap();
this.methodInvocation = methodInvocation;
this.positionDelegate = positionDelegate;
}
示例3: ExpressionScanner
import com.sun.source.tree.CompilationUnitTree; //導入方法依賴的package包/類
public ExpressionScanner(int lineNumber, int statementStart, int statementEnd,
CompilationUnitTree tree, SourcePositions positions) {
this.tree = tree;
this.lineNumber = lineNumber;
this.statementStart = statementStart;
this.statementEnd = statementEnd;
this.positions = positions;
this.lineMap = tree.getLineMap();
}
示例4: getLineNumber
import com.sun.source.tree.CompilationUnitTree; //導入方法依賴的package包/類
public long getLineNumber(Element e) {
TreePath path = getTreePath(e);
if (path == null) { // maybe null if synthesized
TypeElement encl = getEnclosingTypeElement(e);
path = getTreePath(encl);
}
CompilationUnitTree cu = path.getCompilationUnit();
LineMap lineMap = cu.getLineMap();
DocSourcePositions spos = docTrees.getSourcePositions();
long pos = spos.getStartPosition(cu, path.getLeaf());
return lineMap.getLineNumber(pos);
}
示例5: testStatement
import com.sun.source.tree.CompilationUnitTree; //導入方法依賴的package包/類
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;
}