本文整理汇总了Java中com.sun.source.util.DocTreePath.getLeaf方法的典型用法代码示例。如果您正苦于以下问题:Java DocTreePath.getLeaf方法的具体用法?Java DocTreePath.getLeaf怎么用?Java DocTreePath.getLeaf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.source.util.DocTreePath
的用法示例。
在下文中一共展示了DocTreePath.getLeaf方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: performRewrite
import com.sun.source.util.DocTreePath; //导入方法依赖的package包/类
@Override
protected void performRewrite(TransformationContext ctx) throws Exception {
WorkingCopy javac = ctx.getWorkingCopy();
DocTreePath path = dtph.resolve(javac);
if(path == null) {
LOG.log(Level.WARNING, "Cannot resolve DocTreePathHandle: {0}", dtph);
return;
}
DocCommentTree docComment = path.getDocComment();
TreeMaker make = javac.getTreeMaker();
final List<DocTree> blockTags = new LinkedList<DocTree>();
for (DocTree docTree : docComment.getBlockTags()) {
if (docTree != path.getLeaf()) {
blockTags.add(docTree);
}
}
DocCommentTree newDoc = make.DocComment(docComment.getFirstSentence(), docComment.getBody(), blockTags);
Tree tree = ctx.getPath().getLeaf();
javac.rewrite(tree, docComment, newDoc);
}
示例2: qualifyDocReference
import com.sun.source.util.DocTreePath; //导入方法依赖的package包/类
/**
* Fully qualifies a javadoc reference, e.g. for replacing {@code {@link List}} with {@code {@link
* java.util.List}}
*
* @param fix the fix builder to add to
* @param docPath the path to a {@link DCTree.DCReference} element
*/
public static void qualifyDocReference(
SuggestedFix.Builder fix, DocTreePath docPath, VisitorState state) {
DocTree leaf = docPath.getLeaf();
checkArgument(
leaf.getKind() == DocTree.Kind.REFERENCE,
"expected a path to a reference, got %s instead",
leaf.getKind());
DCTree.DCReference reference = (DCTree.DCReference) leaf;
Symbol sym = (Symbol) JavacTrees.instance(state.context).getElement(docPath);
if (sym == null) {
return;
}
String refString = reference.toString();
String qualifiedName;
int idx = refString.indexOf('#');
if (idx >= 0) {
qualifiedName = sym.owner.getQualifiedName() + refString.substring(idx, refString.length());
} else {
qualifiedName = sym.getQualifiedName().toString();
}
replaceDocTree(fix, docPath, qualifiedName);
}
示例3: getReferenceClass
import com.sun.source.util.DocTreePath; //导入方法依赖的package包/类
/**Find the type (the part before {@code #}) that is being referenced by the given {@link ReferenceTree}.
*
* @param path the leaf must be {@link ReferenceTree}
* @return the referred type, or {@code null} if none.
* @since 0.124
*/
public @CheckForNull ExpressionTree getReferenceClass(@NonNull DocTreePath path) {
TreePath tp = path.getTreePath();
DCReference ref = (DCReference) path.getLeaf();
((DocTrees) this.info.getTrees()).getElement(path);
// was:
// ((JavacTrees) this.info.getTrees()).ensureDocReferenceAttributed(tp, ref);
return (ExpressionTree) ref.qualifierExpression;
}
示例4: getReferenceParameters
import com.sun.source.util.DocTreePath; //导入方法依赖的package包/类
/**Find the parameters that are specified in the given {@link ReferenceTree}.
*
* @param path the leaf must be {@link ReferenceTree}
* @return the parameters for the referred method, or {@code null} if none.
* @since 0.124
*/
public @CheckForNull List<? extends Tree> getReferenceParameters(@NonNull DocTreePath path) {
TreePath tp = path.getTreePath();
DCReference ref = (DCReference) path.getLeaf();
((DocTrees) this.info.getTrees()).getElement(path);
// was:
// ((JavacTrees) this.info.getTrees()).ensureDocReferenceAttributed(tp, ref);
return ref.paramTypes;
}
示例5: getElement
import com.sun.source.util.DocTreePath; //导入方法依赖的package包/类
@Override
public Element getElement(DocTreePath path) {
DocTree forTree = path.getLeaf();
if (forTree instanceof DCReference)
return attributeDocReference(path.getTreePath(), ((DCReference) forTree));
if (forTree instanceof DCIdentifier) {
if (path.getParentPath().getLeaf() instanceof DCParam) {
return attributeParamIdentifier(path.getTreePath(), (DCParam) path.getParentPath().getLeaf());
}
}
return null;
}
示例6: getElement
import com.sun.source.util.DocTreePath; //导入方法依赖的package包/类
@Override @DefinedBy(Api.COMPILER_TREE)
public Element getElement(DocTreePath path) {
DocTree forTree = path.getLeaf();
if (forTree instanceof DCReference)
return attributeDocReference(path.getTreePath(), ((DCReference) forTree));
if (forTree instanceof DCIdentifier) {
if (path.getParentPath().getLeaf() instanceof DCParam) {
return attributeParamIdentifier(path.getTreePath(), (DCParam) path.getParentPath().getLeaf());
}
}
return null;
}
示例7: replaceDocTree
import com.sun.source.util.DocTreePath; //导入方法依赖的package包/类
/** Replaces the leaf doctree in the given path with {@code replacement}. */
public static void replaceDocTree(
SuggestedFix.Builder fix, DocTreePath docPath, String replacement) {
DocTree leaf = docPath.getLeaf();
checkArgument(
leaf instanceof DCTree.DCEndPosTree, "no end position information for %s", leaf.getKind());
DCTree.DCEndPosTree<?> node = (DCTree.DCEndPosTree<?>) leaf;
DCTree.DCDocComment comment = (DCTree.DCDocComment) docPath.getDocComment();
fix.replace((int) node.getSourcePosition(comment), node.getEndPos(comment), replacement);
}
示例8: getReferenceName
import com.sun.source.util.DocTreePath; //导入方法依赖的package包/类
/**Find the name (the name after {@code #}) that is being referenced by the given {@link ReferenceTree}.
*
* @param path the leaf must be {@link ReferenceTree}
* @return the referred member name, or {@code null} if none.
* @since 0.124
*/
public @CheckForNull Name getReferenceName(@NonNull DocTreePath path) {
return ((DCReference) path.getLeaf()).memberName;
}