本文整理汇总了Java中com.intellij.psi.javadoc.PsiDocComment.findTagsByName方法的典型用法代码示例。如果您正苦于以下问题:Java PsiDocComment.findTagsByName方法的具体用法?Java PsiDocComment.findTagsByName怎么用?Java PsiDocComment.findTagsByName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.javadoc.PsiDocComment
的用法示例。
在下文中一共展示了PsiDocComment.findTagsByName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isApplicable
import com.intellij.psi.javadoc.PsiDocComment; //导入方法依赖的package包/类
public static boolean isApplicable(@NotNull PsiJavaCodeReferenceElement reference) {
final PsiElement parent = reference.getParent();
final PsiElement grandParent = parent.getParent();
if (!(grandParent instanceof PsiMethod)) {
return false;
}
final PsiMethod method = (PsiMethod)grandParent;
final PsiDocComment docComment = method.getDocComment();
if (docComment == null) {
return true;
}
final PsiElement throwsTarget = reference.resolve();
if (throwsTarget == null) {
return true;
}
final PsiDocTag[] tags = docComment.findTagsByName("throws");
for (PsiDocTag tag : tags) {
final PsiDocTagValue valueElement = tag.getValueElement();
if (valueElement == null) {
continue;
}
final PsiElement child = valueElement.getFirstChild();
if (child == null) {
continue;
}
final PsiElement grandChild = child.getFirstChild();
if (!(grandChild instanceof PsiJavaCodeReferenceElement)) {
continue;
}
final PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)grandChild;
final PsiElement target = referenceElement.resolve();
if (throwsTarget.equals(target)) {
return false;
}
}
return true;
}
示例2: generateParametersTakingDocFromSuperMethods
import com.intellij.psi.javadoc.PsiDocComment; //导入方法依赖的package包/类
public static void generateParametersTakingDocFromSuperMethods(Project project,
StringBuilder builder,
CodeDocumentationAwareCommenter commenter, PsiMethod psiMethod) {
final PsiParameter[] parameters = psiMethod.getParameterList().getParameters();
final Map<String, String> param2Description = new HashMap<String, String>();
final PsiMethod[] superMethods = psiMethod.findSuperMethods();
for (PsiMethod superMethod : superMethods) {
final PsiDocComment comment = superMethod.getDocComment();
if (comment != null) {
final PsiDocTag[] params = comment.findTagsByName("param");
for (PsiDocTag param : params) {
final PsiElement[] dataElements = param.getDataElements();
if (dataElements != null) {
String paramName = null;
for (PsiElement dataElement : dataElements) {
if (dataElement instanceof PsiDocParamRef) {
//noinspection ConstantConditions
paramName = dataElement.getReference().getCanonicalText();
break;
}
}
if (paramName != null) {
param2Description.put(paramName, param.getText());
}
}
}
}
}
for (PsiParameter parameter : parameters) {
String description = param2Description.get(parameter.getName());
if (description != null) {
builder.append(CodeDocumentationUtil.createDocCommentLine("", project, commenter));
if (description.indexOf('\n') > -1) description = description.substring(0, description.lastIndexOf('\n'));
builder.append(description);
}
else {
builder.append(CodeDocumentationUtil.createDocCommentLine(PARAM_TAG, project, commenter));
builder.append(parameter.getName());
}
builder.append(LINE_SEPARATOR);
}
}