mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
cleanup: highlighting passes instantiation
GitOrigin-RevId: 0e6f807451b5f0c57ea5355ece6377982d082ef7
This commit is contained in:
committed by
intellij-monorepo-bot
parent
8c0b6fbf06
commit
f59c40b9e4
@@ -330,9 +330,7 @@ public abstract class PsiJavaFileBaseImpl extends PsiFileImpl implements PsiJava
|
||||
|
||||
Map<String, Iterable<ResultWithContext>> result = new LinkedHashMap<>();
|
||||
for (String name : ContainerUtil.newLinkedHashSet(ContainerUtil.concat(ownClasses.keySet(), typeImports.keySet(), staticImports.keySet()))) {
|
||||
NotNullLazyValue<Iterable<ResultWithContext>> lazy = NotNullLazyValue.volatileLazy(() -> {
|
||||
return findExplicitDeclarations(name, ownClasses, typeImports, staticImports);
|
||||
});
|
||||
NotNullLazyValue<Iterable<ResultWithContext>> lazy = NotNullLazyValue.volatileLazy(() -> findExplicitDeclarations(name, ownClasses, typeImports, staticImports));
|
||||
result.put(name, () -> lazy.getValue().iterator());
|
||||
}
|
||||
return CachedValueProvider.Result.create(result, PsiModificationTracker.MODIFICATION_COUNT);
|
||||
@@ -458,11 +456,9 @@ public abstract class PsiJavaFileBaseImpl extends PsiFileImpl implements PsiJava
|
||||
|
||||
private static boolean processOnDemandTarget(PsiElement target, PsiScopeProcessor processor, ResolveState substitutor, PsiElement place) {
|
||||
if (target instanceof PsiPackage) {
|
||||
if (!processPackageDeclarations(processor, substitutor, place, (PsiPackage)target)) {
|
||||
return false;
|
||||
}
|
||||
return processPackageDeclarations(processor, substitutor, place, (PsiPackage)target);
|
||||
}
|
||||
else if (target instanceof PsiClass) {
|
||||
if (target instanceof PsiClass) {
|
||||
PsiClass[] inners = ((PsiClass)target).getInnerClasses();
|
||||
if (((PsiClass)target).hasTypeParameters()) {
|
||||
substitutor = substitutor.put(PsiSubstitutor.KEY, createRawSubstitutor((PsiClass)target));
|
||||
@@ -528,6 +524,7 @@ public abstract class PsiJavaFileBaseImpl extends PsiFileImpl implements PsiJava
|
||||
|
||||
private static final Key<String> SHEBANG_SOURCE_LEVEL = Key.create("SHEBANG_SOURCE_LEVEL");
|
||||
|
||||
@NotNull
|
||||
private LanguageLevel getLanguageLevelInner() {
|
||||
if (myOriginalFile instanceof PsiJavaFile) {
|
||||
return ((PsiJavaFile)myOriginalFile).getLanguageLevel();
|
||||
@@ -554,7 +551,8 @@ public abstract class PsiJavaFileBaseImpl extends PsiFileImpl implements PsiJava
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Throwable ignored) { }
|
||||
catch (Throwable ignored) {
|
||||
}
|
||||
finally {
|
||||
if (!Objects.equals(sourceLevel, virtualFile.getUserData(SHEBANG_SOURCE_LEVEL)) && virtualFile.isInLocalFileSystem()) {
|
||||
virtualFile.putUserData(SHEBANG_SOURCE_LEVEL, sourceLevel);
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
// Copyright 2000-2020 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.codeInsight.problems;
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.daemon.impl;
|
||||
|
||||
import com.intellij.codeInsight.daemon.DaemonAnalyzerTestCase;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.codeInsight.daemon.impl.WolfTheProblemSolverImpl;
|
||||
import com.intellij.compiler.CompilerConfiguration;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -127,7 +125,7 @@ public class WolfTheProblemSolverTest extends DaemonAnalyzerTestCase {
|
||||
public static MockWolfTheProblemSolver prepareWolf(@NotNull Project project, @NotNull Disposable parentDisposable) {
|
||||
MockWolfTheProblemSolver wolfTheProblemSolver = (MockWolfTheProblemSolver)WolfTheProblemSolver.getInstance(project);
|
||||
|
||||
WolfTheProblemSolverImpl theRealSolver = (WolfTheProblemSolverImpl)WolfTheProblemSolverImpl.createInstance(project);
|
||||
WolfTheProblemSolverImpl theRealSolver = (WolfTheProblemSolverImpl)WolfTheProblemSolverImpl.createTestInstance(project);
|
||||
wolfTheProblemSolver.setDelegate(theRealSolver);
|
||||
Disposer.register(parentDisposable, theRealSolver);
|
||||
return wolfTheProblemSolver;
|
||||
@@ -70,8 +70,7 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP
|
||||
final EditorColorsScheme myGlobalScheme;
|
||||
private volatile NotNullProducer<HighlightVisitor[]> myHighlightVisitorProducer = this::cloneHighlightVisitors;
|
||||
|
||||
GeneralHighlightingPass(@NotNull Project project,
|
||||
@NotNull PsiFile file,
|
||||
GeneralHighlightingPass(@NotNull PsiFile file,
|
||||
@NotNull Document document,
|
||||
int startOffset,
|
||||
int endOffset,
|
||||
@@ -79,7 +78,7 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP
|
||||
@NotNull ProperTextRange priorityRange,
|
||||
@Nullable Editor editor,
|
||||
@NotNull HighlightInfoProcessor highlightInfoProcessor) {
|
||||
super(project, document, getPresentableNameText(), file, editor, TextRange.create(startOffset, endOffset), true, highlightInfoProcessor);
|
||||
super(file.getProject(), document, getPresentableNameText(), file, editor, TextRange.create(startOffset, endOffset), true, highlightInfoProcessor);
|
||||
myUpdateAll = updateAll;
|
||||
myPriorityRange = priorityRange;
|
||||
|
||||
|
||||
@@ -59,8 +59,13 @@ public abstract class ProgressableTextEditorHighlightingPass extends TextEditorH
|
||||
myEditor = editor;
|
||||
myRestrictRange = restrictRange;
|
||||
myHighlightInfoProcessor = highlightInfoProcessor;
|
||||
if (file != null && InjectedLanguageManager.getInstance(project).isInjectedFragment(file)) {
|
||||
throw new IllegalArgumentException("File must be top-level but " + file + " is an injected fragment");
|
||||
if (file != null) {
|
||||
if (file.getProject() != project) {
|
||||
throw new IllegalArgumentException("File '" + file +"' ("+file.getClass()+") is from an alien project (" + file.getProject()+") but expected: "+project);
|
||||
}
|
||||
if (InjectedLanguageManager.getInstance(project).isInjectedFragment(file)) {
|
||||
throw new IllegalArgumentException("File '" + file +"' ("+file.getClass()+") is an injected fragment but expected top-level");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ final class ChameleonSyntaxHighlightingPass extends GeneralHighlightingPass {
|
||||
TextRange restrict = FileStatusMap.getDirtyTextRange(editor, Pass.UPDATE_ALL);
|
||||
if (restrict == null) return new ProgressableTextEditorHighlightingPass.EmptyPass(project, editor.getDocument());
|
||||
ProperTextRange priority = VisibleHighlightingPassFactory.calculateVisibleRange(editor);
|
||||
return new ChameleonSyntaxHighlightingPass(project, file, editor.getDocument(), ProperTextRange.create(restrict),
|
||||
return new ChameleonSyntaxHighlightingPass(file, editor.getDocument(), ProperTextRange.create(restrict),
|
||||
priority, editor, new DefaultHighlightInfoProcessor());
|
||||
}
|
||||
|
||||
@@ -54,18 +54,17 @@ final class ChameleonSyntaxHighlightingPass extends GeneralHighlightingPass {
|
||||
@NotNull Document document,
|
||||
@NotNull HighlightInfoProcessor highlightInfoProcessor) {
|
||||
ProperTextRange range = VisibleHighlightingPassFactory.calculateVisibleRange(document);
|
||||
return new ChameleonSyntaxHighlightingPass(file.getProject(), file, document, range, range, null, highlightInfoProcessor);
|
||||
return new ChameleonSyntaxHighlightingPass(file, document, range, range, null, highlightInfoProcessor);
|
||||
}
|
||||
}
|
||||
|
||||
private ChameleonSyntaxHighlightingPass(@NotNull Project project,
|
||||
@NotNull PsiFile file,
|
||||
private ChameleonSyntaxHighlightingPass(@NotNull PsiFile file,
|
||||
@NotNull Document document,
|
||||
@NotNull ProperTextRange restrictRange,
|
||||
@NotNull ProperTextRange priorityRange,
|
||||
@Nullable Editor editor,
|
||||
@NotNull HighlightInfoProcessor highlightInfoProcessor) {
|
||||
super(project, file, document, restrictRange.getStartOffset(), restrictRange.getEndOffset(), true, priorityRange, editor,
|
||||
super(file, document, restrictRange.getStartOffset(), restrictRange.getEndOffset(), true, priorityRange, editor,
|
||||
highlightInfoProcessor);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ final class GeneralHighlightingPassFactory implements MainHighlightingPassFactor
|
||||
TextRange textRange = FileStatusMap.getDirtyTextRange(editor, Pass.UPDATE_ALL);
|
||||
if (textRange == null) return new EmptyPass(project, editor.getDocument());
|
||||
ProperTextRange visibleRange = VisibleHighlightingPassFactory.calculateVisibleRange(editor);
|
||||
return new GeneralHighlightingPass(project, file, editor.getDocument(), textRange.getStartOffset(), textRange.getEndOffset(), true, visibleRange, editor, new DefaultHighlightInfoProcessor());
|
||||
return new GeneralHighlightingPass(file, editor.getDocument(), textRange.getStartOffset(), textRange.getEndOffset(), true, visibleRange, editor, new DefaultHighlightInfoProcessor());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -35,7 +35,7 @@ final class GeneralHighlightingPassFactory implements MainHighlightingPassFactor
|
||||
@NotNull HighlightInfoProcessor highlightInfoProcessor) {
|
||||
ProperTextRange visibleRange = VisibleHighlightingPassFactory.calculateVisibleRange(document);
|
||||
// no applying to the editor - for read-only analysis only
|
||||
return new GeneralHighlightingPass(file.getProject(), file, document, 0, file.getTextLength(),
|
||||
return new GeneralHighlightingPass(file, document, 0, file.getTextLength(),
|
||||
true, visibleRange, null, highlightInfoProcessor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import com.intellij.openapi.editor.markup.TextAttributes;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.ProperTextRange;
|
||||
import com.intellij.openapi.util.Segment;
|
||||
@@ -41,8 +40,7 @@ import java.util.*;
|
||||
import static com.intellij.openapi.editor.colors.EditorColors.createInjectedLanguageFragmentKey;
|
||||
|
||||
public final class InjectedGeneralHighlightingPass extends GeneralHighlightingPass {
|
||||
InjectedGeneralHighlightingPass(@NotNull Project project,
|
||||
@NotNull PsiFile file,
|
||||
InjectedGeneralHighlightingPass(@NotNull PsiFile file,
|
||||
@NotNull Document document,
|
||||
int startOffset,
|
||||
int endOffset,
|
||||
@@ -50,7 +48,7 @@ public final class InjectedGeneralHighlightingPass extends GeneralHighlightingPa
|
||||
@NotNull ProperTextRange priorityRange,
|
||||
@Nullable Editor editor,
|
||||
@NotNull HighlightInfoProcessor highlightInfoProcessor) {
|
||||
super(project, file, document, startOffset, endOffset, updateAll, priorityRange, editor, highlightInfoProcessor);
|
||||
super(file, document, startOffset, endOffset, updateAll, priorityRange, editor, highlightInfoProcessor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,11 +24,10 @@ public final class InjectedGeneralHighlightingPassFactory implements MainHighlig
|
||||
@NotNull
|
||||
@Override
|
||||
public TextEditorHighlightingPass createHighlightingPass(@NotNull PsiFile file, @NotNull final Editor editor) {
|
||||
Project project = file.getProject();
|
||||
TextRange textRange = FileStatusMap.getDirtyTextRange(editor, Pass.UPDATE_ALL);
|
||||
if (textRange == null) return new ProgressableTextEditorHighlightingPass.EmptyPass(project, editor.getDocument());
|
||||
if (textRange == null) return new ProgressableTextEditorHighlightingPass.EmptyPass(file.getProject(), editor.getDocument());
|
||||
ProperTextRange visibleRange = VisibleHighlightingPassFactory.calculateVisibleRange(editor);
|
||||
return new InjectedGeneralHighlightingPass(project, file, editor.getDocument(), textRange.getStartOffset(), textRange.getEndOffset(), true, visibleRange, editor,
|
||||
return new InjectedGeneralHighlightingPass(file, editor.getDocument(), textRange.getStartOffset(), textRange.getEndOffset(), true, visibleRange, editor,
|
||||
new DefaultHighlightInfoProcessor());
|
||||
}
|
||||
|
||||
@@ -37,7 +36,7 @@ public final class InjectedGeneralHighlightingPassFactory implements MainHighlig
|
||||
@NotNull Document document,
|
||||
@NotNull HighlightInfoProcessor highlightInfoProcessor) {
|
||||
ProperTextRange visibleRange = VisibleHighlightingPassFactory.calculateVisibleRange(document);
|
||||
return new InjectedGeneralHighlightingPass(file.getProject(), file, document, 0, document.getTextLength(), true, visibleRange, null,
|
||||
return new InjectedGeneralHighlightingPass(file, document, 0, document.getTextLength(), true, visibleRange, null,
|
||||
highlightInfoProcessor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright 2000-2019 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-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
|
||||
package com.intellij.codeInsight.problems;
|
||||
package com.intellij.codeInsight.daemon.impl;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.module.Module;
|
||||
@@ -7,6 +7,7 @@ import com.intellij.ide.plugins.DynamicPluginListener;
|
||||
import com.intellij.ide.plugins.IdeaPluginDescriptor;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ReadAction;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
@@ -41,6 +42,7 @@ import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.messages.MessageBusConnection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -54,7 +56,7 @@ public final class WolfTheProblemSolverImpl extends WolfTheProblemSolver impleme
|
||||
|
||||
private final Project myProject;
|
||||
|
||||
WolfTheProblemSolverImpl(@NotNull Project project) {
|
||||
private WolfTheProblemSolverImpl(@NotNull Project project) {
|
||||
myProject = project;
|
||||
PsiTreeChangeListener changeListener = new PsiTreeChangeAdapter() {
|
||||
@Override
|
||||
@@ -252,7 +254,7 @@ public final class WolfTheProblemSolverImpl extends WolfTheProblemSolver impleme
|
||||
AtomicReference<HighlightInfo> error = new AtomicReference<>();
|
||||
AtomicBoolean hasErrorElement = new AtomicBoolean();
|
||||
try {
|
||||
GeneralHighlightingPass pass = new GeneralHighlightingPass(myProject, psiFile, document, 0, document.getTextLength(),
|
||||
GeneralHighlightingPass pass = new GeneralHighlightingPass(psiFile, document, 0, document.getTextLength(),
|
||||
false, new ProperTextRange(0, document.getTextLength()), null, HighlightInfoProcessor.getEmpty()) {
|
||||
@NotNull
|
||||
@Override
|
||||
@@ -374,9 +376,8 @@ public final class WolfTheProblemSolverImpl extends WolfTheProblemSolver impleme
|
||||
@Override
|
||||
public void weHaveGotNonIgnorableProblems(@NotNull VirtualFile virtualFile, @NotNull List<? extends Problem> problems) {
|
||||
if (problems.isEmpty()) return;
|
||||
boolean fireListener = false;
|
||||
ProblemFileInfo storedProblems = myProblems.computeIfAbsent(virtualFile, __ -> new ProblemFileInfo());
|
||||
fireListener = storedProblems.problems.isEmpty();
|
||||
boolean fireListener = storedProblems.problems.isEmpty();
|
||||
storedProblems.problems.addAll(problems);
|
||||
doQueue(virtualFile);
|
||||
if (fireListener) {
|
||||
@@ -505,7 +506,10 @@ public final class WolfTheProblemSolverImpl extends WolfTheProblemSolver impleme
|
||||
return ContainerUtil.process(myProblems.keySet(), processor);
|
||||
}
|
||||
|
||||
public static WolfTheProblemSolver createInstance(Project project){
|
||||
@NotNull
|
||||
@TestOnly
|
||||
public static WolfTheProblemSolver createTestInstance(@NotNull Project project){
|
||||
assert ApplicationManager.getApplication().isUnitTestMode();
|
||||
return new WolfTheProblemSolverImpl(project);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<component>
|
||||
<interface-class>com.intellij.problems.WolfTheProblemSolver</interface-class>
|
||||
<implementation-class>com.intellij.codeInsight.daemon.impl.WolfTheProblemSolverImpl</implementation-class>
|
||||
<headless-implementation-class>com.intellij.codeInsight.problems.MockWolfTheProblemSolver</headless-implementation-class>
|
||||
<headless-implementation-class>com.intellij.codeInsight.daemon.impl.MockWolfTheProblemSolver</headless-implementation-class>
|
||||
</component>
|
||||
|
||||
<component>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.kotlin.checkers
|
||||
|
||||
import com.intellij.codeInsight.problems.MockWolfTheProblemSolver
|
||||
import com.intellij.codeInsight.daemon.impl.MockWolfTheProblemSolver
|
||||
import com.intellij.codeInsight.daemon.impl.WolfTheProblemSolverImpl
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.project.Project
|
||||
@@ -42,7 +42,7 @@ abstract class AbstractKotlinHighlightWolfPassTest: KotlinLightCodeInsightFixtur
|
||||
|
||||
private fun prepareWolf(project: Project, parentDisposable: Disposable): MockWolfTheProblemSolver {
|
||||
val wolfTheProblemSolver = WolfTheProblemSolver.getInstance(project) as MockWolfTheProblemSolver
|
||||
val theRealSolver = WolfTheProblemSolverImpl.createInstance(project)
|
||||
val theRealSolver = WolfTheProblemSolverImpl.createTestInstance(project)
|
||||
wolfTheProblemSolver.setDelegate(theRealSolver)
|
||||
Disposer.register(parentDisposable, (theRealSolver as Disposable))
|
||||
return wolfTheProblemSolver
|
||||
|
||||
Reference in New Issue
Block a user