catch SIOOBE in PythonNamesValidator

This commit is contained in:
Dmitry Jemerov
2009-12-25 17:34:58 +03:00
parent a5916b1977
commit f27cd6f234
@@ -7,29 +7,36 @@ import com.jetbrains.python.lexer.PythonLexer;
import org.jetbrains.annotations.NotNull;
/**
* Created by IntelliJ IDEA.
* User: Alexey.Ivanov
* Date: Aug 19, 2009
* Time: 10:23:26 PM
* @author Alexey.Ivanov
*/
public class PythonNamesValidator implements NamesValidator {
private static final PythonLexer ourLexer = new PythonLexer();
public synchronized boolean isKeyword(@NotNull final String name, final Project project) {
ourLexer.start(name);
if (!PyTokenTypes.KEYWORDS.contains(ourLexer.getTokenType())) {
try {
ourLexer.start(name);
if (!PyTokenTypes.KEYWORDS.contains(ourLexer.getTokenType())) {
return false;
}
ourLexer.advance();
return ourLexer.getTokenType() == null;
}
catch (StringIndexOutOfBoundsException e) {
return false;
}
ourLexer.advance();
return ourLexer.getTokenType() == null;
}
public synchronized boolean isIdentifier(@NotNull final String name, final Project project) {
ourLexer.start(name);
if (ourLexer.getTokenType() != PyTokenTypes.IDENTIFIER) {
try {
ourLexer.start(name);
if (ourLexer.getTokenType() != PyTokenTypes.IDENTIFIER) {
return false;
}
ourLexer.advance();
return ourLexer.getTokenType() == null;
}
catch (StringIndexOutOfBoundsException e) {
return false;
}
ourLexer.advance();
return ourLexer.getTokenType() == null;
}
}