blame plugins on EA-134737 - ISE: DefaultWordsScanner.processWords

This commit is contained in:
peter
2019-01-31 16:49:54 +01:00
parent 02eb98d0a7
commit 7cfc7fa088
@@ -15,6 +15,9 @@
*/
package com.intellij.lang.cacheBuilder;
import com.intellij.diagnostic.PluginException;
import com.intellij.lexer.DelegateLexer;
import com.intellij.lexer.FlexAdapter;
import com.intellij.lexer.Lexer;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.TokenSet;
@@ -89,8 +92,10 @@ public class DefaultWordsScanner extends VersionedWordsScanner {
@Override
public void processWords(CharSequence fileText, Processor<WordOccurrence> processor) {
if (myBusy) {
throw new IllegalStateException("Different word scanner instances should be used for different threads, " +
"make sure that " + this + " with " + myLexer + " is instantiated on every request and not shared");
throw PluginException.createByClass("Different word scanner instances should be used for different threads, " +
"make sure that " + this + " with " + myLexer + " is instantiated on every request and not shared",
null,
guessPluginClass());
}
myBusy = true;
try {
@@ -124,6 +129,28 @@ public class DefaultWordsScanner extends VersionedWordsScanner {
}
}
private Class<?> guessPluginClass() {
if (myIdentifierTokenSet.getTypes().length > 0) {
return myIdentifierTokenSet.getTypes()[0].getClass();
}
if (myLiteralTokenSet.getTypes().length > 0) {
return myLiteralTokenSet.getTypes()[0].getClass();
}
Object lexer = myLexer;
while (true) {
if (lexer instanceof FlexAdapter) {
lexer = ((FlexAdapter)lexer).getFlex();
}
else if (lexer instanceof DelegateLexer) {
lexer = ((DelegateLexer)lexer).getDelegate();
}
else {
break;
}
}
return lexer.getClass();
}
protected static boolean stripWords(final Processor<? super WordOccurrence> processor,
final CharSequence tokenText,
int from,