Add module-info.java checking to "Declaration has problems in Javadoc references" inspection

This commit is contained in:
Bas Leijdekkers
2017-03-12 17:08:12 +01:00
parent 12c8edc10b
commit 5e8b71d109
3 changed files with 26 additions and 10 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -106,14 +106,18 @@ public class JavaDocReferenceInspectionBase extends BaseJavaBatchLocalInspectio
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
if (!PsiPackage.PACKAGE_INFO_FILE.equals(file.getName()) || !(file instanceof PsiJavaFile)) {
return null;
final String fileName = file.getName();
if (PsiPackage.PACKAGE_INFO_FILE.equals(fileName)) {
final PsiDocComment docComment = PsiTreeUtil.getChildOfType(file, PsiDocComment.class);
return checkComment(docComment, file, manager, isOnTheFly);
}
final PsiDocComment docComment = PsiTreeUtil.getChildOfType(file, PsiDocComment.class);
final PsiJavaFile javaFile = (PsiJavaFile)file;
final String packageName = javaFile.getPackageName();
final PsiPackage aPackage = JavaPsiFacade.getInstance(file.getProject()).findPackage(packageName);
return checkComment(docComment, aPackage, manager, isOnTheFly);
else if (PsiJavaModule.MODULE_INFO_FILE.equals(fileName)) {
final PsiJavaModule module = PsiTreeUtil.getChildOfType(file, PsiJavaModule.class);
if (module != null) {
return checkComment(module.getDocComment(), file, manager, isOnTheFly);
}
}
return null;
}
@Override
@@ -139,7 +143,7 @@ public class JavaDocReferenceInspectionBase extends BaseJavaBatchLocalInspectio
return checkComment(docCommentOwner.getDocComment(), docCommentOwner, manager, isOnTheFly);
}
private ProblemDescriptor[] checkComment(PsiDocComment docComment, PsiElement context, InspectionManager manager, boolean isOnTheFly) {
private ProblemDescriptor[] checkComment(@Nullable PsiDocComment docComment, PsiElement context, InspectionManager manager, boolean isOnTheFly) {
if (docComment == null) return null;
final List<ProblemDescriptor> problems = new ArrayList<>();
@@ -0,0 +1,7 @@
/**
* {@linkplain <error descr="Cannot resolve symbol 'Foo'">Foo</error>}
* @see <error descr="Cannot resolve symbol 'Foo'">Foo</error>
*/
module com.ref.test.test.test {
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,8 @@ package com.intellij.codeInsight.daemon;
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.javaDoc.JavaDocLocalInspection;
import com.intellij.codeInspection.javaDoc.JavaDocReferenceInspection;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.pom.java.LanguageLevel;
public class JavadocResolveTest extends DaemonAnalyzerTestCase {
private static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/javaDoc/resolve";
@@ -33,6 +35,9 @@ public class JavadocResolveTest extends DaemonAnalyzerTestCase {
public void testSee3() throws Exception { doTest(); }
public void testPackageInfo() throws Exception { doTest(BASE_PATH + "/pkg/package-info.java", BASE_PATH, false, false); }
public void testBrokenPackageInfo() throws Exception { doTest(BASE_PATH + "/pkg1/package-info.java", BASE_PATH, false, false); }
public void testModuleInfo() throws Exception {
LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.JDK_1_9);
doTest(BASE_PATH + "/pkg/module-info.java", BASE_PATH, false, false); }
private void doTest() throws Exception {
doTest(BASE_PATH + "/pkg/" + getTestName(false) + ".java", BASE_PATH, false, false);