[java] numeric literal underscores should not affect highlighting (IDEA-145942)

This commit is contained in:
Roman Shevchenko
2015-10-05 12:55:06 +02:00
parent edf4b0270e
commit 78acdfef1f
2 changed files with 12 additions and 9 deletions
@@ -1030,39 +1030,40 @@ public class HighlightUtil extends HighlightUtilBase {
final PsiElement parent = expression.getParent();
if (type == JavaTokenType.INTEGER_LITERAL) {
String cleanText = StringUtil.replace(text, "_", "");
//literal 2147483648 may appear only as the operand of the unary negation operator -.
if (!(text.equals(PsiLiteralExpressionImpl._2_IN_31) &&
if (!(cleanText.equals(PsiLiteralExpressionImpl._2_IN_31) &&
parent instanceof PsiPrefixExpression &&
((PsiPrefixExpression)parent).getOperationTokenType() == JavaTokenType.MINUS)) {
if (text.equals(PsiLiteralExpressionImpl.HEX_PREFIX)) {
if (cleanText.equals(PsiLiteralExpressionImpl.HEX_PREFIX)) {
String message = JavaErrorMessages.message("hexadecimal.numbers.must.contain.at.least.one.hexadecimal.digit");
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
}
if (text.equals(PsiLiteralExpressionImpl.BIN_PREFIX)) {
if (cleanText.equals(PsiLiteralExpressionImpl.BIN_PREFIX)) {
String message = JavaErrorMessages.message("binary.numbers.must.contain.at.least.one.hexadecimal.digit");
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
}
if (value == null || text.equals(PsiLiteralExpressionImpl._2_IN_31)) {
if (value == null || cleanText.equals(PsiLiteralExpressionImpl._2_IN_31)) {
String message = JavaErrorMessages.message("integer.number.too.large");
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
}
}
}
else if (type == JavaTokenType.LONG_LITERAL) {
String mText = text.endsWith("l") ? text.substring(0, text.length() - 1) : text;
String cleanText = StringUtil.replace(StringUtil.trimEnd(text, 'l'), "_", "");
//literal 9223372036854775808L may appear only as the operand of the unary negation operator -.
if (!(mText.equals(PsiLiteralExpressionImpl._2_IN_63) &&
if (!(cleanText.equals(PsiLiteralExpressionImpl._2_IN_63) &&
parent instanceof PsiPrefixExpression &&
((PsiPrefixExpression)parent).getOperationTokenType() == JavaTokenType.MINUS)) {
if (mText.equals(PsiLiteralExpressionImpl.HEX_PREFIX)) {
if (cleanText.equals(PsiLiteralExpressionImpl.HEX_PREFIX)) {
String message = JavaErrorMessages.message("hexadecimal.numbers.must.contain.at.least.one.hexadecimal.digit");
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
}
if (mText.equals(PsiLiteralExpressionImpl.BIN_PREFIX)) {
if (cleanText.equals(PsiLiteralExpressionImpl.BIN_PREFIX)) {
String message = JavaErrorMessages.message("binary.numbers.must.contain.at.least.one.hexadecimal.digit");
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
}
if (value == null || mText.equals(PsiLiteralExpressionImpl._2_IN_63)) {
if (value == null || cleanText.equals(PsiLiteralExpressionImpl._2_IN_63)) {
String message = JavaErrorMessages.message("long.number.too.large");
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
}
@@ -20,6 +20,8 @@ public class NumericLiterals {
long l5 = 0b0001_0010_0100_1000l;
long l6 = <error descr="Binary numbers must contain at least one binary digit">0Bl</error>;
long l7 = <error descr="Long number too large">0B1_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111_1111L</error>;
long l8 = <error descr="Long number too large">9_223_372_036_854_775_808L</error>;
long l9 = -9_223_372_036_854_775_808L;
float f1 = 1_0f;
float f2 = 1e1_2f;