KT-8275 Unterminated multi-line comment should be compilation error
#KT-8275 fixed
This commit is contained in:
committed by
Andrey Breslav
parent
7cad65a1e7
commit
0d79c65d73
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.parsing;
|
package org.jetbrains.kotlin.parsing;
|
||||||
|
|
||||||
import com.intellij.lang.PsiBuilder;
|
import com.intellij.lang.PsiBuilder;
|
||||||
|
import com.intellij.lang.WhitespacesBinders;
|
||||||
import com.intellij.openapi.diagnostic.Logger;
|
import com.intellij.openapi.diagnostic.Logger;
|
||||||
import com.intellij.psi.tree.IElementType;
|
import com.intellij.psi.tree.IElementType;
|
||||||
import com.intellij.psi.tree.TokenSet;
|
import com.intellij.psi.tree.TokenSet;
|
||||||
@@ -112,9 +113,23 @@ public class KotlinParsing extends AbstractKotlinParsing {
|
|||||||
parseTopLevelDeclaration();
|
parseTopLevelDeclaration();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkUnclosedBlockComment();
|
||||||
fileMarker.done(KT_FILE);
|
fileMarker.done(KT_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkUnclosedBlockComment() {
|
||||||
|
if (TokenSet.create(BLOCK_COMMENT, DOC_COMMENT).contains(myBuilder.rawLookup(-1))) {
|
||||||
|
int startOffset = myBuilder.rawTokenTypeStart(-1);
|
||||||
|
int endOffset = myBuilder.rawTokenTypeStart(0);
|
||||||
|
CharSequence tokenChars = myBuilder.getOriginalText().subSequence(startOffset, endOffset);
|
||||||
|
if (!(tokenChars.length() > 2 && tokenChars.subSequence(tokenChars.length() - 2, tokenChars.length()).toString().equals("*/"))) {
|
||||||
|
PsiBuilder.Marker marker = myBuilder.mark();
|
||||||
|
marker.error("Unclosed comment");
|
||||||
|
marker.setCustomEdgeTokenBinders(WhitespacesBinders.GREEDY_RIGHT_BINDER, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void parseTypeCodeFragment() {
|
void parseTypeCodeFragment() {
|
||||||
PsiBuilder.Marker marker = mark();
|
PsiBuilder.Marker marker = mark();
|
||||||
parseTypeRef();
|
parseTypeRef();
|
||||||
|
|||||||
@@ -4,3 +4,5 @@ JetFile: BlockCommentAtBeginningOfFile1.kt
|
|||||||
IMPORT_LIST
|
IMPORT_LIST
|
||||||
<empty list>
|
<empty list>
|
||||||
PsiComment(BLOCK_COMMENT)('/*')
|
PsiComment(BLOCK_COMMENT)('/*')
|
||||||
|
PsiErrorElement:Unclosed comment
|
||||||
|
<empty list>
|
||||||
@@ -4,3 +4,5 @@ JetFile: BlockCommentAtBeginningOfFile2.kt
|
|||||||
IMPORT_LIST
|
IMPORT_LIST
|
||||||
<empty list>
|
<empty list>
|
||||||
PsiComment(BLOCK_COMMENT)('/*\n/*')
|
PsiComment(BLOCK_COMMENT)('/*\n/*')
|
||||||
|
PsiErrorElement:Unclosed comment
|
||||||
|
<empty list>
|
||||||
@@ -4,3 +4,5 @@ JetFile: BlockCommentAtBeginningOfFile3.kt
|
|||||||
IMPORT_LIST
|
IMPORT_LIST
|
||||||
<empty list>
|
<empty list>
|
||||||
PsiComment(BLOCK_COMMENT)('/*\n\nfooo')
|
PsiComment(BLOCK_COMMENT)('/*\n\nfooo')
|
||||||
|
PsiErrorElement:Unclosed comment
|
||||||
|
<empty list>
|
||||||
@@ -4,3 +4,5 @@ JetFile: BlockCommentAtBeginningOfFile4.kt
|
|||||||
IMPORT_LIST
|
IMPORT_LIST
|
||||||
<empty list>
|
<empty list>
|
||||||
PsiComment(BLOCK_COMMENT)('/*\n\n/*foo*/\n\nasdfas')
|
PsiComment(BLOCK_COMMENT)('/*\n\n/*foo*/\n\nasdfas')
|
||||||
|
PsiErrorElement:Unclosed comment
|
||||||
|
<empty list>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun f() {
|
||||||
|
*/
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
JetFile: BlockCommentUnmatchedClosing_ERR.kt
|
||||||
|
PACKAGE_DIRECTIVE
|
||||||
|
<empty list>
|
||||||
|
IMPORT_LIST
|
||||||
|
<empty list>
|
||||||
|
FUN
|
||||||
|
PsiElement(fun)('fun')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(IDENTIFIER)('f')
|
||||||
|
VALUE_PARAMETER_LIST
|
||||||
|
PsiElement(LPAR)('(')
|
||||||
|
PsiElement(RPAR)(')')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
BLOCK
|
||||||
|
PsiElement(LBRACE)('{')
|
||||||
|
PsiWhiteSpace('\n ')
|
||||||
|
PsiErrorElement:Expecting an element
|
||||||
|
PsiElement(MUL)('*')
|
||||||
|
PsiErrorElement:Unexpected tokens (use ';' to separate expressions on the same line)
|
||||||
|
PsiElement(DIV)('/')
|
||||||
|
PsiWhiteSpace('\n')
|
||||||
|
PsiElement(RBRACE)('}')
|
||||||
@@ -7,3 +7,5 @@ JetFile: DocCommentAtBeginningOfFile1.kt
|
|||||||
PsiElement(KDOC_START)('/**')
|
PsiElement(KDOC_START)('/**')
|
||||||
KDOC_SECTION
|
KDOC_SECTION
|
||||||
<empty list>
|
<empty list>
|
||||||
|
PsiErrorElement:Unclosed comment
|
||||||
|
<empty list>
|
||||||
@@ -8,3 +8,5 @@ JetFile: DocCommentAtBeginningOfFile2.kt
|
|||||||
PsiWhiteSpace('\n')
|
PsiWhiteSpace('\n')
|
||||||
KDOC_SECTION
|
KDOC_SECTION
|
||||||
PsiElement(KDOC_TEXT)('/**')
|
PsiElement(KDOC_TEXT)('/**')
|
||||||
|
PsiErrorElement:Unclosed comment
|
||||||
|
<empty list>
|
||||||
@@ -8,3 +8,5 @@ JetFile: DocCommentAtBeginningOfFile3.kt
|
|||||||
PsiWhiteSpace('\n\n')
|
PsiWhiteSpace('\n\n')
|
||||||
KDOC_SECTION
|
KDOC_SECTION
|
||||||
PsiElement(KDOC_TEXT)('fooo')
|
PsiElement(KDOC_TEXT)('fooo')
|
||||||
|
PsiErrorElement:Unclosed comment
|
||||||
|
<empty list>
|
||||||
@@ -10,3 +10,5 @@ JetFile: DocCommentAtBeginningOfFile4.kt
|
|||||||
PsiElement(KDOC_TEXT)('/**foo*/')
|
PsiElement(KDOC_TEXT)('/**foo*/')
|
||||||
PsiWhiteSpace('\n\n')
|
PsiWhiteSpace('\n\n')
|
||||||
PsiElement(KDOC_TEXT)('asdfas')
|
PsiElement(KDOC_TEXT)('asdfas')
|
||||||
|
PsiErrorElement:Unclosed comment
|
||||||
|
<empty list>
|
||||||
+2
@@ -8,3 +8,5 @@ JetFile: Incomplete.kt
|
|||||||
PsiWhiteSpace('\n ')
|
PsiWhiteSpace('\n ')
|
||||||
KDOC_SECTION
|
KDOC_SECTION
|
||||||
PsiElement(KDOC_TEXT)('contents')
|
PsiElement(KDOC_TEXT)('contents')
|
||||||
|
PsiErrorElement:Unclosed comment
|
||||||
|
<empty list>
|
||||||
@@ -97,6 +97,12 @@ public class ParsingTestGenerated extends AbstractParsingTest {
|
|||||||
doParsingTest(fileName);
|
doParsingTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("BlockCommentUnmatchedClosing_ERR.kt")
|
||||||
|
public void testBlockCommentUnmatchedClosing_ERR() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/psi/BlockCommentUnmatchedClosing_ERR.kt");
|
||||||
|
doParsingTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("ByClauses.kt")
|
@TestMetadata("ByClauses.kt")
|
||||||
public void testByClauses() throws Exception {
|
public void testByClauses() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/psi/ByClauses.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/psi/ByClauses.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user