From 2114abd535e4194b1b7c454fbf9cda8679934b83 Mon Sep 17 00:00:00 2001 From: Yaroslav Pankratyev Date: Wed, 5 Sep 2018 12:06:54 +0300 Subject: [PATCH] IDEA-194133 Introduce ScheduledForRemovalInspection --- .../resources/META-INF/JvmAnalysisPlugin.xml | 5 +++ .../jvm/analysis/JvmAnalysisBundle.properties | 2 ++ .../ScheduledForRemoval.html | 7 ++++ .../AnnotatedElementInspectionBase.java | 13 ++++++++ .../ScheduledForRemovalInspection.java | 32 +++++++++++++++++++ .../UnstableApiUsageInspection.java | 13 -------- 6 files changed, 59 insertions(+), 13 deletions(-) create mode 100644 jvm/jvm-analysis-impl/resources/inspectionDescriptions/ScheduledForRemoval.html create mode 100644 jvm/jvm-analysis-impl/src/com/intellij/codeInspection/ScheduledForRemovalInspection.java diff --git a/jvm/jvm-analysis-impl/resources/META-INF/JvmAnalysisPlugin.xml b/jvm/jvm-analysis-impl/resources/META-INF/JvmAnalysisPlugin.xml index b404b1c6e454..57218d57b508 100644 --- a/jvm/jvm-analysis-impl/resources/META-INF/JvmAnalysisPlugin.xml +++ b/jvm/jvm-analysis-impl/resources/META-INF/JvmAnalysisPlugin.xml @@ -15,6 +15,11 @@ enabledByDefault="true" level="WARNING" key="jvm.inspections.blocking.method.display.name" bundle="com.intellij.jvm.analysis.JvmAnalysisBundle" implementationClass="com.intellij.codeInspection.blockingCallsDetection.BlockingMethodInNonBlockingContextInspection"/> + + diff --git a/jvm/jvm-analysis-impl/resources/com/intellij/jvm/analysis/JvmAnalysisBundle.properties b/jvm/jvm-analysis-impl/resources/com/intellij/jvm/analysis/JvmAnalysisBundle.properties index 89fb2c64c329..444ef215ebb1 100644 --- a/jvm/jvm-analysis-impl/resources/com/intellij/jvm/analysis/JvmAnalysisBundle.properties +++ b/jvm/jvm-analysis-impl/resources/com/intellij/jvm/analysis/JvmAnalysisBundle.properties @@ -4,6 +4,8 @@ jvm.inspections.unstable.api.usage.display.name=Unstable API Usage jvm.inspections.unstable.api.usage.annotations.list=Unstable API annotations jvm.inspections.unstable.api.usage.ignore.inside.imports=Ignore inside imports jvm.inspections.unstable.api.usage.description=''{0}'' is marked unstable +jvm.inspections.scheduled.for.removal.display.name=Usage of API scheduled for removal +jvm.inspections.scheduled.for.removal.description=''{0}'' is scheduled for removal jvm.inspections.blocking.method.problem.descriptor=Inappropriate blocking method call jvm.inspections.blocking.method.display.name=Inappropriate thread-blocking method call jvm.inspections.blocking.method.annotation.blocking=Blocking Annotations diff --git a/jvm/jvm-analysis-impl/resources/inspectionDescriptions/ScheduledForRemoval.html b/jvm/jvm-analysis-impl/resources/inspectionDescriptions/ScheduledForRemoval.html new file mode 100644 index 000000000000..aacefba0f17a --- /dev/null +++ b/jvm/jvm-analysis-impl/resources/inspectionDescriptions/ScheduledForRemoval.html @@ -0,0 +1,7 @@ + + +This inspection reports usages of API scheduled for removal (annotated with +@ApiStatus.ScheduledForRemoval) +New in 2018.3 + + diff --git a/jvm/jvm-analysis-impl/src/com/intellij/codeInspection/AnnotatedElementInspectionBase.java b/jvm/jvm-analysis-impl/src/com/intellij/codeInspection/AnnotatedElementInspectionBase.java index b02ad1adeb17..02186018302f 100644 --- a/jvm/jvm-analysis-impl/src/com/intellij/codeInspection/AnnotatedElementInspectionBase.java +++ b/jvm/jvm-analysis-impl/src/com/intellij/codeInspection/AnnotatedElementInspectionBase.java @@ -4,6 +4,7 @@ package com.intellij.codeInspection; import com.intellij.analysis.JvmAnalysisBundle; import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.*; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.util.PsiTreeUtil; @@ -113,4 +114,16 @@ public abstract class AnnotatedElementInspectionBase extends LocalInspectionTool return false; } + + @NotNull + protected static String getReferenceText(@NotNull PsiReference reference) { + if (reference instanceof PsiQualifiedReference) { + String referenceName = ((PsiQualifiedReference)reference).getReferenceName(); + if (referenceName != null) { + return referenceName; + } + } + // references are not PsiQualifiedReference for annotation attributes + return StringUtil.getShortName(reference.getCanonicalText()); + } } \ No newline at end of file diff --git a/jvm/jvm-analysis-impl/src/com/intellij/codeInspection/ScheduledForRemovalInspection.java b/jvm/jvm-analysis-impl/src/com/intellij/codeInspection/ScheduledForRemovalInspection.java new file mode 100644 index 000000000000..0097385757fb --- /dev/null +++ b/jvm/jvm-analysis-impl/src/com/intellij/codeInspection/ScheduledForRemovalInspection.java @@ -0,0 +1,32 @@ +// Copyright 2000-2018 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; + +import com.intellij.analysis.JvmAnalysisBundle; +import com.intellij.psi.PsiModifierListOwner; +import com.intellij.psi.PsiReference; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; + +//TODO quickfix like in deprecation inspection? +public class ScheduledForRemovalInspection extends AnnotatedElementInspectionBase { + @NotNull + @Override + protected List getAnnotations() { + return Collections.singletonList(ApiStatus.ScheduledForRemoval.class.getCanonicalName()); + } + + @Override + protected void createProblem(@NotNull PsiReference reference, @NotNull ProblemsHolder holder) { + //TODO determine highlight severity like in MarkedForRemovalInspection (and extend the description)? + String message = JvmAnalysisBundle.message("jvm.inspections.scheduled.for.removal.description", getReferenceText(reference)); + holder.registerProblem(reference, message, ProblemHighlightType.LIKE_MARKED_FOR_REMOVAL); + } + + @Override + protected boolean shouldProcessElement(@NotNull PsiModifierListOwner element) { + return true; + } +} diff --git a/jvm/jvm-analysis-impl/src/com/intellij/codeInspection/UnstableApiUsageInspection.java b/jvm/jvm-analysis-impl/src/com/intellij/codeInspection/UnstableApiUsageInspection.java index 5cc93923f526..7f46da8bce9f 100644 --- a/jvm/jvm-analysis-impl/src/com/intellij/codeInspection/UnstableApiUsageInspection.java +++ b/jvm/jvm-analysis-impl/src/com/intellij/codeInspection/UnstableApiUsageInspection.java @@ -5,7 +5,6 @@ import com.intellij.analysis.JvmAnalysisBundle; import com.intellij.codeInspection.util.SpecialAnnotationsUtil; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.roots.ProjectFileIndex; -import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.*; import com.siyeh.ig.ui.ExternalizableStringSet; @@ -74,16 +73,4 @@ public class UnstableApiUsageInspection extends AnnotatedElementInspectionBase { } return ProjectFileIndex.getInstance(element.getProject()).isInLibraryClasses(containingVirtualFile); } - - @NotNull - private static String getReferenceText(@NotNull PsiReference reference) { - if (reference instanceof PsiQualifiedReference) { - String referenceName = ((PsiQualifiedReference)reference).getReferenceName(); - if (referenceName != null) { - return referenceName; - } - } - // references are not PsiQualifiedReference for annotation attributes - return StringUtil.getShortName(reference.getCanonicalText()); - } }