mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Cleanup (extracts module ref. resolve routine)
This commit is contained in:
+6
-10
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
-13
@@ -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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<PsiJavaModuleR
|
||||
private static final Key<CachedValue<Collection<PsiJavaModule>>> K_COMPLETE = Key.create("java.module.ref.text.resolve.complete");
|
||||
private static final Key<CachedValue<Collection<PsiJavaModule>>> 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<PsiJavaModule> modules = multiResolve(refOwner, refText, incompleteCode);
|
||||
|
||||
Reference in New Issue
Block a user