本文整理汇总了Java中com.sun.source.util.DocSourcePositions类的典型用法代码示例。如果您正苦于以下问题:Java DocSourcePositions类的具体用法?Java DocSourcePositions怎么用?Java DocSourcePositions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DocSourcePositions类属于com.sun.source.util包,在下文中一共展示了DocSourcePositions类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitIdentifier
import com.sun.source.util.DocSourcePositions; //导入依赖的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: visitDocComment
import com.sun.source.util.DocSourcePositions; //导入依赖的package包/类
@Override
public Void visitDocComment(DocCommentTree node, List<ErrorDescription> errors) {
DocTreePath currentDocPath = getCurrentPath();
Void value = super.visitDocComment(node, errors);
DocSourcePositions sp = (DocSourcePositions) javac.getTrees().getSourcePositions();
while (!tagStack.isEmpty()) {
StartElementTree startTree = tagStack.pop();
Name tagName = startTree.getName();
HtmlTag tag = HtmlTag.get(tagName);
if (tag.endKind == HtmlTag.EndKind.REQUIRED) {
int s = (int) sp.getStartPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), startTree);
int e = (int) sp.getEndPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), startTree);
errors.add(ErrorDescriptionFactory.forSpan(ctx, s, e, TAG_START_UNMATCHED(tagName)));
}
}
return value;
}
示例3: visitText
import com.sun.source.util.DocSourcePositions; //导入依赖的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);
}
示例4: resolveContext
import com.sun.source.util.DocSourcePositions; //导入依赖的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;
}
示例5: visitReturn
import com.sun.source.util.DocSourcePositions; //导入依赖的package包/类
@Override
@NbBundle.Messages({"[email protected] tag cannot be used in method with void return type.",
"WRONG_CONSTRUCTOR_RETURN_DESC=Illegal @return tag.",
"DUPLICATE_RETURN_DESC=Duplicate @return tag."})
public Void visitReturn(ReturnTree node, List<ErrorDescription> errors) {
boolean oldInheritDoc = foundInheritDoc;
DocTreePath currentDocPath = getCurrentPath();
DocTreePathHandle dtph = DocTreePathHandle.create(currentDocPath, javac);
if(dtph == null) {
return null;
}
DocSourcePositions sp = (DocSourcePositions) javac.getTrees().getSourcePositions();
int start = (int) sp.getStartPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), node);
int end = (int) sp.getEndPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), node);
if(returnType == null) {
errors.add(ErrorDescriptionFactory.forSpan(ctx, start, end, WRONG_CONSTRUCTOR_RETURN_DESC(),
new RemoveTagFix(dtph, "@return").toEditorFix()));
} else if (returnType.getKind() == TypeKind.VOID) {
errors.add(ErrorDescriptionFactory.forSpan(ctx, start, end, WRONG_RETURN_DESC(),
new RemoveTagFix(dtph, "@return").toEditorFix()));
} else if(returnTypeFound) {
errors.add(ErrorDescriptionFactory.forSpan(ctx, start, end, DUPLICATE_RETURN_DESC(),
new RemoveTagFix(dtph, "@return").toEditorFix()));
} else {
returnTypeFound = true;
}
super.visitReturn(node, errors);
foundInheritDoc = oldInheritDoc;
return null;
}
示例6: visitStartElement
import com.sun.source.util.DocSourcePositions; //导入依赖的package包/类
@Override
@Messages({"# {0} - Tag name",
"TAG_UNKNOWN=Unknown HTML Tag: <{0}>",
"# {0} - Tag name",
"TAG_END_UNKNOWN=Unknown HTML End Tag: </{0}>",
"TAG_SELF_CLOSING=Self-closing element not allowed"})
public Void visitStartElement(StartElementTree node, List<ErrorDescription> errors) {
DocTreePath currentDocPath = getCurrentPath();
DocTreePathHandle dtph = DocTreePathHandle.create(currentDocPath, javac);
if(dtph == null) {
return null;
}
DocSourcePositions sp = (DocSourcePositions) javac.getTrees().getSourcePositions();
int start = (int) sp.getStartPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), node);
int end = (int) sp.getEndPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), node);
final Name treeName = node.getName();
final HtmlTag t = HtmlTag.get(treeName);
if (t == null) {
errors.add(ErrorDescriptionFactory.forSpan(ctx, start, end, TAG_UNKNOWN(treeName)));
} else {
if(t.endKind != HtmlTag.EndKind.NONE) {
tagStack.push(node);
}
}
if (node.isSelfClosing()) {
errors.add(ErrorDescriptionFactory.forSpan(ctx, start, end, TAG_SELF_CLOSING()));
}
return super.visitStartElement(node, errors);
}
示例7: getDiagSource
import com.sun.source.util.DocSourcePositions; //导入依赖的package包/类
private String getDiagSource(DocTreePath path) {
if (path == null || path.getTreePath() == null) {
return programName;
}
JavacTrees trees = JavacTrees.instance(context);
DocSourcePositions sourcePositions = trees.getSourcePositions();
CompilationUnitTree cu = path.getTreePath().getCompilationUnit();
long spos = sourcePositions.getStartPosition(cu, path.getDocComment(), path.getLeaf());
long lineNumber = cu.getLineMap().getLineNumber(spos);
String fname = cu.getSourceFile().getName();
String posString = fname + ":" + lineNumber;
return posString;
}
示例8: getLineNumber
import com.sun.source.util.DocSourcePositions; //导入依赖的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);
}
示例9: getDiagSource
import com.sun.source.util.DocSourcePositions; //导入依赖的package包/类
private String getDiagSource(DocTreePath path) {
if (path == null) {
return programName;
}
JavacTrees trees = JavacTrees.instance(context);
DocSourcePositions sourcePositions = trees.getSourcePositions();
CompilationUnitTree cu = path.getTreePath().getCompilationUnit();
long spos = sourcePositions.getStartPosition(cu, path.getDocComment(), path.getLeaf());
long lineNumber = cu.getLineMap().getLineNumber(spos);
String fname = cu.getSourceFile().getName();
String posString = fname + ":" + lineNumber;
return posString;
}
示例10: endPos
import com.sun.source.util.DocSourcePositions; //导入依赖的package包/类
public int endPos(DCTree oldT, DCDocComment doc) {
DocSourcePositions sp = JavacTrees.instance(context).getSourcePositions();
return (int) sp.getEndPosition(null, doc, oldT);
}
示例11: getSourcePositions
import com.sun.source.util.DocSourcePositions; //导入依赖的package包/类
@Override
public DocSourcePositions getSourcePositions() {
return delegate.getSourcePositions();
}
示例12: visitEndElement
import com.sun.source.util.DocSourcePositions; //导入依赖的package包/类
@Override
@Messages({"# {0} - Tag Name", "TAG_END_NOT_PERMITTED=Invalid End Tag: </{0}>",
"# {0} - Tag Name", "TAG_END_UNEXPECTED=Unexpected End Tag: </{0}>",
"# {0} - Tag Name", "TAG_START_UNMATCHED=End Tag Missing: </{0}>"})
public Void visitEndElement(EndElementTree node, List<ErrorDescription> errors) {
DocTreePath currentDocPath = getCurrentPath();
DocTreePathHandle dtph = DocTreePathHandle.create(currentDocPath, javac);
if(dtph == null) {
return null;
}
DocSourcePositions sp = (DocSourcePositions) javac.getTrees().getSourcePositions();
int start = (int) sp.getStartPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), node);
int end = (int) sp.getEndPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), node);
final Name treeName = node.getName();
final HtmlTag t = HtmlTag.get(treeName);
if (t == null) {
errors.add(ErrorDescriptionFactory.forSpan(ctx, start, end, TAG_END_UNKNOWN(treeName)));
} else if (t.endKind == HtmlTag.EndKind.NONE) {
// env.messages.error(HTML, node, "dc.tag.end.not.permitted", treeName);
errors.add(ErrorDescriptionFactory.forSpan(ctx, start, end, TAG_END_NOT_PERMITTED(treeName)));
} else {
boolean done = false;
while (!tagStack.isEmpty()) {
StartElementTree startTree = tagStack.peek();
Name tagName = startTree.getName();
HtmlTag tag = HtmlTag.get(tagName);
if (t == tag) {
tagStack.pop();
done = true;
break;
} else if (tag.endKind != HtmlTag.EndKind.REQUIRED) {
tagStack.pop();
} else {
boolean found = false;
for (StartElementTree set : tagStack) {
HtmlTag si = HtmlTag.get(set.getName());
if (si == t) {
found = true;
break;
}
}
if (found) {
int s = (int) sp.getStartPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), startTree);
int e = (int) sp.getEndPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), startTree);
errors.add(ErrorDescriptionFactory.forSpan(ctx, s, e, TAG_START_UNMATCHED(tagName)));
tagStack.pop();
} else {
errors.add(ErrorDescriptionFactory.forSpan(ctx, start, end, TAG_END_UNEXPECTED(treeName)));
done = true;
break;
}
}
}
if (!done && tagStack.isEmpty()) {
errors.add(ErrorDescriptionFactory.forSpan(ctx, start, end, TAG_END_UNEXPECTED(treeName)));
}
}
return super.visitEndElement(node, errors);
}
示例13: visitParam
import com.sun.source.util.DocSourcePositions; //导入依赖的package包/类
@Override
@NbBundle.Messages({"# {0} - tag name", "# {1} - element type", "INVALID_TAG_DESC={0} tag cannot be used on {1}."})
public Void visitParam(ParamTree tree, List<ErrorDescription> errors) {
boolean oldInheritDoc = foundInheritDoc;
DocTreePath currentDocPath = getCurrentPath();
DocTreePathHandle dtph = DocTreePathHandle.create(currentDocPath, javac);
if(dtph == null) {
return null;
}
DocSourcePositions sp = (DocSourcePositions) javac.getTrees().getSourcePositions();
int start = (int) sp.getStartPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), tree);
int end = (int) sp.getEndPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), tree);
if(ctx.isCanceled()) { return null; }
boolean typaram = tree.isTypeParameter();
switch (currentElement.getKind()) {
case METHOD:
case CONSTRUCTOR: {
ExecutableElement ee = (ExecutableElement) currentElement;
checkParamDeclared(tree, typaram ? ee.getTypeParameters() : ee.getParameters(), dtph, start, end, errors);
break;
}
case CLASS:
case INTERFACE: {
TypeElement te = (TypeElement) currentElement;
if (typaram) {
checkParamDeclared(tree, te.getTypeParameters(), dtph, start, end, errors);
} else {
errors.add(ErrorDescriptionFactory.forSpan(ctx, start, end, INVALID_TAG_DESC("@param", currentElement.getKind()), new RemoveTagFix(dtph, "@param").toEditorFix())); //NOI18N
// env.messages.error(REFERENCE, tree, "dc.invalid.param");
}
break;
}
default:
errors.add(ErrorDescriptionFactory.forSpan(ctx, start, end, INVALID_TAG_DESC("@param", currentElement.getKind()), new RemoveTagFix(dtph, "@param").toEditorFix())); //NOI18N
// env.messages.error(REFERENCE, tree, "dc.invalid.param");
break;
}
warnIfEmpty(tree, tree.getDescription());
super.visitParam(tree, errors);
foundInheritDoc = oldInheritDoc;
return null;
}
示例14: visitThrows
import com.sun.source.util.DocSourcePositions; //导入依赖的package包/类
@Override
public Void visitThrows(ThrowsTree tree, List<ErrorDescription> errors) {
boolean oldInheritDoc = foundInheritDoc;
ReferenceTree exName = tree.getExceptionName();
DocTreePath refPath = new DocTreePath(getCurrentPath(), tree.getExceptionName());
Element ex = javac.getDocTrees().getElement(refPath);
Types types = javac.getTypes();
Elements elements = javac.getElements();
final TypeElement throwableEl = elements.getTypeElement("java.lang.Throwable");
final TypeElement errorEl = elements.getTypeElement("java.lang.Error");
final TypeElement runtimeEl = elements.getTypeElement("java.lang.RuntimeException");
if(throwableEl == null || errorEl == null || runtimeEl == null) {
LOG.warning("Broken java-platform, cannot resolve " + throwableEl == null? "java.lang.Throwable" : errorEl == null? "java.lang.Error" : "java.lang.RuntimeException"); //NOI18N
return null;
}
TypeMirror throwable = throwableEl.asType();
TypeMirror error = errorEl.asType();
TypeMirror runtime = runtimeEl.asType();
DocTreePath currentDocPath = getCurrentPath();
DocTreePathHandle dtph = DocTreePathHandle.create(currentDocPath, javac);
if(dtph == null) {
return null;
}
DocSourcePositions sp = (DocSourcePositions) javac.getTrees().getSourcePositions();
int start = (int) sp.getStartPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), tree);
int end = (int) sp.getEndPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), tree);
if (ex == null || (ex.asType().getKind() == TypeKind.DECLARED
&& types.isAssignable(ex.asType(), throwable))) {
switch (currentElement.getKind()) {
case CONSTRUCTOR:
case METHOD:
if (ex == null || !(types.isAssignable(ex.asType(), error)
|| types.isAssignable(ex.asType(), runtime))) {
ExecutableElement ee = (ExecutableElement) currentElement;
String fqn;
if (ex != null) {
fqn = ((TypeElement) ex).getQualifiedName().toString();
} else {
ExpressionTree referenceClass = javac.getTreeUtilities().getReferenceClass(new DocTreePath(currentDocPath, exName));
if(referenceClass == null) break;
fqn = referenceClass.toString();
}
checkThrowsDeclared(tree, ex, fqn, ee.getThrownTypes(), dtph, start, end, errors);
}
break;
default:
// env.messages.error(REFERENCE, tree, "dc.invalid.throws");
}
} else {
// env.messages.error(REFERENCE, tree, "dc.invalid.throws");
}
warnIfEmpty(tree, tree.getDescription());
super.visitThrows(tree, errors);
foundInheritDoc = oldInheritDoc;
return null;
}