EA-52671 - assert: AbstractMappingStrategy.processFoldRegion

This commit is contained in:
Dmitry Batrak
2014-02-10 10:58:36 +04:00
parent 37b45f0303
commit 143c66bc11
5 changed files with 78 additions and 76 deletions

View File

@@ -0,0 +1,9 @@
class Test {
int b;
java.util.List<String> values = new java.util.ArrayList<String>();
int getB() {
<caret> java.util.List<String> values = new java.util.ArrayList<String>();
return b;
}
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.editor.impl;
import com.intellij.codeHighlighting.TextEditorHighlightingPass;
import com.intellij.codeInsight.daemon.impl.CodeFoldingPassFactory;
import com.intellij.mock.MockProgressIndicator;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.testFramework.EditorTestUtil;
import com.intellij.testFramework.LightCodeInsightTestCase;
public class FoldingExceptionTest extends LightCodeInsightTestCase {
public void test() {
configureByFile("/codeInsight/folding/FoldingExceptionTest.java");
EditorTestUtil.configureSoftWraps(myEditor, 120);
runFoldingPass();
deleteLine();
runFoldingPass();
// we just verify here that the operation completes normally - it was known to fail previously
}
private static void runFoldingPass() {
PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(getProject());
psiDocumentManager.commitAllDocuments();
PsiFile psiFile = psiDocumentManager.getPsiFile(myEditor.getDocument());
assertNotNull(psiFile);
CodeFoldingPassFactory factory = getProject().getComponent(CodeFoldingPassFactory.class);
TextEditorHighlightingPass highlightingPass = factory.createHighlightingPass(psiFile, myEditor);
highlightingPass.collectInformation(new MockProgressIndicator());
highlightingPass.doApplyInformationToEditor();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2012 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -70,7 +70,6 @@ public class SoftWrapModelImpl implements SoftWrapModelEx, PrioritizedDocumentLi
private final FoldProcessingEndTask myFoldProcessingEndTask = new FoldProcessingEndTask();
private final List<DocumentListener> myDocumentListeners = new ArrayList<DocumentListener>();
private final List<SoftWrapFoldingListener> myFoldListeners = new ArrayList<SoftWrapFoldingListener>();
private final List<SoftWrapChangeListener> mySoftWrapListeners = new ArrayList<SoftWrapChangeListener>();
/**
@@ -160,7 +159,6 @@ public class SoftWrapModelImpl implements SoftWrapModelEx, PrioritizedDocumentLi
myVisualSizeManager = new SoftWrapAwareVisualSizeManager(painter);
myDocumentListeners.add(myApplianceManager);
myFoldListeners.add(myApplianceManager);
applianceManager.addListener(myVisualSizeManager);
applianceManager.addListener(new SoftWrapAwareDocumentParsingListenerAdapter() {
@Override
@@ -624,7 +622,9 @@ public class SoftWrapModelImpl implements SoftWrapModelEx, PrioritizedDocumentLi
myDirty = true;
return;
}
// We delay processing of changed fold regions till the invocation of onFoldProcessingEnd(), as
// FoldingModel can return inconsistent data before that moment.
myDeferredFoldRegions.add(new FoldRegionInfo(region));
}
@@ -689,7 +689,7 @@ public class SoftWrapModelImpl implements SoftWrapModelEx, PrioritizedDocumentLi
try {
task.run(true);
} catch (Throwable e) {
if (Boolean.getBoolean(DEBUG_PROPERTY_NAME)) {
if (Boolean.getBoolean(DEBUG_PROPERTY_NAME) || ApplicationManager.getApplication().isUnitTestMode()) {
String info = "";
if (myEditor instanceof EditorImpl) {
info = ((EditorImpl)myEditor).dumpState();
@@ -813,28 +813,26 @@ public class SoftWrapModelImpl implements SoftWrapModelEx, PrioritizedDocumentLi
}
try {
for (FoldRegionInfo info : myDeferredFoldRegions) {
// There is a possible case that given fold region is contained inside another collapsed fold region. We don't want to process
// such nested region then.
FoldRegion outerRegion = myEditor.getFoldingModel().getCollapsedRegionAtOffset(info.start);
if (outerRegion != null && outerRegion != info.region && outerRegion.getStartOffset() <= info.start
&& outerRegion.getEndOffset() >= info.end)
{
continue;
}
for (SoftWrapFoldingListener listener : myFoldListeners) {
listener.onFoldRegionStateChange(info.start, info.end);
if (!myDirty) { // no need to recalculate specific areas if the whole document will be reprocessed
for (FoldRegionInfo info : myDeferredFoldRegions) {
// There is a possible case that given fold region is contained inside another collapsed fold region. We don't want to process
// such nested region then.
FoldRegion outerRegion = myEditor.getFoldingModel().getCollapsedRegionAtOffset(info.start);
if (outerRegion != null && outerRegion != info.region && outerRegion.getStartOffset() <= info.start
&& outerRegion.getEndOffset() >= info.end)
{
continue;
}
myApplianceManager.onFoldRegionStateChange(info.start, info.end);
}
}
}
finally {
myDeferredFoldRegions.clear();
}
for (SoftWrapFoldingListener listener : myFoldListeners) {
listener.onFoldProcessingEnd();
}
myApplianceManager.onFoldProcessingEnd();
}
@Override

View File

@@ -1,51 +0,0 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.editor.impl.softwrap;
import com.intellij.openapi.editor.FoldRegion;
import com.intellij.openapi.editor.ex.FoldingListener;
/**
* Adapts {@link FoldingListener} to soft wraps specific.
* <p/>
* Generally, replaces {@link FoldingListener#onFoldRegionStateChange(FoldRegion)} by {@link #onFoldRegionStateChange(int, int)}.
* The reason is that soft wraps are assumed to be processed after fold regions, i.e. every time the document is changed, folding
* is processed at first place (notifying soft wraps via {@link FoldingListener}) and soft wraps are assumed to be processed
* only on {@link #onFoldProcessingEnd()}. Hence, there is a possible case that changed {@link FoldRegion} object
* is out-of-date (e.g. its offsets info is dropped if the region is removed), so, we can't use
* {@link FoldingListener#onFoldRegionStateChange(FoldRegion)}.
*
* @author Denis Zhdanov
* @since 5/4/11 3:48 PM
*/
public interface SoftWrapFoldingListener {
/**
* Informs that <code>'collapsed'</code> state of fold region that is/was located at the target range is just changed.
* <p/>
* <b>Note:</b> listener should delay fold region state processing until {@link #onFoldProcessingEnd()} is called.
* I.e. folding model may return inconsistent data between current moment and {@link #onFoldProcessingEnd()}.
*
* @param startOffset start offset of the target fold region (inclusive)
* @param endOffset end offset of the target fold region (exclusive)
*/
void onFoldRegionStateChange(int startOffset, int endOffset);
/**
* Informs that fold processing is done.
*/
void onFoldProcessingEnd();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -56,7 +56,7 @@ import java.util.List;
* @author Denis Zhdanov
* @since Jul 5, 2010 10:01:27 AM
*/
public class SoftWrapApplianceManager implements SoftWrapFoldingListener, DocumentListener, Dumpable {
public class SoftWrapApplianceManager implements DocumentListener, Dumpable {
private static final Logger LOG = Logger.getInstance("#" + SoftWrapApplianceManager.class.getName());
@@ -986,7 +986,6 @@ public class SoftWrapApplianceManager implements SoftWrapFoldingListener, Docume
}
}
@Override
public void onFoldRegionStateChange(int startOffset, int endOffset) {
assert ApplicationManagerEx.getApplicationEx().isDispatchThread();
@@ -1002,7 +1001,6 @@ public class SoftWrapApplianceManager implements SoftWrapFoldingListener, Docume
myEventsStorage.add(document, new IncrementalCacheUpdateEvent(document, recalculationStartOffset, recalculationEndOffset));
}
@Override
public void onFoldProcessingEnd() {
//CachingSoftWrapDataMapper.log("xxxxxxxxxxx On fold region processing end");
recalculateSoftWraps();