mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
IDEA-379405 javadoc: mk references are now properly highlighted in red when they aren't found.
Also merged some strangely similar code logic from the RemoveTagFix. #IDEA-379405 Fixed GitOrigin-RevId: d5415909ceb45589cd68c0e4e4e572cd66e209e6
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ab118c5eab
commit
f4d1cc8f2d
@@ -146,6 +146,11 @@ public final class JavaDocReferenceInspection extends LocalInspectionTool {
|
||||
super.visitDocTag(tag);
|
||||
visitRefInDocTag(tag, javadocManager, context, holder, isOnTheFly);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitMarkdownReferenceLink(@NotNull PsiMarkdownReferenceLink referenceLink) {
|
||||
visitMarkdownReference(referenceLink, context, holder, isOnTheFly);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -184,6 +189,31 @@ public final class JavaDocReferenceInspection extends LocalInspectionTool {
|
||||
element, message, fix, ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, isOnTheFly));
|
||||
}
|
||||
}
|
||||
|
||||
private void visitMarkdownReference(PsiMarkdownReferenceLink referenceLink, PsiElement context, ProblemsHolder holder, boolean isOnTheFly) {
|
||||
PsiElement linkElement = referenceLink.getLinkElement();
|
||||
if (linkElement == null) return;
|
||||
PsiReference reference = linkElement.getReference();
|
||||
if (reference == null) return;
|
||||
PsiElement element = reference.resolve();
|
||||
|
||||
String linkText = linkElement.getText();
|
||||
String message = element == null && reference instanceof PsiPolyVariantReference ?
|
||||
getResolveErrorMessage(((PsiPolyVariantReference)reference).multiResolve(false), context, linkText) :
|
||||
getResolveErrorMessage(element, context, linkText);
|
||||
if (message == null) return;
|
||||
|
||||
List<LocalQuickFix> fixes = new ArrayList<>(2);
|
||||
fixes.add(new RemoveReferenceFix(linkText));
|
||||
|
||||
if (isOnTheFly && element != null && REPORT_INACCESSIBLE) {
|
||||
fixes.add(LocalQuickFix.from(new UpdateInspectionOptionFix(
|
||||
this, "REPORT_INACCESSIBLE", JavaBundle.message("disable.report.inaccessible.symbols.fix"), false)));
|
||||
}
|
||||
|
||||
holder.registerProblem(holder.getManager().createProblemDescriptor(
|
||||
linkElement, reference.getRangeInElement(), message, ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, isOnTheFly, fixes.toArray(LocalQuickFix.EMPTY_ARRAY)));
|
||||
}
|
||||
|
||||
private void visitRefInDocTag(PsiDocTag tag, JavadocManager manager, PsiElement context, ProblemsHolder holder, boolean isOnTheFly) {
|
||||
PsiDocTagValue value = tag.getValueElement();
|
||||
@@ -380,31 +410,29 @@ public final class JavaDocReferenceInspection extends LocalInspectionTool {
|
||||
}
|
||||
}
|
||||
|
||||
private static class RemoveTagFix extends PsiUpdateModCommandQuickFix {
|
||||
private final String myTagName;
|
||||
private final String myParamName;
|
||||
/// *"Fix"* that simply remove the Markdown reference and its label
|
||||
private static class RemoveReferenceFix extends PsiUpdateModCommandQuickFix {
|
||||
private final String referenceName;
|
||||
|
||||
RemoveTagFix(String tagName, String paramName) {
|
||||
myTagName = tagName;
|
||||
myParamName = paramName;
|
||||
RemoveReferenceFix(String referenceName) {
|
||||
this.referenceName = referenceName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getName() {
|
||||
return JavaBundle.message("quickfix.text.remove.javadoc.0.1", myTagName, myParamName);
|
||||
return JavaBundle.message("quickfix.text.remove.javadoc.reference", referenceName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getFamilyName() {
|
||||
return JavaBundle.message("quickfix.family.remove.javadoc.tag");
|
||||
return JavaBundle.message("quickfix.family.remove.javadoc.reference");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) {
|
||||
PsiDocTag myTag = PsiTreeUtil.getParentOfType(element, PsiDocTag.class);
|
||||
if (myTag != null) {
|
||||
myTag.delete();
|
||||
}
|
||||
PsiMarkdownReferenceLink link = PsiTreeUtil.getParentOfType(element, PsiMarkdownReferenceLink.class);
|
||||
if (link == null) return;
|
||||
link.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,14 +12,23 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class RemoveTagFix extends PsiUpdateModCommandQuickFix {
|
||||
private final String myTagName;
|
||||
private final String myParamName;
|
||||
|
||||
RemoveTagFix(String tagName) {
|
||||
myTagName = tagName;
|
||||
myParamName = null;
|
||||
}
|
||||
|
||||
RemoveTagFix(String tagName, String paramName) {
|
||||
myTagName = tagName;
|
||||
myParamName = paramName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getName() {
|
||||
return JavaBundle.message("quickfix.text.remove.javadoc.0", myTagName);
|
||||
return myParamName == null
|
||||
? JavaBundle.message("quickfix.text.remove.javadoc.0", myTagName)
|
||||
: JavaBundle.message("quickfix.text.remove.javadoc.0.1", myTagName, myParamName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
/// [#<error descr="Cannot resolve symbol '#baz()'">baz</error>()]
|
||||
/// {@link #<error descr="Cannot resolve symbol 'baz()'">baz</error>()}
|
||||
class Test {
|
||||
public void foo() {}
|
||||
|
||||
}
|
||||
@@ -79,6 +79,7 @@ public class JavadocDeclarationHighlightingTest extends LightDaemonAnalyzerTestC
|
||||
public void testInheritJavaDoc() { setLanguageLevel(LanguageLevel.JDK_1_3); doTest(); }
|
||||
public void testLink0() { doTest(); }
|
||||
public void testLink1() { doTest(); }
|
||||
public void testLink2() { doTest(); }
|
||||
public void testLinkFromInnerClassToSelfMethod() { doTest(); }
|
||||
public void testValueBadReference() { doTest(); }
|
||||
public void testValueGoodReference() { doTest(); }
|
||||
|
||||
@@ -1171,6 +1171,7 @@ quickfix.family.avoid.mutation.using.stream.api=Avoid mutation using Stream API
|
||||
quickfix.family.change.javadoc.to=Change to \u2026
|
||||
quickfix.family.find.cause=Find cause
|
||||
quickfix.family.remove.javadoc.tag=Remove tag
|
||||
quickfix.family.remove.javadoc.reference=Remove tag
|
||||
quickfix.family.remove.redundant.parameter=Remove redundant parameter
|
||||
quickfix.family.remove.redundant.parameter.types=Remove redundant parameter types
|
||||
quickfix.family.replace.cast.type=Replace cast type
|
||||
@@ -1191,6 +1192,7 @@ quickfix.text.0.may.not.work.before.jdk.11.0.2={0} (may not work before JDK 11.0
|
||||
quickfix.text.avoid.mutation.using.stream.api.0.operation=Avoid mutation using Stream API ''{0}()'' operation
|
||||
quickfix.text.remove.javadoc.0=Remove ''@{0}'' tag
|
||||
quickfix.text.remove.javadoc.0.1=Remove @{0} {1}
|
||||
quickfix.text.remove.javadoc.reference=Remove ''@{0}'' reference
|
||||
quickfix.text.remove.not.null.annotation=Remove non-null annotation
|
||||
quickfix.text.replace.0.stream.with.1.2=Replace {0}.stream() with {1}.{2}()
|
||||
quickfix.text.replace.collect.0.with.1.2=Replace ''collect({0}())'' with ''{1}''{2}
|
||||
|
||||
Reference in New Issue
Block a user