KT-8275 Unterminated multi-line comment should be compilation error

#KT-8275 fixed
This commit is contained in:
Evgeny Gerashchenko
2015-12-17 18:09:43 +03:00
committed by Andrey Breslav
parent 7cad65a1e7
commit 0d79c65d73
13 changed files with 68 additions and 4 deletions
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.parsing;
import com.intellij.lang.PsiBuilder;
import com.intellij.lang.WhitespacesBinders;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.TokenSet;
@@ -112,9 +113,23 @@ public class KotlinParsing extends AbstractKotlinParsing {
parseTopLevelDeclaration();
}
checkUnclosedBlockComment();
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() {
PsiBuilder.Marker marker = mark();
parseTypeRef();
+3 -1
View File
@@ -3,4 +3,6 @@ JetFile: BlockCommentAtBeginningOfFile1.kt
<empty list>
IMPORT_LIST
<empty list>
PsiComment(BLOCK_COMMENT)('/*')
PsiComment(BLOCK_COMMENT)('/*')
PsiErrorElement:Unclosed comment
<empty list>
+3 -1
View File
@@ -3,4 +3,6 @@ JetFile: BlockCommentAtBeginningOfFile2.kt
<empty list>
IMPORT_LIST
<empty list>
PsiComment(BLOCK_COMMENT)('/*\n/*')
PsiComment(BLOCK_COMMENT)('/*\n/*')
PsiErrorElement:Unclosed comment
<empty list>
+3 -1
View File
@@ -3,4 +3,6 @@ JetFile: BlockCommentAtBeginningOfFile3.kt
<empty list>
IMPORT_LIST
<empty list>
PsiComment(BLOCK_COMMENT)('/*\n\nfooo')
PsiComment(BLOCK_COMMENT)('/*\n\nfooo')
PsiErrorElement:Unclosed comment
<empty list>
+3 -1
View File
@@ -3,4 +3,6 @@ JetFile: BlockCommentAtBeginningOfFile4.kt
<empty list>
IMPORT_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)('/**')
KDOC_SECTION
<empty list>
PsiErrorElement:Unclosed comment
<empty list>
@@ -8,3 +8,5 @@ JetFile: DocCommentAtBeginningOfFile2.kt
PsiWhiteSpace('\n')
KDOC_SECTION
PsiElement(KDOC_TEXT)('/**')
PsiErrorElement:Unclosed comment
<empty list>
@@ -8,3 +8,5 @@ JetFile: DocCommentAtBeginningOfFile3.kt
PsiWhiteSpace('\n\n')
KDOC_SECTION
PsiElement(KDOC_TEXT)('fooo')
PsiErrorElement:Unclosed comment
<empty list>
@@ -10,3 +10,5 @@ JetFile: DocCommentAtBeginningOfFile4.kt
PsiElement(KDOC_TEXT)('/**foo*/')
PsiWhiteSpace('\n\n')
PsiElement(KDOC_TEXT)('asdfas')
PsiErrorElement:Unclosed comment
<empty list>
+2
View File
@@ -8,3 +8,5 @@ JetFile: Incomplete.kt
PsiWhiteSpace('\n ')
KDOC_SECTION
PsiElement(KDOC_TEXT)('contents')
PsiErrorElement:Unclosed comment
<empty list>
@@ -97,6 +97,12 @@ public class ParsingTestGenerated extends AbstractParsingTest {
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")
public void testByClauses() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/psi/ByClauses.kt");