KT-35811: Type parameter angle brackets followed by equal sign are parsed incorrectly if whitespace is missing

This commit is contained in:
Iven Krall
2022-07-21 09:40:42 +02:00
committed by teamcity
parent c1f0e71056
commit 2053363def
20 changed files with 705 additions and 387 deletions
@@ -283,7 +283,6 @@ LONELY_BACKTICK=`
"++" { return KtTokens.PLUSPLUS ; }
"--" { return KtTokens.MINUSMINUS; }
"<=" { return KtTokens.LTEQ ; }
">=" { return KtTokens.GTEQ ; }
"==" { return KtTokens.EQEQ ; }
"!=" { return KtTokens.EXCLEQ ; }
"&&" { return KtTokens.ANDAND ; }
File diff suppressed because it is too large Load Diff
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.lexer.KtTokens;
import static org.jetbrains.kotlin.lexer.KtTokens.*;
public class SemanticWhitespaceAwarePsiBuilderImpl extends PsiBuilderAdapter implements SemanticWhitespaceAwarePsiBuilder {
private final TokenSet complexTokens = TokenSet.create(SAFE_ACCESS, ELVIS, EXCLEXCL);
private final TokenSet complexTokens = TokenSet.create(SAFE_ACCESS, ELVIS, EXCLEXCL, GTEQ);
private final Stack<Boolean> joinComplexTokens = new Stack<>();
private final Stack<Boolean> newlinesEnabled = new Stack<>();
@@ -155,6 +155,10 @@ public class SemanticWhitespaceAwarePsiBuilderImpl extends PsiBuilderAdapter imp
IElementType nextRawToken = rawLookup(rawLookupSteps);
if (nextRawToken == EXCL) return EXCLEXCL;
}
else if (rawTokenType == GT){
IElementType nextRawToken = rawLookup(rawLookupSteps);
if (nextRawToken == EQ) return GTEQ;
}
return rawTokenType;
}
@@ -181,9 +185,11 @@ public class SemanticWhitespaceAwarePsiBuilderImpl extends PsiBuilderAdapter imp
if (!joinComplexTokens()) return super.getTokenText();
IElementType tokenType = getTokenType();
if (complexTokens.contains(tokenType)) {
if (tokenType == ELVIS) return "?:";
if (tokenType == SAFE_ACCESS) return "?.";
}
if (tokenType == ELVIS) return "?:";
if (tokenType == SAFE_ACCESS) return "?.";
if (tokenType == EXCLEXCL) return "!!";
if (tokenType == GTEQ) return ">=";
}
return super.getTokenText();
}