use of com.intellij.psi.javadoc.PsiDocTag in project intellij-community by JetBrains.
the class PsiDocTagValueImpl method getReference.
@Override
public PsiReference getReference() {
PsiDocTag docTag = PsiTreeUtil.getParentOfType(this, PsiDocTag.class);
if (docTag == null) {
return null;
}
final String name = docTag.getName();
final JavadocManager manager = JavadocManager.SERVICE.getInstance(getProject());
final JavadocTagInfo info = manager.getTagInfo(name);
if (info == null)
return null;
return info.getReference(this);
}
use of com.intellij.psi.javadoc.PsiDocTag in project intellij-community by JetBrains.
the class JavaSuppressionUtil method getSuppressedInspectionIdsIn.
public static String getSuppressedInspectionIdsIn(@NotNull PsiElement element) {
if (element instanceof PsiComment) {
String text = element.getText();
Matcher matcher = SuppressionUtil.SUPPRESS_IN_LINE_COMMENT_PATTERN.matcher(text);
if (matcher.matches()) {
return matcher.group(1).trim();
}
}
if (element instanceof PsiJavaDocumentedElement) {
PsiDocComment docComment = ((PsiJavaDocumentedElement) element).getDocComment();
if (docComment != null) {
PsiDocTag inspectionTag = docComment.findTagByName(SuppressionUtilCore.SUPPRESS_INSPECTIONS_TAG_NAME);
if (inspectionTag != null) {
String valueText = "";
for (PsiElement dataElement : inspectionTag.getDataElements()) {
valueText += dataElement.getText();
}
return valueText;
}
}
}
if (element instanceof PsiModifierListOwner) {
Collection<String> suppressedIds = getInspectionIdsSuppressedInAnnotation((PsiModifierListOwner) element);
return suppressedIds.isEmpty() ? null : StringUtil.join(suppressedIds, ",");
}
return null;
}
use of com.intellij.psi.javadoc.PsiDocTag in project intellij-community by JetBrains.
the class JavadocParamTagsTest method testAddTag2.
public void testAddTag2() throws Exception {
final PsiElementFactory factory = getFactory();
final PsiMethod method = factory.createMethodFromText("/**\n" + " * Javadoc\n" + " * @param p1\n" + " */\n" + "void m();", null);
final PsiDocComment docComment = method.getDocComment();
assertNotNull(docComment);
final PsiDocTag[] tags = docComment.getTags();
final PsiDocTag tag2 = factory.createParamTag("p2", "");
docComment.addBefore(tag2, tags[0]);
assertEquals("/**\n" + " * Javadoc\n" + " * @param p2\n" + " * @param p1\n" + " */", docComment.getText());
}
use of com.intellij.psi.javadoc.PsiDocTag in project intellij-community by JetBrains.
the class JavadocParamTagsTest method testDeleteTag2.
public void testDeleteTag2() throws Exception {
final PsiElementFactory factory = getFactory();
final PsiMethod method = factory.createMethodFromText("/**\n" + " * Javadoc\n" + " * @param p1\n" + " * @param p2\n" + " */" + " void m() {}", null);
final PsiDocComment docComment = method.getDocComment();
assertNotNull(docComment);
final PsiDocTag[] tags = docComment.getTags();
ApplicationManager.getApplication().runWriteAction(() -> tags[1].delete());
assertEquals("/**\n" + " * Javadoc\n" + " * @param p1\n" + " */", docComment.getText());
}
use of com.intellij.psi.javadoc.PsiDocTag in project intellij-community by JetBrains.
the class JavaIntroduceParameterMethodUsagesProcessor method processChangeMethodSignature.
public boolean processChangeMethodSignature(IntroduceParameterData data, UsageInfo usage, UsageInfo[] usages) throws IncorrectOperationException {
if (!(usage.getElement() instanceof PsiMethod) || !isJavaUsage(usage))
return true;
PsiMethod method = (PsiMethod) usage.getElement();
final FieldConflictsResolver fieldConflictsResolver = new FieldConflictsResolver(data.getParameterName(), method.getBody());
final MethodJavaDocHelper javaDocHelper = new MethodJavaDocHelper(method);
PsiElementFactory factory = JavaPsiFacade.getInstance(data.getProject()).getElementFactory();
final PsiClass superClass = data.getMethodToSearchFor().getContainingClass();
final PsiClass containingClass = method.getContainingClass();
final PsiSubstitutor substitutor = superClass != null && containingClass != null ? TypeConversionUtil.getSuperClassSubstitutor(superClass, containingClass, PsiSubstitutor.EMPTY) : PsiSubstitutor.EMPTY;
PsiParameter parameter = factory.createParameter(data.getParameterName(), substitutor.substitute(data.getForcedType()));
PsiUtil.setModifierProperty(parameter, PsiModifier.FINAL, data.isDeclareFinal());
final PsiParameterList parameterList = method.getParameterList();
final PsiParameter[] parameters = parameterList.getParameters();
data.getParametersToRemove().forEachDescending(new TIntProcedure() {
public boolean execute(final int paramNum) {
try {
PsiParameter param = parameters[paramNum];
PsiDocTag tag = javaDocHelper.getTagForParameter(param);
if (tag != null) {
tag.delete();
}
param.delete();
} catch (IncorrectOperationException e) {
LOG.error(e);
}
return true;
}
});
final PsiParameter anchorParameter = getAnchorParameter(method);
parameter = (PsiParameter) parameterList.addAfter(parameter, anchorParameter);
JavaCodeStyleManager.getInstance(data.getProject()).shortenClassReferences(parameter);
final PsiDocTag tagForAnchorParameter = javaDocHelper.getTagForParameter(anchorParameter);
javaDocHelper.addParameterAfter(data.getParameterName(), tagForAnchorParameter);
fieldConflictsResolver.fix();
return false;
}
Aggregations