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

This commit is contained in:
Bas Leijdekkers
2013-10-07 15:13:09 +02:00
parent 53c1eff0ba
commit 4684ba71e0
3 changed files with 27 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2013 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.
@@ -28,7 +28,6 @@ import com.intellij.ide.DataManager;
import com.intellij.ide.util.FQNameCellRenderer;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Editor;
@@ -57,6 +56,19 @@ public class JavaDocReferenceInspection extends BaseLocalInspectionTool {
return manager.createProblemDescriptor(element, template, onTheFly, null, ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
}
@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 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);
}
@Override
@Nullable
public ProblemDescriptor[] checkMethod(@NotNull PsiMethod psiMethod, @NotNull InspectionManager manager, boolean isOnTheFly) {
@@ -77,12 +89,15 @@ public class JavaDocReferenceInspection extends BaseLocalInspectionTool {
@Nullable
private ProblemDescriptor[] checkMember(final PsiDocCommentOwner docCommentOwner, final InspectionManager manager, final boolean isOnTheFly) {
final ArrayList<ProblemDescriptor> problems = new ArrayList<ProblemDescriptor>();
final PsiDocComment docComment = docCommentOwner.getDocComment();
return checkComment(docCommentOwner.getDocComment(), docCommentOwner, manager, isOnTheFly);
}
private ProblemDescriptor[] checkComment(PsiDocComment docComment, PsiElement context, InspectionManager manager, boolean isOnTheFly) {
if (docComment == null) return null;
final ArrayList<ProblemDescriptor> problems = new ArrayList<ProblemDescriptor>();
final Set<PsiJavaCodeReferenceElement> references = new HashSet<PsiJavaCodeReferenceElement>();
docComment.accept(getVisitor(references, docCommentOwner, problems, manager, isOnTheFly));
docComment.accept(getVisitor(references, context, problems, manager, isOnTheFly));
for (PsiJavaCodeReferenceElement reference : references) {
final List<PsiClass> classesToImport = new ImportClassFix(reference).getClassesToImport();
final PsiElement referenceNameElement = reference.getReferenceNameElement();

View File

@@ -0,0 +1,5 @@
/**
* {@linkplain <error descr="Cannot resolve symbol 'File'">File</error>} {@link <error descr="Cannot resolve symbol 'Set'">Set</error>}
* @see <error descr="Cannot resolve symbol 'List'">List</error>
*/
package pkg;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2013 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.
@@ -31,6 +31,7 @@ public class JavadocResolveTest extends DaemonAnalyzerTestCase {
public void testSee1() throws Exception { doTest(); }
public void testSee2() throws Exception { doTest(); }
public void testSee3() throws Exception { doTest(); }
public void testPackageInfo() throws Exception { doTest(BASE_PATH + "/pkg/package-info.java", BASE_PATH, false, false); }
private void doTest() throws Exception {
doTest(BASE_PATH + "/pkg/" + getTestName(false) + ".java", BASE_PATH, false, false);