diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/unneededThrows/RedundantThrowsDeclarationInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/unneededThrows/RedundantThrowsDeclarationInspection.java index f9216e6a3f14..e7f28f32f797 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/unneededThrows/RedundantThrowsDeclarationInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/unneededThrows/RedundantThrowsDeclarationInspection.java @@ -1,17 +1,5 @@ /* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.codeInspection.unneededThrows; @@ -262,15 +250,10 @@ public class RedundantThrowsDeclarationInspection extends GlobalJavaBatchInspect } } - @Override - public boolean startInWriteAction() { - return false; - } - - private static void removeException(final RefMethod refMethod, - final PsiType exceptionType, - final List refsToDelete, - final PsiMethod psiMethod) { + private void removeException(RefMethod refMethod, + PsiType exceptionType, + List refsToDelete, + PsiMethod psiMethod) { PsiManager psiManager = psiMethod.getManager(); PsiJavaCodeReferenceElement[] refs = psiMethod.getThrowsList().getReferenceElements(); @@ -282,12 +265,15 @@ public class RedundantThrowsDeclarationInspection extends GlobalJavaBatchInspect } if (refMethod != null) { + assert myProcessor != null; + for (RefMethod refDerived : refMethod.getDerivedMethods()) { PsiModifierListOwner method = refDerived.getElement(); if (method != null) { removeException(refDerived, exceptionType, refsToDelete, (PsiMethod)method); } } + ProblemDescriptionsProcessor.resolveAllProblemsInElement(myProcessor, refMethod); } else { final Query query = OverridingMethodsSearch.search(psiMethod); query.forEach(m -> { @@ -296,6 +282,11 @@ public class RedundantThrowsDeclarationInspection extends GlobalJavaBatchInspect }); } } + + @Override + public boolean startInWriteAction() { + return false; + } } @Nullable diff --git a/platform/analysis-api/src/com/intellij/codeInspection/ProblemDescriptionsProcessor.java b/platform/analysis-api/src/com/intellij/codeInspection/ProblemDescriptionsProcessor.java index ceb0ca61b996..0f6d530758cd 100644 --- a/platform/analysis-api/src/com/intellij/codeInspection/ProblemDescriptionsProcessor.java +++ b/platform/analysis-api/src/com/intellij/codeInspection/ProblemDescriptionsProcessor.java @@ -1,17 +1,5 @@ /* - * Copyright 2000-2016 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.codeInspection; @@ -43,8 +31,9 @@ public interface ProblemDescriptionsProcessor { * * @param refEntity the reference graph node. */ - default void ignoreElement(@NotNull RefEntity refEntity) { - } + default void ignoreElement(@NotNull RefEntity refEntity) {} + + default void resolveProblem(@NotNull CommonProblemDescriptor descriptor) {} /** * Registers a problem or several problems, with optional quickfixes, for the specified @@ -59,4 +48,13 @@ public interface ProblemDescriptionsProcessor { default RefEntity getElement(@NotNull CommonProblemDescriptor descriptor) { return null; } + + static void resolveAllProblemsInElement(@NotNull ProblemDescriptionsProcessor processor, @NotNull RefEntity element) { + CommonProblemDescriptor[] descriptors = processor.getDescriptions(element); + if (descriptors != null) { + for (CommonProblemDescriptor descriptor : descriptors) { + processor.resolveProblem(descriptor); + } + } + } } diff --git a/platform/analysis-impl/src/com/intellij/codeInspection/InspectionEngine.java b/platform/analysis-impl/src/com/intellij/codeInspection/InspectionEngine.java index dfba457a34df..a9da2e30a0e7 100644 --- a/platform/analysis-impl/src/com/intellij/codeInspection/InspectionEngine.java +++ b/platform/analysis-impl/src/com/intellij/codeInspection/InspectionEngine.java @@ -1,17 +1,5 @@ /* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. */ package com.intellij.codeInspection; @@ -199,7 +187,12 @@ public class InspectionEngine { @Override public void ignoreElement(@NotNull RefEntity refEntity) { - throw new RuntimeException(); + throw new UnsupportedOperationException(); + } + + @Override + public void resolveProblem(@NotNull CommonProblemDescriptor descriptor) { + throw new UnsupportedOperationException(); } @Override diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionToolPresentation.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionToolPresentation.java index e2e6d0000e30..9ab12b4bc543 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionToolPresentation.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/InspectionToolPresentation.java @@ -53,8 +53,6 @@ public interface InspectionToolPresentation extends ProblemDescriptionsProcessor @NotNull Map> getContent(); - void resolveProblem(@NotNull CommonProblemDescriptor descriptor); - boolean isProblemResolved(@Nullable CommonProblemDescriptor descriptor); boolean isProblemResolved(@Nullable RefEntity entity);