Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

Commit

Permalink
Fix ClassCastException in Compare View.
Browse files Browse the repository at this point in the history
Bug can be reproduced by e.g. doing <right-click> --> Compare with HEAD
revision on an xtend file in a Git repo.
Or select one xtext document and a non-xtext document and do a compare.

Signed-off-by: Anders Dahlberg <anders.xb.dahlberg@ericsson.com>
  • Loading branch information
qdagans committed Jan 30, 2019
1 parent 0255c89 commit 2c2b751
Showing 1 changed file with 10 additions and 0 deletions.
Expand Up @@ -7,6 +7,7 @@
*******************************************************************************/
package org.eclipse.xtext.ui.editor.syntaxcoloring;

import java.util.Collections;
import java.util.Iterator;
import java.util.NoSuchElementException;

Expand All @@ -19,6 +20,8 @@
import org.eclipse.xtext.ui.editor.model.XtextDocument;

import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import com.google.common.collect.Streams;
import com.google.common.collect.UnmodifiableIterator;
import com.google.inject.Inject;

Expand Down Expand Up @@ -134,6 +137,13 @@ public void setRange(IDocument document, final int offset, final int length) {
}

protected Iterable<ILexerTokenRegion> getTokens(IDocument document) {
if (!(document instanceof XtextDocument)) {
// User might have selected a non-xtext document in e.g. a compare operation.
// Return an empty iterable, this will disable syntax highlighting
// for the "non-xtext editor".
Iterator<ILexerTokenRegion> iterator = Collections.<ILexerTokenRegion>emptyIterator();
return () -> iterator;
}
XtextDocument doc = (XtextDocument) document;
return doc.getTokens();
}
Expand Down

0 comments on commit 2c2b751

Please sign in to comment.