more assertions on completion state

This commit is contained in:
peter
2011-01-20 16:29:52 +01:00
parent e58ea835ec
commit ff93a1cb36
3 changed files with 23 additions and 11 deletions
@@ -490,6 +490,8 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
// the insert handler may have started a live template with completion
if (CompletionService.getCompletionService().getCurrentCompletion() == null) {
indicator.liveAfterDeath(null);
} else {
LOG.assertTrue(indicator.isZombie(), indicator);
}
}
}
@@ -289,7 +289,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
if (code == KeyEvent.VK_CONTROL || code == KeyEvent.VK_META || code == KeyEvent.VK_ALT || code == KeyEvent.VK_SHIFT) {
myState.modifiersChanged();
if (myState.isWaitingAfterAutoInsertion()) {
unregisterItself();
unregisterItself(true);
}
contentComponent.removeKeyListener(this);
}
@@ -297,6 +297,10 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
});
}
boolean isZombie() {
return myState.isZombie();
}
private void setMergeCommand() {
CommandProcessor.getInstance().setCurrentCommandGroupId(getCompletionCommandName());
}
@@ -330,23 +334,23 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
final HintListener hintListener = new HintListener() {
public void hintHidden(final EventObject event) {
unregisterItself();
unregisterItself(true);
}
};
final DocumentAdapter documentListener = new DocumentAdapter() {
@Override
public void beforeDocumentChange(DocumentEvent e) {
unregisterItself();
unregisterItself(true);
}
};
final SelectionListener selectionListener = new SelectionListener() {
public void selectionChanged(SelectionEvent e) {
unregisterItself();
unregisterItself(true);
}
};
final CaretListener caretListener = new CaretListener() {
public void caretPositionChanged(CaretEvent e) {
unregisterItself();
unregisterItself(true);
}
};
@@ -475,7 +479,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
ApplicationManager.getApplication().assertIsDispatchThread();
Disposer.dispose(myQueue);
unregisterItself();
unregisterItself(false);
}
@TestOnly
@@ -486,8 +490,8 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
}
}
private void unregisterItself() {
myState.handleDeath();
private void unregisterItself(boolean afterDeath) {
myState.handleDeath(afterDeath);
CompletionProgressIndicator currentCompletion = CompletionServiceImpl.getCompletionService().getCurrentCompletion();
assert currentCompletion == this : currentCompletion + "!=" + this;
CompletionServiceImpl.getCompletionService().setCurrentCompletion(null);
@@ -91,7 +91,7 @@ public class CompletionState {
}
public boolean isWaitingAfterAutoInsertion() {
return myRestorePrefix != null;
return myRestorePrefix != null && isZombie();
}
public void setRestorePrefix(Runnable restorePrefix) {
@@ -127,10 +127,12 @@ public class CompletionState {
}
}
public void handleDeath() {
public void handleDeath(boolean afterDeath) {
ApplicationManager.getApplication().assertIsDispatchThread();
boolean zombie = isZombie();
LOG.assertTrue(afterDeath == zombie, this);
assertDisposed();
if (myZombieCleanup != null) {
if (zombie) {
myZombieCleanup.run();
}
myZombieCleanup = null;
@@ -138,6 +140,10 @@ public class CompletionState {
setRestorePrefix(null);
}
public boolean isZombie() {
return myZombieCleanup != null;
}
int incCount() {
return ++myCount;
}