mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
assertion for modifying fileststatusmap during highlighting added
This commit is contained in:
@@ -290,9 +290,10 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
|
||||
toIgnore.add(Pass.VISIBLE_LINE_MARKERS);
|
||||
}
|
||||
|
||||
CodeInsightTestFixtureImpl.instantiateAndRun(getFile(), getEditor(), toIgnore.toNativeArray());
|
||||
boolean canChange = canChangeDocumentDuringHighlighting();
|
||||
CodeInsightTestFixtureImpl.instantiateAndRun(getFile(), getEditor(), toIgnore.toNativeArray(), canChange);
|
||||
|
||||
if (!canChangeDocumentDuringHighlighting()) {
|
||||
if (!canChange) {
|
||||
Document document = getDocument(getFile());
|
||||
((DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(getProject())).getFileStatusMap().assertAllDirtyScopesAreNull(document);
|
||||
}
|
||||
|
||||
+1
-1
@@ -85,7 +85,7 @@ public abstract class LightDaemonAnalyzerTestCase extends LightCodeInsightTestCa
|
||||
file = InjectedLanguageUtil.getTopLevelFile(file);
|
||||
}
|
||||
|
||||
return CodeInsightTestFixtureImpl.instantiateAndRun(file, editor, toIgnore);
|
||||
return CodeInsightTestFixtureImpl.instantiateAndRun(file, editor, toIgnore, false);
|
||||
}
|
||||
|
||||
protected boolean doFolding() {
|
||||
|
||||
@@ -40,13 +40,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class FileStatusMap implements Disposable {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.FileStatusMap");
|
||||
private final Project myProject;
|
||||
private final Map<Document,FileStatus> myDocumentToStatusMap = new WeakHashMap<Document, FileStatus>(); // all dirty if absent
|
||||
private final AtomicInteger myClearModificationCount = new AtomicInteger();
|
||||
private boolean myAllowDirt = true;
|
||||
|
||||
public FileStatusMap(@NotNull Project project) {
|
||||
myProject = project;
|
||||
@@ -152,11 +151,11 @@ public class FileStatusMap implements Disposable {
|
||||
}
|
||||
|
||||
public void markAllFilesDirty() {
|
||||
assert myAllowDirt;
|
||||
LOG.debug("********************************* Mark all dirty");
|
||||
synchronized(myDocumentToStatusMap){
|
||||
synchronized (myDocumentToStatusMap) {
|
||||
myDocumentToStatusMap.clear();
|
||||
}
|
||||
myClearModificationCount.incrementAndGet();
|
||||
}
|
||||
|
||||
public void markFileUpToDate(@NotNull Document document, @NotNull PsiFile file, int passId) {
|
||||
@@ -206,6 +205,7 @@ public class FileStatusMap implements Disposable {
|
||||
}
|
||||
|
||||
public void markFileScopeDirty(@NotNull Document document, int passId) {
|
||||
assert myAllowDirt;
|
||||
synchronized(myDocumentToStatusMap){
|
||||
FileStatus status = myDocumentToStatusMap.get(document);
|
||||
if (status == null){
|
||||
@@ -227,6 +227,7 @@ public class FileStatusMap implements Disposable {
|
||||
}
|
||||
|
||||
public void markFileScopeDirtyDefensively(@NotNull PsiFile file) {
|
||||
assert myAllowDirt;
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("********************************* Mark dirty file defensively: "+file.getName());
|
||||
}
|
||||
@@ -242,6 +243,7 @@ public class FileStatusMap implements Disposable {
|
||||
}
|
||||
|
||||
public void markFileScopeDirty(@NotNull Document document, @NotNull TextRange scope, int fileLength) {
|
||||
assert myAllowDirt;
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("********************************* Mark dirty: "+scope);
|
||||
}
|
||||
@@ -288,4 +290,9 @@ public class FileStatusMap implements Disposable {
|
||||
assert status != null && !status.defensivelyMarked && status.wolfPassFinfished && status.allDirtyScopesAreNull() : status;
|
||||
}
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
public void allowDirt(boolean allow) {
|
||||
myAllowDirt = allow;
|
||||
}
|
||||
}
|
||||
|
||||
+29
-16
@@ -25,6 +25,7 @@ import com.intellij.codeInsight.completion.CodeCompletionHandlerBase;
|
||||
import com.intellij.codeInsight.completion.CompletionContext;
|
||||
import com.intellij.codeInsight.completion.CompletionProgressIndicator;
|
||||
import com.intellij.codeInsight.completion.CompletionType;
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzerSettings;
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInsight.daemon.impl.*;
|
||||
@@ -69,6 +70,7 @@ import com.intellij.openapi.fileTypes.FileTypeManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.DumbServiceImpl;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
@@ -87,6 +89,7 @@ import com.intellij.psi.impl.source.resolve.FileContextUtil;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.UsageSearchContext;
|
||||
import com.intellij.psi.stubs.StubUpdatingIndex;
|
||||
import com.intellij.psi.util.PsiUtilBase;
|
||||
import com.intellij.refactoring.move.moveFilesOrDirectories.MoveFilesOrDirectoriesProcessor;
|
||||
import com.intellij.refactoring.rename.RenameProcessor;
|
||||
@@ -99,6 +102,7 @@ import com.intellij.util.CommonProcessors;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.indexing.FileBasedIndex;
|
||||
import gnu.trove.THashMap;
|
||||
import junit.framework.Assert;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -1070,28 +1074,37 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
return
|
||||
ApplicationManager.getApplication().runReadAction(new Computable<List<HighlightInfo>>() {
|
||||
public List<HighlightInfo> compute() {
|
||||
return instantiateAndRun(getFile(), getEditor(), ArrayUtil.EMPTY_INT_ARRAY);
|
||||
return instantiateAndRun(getFile(), getEditor(), ArrayUtil.EMPTY_INT_ARRAY, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<HighlightInfo> instantiateAndRun(PsiFile file, Editor editor, int[] toIgnore) {
|
||||
TextEditorHighlightingPassRegistrarEx registrar = TextEditorHighlightingPassRegistrarEx.getInstanceEx(file.getProject());
|
||||
final List<TextEditorHighlightingPass> passes = registrar.instantiatePasses(file, editor, toIgnore);
|
||||
final ProgressIndicator progress = new DaemonProgressIndicator();
|
||||
ProgressManager.getInstance().runProcess(new Runnable() {
|
||||
public void run() {
|
||||
for (TextEditorHighlightingPass pass : passes) {
|
||||
pass.collectInformation(progress);
|
||||
public static List<HighlightInfo> instantiateAndRun(PsiFile file, Editor editor, int[] toIgnore, boolean allowDirt) {
|
||||
Project project = file.getProject();
|
||||
FileBasedIndex.getInstance().ensureUpToDate(StubUpdatingIndex.INDEX_ID, project, null);
|
||||
assertTrue(!DumbServiceImpl.getInstance(project).isDumb());
|
||||
((DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(project)).getFileStatusMap().allowDirt(allowDirt);
|
||||
try {
|
||||
TextEditorHighlightingPassRegistrarEx registrar = TextEditorHighlightingPassRegistrarEx.getInstanceEx(project);
|
||||
final List<TextEditorHighlightingPass> passes = registrar.instantiatePasses(file, editor, toIgnore);
|
||||
final ProgressIndicator progress = new DaemonProgressIndicator();
|
||||
ProgressManager.getInstance().runProcess(new Runnable() {
|
||||
public void run() {
|
||||
for (TextEditorHighlightingPass pass : passes) {
|
||||
pass.collectInformation(progress);
|
||||
}
|
||||
for (TextEditorHighlightingPass pass : passes) {
|
||||
pass.applyInformationToEditor();
|
||||
}
|
||||
}
|
||||
for (TextEditorHighlightingPass pass : passes) {
|
||||
pass.applyInformationToEditor();
|
||||
}
|
||||
}
|
||||
}, progress);
|
||||
List<HighlightInfo> infos = DaemonCodeAnalyzerImpl.getHighlights(editor.getDocument(), file.getProject());
|
||||
return infos == null ? Collections.<HighlightInfo>emptyList() : new ArrayList<HighlightInfo>(infos);
|
||||
}, progress);
|
||||
List<HighlightInfo> infos = DaemonCodeAnalyzerImpl.getHighlights(editor.getDocument(), project);
|
||||
return infos == null ? Collections.<HighlightInfo>emptyList() : new ArrayList<HighlightInfo>(infos);
|
||||
}
|
||||
finally {
|
||||
((DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(project)).getFileStatusMap().allowDirt(true);
|
||||
}
|
||||
}
|
||||
|
||||
public String getTestDataPath() {
|
||||
|
||||
+1
-1
@@ -105,7 +105,7 @@ public class XsltHighlightingTest extends TestBase {
|
||||
return ApplicationManager.getApplication().runReadAction(new Computable<Long>() {
|
||||
public Long compute() {
|
||||
final long l = System.currentTimeMillis();
|
||||
CodeInsightTestFixtureImpl.instantiateAndRun(myFixture.getFile(), myFixture.getEditor(), ArrayUtil.EMPTY_INT_ARRAY);
|
||||
CodeInsightTestFixtureImpl.instantiateAndRun(myFixture.getFile(), myFixture.getEditor(), ArrayUtil.EMPTY_INT_ARRAY, false);
|
||||
return System.currentTimeMillis() - l;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user