Skip to content
Browse files

MPS-11123 java.lang.AssertionError: Two EditorMessages with same type…

… are attached to the same EditorCell

Conflicts:

	core/languageDesign/editor/source/jetbrains/mps/nodeEditor/NodeHighlightManager.java
  • Loading branch information...
1 parent 606da66 commit 76c7a5b84593c23184666fc7db23d91ea5f89f5e @ashatalin ashatalin committed Dec 29, 2010
View
69 core/languageDesign/editor/source/jetbrains/mps/nodeEditor/NodeHighlightManager.java
@@ -53,21 +53,28 @@ public int compare(EditorMessage m1, EditorMessage m2) {
* all Chaches are synchronized using myMessagesLock
*/
private Map<EditorCell, List<EditorMessage>> myMessagesCache;
- public ReloadAdapter myHandler;
+ private ReloadAdapter myHandler;
private RebuildListener myRebuildListener;
private Set<EditorMessageIconRenderer> myIconRenderersCache = new HashSet<EditorMessageIconRenderer>();
private boolean myRebuildIconRenderersCacheFlag;
+ private volatile boolean myDisposed = false;
public NodeHighlightManager(@NotNull EditorComponent edtitor) {
myEditor = edtitor;
myHandler = new ReloadAdapter() {
public void onReload() {
+ if (myDisposed) {
+ return;
+ }
clear();
}
};
edtitor.addRebuildListener(myRebuildListener = new RebuildListener() {
public void editorRebuilt(EditorComponent editor) {
+ if (myDisposed) {
+ return;
+ }
synchronized (myMessagesLock) {
if (myMessagesCache == null) {
return;
@@ -142,6 +149,9 @@ private void rebuildMessages(EditorCell root) {
}
public List<EditorMessage> getMessages(EditorCell cell) {
+ if (myDisposed) {
+ return Collections.<EditorMessage>emptyList();
+ }
List<EditorMessage> result = getMessagesCache().get(cell);
if (result != null) {
return new ArrayList<EditorMessage>(result);
@@ -217,6 +227,9 @@ private boolean removeMessage(EditorMessage m) {
}
public void mark(EditorMessage message) {
+ if (myDisposed) {
+ return;
+ }
for (EditorMessage msg : getMessages()) {
if (msg.sameAs(message)) return;
}
@@ -229,11 +242,17 @@ public void mark(EditorMessage message) {
}
public void unmarkSingleMessage(EditorMessage message) {
+ if (myDisposed) {
+ return;
+ }
unmark(message);
repaintAndRebuildEditorMessages();
}
public void unmark(EditorMessage message) {
+ if (myDisposed) {
+ return;
+ }
synchronized (myMessagesLock) {
if (removeMessage(message)) {
rebuildMessages();
@@ -256,10 +275,16 @@ private void clear() {
}
public boolean clearForOwner(EditorMessageOwner owner) {
+ if (myDisposed) {
+ return false;
+ }
return clearForOwner(owner, true);
}
public boolean clearForOwner(EditorMessageOwner owner, boolean repaintAndRebuild) {
+ if (myDisposed) {
+ return false;
+ }
boolean result = myEditor.getMessagesGutter().removeMessages(owner);
synchronized (myMessagesLock) {
if (myOwnerToMessages.containsKey(owner)) {
@@ -281,8 +306,14 @@ public boolean clearForOwner(EditorMessageOwner owner, boolean repaintAndRebuild
* and repaint associated EditorComponent
*/
public void repaintAndRebuildEditorMessages() {
+ if (myDisposed) {
+ return;
+ }
ModelAccess.instance().runReadInEDT(new Runnable() {
public void run() {
+ if (myDisposed) {
+ return;
+ }
refreshLeftHighlighterMessages();
myEditor.getExternalComponent().repaint();
}
@@ -311,24 +342,36 @@ private void refreshLeftHighlighterMessages() {
}
public void mark(SNode node, Color color, String messageText, EditorMessageOwner owner) {
+ if (myDisposed) {
+ return;
+ }
if (node == null) return;
mark(new DefaultEditorMessage(node, color, messageText, owner));
}
public void mark(List<EditorMessage> messages) {
+ if (myDisposed) {
+ return;
+ }
for (int i = 0; i < messages.size(); i++) {
mark(messages.get(i));
}
repaintAndRebuildEditorMessages();
}
public void markSingleMessage(EditorMessage message) {
+ if (myDisposed) {
+ return;
+ }
mark(message);
repaintAndRebuildEditorMessages();
}
public Set<EditorMessage> getMessages() {
Set<EditorMessage> result = new HashSet<EditorMessage>();
+ if (myDisposed) {
+ return result;
+ }
synchronized (myMessagesLock) {
result.addAll(myMessages);
}
@@ -338,6 +381,9 @@ public void markSingleMessage(EditorMessage message) {
// not used anymore?
@Deprecated
public Color getColorFor(SNode node) {
+ if (myDisposed) {
+ return null;
+ }
synchronized (myMessagesLock) {
for (EditorMessage msg : myMessages) {
if (msg.getNode() == node) return msg.getColor();
@@ -347,6 +393,9 @@ public Color getColorFor(SNode node) {
}
public EditorMessage getMessageFor(SNode node) {
+ if (myDisposed) {
+ return null;
+ }
synchronized (myMessagesLock) {
for (EditorMessage msg : myMessages) {
if (msg.getNode() == node) return msg;
@@ -357,6 +406,9 @@ public EditorMessage getMessageFor(SNode node) {
public List<EditorMessage> getMessagesFor(SNode node) {
List<EditorMessage> result = new ArrayList<EditorMessage>();
+ if (myDisposed) {
+ return null;
+ }
synchronized (myMessagesLock) {
result.addAll(myMessagesToNodes.getBySecond(node));
}
@@ -365,6 +417,9 @@ public EditorMessage getMessageFor(SNode node) {
public List<EditorMessage> getMessagesFor(SNode node, EditorMessageOwner owner) {
List<EditorMessage> result = new ArrayList<EditorMessage>();
+ if (myDisposed) {
+ return result;
+ }
synchronized (myMessagesLock) {
for (EditorMessage message : myMessagesToNodes.getBySecond(node)) {
if (message.getOwner() == owner) {
@@ -376,11 +431,21 @@ public EditorMessage getMessageFor(SNode node) {
}
public void dispose() {
+ assert ModelAccess.instance().isInEDT() : "dispose() should be called from EDT only";
+ myDisposed = true;
ClassLoaderManager.getInstance().removeReloadHandler(myHandler);
myEditor.removeRebuildListener(myRebuildListener);
+ Set<EditorMessageIconRenderer> iconRenderers;
+ synchronized (myMessagesLock) {
+ iconRenderers = myIconRenderersCache;
+ }
+ myEditor.getLeftEditorHighlighter().removeAllIconRenderers(iconRenderers);
}
public EditorCell getCell(EditorMessage change) {
+ if (myDisposed) {
+ return null;
+ }
for (Entry<EditorCell, List<EditorMessage>> e: getMessagesCache().entrySet()) {
if (e.getValue().contains(change)) {
return e.getKey();
@@ -389,4 +454,4 @@ public EditorCell getCell(EditorMessage change) {
return null;
}
-}
+}

0 comments on commit 76c7a5b

Please sign in to comment.
Something went wrong with that request. Please try again.