本文整理汇总了Java中com.sun.source.util.DocTrees.getSourcePositions方法的典型用法代码示例。如果您正苦于以下问题:Java DocTrees.getSourcePositions方法的具体用法?Java DocTrees.getSourcePositions怎么用?Java DocTrees.getSourcePositions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.source.util.DocTrees
的用法示例。
在下文中一共展示了DocTrees.getSourcePositions方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitIdentifier
import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
@Override
public DocTree visitIdentifier(com.sun.source.doctree.IdentifierTree node, Element p) {
DocTrees trees = info.getDocTrees();
Element el = trees.getElement(getCurrentPath());
if (el != null && el.equals(toFind)) {
DocSourcePositions sp = trees.getSourcePositions();
CompilationUnitTree cut = info.getCompilationUnit();
DocCommentTree docComment = getCurrentPath().getDocComment();
long start = sp.getStartPosition(cut, docComment, node);
long end = sp.getEndPosition(cut, docComment, node);
if(start != Diagnostic.NOPOS && end != Diagnostic.NOPOS) {
try {
MutablePositionRegion region = createRegion(doc, (int)start, (int)end);
usages.add(region);
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
}
}
}
return super.visitIdentifier(node, p);
}
示例2: run
import com.sun.source.util.DocTrees; //导入方法依赖的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;
}
示例3: run
import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
public boolean run(DocletEnvironment root) {
DocTrees trees = root.getDocTrees();
SourcePositions sourcePositions = trees.getSourcePositions();
for (TypeElement klass : root.getIncludedClasses()) {
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;
}
示例4: visitText
import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
@Override
public DocTree visitText(TextTree node, Element p) {
if(searchComment) {
DocTrees trees = info.getDocTrees();
DocSourcePositions sourcePositions = trees.getSourcePositions();
DocTreePath currentDocPath = getCurrentPath();
if(toFind.getKind() == ElementKind.PARAMETER) {
VariableElement var = (VariableElement) toFind;
Element method = trees.getElement(currentDocPath);
if(!var.getEnclosingElement().equals(method)) {
return super.visitText(node, p);
}
}
String text = node.getBody();
String name = toFind.getSimpleName().toString();
if(text.contains(name)) {
int start = (int) sourcePositions.getStartPosition(info.getCompilationUnit(), currentDocPath.getDocComment(), node);
int length = name.length();
int offset = -1;
do {
offset = text.indexOf(name, ++offset);
if(offset != -1) {
try {
MutablePositionRegion region = createRegion(doc, start + offset, start + offset + length);
comments.add(region);
} catch(BadLocationException ex) {
Exceptions.printStackTrace(ex);
}
}
} while (offset != -1);
}
}
return super.visitText(node, p);
}
示例5: resolveContext
import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
private boolean resolveContext(CompilationInfo javac, JavadocContext jdctx) throws IOException {
jdctx.doc = javac.getDocument();
// find class context: class, method, ...
DocTrees trees = javac.getDocTrees();
TreePath javadocFor = JavadocCompletionUtils.findJavadoc(javac, this.caretOffset);
if (javadocFor == null) {
return false;
}
jdctx.javadocFor = javadocFor;
DocCommentTree docCommentTree = trees.getDocCommentTree(javadocFor);
if (docCommentTree == null) {
return false;
}
jdctx.comment = docCommentTree;
Element elm = trees.getElement(javadocFor);
if (elm == null) {
return false;
}
jdctx.handle = ElementHandle.create(elm);
jdctx.commentFor = elm;
jdctx.jdts = JavadocCompletionUtils.findJavadocTokenSequence(javac, this.caretOffset);
if (jdctx.jdts == null) {
return false;
}
jdctx.positions = (DocSourcePositions) trees.getSourcePositions();
return jdctx.positions != null;
}
示例6: Checker
import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
Checker(DocTrees trees) {
this.trees = trees;
srcPosns = trees.getSourcePositions();
}