use of com.intellij.psi.javadoc.PsiDocTag in project intellij-community by JetBrains.
the class RemoveSuppressWarningAction method removeFromJavaDoc.
private void removeFromJavaDoc(PsiDocComment docComment) throws IncorrectOperationException {
PsiDocTag tag = docComment.findTagByName(SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME);
if (tag == null)
return;
String newText = removeFromElementText(tag.getDataElements());
if (newText != null && newText.isEmpty()) {
tag.delete();
} else if (newText != null) {
newText = "@" + SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME + " " + newText;
PsiDocTag newTag = JavaPsiFacade.getInstance(tag.getProject()).getElementFactory().createDocTagFromText(newText);
tag.replace(newTag);
}
}
use of com.intellij.psi.javadoc.PsiDocTag in project intellij-community by JetBrains.
the class MethodJavaDocHelper method appendParameter.
public PsiDocTag appendParameter(String name) throws IncorrectOperationException {
if (!myDoCorrectJavaDoc)
return null;
final PsiDocTag[] paramTags = myDocComment.findTagsByName("param");
final PsiDocTag newTag = JavaPsiFacade.getInstance(myMethod.getProject()).getElementFactory().createParamTag(name, "");
if (paramTags.length > 0) {
return (PsiDocTag) myDocComment.addAfter(newTag, paramTags[paramTags.length - 1]);
} else {
return (PsiDocTag) myDocComment.add(newTag);
}
}
use of com.intellij.psi.javadoc.PsiDocTag in project intellij-community by JetBrains.
the class MethodJavaDocHelper method addParameterAfter.
public PsiDocTag addParameterAfter(String name, PsiDocTag anchor) throws IncorrectOperationException {
if (!myDoCorrectJavaDoc)
return null;
if (anchor == null)
return prependParameter(name);
LOG.assertTrue(anchor.getParent() == myDocComment);
final PsiDocTag paramTag = JavaPsiFacade.getInstance(myMethod.getProject()).getElementFactory().createParamTag(name, "");
return (PsiDocTag) myDocComment.addAfter(paramTag, anchor);
}
use of com.intellij.psi.javadoc.PsiDocTag in project intellij-community by JetBrains.
the class RefactoringUtil method fixJavadocsForParams.
public static void fixJavadocsForParams(PsiMethod method, Set<PsiParameter> newParameters, Condition<Pair<PsiParameter, String>> eqCondition, Condition<String> matchedToOldParam) throws IncorrectOperationException {
final PsiDocComment docComment = method.getDocComment();
if (docComment == null)
return;
final PsiParameter[] parameters = method.getParameterList().getParameters();
final PsiDocTag[] paramTags = docComment.findTagsByName("param");
if (parameters.length > 0 && newParameters.size() < parameters.length && paramTags.length == 0)
return;
Map<PsiParameter, PsiDocTag> tagForParam = new HashMap<>();
for (PsiParameter parameter : parameters) {
boolean found = false;
for (PsiDocTag paramTag : paramTags) {
if (parameter.getName().equals(getNameOfReferencedParameter(paramTag))) {
tagForParam.put(parameter, paramTag);
found = true;
break;
}
}
if (!found) {
for (PsiDocTag paramTag : paramTags) {
final String paramName = getNameOfReferencedParameter(paramTag);
if (eqCondition.value(Pair.create(parameter, paramName))) {
tagForParam.put(parameter, paramTag);
found = true;
break;
}
}
}
if (!found && !newParameters.contains(parameter)) {
tagForParam.put(parameter, null);
}
}
List<PsiDocTag> newTags = new ArrayList<>();
for (PsiDocTag paramTag : paramTags) {
final String paramName = getNameOfReferencedParameter(paramTag);
if (!tagForParam.containsValue(paramTag) && !matchedToOldParam.value(paramName)) {
newTags.add((PsiDocTag) paramTag.copy());
}
}
for (PsiParameter parameter : parameters) {
if (tagForParam.containsKey(parameter)) {
final PsiDocTag psiDocTag = tagForParam.get(parameter);
if (psiDocTag != null) {
final PsiDocTag copy = (PsiDocTag) psiDocTag.copy();
final PsiDocTagValue valueElement = copy.getValueElement();
if (valueElement != null) {
valueElement.replace(createParamTag(parameter).getValueElement());
}
newTags.add(copy);
}
} else {
newTags.add(createParamTag(parameter));
}
}
PsiElement anchor = paramTags.length > 0 ? paramTags[0].getPrevSibling() : null;
for (PsiDocTag paramTag : paramTags) {
paramTag.delete();
}
for (PsiDocTag psiDocTag : newTags) {
anchor = anchor != null && anchor.isValid() ? docComment.addAfter(psiDocTag, anchor) : docComment.add(psiDocTag);
}
}
use of com.intellij.psi.javadoc.PsiDocTag in project intellij-community by JetBrains.
the class JavaDocCommentFixer method locateCaret.
private static void locateCaret(@NotNull PsiDocComment comment, @NotNull Editor editor, @NotNull PsiFile file) {
Document document = editor.getDocument();
int lineToNavigate = -1;
for (PsiDocTag tag : comment.getTags()) {
PsiElement nameElement = tag.getNameElement();
if (nameElement == null || !CARET_ANCHOR_TAGS.contains(nameElement.getText())) {
continue;
}
boolean good = false;
PsiElement[] dataElements = tag.getDataElements();
if (dataElements != null) {
PsiDocTagValue valueElement = tag.getValueElement();
for (PsiElement element : dataElements) {
if (element == valueElement) {
continue;
}
if (!StringUtil.isEmptyOrSpaces(element.getText())) {
good = true;
break;
}
}
}
if (!good) {
int offset = tag.getTextRange().getEndOffset();
CharSequence text = document.getCharsSequence();
int i = CharArrayUtil.shiftBackward(text, offset - 1, " \t*");
if (i > 0 && text.charAt(i) == '\n') {
offset = i - 1;
}
lineToNavigate = document.getLineNumber(offset);
break;
}
}
if (lineToNavigate >= 0) {
editor.getCaretModel().moveToOffset(document.getLineEndOffset(lineToNavigate));
JavadocNavigationDelegate.navigateToLineEnd(editor, file);
}
}
Aggregations