use of com.intellij.psi.tree.IElementType in project intellij-community by JetBrains.
the class FormSourceCodeGenerator method lexemsEqual.
private static boolean lexemsEqual(final PsiClass classToBind, final PsiClass newClass) {
Lexer oldTextLexer = JavaParserDefinition.createLexer(LanguageLevel.HIGHEST);
Lexer newTextLexer = JavaParserDefinition.createLexer(LanguageLevel.HIGHEST);
String oldBuffer = classToBind.getText();
String newBuffer = newClass.getText();
oldTextLexer.start(oldBuffer);
newTextLexer.start(newBuffer);
while (true) {
IElementType oldLexem = oldTextLexer.getTokenType();
IElementType newLexem = newTextLexer.getTokenType();
if (oldLexem == null || newLexem == null) {
// must terminate at the same time
return oldLexem == null && newLexem == null;
}
if (oldLexem != newLexem) {
return false;
}
if (oldLexem != TokenType.WHITE_SPACE && oldLexem != JavaDocElementType.DOC_COMMENT) {
int oldStart = oldTextLexer.getTokenStart();
int newStart = newTextLexer.getTokenStart();
int oldLength = oldTextLexer.getTokenEnd() - oldTextLexer.getTokenStart();
int newLength = newTextLexer.getTokenEnd() - newTextLexer.getTokenStart();
if (oldLength != newLength) {
return false;
}
for (int i = 0; i < oldLength; i++) {
if (oldBuffer.charAt(oldStart + i) != newBuffer.charAt(newStart + i)) {
return false;
}
}
}
oldTextLexer.advance();
newTextLexer.advance();
}
}
use of com.intellij.psi.tree.IElementType in project intellij-community by JetBrains.
the class CommandLineParserUtil method bound_argument.
static void bound_argument(@NotNull final PsiBuilder b, final int i) {
final IElementType tokenType = b.getTokenType();
final IElementType leftElement = b.rawLookup(-1);
final IElementType rightElement = b.rawLookup(1);
if (leftElement == null || TokenType.WHITE_SPACE.equals(leftElement)) {
return;
}
/**
* At '=' position: if no whitespace to left and right, we move to argument.
* And we report error if whitespace to the left.
*/
if (tokenType == CommandLineElementTypes.EQ) {
if (leftElement.equals(CommandLineElementTypes.LONG_OPTION_NAME_TOKEN)) {
if (rightElement == null || TokenType.WHITE_SPACE.equals(rightElement)) {
b.error("Space between argument is its value is unexpected");
}
b.advanceLexer();
}
}
}
use of com.intellij.psi.tree.IElementType in project intellij-community by JetBrains.
the class RestLexerTest method doTest.
private static void doTest(String text, String... expected) throws IOException {
_RestFlexLexer lexer = createLexer(text);
for (String expectedTokenText : expected) {
IElementType type = lexer.advance();
if (type == null) {
fail("Not enough tokens");
}
String tokenText = "[" + lexer.yytext() + ", " + type + "]";
assertEquals(expectedTokenText, tokenText);
}
}
use of com.intellij.psi.tree.IElementType in project intellij-community by JetBrains.
the class RestBlock method buildSubBlock.
private RestBlock buildSubBlock(ASTNode child) {
IElementType parentType = myNode.getElementType();
IElementType childType = child.getElementType();
IElementType grandparentType = myNode.getTreeParent() == null ? null : myNode.getTreeParent().getElementType();
Wrap wrap = null;
Indent childIndent = Indent.getNoneIndent();
Alignment childAlignment = null;
if (grandparentType == RestElementTypes.FIELD_LIST && parentType == RestElementTypes.LINE_TEXT && childType == RestTokenTypes.LINE) {
childIndent = Indent.getNormalIndent();
}
return new RestBlock(this, child, childAlignment, childIndent, wrap);
}
use of com.intellij.psi.tree.IElementType in project intellij-community by JetBrains.
the class RestBlock method buildSubBlocks.
private List<RestBlock> buildSubBlocks() {
List<RestBlock> blocks = new ArrayList<>();
for (ASTNode child = myNode.getFirstChildNode(); child != null; child = child.getTreeNext()) {
IElementType childType = child.getElementType();
if (child.getTextRange().getLength() == 0)
continue;
if (childType == RestTokenTypes.WHITESPACE) {
continue;
}
blocks.add(buildSubBlock(child));
}
return Collections.unmodifiableList(blocks);
}
Aggregations