[java] text blocks: basic highlighting (IDEA-215312)

GitOrigin-RevId: 66780cacc839496911748c788ef8ca79a6cd0c9d
This commit is contained in:
Roman Shevchenko
2019-06-16 05:20:01 +03:00
committed by intellij-monorepo-bot
parent ec5748085c
commit 74f5d16bd7
7 changed files with 46 additions and 1 deletions
@@ -1144,6 +1144,19 @@ public class HighlightUtil extends HighlightUtilBase {
}
}
}
else if (type == JavaTokenType.TEXT_BLOCK_LITERAL) {
if (value == null) {
if (text.charAt(3) != '\n') {
String message = JavaErrorMessages.message("text.block.new.line");
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(message).create();
}
if (!text.endsWith("\"\"\"")) {
String message = JavaErrorMessages.message("text.block.unclosed");
int p = expression.getTextRange().getEndOffset();
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(p, p).endOfLine().descriptionAndTooltip(message).create();
}
}
}
if (value instanceof Float) {
Float number = (Float)value;
@@ -64,5 +64,5 @@ public interface ElementType extends JavaTokenType, JavaDocTokenType, JavaElemen
TokenSet INTEGER_LITERALS = TokenSet.create(INTEGER_LITERAL, LONG_LITERAL);
TokenSet REAL_LITERALS = TokenSet.create(FLOAT_LITERAL, DOUBLE_LITERAL);
TokenSet STRING_LITERALS = TokenSet.create(STRING_LITERAL, RAW_STRING_LITERAL);
TokenSet STRING_LITERALS = TokenSet.create(STRING_LITERAL, TEXT_BLOCK_LITERAL, RAW_STRING_LITERAL);
}
@@ -335,6 +335,8 @@ illegal.escape.character.in.string.literal=Illegal escape character in string li
floating.point.number.too.large=Floating point number too large
floating.point.number.too.small=Floating point number too small
illegal.underscore=Illegal underscore
text.block.new.line=Illegal text block start: missing new line after opening quotes
text.block.unclosed=Unclosed text block
import.statement.identifier.or.asterisk.expected.=Identifier or '*' expected
@@ -0,0 +1,7 @@
class C {
String empty = """
""";
String invalid1 = <error descr="Illegal text block start: missing new line after opening quotes">""""""</error>;
String invalid2 = <error descr="Illegal text block start: missing new line after opening quotes">""" """</error>;
String invalid3 = <error descr="Illegal text block start: missing new line after opening quotes">"""\\n """</error>;
}
@@ -0,0 +1,4 @@
class C {
String unclosed = """
\""";
}<EOLError descr="Unclosed text block"></EOLError><EOLError descr="'}' expected"></EOLError><EOLError descr="';' expected"></EOLError>
@@ -0,0 +1,18 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.java.codeInsight.daemon
import com.intellij.JavaTestUtil
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
class LightJava13HighlightingTest : LightCodeInsightFixtureTestCase() {
override fun getProjectDescriptor() = JAVA_13
override fun getBasePath() = JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/daemonCodeAnalyzer/advHighlighting13"
fun testTextBlocks() = doTest()
fun testUnclosedTextBlock() = doTest()
private fun doTest() {
myFixture.configureByFile(getTestName(false) + ".java")
myFixture.checkHighlighting()
}
}
@@ -71,6 +71,7 @@ public abstract class LightCodeInsightFixtureTestCase extends UsefulTestCase {
public static final @NotNull LightProjectDescriptor JAVA_10_ANNOTATED = new ProjectDescriptor(LanguageLevel.JDK_10, true);
public static final @NotNull LightProjectDescriptor JAVA_11 = new ProjectDescriptor(LanguageLevel.JDK_11);
public static final @NotNull LightProjectDescriptor JAVA_12 = new ProjectDescriptor(LanguageLevel.JDK_12_PREVIEW);
public static final @NotNull LightProjectDescriptor JAVA_13 = new ProjectDescriptor(LanguageLevel.JDK_13_PREVIEW);
public static final @NotNull LightProjectDescriptor JAVA_X = new ProjectDescriptor(LanguageLevel.JDK_X);
public static final @NotNull LightProjectDescriptor JAVA_LATEST = new ProjectDescriptor(LanguageLevel.HIGHEST) {