From 8fb3a2a0759e3820c87a0ae5936f33e8fbc40e31 Mon Sep 17 00:00:00 2001 From: UNV Date: Tue, 2 Dec 2025 23:32:08 +0300 Subject: [PATCH] Fixing compilation after localizing ProblemDescriptor. --- .../impl/inspections/PyInspectionVisitor.java | 219 ++++++++++-------- .../impl/validation/UnsupportedFeatures.java | 106 +++++---- 2 files changed, 177 insertions(+), 148 deletions(-) diff --git a/python-impl/src/main/java/com/jetbrains/python/impl/inspections/PyInspectionVisitor.java b/python-impl/src/main/java/com/jetbrains/python/impl/inspections/PyInspectionVisitor.java index 7f7ce4b3..ccd1e5eb 100644 --- a/python-impl/src/main/java/com/jetbrains/python/impl/inspections/PyInspectionVisitor.java +++ b/python-impl/src/main/java/com/jetbrains/python/impl/inspections/PyInspectionVisitor.java @@ -15,6 +15,8 @@ */ package com.jetbrains.python.impl.inspections; +import consulo.annotation.access.RequiredReadAction; +import consulo.localize.LocalizeValue; import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; import consulo.language.editor.intention.HintAction; @@ -36,116 +38,129 @@ /** * @author dcheryasov */ -public abstract class PyInspectionVisitor extends PyElementVisitor -{ - @Nullable - private final ProblemsHolder myHolder; - @Nonnull - private final LocalInspectionToolSession mySession; - protected final TypeEvalContext myTypeEvalContext; +public abstract class PyInspectionVisitor extends PyElementVisitor { + @Nullable + private final ProblemsHolder myHolder; + @Nonnull + private final LocalInspectionToolSession mySession; + protected final TypeEvalContext myTypeEvalContext; - public static final Key INSPECTION_TYPE_EVAL_CONTEXT = Key.create("PyInspectionTypeEvalContext"); + public static final Key INSPECTION_TYPE_EVAL_CONTEXT = Key.create("PyInspectionTypeEvalContext"); - public PyInspectionVisitor(@Nullable ProblemsHolder holder, @Nonnull LocalInspectionToolSession session) - { - myHolder = holder; - mySession = session; - TypeEvalContext context; - synchronized(INSPECTION_TYPE_EVAL_CONTEXT) - { - context = session.getUserData(INSPECTION_TYPE_EVAL_CONTEXT); - if(context == null) - { - PsiFile file = session.getFile(); - context = TypeEvalContext.codeAnalysis(file.getProject(), file); - session.putUserData(INSPECTION_TYPE_EVAL_CONTEXT, context); - } - } - myTypeEvalContext = context; - } + public PyInspectionVisitor(@Nullable ProblemsHolder holder, @Nonnull LocalInspectionToolSession session) { + myHolder = holder; + mySession = session; + TypeEvalContext context; + synchronized (INSPECTION_TYPE_EVAL_CONTEXT) { + context = session.getUserData(INSPECTION_TYPE_EVAL_CONTEXT); + if (context == null) { + PsiFile file = session.getFile(); + context = TypeEvalContext.codeAnalysis(file.getProject(), file); + session.putUserData(INSPECTION_TYPE_EVAL_CONTEXT, context); + } + } + myTypeEvalContext = context; + } - protected PyResolveContext getResolveContext() - { - return PyResolveContext.noImplicits().withTypeEvalContext(myTypeEvalContext); - } + protected PyResolveContext getResolveContext() { + return PyResolveContext.noImplicits().withTypeEvalContext(myTypeEvalContext); + } - @Nullable - protected ProblemsHolder getHolder() - { - return myHolder; - } + @Nullable + protected ProblemsHolder getHolder() { + return myHolder; + } - @Nonnull - public LocalInspectionToolSession getSession() - { - return mySession; - } + @Nonnull + public LocalInspectionToolSession getSession() { + return mySession; + } - protected final void registerProblem(final PsiElement element, final String message) - { - if(element == null || element.getTextLength() == 0) - { - return; - } - if(myHolder != null) - { - myHolder.registerProblem(element, message); - } - } + @RequiredReadAction + protected final void registerProblem(PsiElement element, String message) { + if (element == null || element.getTextLength() == 0) { + return; + } + if (myHolder != null) { + myHolder.newProblem(LocalizeValue.of(message)) + .range(element) + .create(); + } + } - protected final void registerProblem(@Nullable final PsiElement element, @Nonnull final String message, @Nonnull final LocalQuickFix... quickFixes) - { - if(element == null || element.getTextLength() == 0) - { - return; - } - if(myHolder != null) - { - myHolder.registerProblem(element, message, quickFixes); - } - } + @RequiredReadAction + protected final void registerProblem( + @Nullable PsiElement element, + @Nonnull String message, + @Nonnull LocalQuickFix... quickFixes + ) { + if (element == null || element.getTextLength() == 0) { + return; + } + if (myHolder != null) { + myHolder.newProblem(LocalizeValue.of(message)) + .range(element) + .withFixes(quickFixes) + .create(); + } + } - protected final void registerProblem(final PsiElement element, final String message, final ProblemHighlightType type) - { - if(element == null || element.getTextLength() == 0) - { - return; - } - if(myHolder != null) - { - myHolder.registerProblem(myHolder.getManager().createProblemDescriptor(element, message, (LocalQuickFix) null, type, myHolder.isOnTheFly())); - } - } + @RequiredReadAction + protected final void registerProblem(PsiElement element, String message, ProblemHighlightType type) { + if (element == null || element.getTextLength() == 0) { + return; + } + if (myHolder != null) { + myHolder.registerProblem(myHolder.getManager().newProblemDescriptor(LocalizeValue.of(message)) + .range(element) + .highlightType(type) + .onTheFly(myHolder.isOnTheFly()) + .create()); + } + } - /** - * The most full-blown version. - * - * @see com.intellij.codeInspection.ProblemDescriptor - */ - protected final void registerProblem(@Nonnull final PsiElement psiElement, - @Nonnull final String descriptionTemplate, - final ProblemHighlightType highlightType, - @Nullable final HintAction hintAction, - final LocalQuickFix... fixes) - { - registerProblem(psiElement, descriptionTemplate, highlightType, hintAction, null, fixes); - } + /** + * The most full-blown version. + * + * @see ProblemDescriptor + */ + @RequiredReadAction + protected final void registerProblem( + @Nonnull PsiElement psiElement, + @Nonnull String descriptionTemplate, + ProblemHighlightType highlightType, + @Nullable HintAction hintAction, + LocalQuickFix... fixes + ) { + registerProblem(psiElement, descriptionTemplate, highlightType, hintAction, null, fixes); + } - /** - * The most full-blown version. - * - * @see ProblemDescriptor - */ - protected final void registerProblem(@Nonnull final PsiElement psiElement, - @Nonnull final String descriptionTemplate, - final ProblemHighlightType highlightType, - @Nullable final HintAction hintAction, - @Nullable final TextRange rangeInElement, - final LocalQuickFix... fixes) - { - if(myHolder != null && !(psiElement instanceof PsiErrorElement)) - { - myHolder.registerProblem(new ProblemDescriptorImpl(psiElement, psiElement, descriptionTemplate, fixes, highlightType, false, rangeInElement, hintAction, myHolder.isOnTheFly())); - } - } + /** + * The most full-blown version. + * + * @see ProblemDescriptor + */ + @RequiredReadAction + protected final void registerProblem( + @Nonnull PsiElement psiElement, + @Nonnull String descriptionTemplate, + ProblemHighlightType highlightType, + @Nullable HintAction hintAction, + @Nullable TextRange rangeInElement, + LocalQuickFix... fixes + ) { + if (myHolder != null && !(psiElement instanceof PsiErrorElement)) { + myHolder.registerProblem(new ProblemDescriptorImpl( + psiElement, + psiElement, + LocalizeValue.of(descriptionTemplate), + fixes, + highlightType, + false, + rangeInElement, + hintAction, + myHolder.isOnTheFly() + )); + } + } } diff --git a/python-impl/src/main/java/com/jetbrains/python/impl/validation/UnsupportedFeatures.java b/python-impl/src/main/java/com/jetbrains/python/impl/validation/UnsupportedFeatures.java index 38442382..1f4eaf4d 100644 --- a/python-impl/src/main/java/com/jetbrains/python/impl/validation/UnsupportedFeatures.java +++ b/python-impl/src/main/java/com/jetbrains/python/impl/validation/UnsupportedFeatures.java @@ -17,6 +17,7 @@ import com.jetbrains.python.psi.LanguageLevel; import com.jetbrains.python.psi.PyElement; +import consulo.annotation.access.RequiredReadAction; import consulo.document.util.TextRange; import consulo.ide.impl.idea.codeInspection.ex.ProblemDescriptorImpl; import consulo.language.editor.inspection.LocalQuickFix; @@ -24,6 +25,7 @@ import consulo.language.editor.intention.IntentionAction; import consulo.language.editor.intention.QuickFixWrapper; import consulo.language.psi.PsiElement; +import consulo.localize.LocalizeValue; import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; @@ -34,58 +36,70 @@ * @author Alexey.Ivanov */ public class UnsupportedFeatures extends CompatibilityVisitor { + public UnsupportedFeatures() { + super(new ArrayList<>()); + } - public UnsupportedFeatures() { - super(new ArrayList<>()); - } + @Override + public void visitPyElement(PyElement node) { + setVersionsToProcess(Arrays.asList(LanguageLevel.forElement(node))); + } - @Override - public void visitPyElement(PyElement node) { - setVersionsToProcess(Arrays.asList(LanguageLevel.forElement(node))); - } + @Override + @RequiredReadAction + protected void registerProblem( + @Nonnull PsiElement node, + @Nonnull TextRange range, + @Nonnull String message, + @Nullable LocalQuickFix localQuickFix, + boolean asError + ) { + if (range.isEmpty()) { + return; + } - @Override - protected void registerProblem(@Nonnull PsiElement node, - @Nonnull TextRange range, - @Nonnull String message, - @Nullable LocalQuickFix localQuickFix, - boolean asError) { - if (range.isEmpty()) { - return; + if (localQuickFix != null) { + if (asError) { + getHolder().createErrorAnnotation(range, message) + .registerFix(createIntention(node, LocalizeValue.of(message), localQuickFix)); + } + else { + getHolder().createWarningAnnotation(range, message) + .registerFix(createIntention(node, LocalizeValue.of(message), localQuickFix)); + } + } + else { + if (asError) { + getHolder().createErrorAnnotation(range, message); + } + else { + getHolder().createWarningAnnotation(range, message); + } + } } - if (localQuickFix != null) { - if (asError) { - getHolder().createErrorAnnotation(range, message).registerFix(createIntention(node, message, localQuickFix)); - } - else { - getHolder().createWarningAnnotation(range, message).registerFix(createIntention(node, message, localQuickFix)); - } - } - else { - if (asError) { - getHolder().createErrorAnnotation(range, message); - } - else { - getHolder().createWarningAnnotation(range, message); - } + @Nonnull + @RequiredReadAction + private static IntentionAction createIntention( + @Nonnull PsiElement node, + @Nonnull LocalizeValue message, + @Nonnull LocalQuickFix localQuickFix + ) { + return createIntention(node, node.getTextRange(), message, localQuickFix); } - } - @Nonnull - private static IntentionAction createIntention(@Nonnull PsiElement node, @Nonnull String message, @Nonnull LocalQuickFix localQuickFix) { - return createIntention(node, node.getTextRange(), message, localQuickFix); - } + @Nonnull + @RequiredReadAction + private static IntentionAction createIntention( + @Nonnull PsiElement node, + @Nullable TextRange range, + @Nonnull LocalizeValue message, + @Nonnull LocalQuickFix localQuickFix + ) { + LocalQuickFix[] quickFixes = {localQuickFix}; + ProblemDescriptorImpl descr = + new ProblemDescriptorImpl(node, node, message, quickFixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, true, range, true); - @Nonnull - private static IntentionAction createIntention(@Nonnull PsiElement node, - @Nullable TextRange range, - @Nonnull String message, - @Nonnull LocalQuickFix localQuickFix) { - final LocalQuickFix[] quickFixes = {localQuickFix}; - final ProblemDescriptorImpl descr = - new ProblemDescriptorImpl(node, node, message, quickFixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, true, range, true); - - return QuickFixWrapper.wrap(descr, 0); - } + return QuickFixWrapper.wrap(descr, 0); + } }