diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/deprecation/DeprecationInspectionBase.java b/java/java-analysis-impl/src/com/intellij/codeInspection/deprecation/DeprecationInspectionBase.java index 980c734fc40f..a47cbc45da59 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/deprecation/DeprecationInspectionBase.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/deprecation/DeprecationInspectionBase.java @@ -18,6 +18,7 @@ import com.intellij.psi.*; import com.intellij.psi.impl.JavaConstantExpressionEvaluator; import com.intellij.psi.impl.PsiImplUtil; import com.intellij.psi.impl.compiled.ClsMethodImpl; +import com.intellij.psi.impl.source.PsiJavaModuleReference; import com.intellij.psi.infos.MethodCandidateInfo; import com.intellij.psi.javadoc.PsiDocComment; import com.intellij.psi.javadoc.PsiDocTag; @@ -188,16 +189,11 @@ abstract class DeprecationInspectionBase extends AbstractBaseJavaLocalInspection @Override public void visitRequiresStatement(PsiRequiresStatement statement) { PsiJavaModuleReferenceElement refElement = statement.getReferenceElement(); - if (refElement != null) { - PsiPolyVariantReference ref = refElement.getReference(); - PsiElement target = ref != null ? ref.resolve() : null; - if (target instanceof PsiJavaModule && - isMarkedForRemoval((PsiJavaModule)target, myForRemoval) && - PsiImplUtil.isDeprecatedByAnnotation((PsiJavaModule)target)) { - String description = JavaErrorMessages.message(myForRemoval ? "marked.for.removal.symbol" : "deprecated.symbol", - HighlightMessageUtil.getSymbolName(target)); - myHolder.registerProblem(refElement, getDescription(description, myForRemoval, myHighlightType), myHighlightType); - } + PsiJavaModule target = PsiJavaModuleReference.resolve(refElement); + if (target != null && isMarkedForRemoval(target, myForRemoval) && PsiImplUtil.isDeprecatedByAnnotation(target)) { + String key = myForRemoval ? "marked.for.removal.symbol" : "deprecated.symbol"; + String description = JavaErrorMessages.message(key, HighlightMessageUtil.getSymbolName(target)); + myHolder.registerProblem(refElement, getDescription(description, myForRemoval, myHighlightType), myHighlightType); } } } diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/java19modules/JavaRequiresAutoModuleInspection.java b/java/java-analysis-impl/src/com/intellij/codeInspection/java19modules/JavaRequiresAutoModuleInspection.java index 7fb39f0afb63..813ee9c8b85b 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/java19modules/JavaRequiresAutoModuleInspection.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/java19modules/JavaRequiresAutoModuleInspection.java @@ -1,4 +1,4 @@ -// 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. +// 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.java19modules; import com.intellij.codeInspection.AbstractBaseJavaLocalInspectionTool; @@ -7,6 +7,7 @@ import com.intellij.codeInspection.ProblemsHolder; import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel; import com.intellij.psi.*; import com.intellij.psi.impl.light.LightJavaModule; +import com.intellij.psi.impl.source.PsiJavaModuleReference; import com.intellij.psi.util.PsiUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -30,18 +31,13 @@ public class JavaRequiresAutoModuleInspection extends AbstractBaseJavaLocalInspe public void visitRequiresStatement(PsiRequiresStatement statement) { super.visitRequiresStatement(statement); PsiJavaModuleReferenceElement refElement = statement.getReferenceElement(); - if (refElement != null) { - PsiPolyVariantReference reference = refElement.getReference(); - if (reference != null) { - PsiElement target = reference.resolve(); - if (target instanceof LightJavaModule) { - if (!TRANSITIVE_ONLY) { - holder.registerProblem(refElement, InspectionsBundle.message("inspection.requires.auto.module.message")); - } - else if (statement.hasModifierProperty(PsiModifier.TRANSITIVE)) { - holder.registerProblem(refElement, InspectionsBundle.message("inspection.requires.auto.module.transitive")); - } - } + PsiJavaModule target = PsiJavaModuleReference.resolve(refElement); + if (target instanceof LightJavaModule) { + if (!TRANSITIVE_ONLY) { + holder.registerProblem(refElement, InspectionsBundle.message("inspection.requires.auto.module.message")); + } + else if (statement.hasModifierProperty(PsiModifier.TRANSITIVE)) { + holder.registerProblem(refElement, InspectionsBundle.message("inspection.requires.auto.module.transitive")); } } } diff --git a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiJavaModuleReference.java b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiJavaModuleReference.java index 1272f7841e20..bf0d7efd0a12 100644 --- a/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiJavaModuleReference.java +++ b/java/java-psi-impl/src/com/intellij/psi/impl/source/PsiJavaModuleReference.java @@ -16,6 +16,7 @@ import com.intellij.psi.util.CachedValuesManager; import com.intellij.psi.util.PsiModificationTracker; import com.intellij.util.ArrayUtil; import com.intellij.util.IncorrectOperationException; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -99,6 +100,22 @@ public class PsiJavaModuleReference extends PsiReferenceBase.Poly>> K_COMPLETE = Key.create("java.module.ref.text.resolve.complete"); private static final Key>> K_INCOMPLETE = Key.create("java.module.ref.text.resolve.incomplete"); + @Nullable + @Contract("null -> null") + public static PsiJavaModule resolve(@Nullable PsiJavaModuleReferenceElement refElement) { + if (refElement != null) { + PsiPolyVariantReference ref = refElement.getReference(); + if (ref != null) { + PsiElement result = ref.resolve(); + if (result instanceof PsiJavaModule) { + return (PsiJavaModule)result; + } + } + } + + return null; + } + @Nullable public static PsiJavaModule resolve(@NotNull PsiElement refOwner, String refText, boolean incompleteCode) { Collection modules = multiResolve(refOwner, refText, incompleteCode);