mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 03:13:40 +07:00
Inspections - pass onTheFly into ProblemDescriptors & use it to create LAZY refs in batch run.
This commit is contained in:
@@ -76,7 +76,7 @@ public class LossyEncodingInspection extends BaseJavaLocalInspectionTool {
|
||||
if (isRepresentable(c, charset)) {
|
||||
if (start != -1) {
|
||||
ProblemDescriptor descriptor = manager.createProblemDescriptor(file, new TextRange(start, i), InspectionsBundle.message(
|
||||
"unsupported.character.for.the.charset", charset), ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
|
||||
"unsupported.character.for.the.charset", charset), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly);
|
||||
descriptors.add(descriptor);
|
||||
start = -1;
|
||||
|
||||
@@ -92,7 +92,7 @@ public class LossyEncodingInspection extends BaseJavaLocalInspectionTool {
|
||||
}
|
||||
if (start != -1) {
|
||||
ProblemDescriptor descriptor = manager.createProblemDescriptor(file, new TextRange(start, text.length()), InspectionsBundle.message(
|
||||
"unsupported.character.for.the.charset", charset), ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
|
||||
"unsupported.character.for.the.charset", charset), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly);
|
||||
descriptors.add(descriptor);
|
||||
}
|
||||
|
||||
@@ -105,4 +105,4 @@ public class LossyEncodingInspection extends BaseJavaLocalInspectionTool {
|
||||
CharBuffer buffer = charset.decode(out);
|
||||
return str.equals(buffer.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,7 +229,8 @@ public class RedundantSuppressInspection extends GlobalInspectionTool{
|
||||
if (identifier == null) {
|
||||
identifier = psiMember;
|
||||
}
|
||||
result.add(manager.createProblemDescriptor(identifier, description, (LocalQuickFix)fix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
|
||||
result.add(manager.createProblemDescriptor(identifier, description, (LocalQuickFix)fix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||
false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ public class CanBeFinalInspection extends GlobalJavaInspectionTool {
|
||||
if (psiIdentifier != null) {
|
||||
return new ProblemDescriptor[]{manager.createProblemDescriptor(psiIdentifier, InspectionsBundle.message(
|
||||
"inspection.export.results.can.be.final.description"), new AcceptSuggested(globalContext.getRefManager()),
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING)};
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false)};
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
+5
-2
@@ -40,11 +40,13 @@ class CatchBodyVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.defaultFileTemplateUsage.CatchBodyVisitor");
|
||||
|
||||
Collection<ProblemDescriptor> myProblemDescriptors;
|
||||
private boolean myOnTheFly;
|
||||
private final InspectionManager myManager;
|
||||
|
||||
public CatchBodyVisitor(InspectionManager manager, Collection<ProblemDescriptor> descriptors) {
|
||||
public CatchBodyVisitor(InspectionManager manager, Collection<ProblemDescriptor> descriptors, boolean onTheFly) {
|
||||
myManager = manager;
|
||||
myProblemDescriptors = descriptors;
|
||||
myOnTheFly = onTheFly;
|
||||
}
|
||||
|
||||
@Override public void visitCatchSection(PsiCatchSection section) {
|
||||
@@ -104,7 +106,8 @@ class CatchBodyVisitor extends JavaRecursiveElementWalkingVisitor {
|
||||
}
|
||||
Pair<? extends PsiElement, ? extends PsiElement> range = DefaultFileTemplateUsageInspection.getInteriorRange(catchBlock);
|
||||
final String description = InspectionsBundle.message("default.file.template.description");
|
||||
ProblemDescriptor descriptor = myManager.createProblemDescriptor(range.first, range.second, description, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, createQuickFix(section));
|
||||
ProblemDescriptor descriptor = myManager.createProblemDescriptor(range.first, range.second, description, ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||
myOnTheFly, createQuickFix(section));
|
||||
myProblemDescriptors.add(descriptor);
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -59,10 +59,10 @@ public class DefaultFileTemplateUsageInspection extends BaseJavaLocalInspectionT
|
||||
public ProblemDescriptor[] checkMethod(@NotNull PsiMethod method, @NotNull InspectionManager manager, boolean isOnTheFly) {
|
||||
Collection<ProblemDescriptor> descriptors = new ArrayList<ProblemDescriptor>();
|
||||
if (CHECK_METHOD_BODY) {
|
||||
MethodBodyChecker.checkMethodBody(method, manager, descriptors);
|
||||
MethodBodyChecker.checkMethodBody(method, manager, descriptors, isOnTheFly);
|
||||
}
|
||||
if (CHECK_TRY_CATCH_SECTION) {
|
||||
CatchBodyVisitor visitor = new CatchBodyVisitor(manager, descriptors);
|
||||
CatchBodyVisitor visitor = new CatchBodyVisitor(manager, descriptors, isOnTheFly);
|
||||
PsiCodeBlock body = method.getBody();
|
||||
if (body != null) {
|
||||
body.accept(visitor);
|
||||
@@ -94,7 +94,7 @@ public class DefaultFileTemplateUsageInspection extends BaseJavaLocalInspectionT
|
||||
@Nullable
|
||||
public ProblemDescriptor[] checkClass(@NotNull PsiClass aClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
|
||||
if (!CHECK_TRY_CATCH_SECTION) return null;
|
||||
CatchBodyVisitor visitor = new CatchBodyVisitor(manager, new ArrayList<ProblemDescriptor>());
|
||||
CatchBodyVisitor visitor = new CatchBodyVisitor(manager, new ArrayList<ProblemDescriptor>(), isOnTheFly);
|
||||
PsiClassInitializer[] initializers = aClass.getInitializers();
|
||||
for (PsiClassInitializer initializer : initializers) {
|
||||
initializer.accept(visitor);
|
||||
@@ -106,7 +106,7 @@ public class DefaultFileTemplateUsageInspection extends BaseJavaLocalInspectionT
|
||||
@Nullable
|
||||
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) {
|
||||
if (!CHECK_FILE_HEADER) return null;
|
||||
ProblemDescriptor descriptor = FileHeaderChecker.checkFileHeader(file, manager);
|
||||
ProblemDescriptor descriptor = FileHeaderChecker.checkFileHeader(file, manager, isOnTheFly);
|
||||
return descriptor == null ? null : new ProblemDescriptor[]{descriptor};
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -49,8 +49,7 @@ import java.util.regex.Pattern;
|
||||
public class FileHeaderChecker {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInspection.defaultFileTemplateUsage.FileHeaderChecker");
|
||||
|
||||
static ProblemDescriptor checkFileHeader(final PsiFile file,
|
||||
final InspectionManager manager) {
|
||||
static ProblemDescriptor checkFileHeader(final PsiFile file, final InspectionManager manager, boolean onTheFly) {
|
||||
FileTemplate template = FileTemplateManager.getInstance().getDefaultTemplate(FileTemplateManager.FILE_HEADER_TEMPLATE_NAME);
|
||||
TIntObjectHashMap<String> offsetToProperty = new TIntObjectHashMap<String>();
|
||||
String templateText = template.getText().trim();
|
||||
@@ -78,7 +77,7 @@ public class FileHeaderChecker {
|
||||
if (element == null) return null;
|
||||
LocalQuickFix[] quickFix = createQuickFix(element, matcher, offsetToProperty);
|
||||
final String description = InspectionsBundle.message("default.file.template.description");
|
||||
return manager.createProblemDescriptor(element, description, quickFix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
|
||||
return manager.createProblemDescriptor(element, description, quickFix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, onTheFly);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
+3
-3
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package com.intellij.codeInspection.defaultFileTemplateUsage;
|
||||
|
||||
import com.intellij.codeInsight.PsiEquivalenceUtil;
|
||||
import com.intellij.codeInsight.CodeInsightUtil;
|
||||
import com.intellij.codeInsight.PsiEquivalenceUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.CreateFromUsageUtils;
|
||||
import com.intellij.codeInsight.generation.OverrideImplementUtil;
|
||||
import com.intellij.codeInspection.*;
|
||||
@@ -86,7 +86,7 @@ public class MethodBodyChecker {
|
||||
|
||||
static void checkMethodBody(final PsiMethod method,
|
||||
final InspectionManager manager,
|
||||
final Collection<ProblemDescriptor> problemDescriptors) {
|
||||
final Collection<ProblemDescriptor> problemDescriptors, boolean onTheFly) {
|
||||
PsiType returnType = method.getReturnType();
|
||||
if (method.isConstructor() || returnType == null) return;
|
||||
PsiCodeBlock body = method.getBody();
|
||||
@@ -112,7 +112,7 @@ public class MethodBodyChecker {
|
||||
Pair<? extends PsiElement, ? extends PsiElement> range = DefaultFileTemplateUsageInspection.getInteriorRange(body);
|
||||
final String description = InspectionsBundle.message("default.file.template.description");
|
||||
ProblemDescriptor problem = manager.createProblemDescriptor(range.first, range.second, description,
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, onTheFly,
|
||||
createMethodBodyQuickFix(method));
|
||||
problemDescriptors.add(problem);
|
||||
}
|
||||
|
||||
+3
-2
@@ -84,7 +84,7 @@ public class DependencyInspection extends BaseLocalInspectionTool {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ProblemDescriptor[] checkFile(@NotNull final PsiFile file, @NotNull final InspectionManager manager, boolean isOnTheFly) {
|
||||
public ProblemDescriptor[] checkFile(@NotNull final PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
|
||||
if (file == null) return null;
|
||||
if (file.getViewProvider().getPsi(StdLanguages.JAVA) == null) return null;
|
||||
final DependencyValidationManager validationManager = DependencyValidationManager.getInstance(file.getProject());
|
||||
@@ -100,7 +100,8 @@ public class DependencyInspection extends BaseLocalInspectionTool {
|
||||
for (DependencyRule dependencyRule : rule) {
|
||||
StringBuffer message = new StringBuffer();
|
||||
message.append(MessageFormat.format(InspectionsBundle.message("inspection.dependency.violator.problem.descriptor"), dependencyRule.getDisplayText()));
|
||||
problems.add(manager.createProblemDescriptor(place, message.toString(), new LocalQuickFix[]{new EditDependencyRulesAction(dependencyRule)}, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
|
||||
problems.add(manager.createProblemDescriptor(place, message.toString(), new LocalQuickFix[]{new EditDependencyRulesAction(dependencyRule)}, ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||
isOnTheFly));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -148,7 +148,7 @@ public class EmptyMethodInspection extends GlobalJavaInspectionTool {
|
||||
|
||||
final ProblemDescriptor descriptor = manager.createProblemDescriptor(refMethod.getElement().getNavigationElement(), message,
|
||||
fixes.toArray(new LocalQuickFix[fixes.size()]),
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false);
|
||||
return new ProblemDescriptor[]{descriptor};
|
||||
}
|
||||
|
||||
|
||||
+72
-56
@@ -269,12 +269,15 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
return new OptionsPanel();
|
||||
}
|
||||
|
||||
private static ProblemDescriptor createDescriptor(@NotNull PsiElement element, String template, InspectionManager manager) {
|
||||
return manager.createProblemDescriptor(element, template, (LocalQuickFix [])null, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
|
||||
private static ProblemDescriptor createDescriptor(@NotNull PsiElement element, String template, InspectionManager manager,
|
||||
boolean onTheFly) {
|
||||
return manager.createProblemDescriptor(element, template, (LocalQuickFix [])null, ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||
onTheFly);
|
||||
}
|
||||
|
||||
private static ProblemDescriptor createDescriptor(@NotNull PsiElement element, String template, @NotNull LocalQuickFix fix, InspectionManager manager) {
|
||||
return manager.createProblemDescriptor(element, template, fix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
|
||||
private static ProblemDescriptor createDescriptor(@NotNull PsiElement element, String template, @NotNull LocalQuickFix fix,
|
||||
InspectionManager manager, boolean onTheFly) {
|
||||
return manager.createProblemDescriptor(element, template, fix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, onTheFly);
|
||||
}
|
||||
|
||||
private static class AddMissingTagFix implements LocalQuickFix {
|
||||
@@ -356,7 +359,7 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
final PsiElement elementToHighlight = nameIdentifier != null ? nameIdentifier : psiClass;
|
||||
if (docComment == null) {
|
||||
return isJavaDocRequired(psiClass)
|
||||
? new ProblemDescriptor[]{createDescriptor(elementToHighlight, REQUIRED_JAVADOC_IS_ABSENT, manager)}
|
||||
? new ProblemDescriptor[]{createDescriptor(elementToHighlight, REQUIRED_JAVADOC_IS_ABSENT, manager, isOnTheFly)}
|
||||
: null;
|
||||
}
|
||||
|
||||
@@ -393,27 +396,27 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
for (int i = 0; i < tagsToCheck.length; i++) {
|
||||
final String tagToCheck = tagsToCheck[i];
|
||||
if (isTagRequired[i] && !isTagPresent[i]) {
|
||||
problems.add(createMissingTagDescriptor(elementToHighlight, tagToCheck, manager));
|
||||
problems.add(createMissingTagDescriptor(elementToHighlight, tagToCheck, manager, isOnTheFly));
|
||||
}
|
||||
}
|
||||
ArrayList<ProblemDescriptor> tagProblems = getTagValuesProblems(psiClass, tags, manager);
|
||||
ArrayList<ProblemDescriptor> tagProblems = getTagValuesProblems(psiClass, tags, manager, isOnTheFly);
|
||||
if (tagProblems != null) {
|
||||
problems.addAll(tagProblems);
|
||||
}
|
||||
checkForPeriodInDoc(docComment, problems, manager);
|
||||
checkForPeriodInDoc(docComment, problems, manager, isOnTheFly);
|
||||
checkInlineTags(manager, problems, docComment.getDescriptionElements(),
|
||||
JavaPsiFacade.getInstance(docComment.getProject()).getJavadocManager());
|
||||
JavaPsiFacade.getInstance(docComment.getProject()).getJavadocManager(), isOnTheFly);
|
||||
|
||||
for (PsiDocTag tag : tags) {
|
||||
for (int i = 0; i < tagsToCheck.length; i++) {
|
||||
final String tagToCheck = tagsToCheck[i];
|
||||
if (tagToCheck.equals(tag.getName()) && extractTagDescription(tag).length() == 0) {
|
||||
problems.add(createDescriptor(elementToHighlight, InspectionsBundle.message(absentDescriptionKeys[i]), manager));
|
||||
problems.add(createDescriptor(elementToHighlight, InspectionsBundle.message(absentDescriptionKeys[i]), manager, isOnTheFly));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
checkDuplicateTags(tags, problems, manager);
|
||||
checkDuplicateTags(tags, problems, manager, isOnTheFly);
|
||||
|
||||
if (isTagRequired(psiClass, "param") && psiClass.hasTypeParameters() && nameIdentifier != null) {
|
||||
ArrayList<PsiTypeParameter> absentParameters = null;
|
||||
@@ -426,7 +429,7 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
}
|
||||
if (absentParameters != null) {
|
||||
for (PsiTypeParameter psiTypeParameter : absentParameters) {
|
||||
problems.add(createMissingParamTagDescriptor(nameIdentifier, psiTypeParameter, manager));
|
||||
problems.add(createMissingParamTagDescriptor(nameIdentifier, psiTypeParameter, manager, isOnTheFly));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -438,9 +441,10 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
|
||||
private static ProblemDescriptor createMissingParamTagDescriptor(final PsiIdentifier nameIdentifier,
|
||||
final PsiTypeParameter psiTypeParameter,
|
||||
final InspectionManager manager) {
|
||||
final InspectionManager manager, boolean isOnTheFly) {
|
||||
String message = InspectionsBundle.message("inspection.javadoc.problem.missing.tag", "<code>@param</code>");
|
||||
return createDescriptor(nameIdentifier, message, new AddMissingTagFix("param", "<" + psiTypeParameter.getName() + ">"), manager);
|
||||
return createDescriptor(nameIdentifier, message, new AddMissingTagFix("param", "<" + psiTypeParameter.getName() + ">"), manager,
|
||||
isOnTheFly);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -452,19 +456,19 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
PsiDocComment docComment = psiField.getDocComment();
|
||||
if (docComment == null) {
|
||||
return isJavaDocRequired(psiField)
|
||||
? new ProblemDescriptor[]{createDescriptor(psiField.getNameIdentifier(), REQUIRED_JAVADOC_IS_ABSENT, manager)}
|
||||
? new ProblemDescriptor[]{createDescriptor(psiField.getNameIdentifier(), REQUIRED_JAVADOC_IS_ABSENT, manager, isOnTheFly)}
|
||||
: null;
|
||||
}
|
||||
|
||||
final ArrayList<ProblemDescriptor> problems = new ArrayList<ProblemDescriptor>(2);
|
||||
ArrayList<ProblemDescriptor> tagProblems = getTagValuesProblems(psiField, docComment.getTags(), manager);
|
||||
ArrayList<ProblemDescriptor> tagProblems = getTagValuesProblems(psiField, docComment.getTags(), manager, isOnTheFly);
|
||||
if (tagProblems != null) {
|
||||
problems.addAll(tagProblems);
|
||||
}
|
||||
checkInlineTags(manager, problems, docComment.getDescriptionElements(),
|
||||
JavaPsiFacade.getInstance(docComment.getProject()).getJavadocManager());
|
||||
checkForPeriodInDoc(docComment, problems, manager);
|
||||
checkDuplicateTags(docComment.getTags(), problems, manager);
|
||||
JavaPsiFacade.getInstance(docComment.getProject()).getJavadocManager(), isOnTheFly);
|
||||
checkForPeriodInDoc(docComment, problems, manager, isOnTheFly);
|
||||
checkDuplicateTags(docComment.getTags(), problems, manager, isOnTheFly);
|
||||
return problems.isEmpty()
|
||||
? null
|
||||
: problems.toArray(new ProblemDescriptor[problems.size()]);
|
||||
@@ -488,7 +492,8 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
}
|
||||
if (superMethods.length == 0) {
|
||||
final PsiIdentifier nameIdentifier = psiMethod.getNameIdentifier();
|
||||
return nameIdentifier != null ? new ProblemDescriptor[] { createDescriptor(nameIdentifier, REQUIRED_JAVADOC_IS_ABSENT, manager)} : null;
|
||||
return nameIdentifier != null ? new ProblemDescriptor[] { createDescriptor(nameIdentifier, REQUIRED_JAVADOC_IS_ABSENT, manager,
|
||||
isOnTheFly)} : null;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
@@ -509,7 +514,7 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
final ArrayList<ProblemDescriptor> problems = new ArrayList<ProblemDescriptor>(2);
|
||||
|
||||
checkInlineTags(manager, problems, descriptionElements,
|
||||
JavaPsiFacade.getInstance(docComment.getProject()).getJavadocManager());
|
||||
JavaPsiFacade.getInstance(docComment.getProject()).getJavadocManager(), isOnTheFly);
|
||||
|
||||
final PsiDocTag tagByName = docComment.findTagByName("inheritDoc");
|
||||
if (tagByName != null) {
|
||||
@@ -550,7 +555,7 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
if (isReturnRequired && isReturnAbsent) {
|
||||
final PsiIdentifier psiIdentifier = psiMethod.getNameIdentifier();
|
||||
if (psiIdentifier != null) {
|
||||
problems.add(createMissingTagDescriptor(psiIdentifier, "return", manager));
|
||||
problems.add(createMissingTagDescriptor(psiIdentifier, "return", manager, isOnTheFly));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -558,7 +563,7 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
for (PsiParameter psiParameter : absentParameters) {
|
||||
final PsiIdentifier nameIdentifier = psiMethod.getNameIdentifier();
|
||||
if (nameIdentifier != null) {
|
||||
problems.add(createMissingParamTagDescriptor(nameIdentifier, psiParameter, manager));
|
||||
problems.add(createMissingParamTagDescriptor(nameIdentifier, psiParameter, manager, isOnTheFly));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -581,7 +586,7 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
if (valueElement != null) {
|
||||
problems.add(createDescriptor(valueElement,
|
||||
InspectionsBundle.message("inspection.javadoc.method.problem.missing.tag.description", "<code>@param " + valueElement.getText() + "</code>"),
|
||||
manager));
|
||||
manager, isOnTheFly));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -597,20 +602,20 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
declaredExceptions.put(classType, psiClass);
|
||||
}
|
||||
}
|
||||
processThrowsTags(tags, declaredExceptions, manager, problems);
|
||||
processThrowsTags(tags, declaredExceptions, manager, problems, isOnTheFly);
|
||||
if (!declaredExceptions.isEmpty()) {
|
||||
for (PsiClassType declaredException : declaredExceptions.keySet()) {
|
||||
problems.add(createMissingThrowsTagDescriptor(psiMethod, manager, declaredException));
|
||||
problems.add(createMissingThrowsTagDescriptor(psiMethod, manager, declaredException, isOnTheFly));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<ProblemDescriptor> tagProblems = getTagValuesProblems(psiMethod, tags, manager);
|
||||
ArrayList<ProblemDescriptor> tagProblems = getTagValuesProblems(psiMethod, tags, manager, isOnTheFly);
|
||||
if (tagProblems != null) {
|
||||
problems.addAll(tagProblems);
|
||||
}
|
||||
|
||||
checkForPeriodInDoc(docComment, problems, manager);
|
||||
checkForPeriodInDoc(docComment, problems, manager, isOnTheFly);
|
||||
|
||||
for (PsiDocTag tag : tags) {
|
||||
if ("param".equals(tag.getName())) {
|
||||
@@ -623,7 +628,7 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
if (paramRef.getReference().isReferenceTo(param)) {
|
||||
problems.add(createDescriptor(value,
|
||||
InspectionsBundle.message("inspection.javadoc.method.problem.descriptor", "<code>@param</code>", "<code>" + param.getName() + "</code>"),
|
||||
manager));
|
||||
manager, isOnTheFly));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -633,13 +638,14 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
if ("return".equals(tag.getName())) {
|
||||
if (extractTagDescription(tag).length() == 0) {
|
||||
String message = InspectionsBundle.message("inspection.javadoc.method.problem.missing.tag.description", "<code>@return</code>");
|
||||
ProblemDescriptor descriptor = manager.createProblemDescriptor(tag.getNameElement(), message, null, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, true);
|
||||
ProblemDescriptor descriptor = manager.createProblemDescriptor(tag.getNameElement(), message, null, ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||
isOnTheFly, true);
|
||||
problems.add(descriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
checkDuplicateTags(tags, problems, manager);
|
||||
checkDuplicateTags(tags, problems, manager, isOnTheFly);
|
||||
|
||||
return problems.isEmpty()
|
||||
? null
|
||||
@@ -665,7 +671,7 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
private static void processThrowsTags(final PsiDocTag[] tags,
|
||||
final Map<PsiClassType, PsiClass> declaredExceptions,
|
||||
final InspectionManager mananger,
|
||||
@NotNull final ArrayList<ProblemDescriptor> problems) {
|
||||
@NotNull final ArrayList<ProblemDescriptor> problems, boolean isOnTheFly) {
|
||||
for (PsiDocTag tag : tags) {
|
||||
if ("throws".equals(tag.getName()) || "exception".equals(tag.getName())) {
|
||||
final PsiDocTagValue value = tag.getValueElement();
|
||||
@@ -683,7 +689,8 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
final PsiClass psiClass = declaredExceptions.get(classType);
|
||||
if (InheritanceUtil.isInheritorOrSelf(exceptionClass, psiClass, true)) {
|
||||
if (extractThrowsTagDescription(tag).length() == 0) {
|
||||
problems.add(createDescriptor(tag.getNameElement(), InspectionsBundle.message("inspection.javadoc.method.problem.missing.tag.description", "<code>" + tag.getName() + "</code>"), mananger));
|
||||
problems.add(createDescriptor(tag.getNameElement(), InspectionsBundle.message("inspection.javadoc.method.problem.missing.tag.description", "<code>" + tag.getName() + "</code>"), mananger,
|
||||
isOnTheFly));
|
||||
}
|
||||
it.remove();
|
||||
}
|
||||
@@ -696,25 +703,26 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
@Nullable
|
||||
private static ProblemDescriptor createMissingThrowsTagDescriptor(final PsiMethod method,
|
||||
final InspectionManager manager,
|
||||
final PsiClassType exceptionClassType) {
|
||||
final PsiClassType exceptionClassType, boolean isOnTheFly) {
|
||||
@NonNls String tag = "throws";
|
||||
String message = InspectionsBundle.message("inspection.javadoc.problem.missing.tag", "<code>@" + tag + "</code> " + exceptionClassType.getCanonicalText());
|
||||
final String firstDeclaredException = exceptionClassType.getCanonicalText();
|
||||
final PsiIdentifier nameIdentifier = method.getNameIdentifier();
|
||||
return nameIdentifier != null ? createDescriptor(nameIdentifier, message,new AddMissingTagFix(tag, firstDeclaredException), manager) : null;
|
||||
return nameIdentifier != null ? createDescriptor(nameIdentifier, message,new AddMissingTagFix(tag, firstDeclaredException), manager,
|
||||
isOnTheFly) : null;
|
||||
}
|
||||
|
||||
private static ProblemDescriptor createMissingTagDescriptor(PsiElement elementToHighlight,
|
||||
@NonNls String tag,
|
||||
final InspectionManager manager) {
|
||||
final InspectionManager manager, boolean isOnTheFly) {
|
||||
String message = InspectionsBundle.message("inspection.javadoc.problem.missing.tag", "<code>@" + tag + "</code>");
|
||||
return createDescriptor(elementToHighlight, message,new AddMissingTagFix(tag), manager);
|
||||
return createDescriptor(elementToHighlight, message,new AddMissingTagFix(tag), manager, isOnTheFly);
|
||||
}
|
||||
private static ProblemDescriptor createMissingParamTagDescriptor(PsiElement elementToHighlight,
|
||||
PsiParameter param,
|
||||
final InspectionManager manager) {
|
||||
final InspectionManager manager, boolean isOnTheFly) {
|
||||
String message = InspectionsBundle.message("inspection.javadoc.method.problem.missing.param.tag", "<code>@param</code>", "<code>" + param.getName() + "</code>");
|
||||
return createDescriptor(elementToHighlight, message, new AddMissingParamTagFix(param), manager);
|
||||
return createDescriptor(elementToHighlight, message, new AddMissingParamTagFix(param), manager, isOnTheFly);
|
||||
}
|
||||
|
||||
private static class AddMissingParamTagFix extends AddMissingTagFix {
|
||||
@@ -809,7 +817,7 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
|
||||
private void checkForPeriodInDoc(PsiDocComment docComment,
|
||||
ArrayList<ProblemDescriptor> problems,
|
||||
InspectionManager manager) {
|
||||
InspectionManager manager, boolean onTheFly) {
|
||||
if (IGNORE_JAVADOC_PERIOD) return;
|
||||
PsiDocTag[] tags = docComment.getTags();
|
||||
int dotIndex = docComment.getText().indexOf('.');
|
||||
@@ -830,13 +838,13 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
problems.add(manager.createProblemDescriptor(docComment.getFirstChild(),
|
||||
InspectionsBundle.message("inspection.javadoc.problem.descriptor1"),
|
||||
null,
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||
false));
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, onTheFly, false));
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ArrayList<ProblemDescriptor> getTagValuesProblems(PsiDocCommentOwner context, PsiDocTag[] tags, InspectionManager inspectionManager) {
|
||||
private ArrayList<ProblemDescriptor> getTagValuesProblems(PsiDocCommentOwner context, PsiDocTag[] tags, InspectionManager inspectionManager,
|
||||
boolean isOnTheFly) {
|
||||
final ArrayList<ProblemDescriptor> problems = new ArrayList<ProblemDescriptor>(2);
|
||||
nextTag:
|
||||
for (PsiDocTag tag : tags) {
|
||||
@@ -851,9 +859,11 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
}
|
||||
|
||||
if (tagInfo == null){
|
||||
problems.add(createDescriptor(tag.getNameElement(), InspectionsBundle.message("inspection.javadoc.problem.wrong.tag", "<code>" + tagName + "</code>"), new AddUnknownTagToCustoms(tag), inspectionManager));
|
||||
problems.add(createDescriptor(tag.getNameElement(), InspectionsBundle.message("inspection.javadoc.problem.wrong.tag", "<code>" + tagName + "</code>"), new AddUnknownTagToCustoms(tag), inspectionManager,
|
||||
isOnTheFly));
|
||||
} else {
|
||||
problems.add(createDescriptor(tag.getNameElement(), InspectionsBundle.message("inspection.javadoc.problem.disallowed.tag", "<code>" + tagName + "</code>"), new AddUnknownTagToCustoms(tag), inspectionManager));
|
||||
problems.add(createDescriptor(tag.getNameElement(), InspectionsBundle.message("inspection.javadoc.problem.disallowed.tag", "<code>" + tagName + "</code>"), new AddUnknownTagToCustoms(tag), inspectionManager,
|
||||
isOnTheFly));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -870,7 +880,8 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
final int textOffset = value.getTextOffset();
|
||||
|
||||
if (textOffset == value.getTextRange().getEndOffset()) {
|
||||
problems.add(inspectionManager.createProblemDescriptor(tag, InspectionsBundle.message("inspection.javadoc.problem.name.expected"), null, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, true));
|
||||
problems.add(inspectionManager.createProblemDescriptor(tag, InspectionsBundle.message("inspection.javadoc.problem.name.expected"), null, ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||
isOnTheFly, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -878,12 +889,13 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
if (message != null) {
|
||||
final PsiDocTagValue valueElement = tag.getValueElement();
|
||||
if (valueElement == null){
|
||||
problems.add(inspectionManager.createProblemDescriptor(tag, InspectionsBundle.message("inspection.javadoc.method.problem.missing.tag.description", "<code>" + tag.getName() + "</code>"), null, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, true));
|
||||
problems.add(inspectionManager.createProblemDescriptor(tag, InspectionsBundle.message("inspection.javadoc.method.problem.missing.tag.description", "<code>" + tag.getName() + "</code>"), null, ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||
isOnTheFly, true));
|
||||
} else {
|
||||
problems.add(createDescriptor(valueElement, message, inspectionManager));
|
||||
problems.add(createDescriptor(valueElement, message, inspectionManager, isOnTheFly));
|
||||
}
|
||||
}
|
||||
checkInlineTags(inspectionManager, problems, tag.getDataElements(), manager);
|
||||
checkInlineTags(inspectionManager, problems, tag.getDataElements(), manager, isOnTheFly);
|
||||
}
|
||||
|
||||
return problems.isEmpty() ? null : problems;
|
||||
@@ -892,14 +904,15 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
private void checkInlineTags(final InspectionManager inspectionManager,
|
||||
final ArrayList<ProblemDescriptor> problems,
|
||||
final PsiElement[] dataElements,
|
||||
final JavadocManager manager) {
|
||||
final JavadocManager manager, boolean isOnTheFly) {
|
||||
for (PsiElement dataElement : dataElements) {
|
||||
if (dataElement instanceof PsiInlineDocTag) {
|
||||
final PsiInlineDocTag inlineDocTag = (PsiInlineDocTag)dataElement;
|
||||
final PsiElement nameElement = inlineDocTag.getNameElement();
|
||||
if (manager.getTagInfo(inlineDocTag.getName()) == null) {
|
||||
if (nameElement != null) {
|
||||
problems.add(createDescriptor(nameElement, InspectionsBundle.message("inspection.javadoc.problem.wrong.tag", "<code>" + inlineDocTag.getName() + "</code>"), new AddUnknownTagToCustoms(inlineDocTag), inspectionManager));
|
||||
problems.add(createDescriptor(nameElement, InspectionsBundle.message("inspection.javadoc.problem.wrong.tag", "<code>" + inlineDocTag.getName() + "</code>"), new AddUnknownTagToCustoms(inlineDocTag), inspectionManager,
|
||||
isOnTheFly));
|
||||
}
|
||||
}
|
||||
final PsiDocTagValue value = inlineDocTag.getValueElement();
|
||||
@@ -910,7 +923,8 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
if (ref != null){
|
||||
if (PsiTreeUtil.getParentOfType(inlineDocTag, PsiDocCommentOwner.class) == PsiTreeUtil.getParentOfType(ref, PsiDocCommentOwner.class, false)) {
|
||||
if (nameElement != null) {
|
||||
problems.add(createDescriptor(nameElement, InspectionsBundle.message("inspection.javadoc.problem.pointing.to.itself"), inspectionManager));
|
||||
problems.add(createDescriptor(nameElement, InspectionsBundle.message("inspection.javadoc.problem.pointing.to.itself"), inspectionManager,
|
||||
isOnTheFly));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -982,7 +996,7 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
|
||||
private static void checkDuplicateTags(final PsiDocTag[] tags,
|
||||
ArrayList<ProblemDescriptor> problems,
|
||||
final InspectionManager manager) {
|
||||
final InspectionManager manager, boolean isOnTheFly) {
|
||||
Set<String> documentedParamNames = null;
|
||||
Set<String> documentedExceptions = null;
|
||||
Set<String> uniqueTags = null;
|
||||
@@ -998,7 +1012,8 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
documentedParamNames = new HashSet<String>();
|
||||
}
|
||||
if (documentedParamNames.contains(paramName)) {
|
||||
problems.add(createDescriptor(tag.getNameElement(), InspectionsBundle.message("inspection.javadoc.problem.duplicate.param", paramName), manager));
|
||||
problems.add(createDescriptor(tag.getNameElement(), InspectionsBundle.message("inspection.javadoc.problem.duplicate.param", paramName), manager,
|
||||
isOnTheFly));
|
||||
}
|
||||
documentedParamNames.add(paramName);
|
||||
}
|
||||
@@ -1020,7 +1035,7 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
if (documentedExceptions.contains(fqName)) {
|
||||
problems.add(createDescriptor(tag.getNameElement(),
|
||||
InspectionsBundle.message("inspection.javadoc.problem.duplicate.throws", fqName),
|
||||
manager));
|
||||
manager, isOnTheFly));
|
||||
}
|
||||
documentedExceptions.add(fqName);
|
||||
}
|
||||
@@ -1033,7 +1048,8 @@ public class JavaDocLocalInspection extends BaseLocalInspectionTool {
|
||||
uniqueTags = new HashSet<String>();
|
||||
}
|
||||
if (uniqueTags.contains(tag.getName())) {
|
||||
problems.add(createDescriptor(tag.getNameElement(), InspectionsBundle.message("inspection.javadoc.problem.duplicate.tag", tag.getName()), manager));
|
||||
problems.add(createDescriptor(tag.getNameElement(), InspectionsBundle.message("inspection.javadoc.problem.duplicate.tag", tag.getName()), manager,
|
||||
isOnTheFly));
|
||||
}
|
||||
uniqueTags.add(tag.getName());
|
||||
}
|
||||
|
||||
+15
-14
@@ -43,8 +43,9 @@ public class JavaDocReferenceInspection extends BaseLocalInspectionTool {
|
||||
public static final String DISPLAY_NAME = InspectionsBundle.message("inspection.javadoc.ref.display.name");
|
||||
|
||||
|
||||
private static ProblemDescriptor createDescriptor(@NotNull PsiElement element, String template, InspectionManager manager) {
|
||||
return manager.createProblemDescriptor(element, template, (LocalQuickFix [])null, ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
|
||||
private static ProblemDescriptor createDescriptor(@NotNull PsiElement element, String template, InspectionManager manager,
|
||||
boolean onTheFly) {
|
||||
return manager.createProblemDescriptor(element, template, (LocalQuickFix [])null, ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, onTheFly);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -64,12 +65,13 @@ public class JavaDocReferenceInspection extends BaseLocalInspectionTool {
|
||||
if (docComment == null) return null;
|
||||
|
||||
final Set<PsiJavaCodeReferenceElement> references = new HashSet<PsiJavaCodeReferenceElement>();
|
||||
docComment.accept(getVisitor(references, docCommentOwner, problems, manager));
|
||||
docComment.accept(getVisitor(references, docCommentOwner, problems, manager, isOnTheFly));
|
||||
for (PsiJavaCodeReferenceElement reference : references) {
|
||||
final List<PsiClass> classesToImport = new ImportClassFix(reference).getClassesToImport();
|
||||
problems.add(manager.createProblemDescriptor(reference, InspectionsBundle.message("inspection.javadoc.problem.cannot.resolve",
|
||||
"<code>" + reference.getText() + "</code>"),
|
||||
!isOnTheFly || classesToImport.isEmpty() ? null : new AddImportFix(classesToImport), ProblemHighlightType.LIKE_UNKNOWN_SYMBOL));
|
||||
!isOnTheFly || classesToImport.isEmpty() ? null : new AddImportFix(classesToImport), ProblemHighlightType.LIKE_UNKNOWN_SYMBOL,
|
||||
isOnTheFly));
|
||||
}
|
||||
|
||||
return problems.isEmpty()
|
||||
@@ -86,7 +88,7 @@ public class JavaDocReferenceInspection extends BaseLocalInspectionTool {
|
||||
private PsiElementVisitor getVisitor(final Set<PsiJavaCodeReferenceElement> references,
|
||||
final PsiElement context,
|
||||
final ArrayList<ProblemDescriptor> problems,
|
||||
final InspectionManager manager) {
|
||||
final InspectionManager manager, final boolean onTheFly) {
|
||||
return new JavaElementVisitor() {
|
||||
@Override public void visitReferenceExpression(PsiReferenceExpression expression) {
|
||||
visitElement(expression);
|
||||
@@ -105,14 +107,14 @@ public class JavaDocReferenceInspection extends BaseLocalInspectionTool {
|
||||
final JavadocManager javadocManager = JavaPsiFacade.getInstance(tag.getProject()).getJavadocManager();
|
||||
final JavadocTagInfo info = javadocManager.getTagInfo(tag.getName());
|
||||
if (info == null || !info.isInline()) {
|
||||
visitRefInDocTag(tag, javadocManager, context, problems, manager);
|
||||
visitRefInDocTag(tag, javadocManager, context, problems, manager, onTheFly);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void visitInlineDocTag(PsiInlineDocTag tag) {
|
||||
super.visitInlineDocTag(tag);
|
||||
final JavadocManager javadocManager = JavaPsiFacade.getInstance(tag.getProject()).getJavadocManager();
|
||||
visitRefInDocTag(tag, javadocManager, context, problems, manager);
|
||||
visitRefInDocTag(tag, javadocManager, context, problems, manager, onTheFly);
|
||||
}
|
||||
|
||||
@Override public void visitElement(PsiElement element) {
|
||||
@@ -127,11 +129,9 @@ public class JavaDocReferenceInspection extends BaseLocalInspectionTool {
|
||||
};
|
||||
}
|
||||
|
||||
public static void visitRefInDocTag(final PsiDocTag tag,
|
||||
final JavadocManager manager,
|
||||
final PsiElement context,
|
||||
ArrayList<ProblemDescriptor> problems,
|
||||
InspectionManager inspectionManager) {
|
||||
public static void visitRefInDocTag(final PsiDocTag tag, final JavadocManager manager, final PsiElement context, ArrayList<ProblemDescriptor> problems,
|
||||
InspectionManager inspectionManager,
|
||||
boolean onTheFly) {
|
||||
String tagName = tag.getName();
|
||||
PsiDocTagValue value = tag.getValueElement();
|
||||
if (value == null) return;
|
||||
@@ -139,7 +139,7 @@ public class JavaDocReferenceInspection extends BaseLocalInspectionTool {
|
||||
if (info != null && !info.isValidInContext(context)) return;
|
||||
String message = info == null || !info.isInline() ? null : info.checkTagValue(value);
|
||||
if (message != null){
|
||||
problems.add(createDescriptor(value, message, inspectionManager));
|
||||
problems.add(createDescriptor(value, message, inspectionManager, onTheFly));
|
||||
}
|
||||
final PsiReference reference = value.getReference();
|
||||
if (reference != null) {
|
||||
@@ -151,7 +151,8 @@ public class JavaDocReferenceInspection extends BaseLocalInspectionTool {
|
||||
final PsiDocTagValue valueElement = tag.getValueElement();
|
||||
if (valueElement != null) {
|
||||
@NonNls String params = "<code>" + value.getContainingFile().getViewProvider().getContents().subSequence(textOffset, value.getTextRange().getEndOffset()) + "</code>";
|
||||
problems.add(createDescriptor(valueElement, InspectionsBundle.message("inspection.javadoc.problem.cannot.resolve", params), inspectionManager));
|
||||
problems.add(createDescriptor(valueElement, InspectionsBundle.message("inspection.javadoc.problem.cannot.resolve", params), inspectionManager,
|
||||
onTheFly));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ import com.intellij.openapi.vfs.ReadonlyStatusHandler;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.controlFlow.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtilBase;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.PsiUtilBase;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -35,7 +35,9 @@ import javax.swing.*;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -55,7 +57,7 @@ public class LocalCanBeFinal extends BaseLocalInspectionTool {
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] checkMethod(@NotNull PsiMethod method, @NotNull InspectionManager manager, boolean isOnTheFly) {
|
||||
List<ProblemDescriptor> list = checkCodeBlock(method.getBody(), manager);
|
||||
List<ProblemDescriptor> list = checkCodeBlock(method.getBody(), manager, isOnTheFly);
|
||||
return list == null ? null : list.toArray(new ProblemDescriptor[list.size()]);
|
||||
}
|
||||
|
||||
@@ -63,7 +65,7 @@ public class LocalCanBeFinal extends BaseLocalInspectionTool {
|
||||
List<ProblemDescriptor> allProblems = null;
|
||||
final PsiClassInitializer[] initializers = aClass.getInitializers();
|
||||
for (PsiClassInitializer initializer : initializers) {
|
||||
final List<ProblemDescriptor> problems = checkCodeBlock(initializer.getBody(), manager);
|
||||
final List<ProblemDescriptor> problems = checkCodeBlock(initializer.getBody(), manager, isOnTheFly);
|
||||
if (problems != null) {
|
||||
if (allProblems == null) {
|
||||
allProblems = new ArrayList<ProblemDescriptor>(1);
|
||||
@@ -75,7 +77,7 @@ public class LocalCanBeFinal extends BaseLocalInspectionTool {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private List<ProblemDescriptor> checkCodeBlock(final PsiCodeBlock body, InspectionManager manager) {
|
||||
private List<ProblemDescriptor> checkCodeBlock(final PsiCodeBlock body, InspectionManager manager, boolean onTheFly) {
|
||||
if (body == null) return null;
|
||||
final ControlFlow flow;
|
||||
try {
|
||||
@@ -216,12 +218,12 @@ public class LocalCanBeFinal extends BaseLocalInspectionTool {
|
||||
if (variable instanceof PsiParameter && !(((PsiParameter)variable).getDeclarationScope() instanceof PsiForeachStatement)) {
|
||||
problems.add(manager.createProblemDescriptor(problemElement,
|
||||
InspectionsBundle.message("inspection.can.be.local.parameter.problem.descriptor"),
|
||||
myQuickFix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
|
||||
myQuickFix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, onTheFly));
|
||||
}
|
||||
else {
|
||||
problems.add(manager.createProblemDescriptor(problemElement,
|
||||
InspectionsBundle.message("inspection.can.be.local.variable.problem.descriptor"),
|
||||
myQuickFix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
|
||||
myQuickFix, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, onTheFly));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -34,7 +34,7 @@ public abstract class GenericsInspectionToolBase extends BaseLocalInspectionTool
|
||||
if (initializers.length == 0) return null;
|
||||
List<ProblemDescriptor> descriptors = new ArrayList<ProblemDescriptor>();
|
||||
for (PsiClassInitializer initializer : initializers) {
|
||||
final ProblemDescriptor[] localDescriptions = getDescriptions(initializer, manager);
|
||||
final ProblemDescriptor[] localDescriptions = getDescriptions(initializer, manager, isOnTheFly);
|
||||
if (localDescriptions != null) {
|
||||
descriptors.addAll(Arrays.asList(localDescriptions));
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public abstract class GenericsInspectionToolBase extends BaseLocalInspectionTool
|
||||
public ProblemDescriptor[] checkField(@NotNull PsiField field, @NotNull InspectionManager manager, boolean isOnTheFly) {
|
||||
final PsiExpression initializer = field.getInitializer();
|
||||
if (initializer != null) {
|
||||
return getDescriptions(initializer, manager);
|
||||
return getDescriptions(initializer, manager, isOnTheFly);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -54,10 +54,10 @@ public abstract class GenericsInspectionToolBase extends BaseLocalInspectionTool
|
||||
public ProblemDescriptor[] checkMethod(@NotNull PsiMethod psiMethod, @NotNull InspectionManager manager, boolean isOnTheFly) {
|
||||
final PsiCodeBlock body = psiMethod.getBody();
|
||||
if (body != null) {
|
||||
return getDescriptions(body, manager);
|
||||
return getDescriptions(body, manager, isOnTheFly);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract ProblemDescriptor[] getDescriptions(PsiElement place, InspectionManager manager);
|
||||
public abstract ProblemDescriptor[] getDescriptions(PsiElement place, InspectionManager manager, boolean isOnTheFly);
|
||||
}
|
||||
|
||||
+3
-2
@@ -57,7 +57,7 @@ public class RedundantArrayForVarargsCallInspection extends GenericsInspectionTo
|
||||
}
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] getDescriptions(PsiElement place, final InspectionManager manager) {
|
||||
public ProblemDescriptor[] getDescriptions(PsiElement place, final InspectionManager manager, final boolean isOnTheFly) {
|
||||
if (!PsiUtil.isLanguageLevel5OrHigher(place)) return null;
|
||||
final List<ProblemDescriptor> problems = new ArrayList<ProblemDescriptor>();
|
||||
place.accept(new JavaRecursiveElementWalkingVisitor() {
|
||||
@@ -98,7 +98,8 @@ public class RedundantArrayForVarargsCallInspection extends GenericsInspectionTo
|
||||
final ProblemDescriptor descriptor = manager.createProblemDescriptor(lastArg,
|
||||
InspectionsBundle.message("inspection.redundant.array.creation.for.varargs.call.descriptor"),
|
||||
myQuickFixAction,
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||
isOnTheFly);
|
||||
|
||||
problems.add(descriptor);
|
||||
}
|
||||
|
||||
+3
-3
@@ -58,12 +58,12 @@ public class RedundantTypeArgsInspection extends GenericsInspectionToolBase {
|
||||
public ProblemDescriptor[] checkMethod(@NotNull PsiMethod psiMethod, @NotNull InspectionManager manager, boolean isOnTheFly) {
|
||||
final PsiCodeBlock body = psiMethod.getBody();
|
||||
if (body != null) {
|
||||
return getDescriptions(body, manager);
|
||||
return getDescriptions(body, manager, isOnTheFly);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] getDescriptions(PsiElement place, final InspectionManager inspectionManager) {
|
||||
public ProblemDescriptor[] getDescriptions(PsiElement place, final InspectionManager inspectionManager, boolean isOnTheFly) {
|
||||
final List<ProblemDescriptor> problems = new ArrayList<ProblemDescriptor>();
|
||||
place.accept(new JavaRecursiveElementWalkingVisitor() {
|
||||
@Override public void visitMethodCallExpression(PsiMethodCallExpression expression) {
|
||||
@@ -120,7 +120,7 @@ public class RedundantTypeArgsInspection extends GenericsInspectionToolBase {
|
||||
final ProblemDescriptor descriptor = inspectionManager.createProblemDescriptor(expression.getTypeArgumentList(),
|
||||
InspectionsBundle.message("inspection.redundant.type.problem.descriptor"),
|
||||
myQuickFixAction,
|
||||
ProblemHighlightType.LIKE_UNUSED_SYMBOL);
|
||||
ProblemHighlightType.LIKE_UNUSED_SYMBOL, false);
|
||||
problems.add(descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -52,20 +52,20 @@ public class RedundantCastInspection extends GenericsInspectionToolBase {
|
||||
myQuickFixAction = new AcceptSuggested();
|
||||
}
|
||||
|
||||
public ProblemDescriptor[] getDescriptions(PsiElement where, InspectionManager manager) {
|
||||
public ProblemDescriptor[] getDescriptions(PsiElement where, InspectionManager manager, boolean isOnTheFly) {
|
||||
List<PsiTypeCastExpression> redundantCasts = RedundantCastUtil.getRedundantCastsInside(where);
|
||||
if (redundantCasts.isEmpty()) return null;
|
||||
ProblemDescriptor[] descriptions = new ProblemDescriptor[redundantCasts.size()];
|
||||
for (int i = 0; i < redundantCasts.size(); i++) {
|
||||
descriptions[i] = createDescription(redundantCasts.get(i), manager);
|
||||
descriptions[i] = createDescription(redundantCasts.get(i), manager, isOnTheFly);
|
||||
}
|
||||
return descriptions;
|
||||
}
|
||||
|
||||
private ProblemDescriptor createDescription(PsiTypeCastExpression cast, InspectionManager manager) {
|
||||
private ProblemDescriptor createDescription(PsiTypeCastExpression cast, InspectionManager manager, boolean onTheFly) {
|
||||
String message = InspectionsBundle.message("inspection.redundant.cast.problem.descriptor",
|
||||
"<code>" + cast.getOperand().getText() + "</code>", "<code>#ref</code> #loc");
|
||||
return manager.createProblemDescriptor(cast.getCastType(), message, myQuickFixAction, ProblemHighlightType.LIKE_UNUSED_SYMBOL);
|
||||
return manager.createProblemDescriptor(cast.getCastType(), message, myQuickFixAction, ProblemHighlightType.LIKE_UNUSED_SYMBOL, onTheFly);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@ public class SameParameterValueInspection extends GlobalJavaInspectionTool {
|
||||
problems.add(manager.createProblemDescriptor(refParameter.getElement(), InspectionsBundle.message(
|
||||
"inspection.same.parameter.problem.descriptor", "<code>" + paramName + "</code>", "<code>" + value + "</code>"),
|
||||
new InlineParameterValueFix(paramName, value),
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -47,7 +47,8 @@ public class SameReturnValueInspection extends GlobalJavaInspectionTool {
|
||||
message = InspectionsBundle.message("inspection.same.return.value.problem.descriptor2", "<code>" + returnValue + "</code>");
|
||||
}
|
||||
|
||||
return new ProblemDescriptor[] {manager.createProblemDescriptor(refMethod.getElement().getNavigationElement(), message, (LocalQuickFix [])null, ProblemHighlightType.GENERIC_ERROR_OR_WARNING)};
|
||||
return new ProblemDescriptor[] {manager.createProblemDescriptor(refMethod.getElement().getNavigationElement(), message, (LocalQuickFix [])null, ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||
false)};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -86,15 +86,18 @@ public class RedundantThrows extends GlobalJavaInspectionTool {
|
||||
|
||||
if (refMethod.isAbstract() || refMethod.getOwnerClass().isInterface()) {
|
||||
problems.add(manager.createProblemDescriptor(throwsRef, InspectionsBundle.message(
|
||||
"inspection.redundant.throws.problem.descriptor", "<code>#ref</code>"), getFix(processor, throwsClassName), ProblemHighlightType.LIKE_UNUSED_SYMBOL));
|
||||
"inspection.redundant.throws.problem.descriptor", "<code>#ref</code>"), getFix(processor, throwsClassName), ProblemHighlightType.LIKE_UNUSED_SYMBOL,
|
||||
false));
|
||||
}
|
||||
else if (!refMethod.getDerivedMethods().isEmpty()) {
|
||||
problems.add(manager.createProblemDescriptor(throwsRef, InspectionsBundle.message(
|
||||
"inspection.redundant.throws.problem.descriptor1", "<code>#ref</code>"), getFix(processor, throwsClassName), ProblemHighlightType.LIKE_UNUSED_SYMBOL));
|
||||
"inspection.redundant.throws.problem.descriptor1", "<code>#ref</code>"), getFix(processor, throwsClassName), ProblemHighlightType.LIKE_UNUSED_SYMBOL,
|
||||
false));
|
||||
}
|
||||
else {
|
||||
problems.add(manager.createProblemDescriptor(throwsRef, InspectionsBundle.message(
|
||||
"inspection.redundant.throws.problem.descriptor2", "<code>#ref</code>"), getFix(processor, throwsClassName), ProblemHighlightType.LIKE_UNUSED_SYMBOL));
|
||||
"inspection.redundant.throws.problem.descriptor2", "<code>#ref</code>"), getFix(processor, throwsClassName), ProblemHighlightType.LIKE_UNUSED_SYMBOL,
|
||||
false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-4
@@ -52,11 +52,11 @@ public class RedundantThrowsDeclaration extends BaseJavaLocalInspectionTool {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, boolean isOnTheFly) {
|
||||
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
|
||||
final Set<ProblemDescriptor> problems = new HashSet<ProblemDescriptor>();
|
||||
file.accept(new JavaRecursiveElementWalkingVisitor() {
|
||||
@Override public void visitReferenceElement(PsiJavaCodeReferenceElement reference) {
|
||||
final ProblemDescriptor descriptor = checkExceptionsNeverThrown(reference, manager);
|
||||
final ProblemDescriptor descriptor = checkExceptionsNeverThrown(reference, manager, isOnTheFly);
|
||||
if (descriptor != null) {
|
||||
problems.add(descriptor);
|
||||
}
|
||||
@@ -69,7 +69,8 @@ public class RedundantThrowsDeclaration extends BaseJavaLocalInspectionTool {
|
||||
|
||||
|
||||
//@top
|
||||
private static ProblemDescriptor checkExceptionsNeverThrown(PsiJavaCodeReferenceElement referenceElement, InspectionManager inspectionManager) {
|
||||
private static ProblemDescriptor checkExceptionsNeverThrown(PsiJavaCodeReferenceElement referenceElement, InspectionManager inspectionManager,
|
||||
boolean onTheFly) {
|
||||
if (!(referenceElement.getParent() instanceof PsiReferenceList)) return null;
|
||||
PsiReferenceList referenceList = (PsiReferenceList)referenceElement.getParent();
|
||||
if (!(referenceList.getParent() instanceof PsiMethod)) return null;
|
||||
@@ -121,7 +122,8 @@ public class RedundantThrowsDeclaration extends BaseJavaLocalInspectionTool {
|
||||
String description = JavaErrorMessages.message("exception.is.never.thrown", HighlightUtil.formatType(exceptionType));
|
||||
|
||||
final LocalQuickFix quickFixes = new DeleteThrowsFix(method, exceptionType);
|
||||
return inspectionManager.createProblemDescriptor(referenceElement, description, quickFixes, ProblemHighlightType.LIKE_UNUSED_SYMBOL);
|
||||
return inspectionManager.createProblemDescriptor(referenceElement, description, quickFixes, ProblemHighlightType.LIKE_UNUSED_SYMBOL,
|
||||
onTheFly);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@ public class UnusedParametersInspection extends GlobalJavaInspectionTool {
|
||||
? InspectionsBundle.message("inspection.unused.parameter.composer")
|
||||
: InspectionsBundle.message("inspection.unused.parameter.composer1"),
|
||||
new AcceptSuggested(globalContext.getRefManager(), processor, refParameter.toString()),
|
||||
ProblemHighlightType.LIKE_UNUSED_SYMBOL));
|
||||
ProblemHighlightType.LIKE_UNUSED_SYMBOL, false));
|
||||
}
|
||||
}
|
||||
return result.toArray(new CommonProblemDescriptor[result.size()]);
|
||||
|
||||
+2
-1
@@ -55,7 +55,8 @@ public class UnusedReturnValue extends GlobalJavaInspectionTool{
|
||||
if (!refMethod.isReturnValueUsed()) {
|
||||
return new ProblemDescriptor[]{manager.createProblemDescriptor(refMethod.getElement().getNavigationElement(),
|
||||
InspectionsBundle.message("inspection.unused.return.value.problem.descriptor"),
|
||||
getFix(processor), ProblemHighlightType.GENERIC_ERROR_OR_WARNING)};
|
||||
getFix(processor), ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||
false)};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@ import com.intellij.codeInspection.*;
|
||||
import com.intellij.codeInspection.ex.EntryPointsManager;
|
||||
import com.intellij.codeInspection.reference.*;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.extensions.ExtensionPoint;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.ReadonlyStatusHandler;
|
||||
import com.intellij.psi.*;
|
||||
@@ -42,8 +42,8 @@ import com.intellij.psi.search.PsiNonJavaFileReferenceProcessor;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.PsiUtilBase;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -181,7 +181,7 @@ public class VisibilityInspection extends GlobalJavaInspectionTool {
|
||||
return new ProblemDescriptor[]{manager.createProblemDescriptor(psiElement,
|
||||
InspectionsBundle.message("inspection.visibility.compose.suggestion", VisibilityUtil.toPresentableText(access)),
|
||||
new AcceptSuggestedAccess(globalContext.getRefManager(), access),
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING)};
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false)};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -55,7 +55,7 @@ public class WrongPackageStatementInspection extends BaseJavaLocalInspectionTool
|
||||
|
||||
return new ProblemDescriptor[]{manager.createProblemDescriptor(classes[0].getNameIdentifier(), description,
|
||||
new AdjustPackageNameFix(javaFile, null, dirPackage),
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING)};
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly)};
|
||||
}
|
||||
if (packageStatement != null) {
|
||||
final PsiJavaCodeReferenceElement packageReference = packageStatement.getPackageReference();
|
||||
@@ -75,7 +75,8 @@ public class WrongPackageStatementInspection extends BaseJavaLocalInspectionTool
|
||||
String description = JavaErrorMessages.message("package.name.file.path.mismatch",
|
||||
packageReference.getText(),
|
||||
dirPackage.getQualifiedName());
|
||||
return new ProblemDescriptor[]{manager.createProblemDescriptor(packageStatement, description, availableFixes.toArray(new LocalQuickFix[availableFixes.size()]), ProblemHighlightType.GENERIC_ERROR_OR_WARNING)};
|
||||
return new ProblemDescriptor[]{manager.createProblemDescriptor(packageStatement, description, availableFixes.toArray(new LocalQuickFix[availableFixes.size()]), ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
|
||||
isOnTheFly)};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user