Fixed doc-comment not attached to the first declaration with no package directive + incorrect placement of comments for enum entry
This commit is contained in:
@@ -40,6 +40,7 @@ object PrecedingWhitespacesAndCommentsBinder : WhitespacesAndCommentsBinder {
|
||||
}
|
||||
else if (tokenType in JetTokens.COMMENTS && tokenType != JetTokens.DOC_COMMENT) {
|
||||
if (atStreamEdge ||
|
||||
idx == 0 ||
|
||||
idx > 0 && tokens[idx - 1] == JetTokens.WHITE_SPACE && StringUtil.containsLineBreak(getter[idx - 1])) {
|
||||
result = idx
|
||||
}
|
||||
|
||||
@@ -199,6 +199,9 @@ public class JetParsing extends AbstractJetParsing {
|
||||
firstEntry.drop();
|
||||
|
||||
consumeIf(SEMICOLON);
|
||||
|
||||
packageDirective.done(PACKAGE_DIRECTIVE);
|
||||
packageDirective.setCustomEdgeTokenBinders(null, TrailingWhitespacesAndCommentsBinder.INSTANCE$);
|
||||
}
|
||||
else {
|
||||
// When package directive is omitted we should not report error on non-file annotations at the beginning of the file.
|
||||
@@ -207,9 +210,10 @@ public class JetParsing extends AbstractJetParsing {
|
||||
|
||||
parseFileAnnotationList(FILE_ANNOTATIONS_WHEN_PACKAGE_OMITTED);
|
||||
packageDirective = mark();
|
||||
packageDirective.done(PACKAGE_DIRECTIVE);
|
||||
// this is necessary to allow comments at the start of the file to be bound to the first declaration:
|
||||
packageDirective.setCustomEdgeTokenBinders(PrecedingWhitespacesAndCommentsBinder.INSTANCE$, null);
|
||||
}
|
||||
packageDirective.done(PACKAGE_DIRECTIVE);
|
||||
packageDirective.setCustomEdgeTokenBinders(null, TrailingWhitespacesAndCommentsBinder.INSTANCE$);
|
||||
|
||||
parseImportDirectives();
|
||||
}
|
||||
@@ -706,8 +710,6 @@ public class JetParsing extends AbstractJetParsing {
|
||||
PsiBuilder.Marker nameAsDeclaration = mark();
|
||||
advance(); // IDENTIFIER
|
||||
nameAsDeclaration.done(OBJECT_DECLARATION_NAME);
|
||||
nameAsDeclaration.setCustomEdgeTokenBinders(PrecedingWhitespacesAndCommentsBinder.INSTANCE$,
|
||||
TrailingWhitespacesAndCommentsBinder.INSTANCE$);
|
||||
|
||||
if (at(COLON)) {
|
||||
advance(); // COLON
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
JetFile: BlockCommentAtBeginningOfFile1.kt
|
||||
PsiComment(BLOCK_COMMENT)('/*')
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
<empty list>
|
||||
PsiComment(BLOCK_COMMENT)('/*')
|
||||
@@ -1,4 +1,4 @@
|
||||
JetFile: BlockCommentAtBeginningOfFile2.kt
|
||||
PsiComment(BLOCK_COMMENT)('/*\n/*')
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
<empty list>
|
||||
PsiComment(BLOCK_COMMENT)('/*\n/*')
|
||||
@@ -1,4 +1,4 @@
|
||||
JetFile: BlockCommentAtBeginningOfFile3.kt
|
||||
PsiComment(BLOCK_COMMENT)('/*\n\nfooo')
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
<empty list>
|
||||
PsiComment(BLOCK_COMMENT)('/*\n\nfooo')
|
||||
@@ -1,4 +1,4 @@
|
||||
JetFile: BlockCommentAtBeginningOfFile4.kt
|
||||
PsiComment(BLOCK_COMMENT)('/*\n\n/*foo*/\n\nasdfas')
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
<empty list>
|
||||
PsiComment(BLOCK_COMMENT)('/*\n\n/*foo*/\n\nasdfas')
|
||||
@@ -269,16 +269,16 @@ JetFile: CommentsBinding.kt
|
||||
ENUM_ENTRY
|
||||
OBJECT_DECLARATION_NAME
|
||||
PsiElement(IDENTIFIER)('A')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiComment(EOL_COMMENT)('// this is A')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiComment(EOL_COMMENT)('// this is A')
|
||||
PsiWhiteSpace('\n ')
|
||||
ENUM_ENTRY
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiElement(KDOC_TEXT)(' This is B ')
|
||||
PsiElement(KDOC_END)('*/')
|
||||
PsiWhiteSpace(' ')
|
||||
OBJECT_DECLARATION_NAME
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiElement(KDOC_TEXT)(' This is B ')
|
||||
PsiElement(KDOC_END)('*/')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('B')
|
||||
PsiWhiteSpace('\n ')
|
||||
ENUM_ENTRY
|
||||
@@ -288,12 +288,12 @@ JetFile: CommentsBinding.kt
|
||||
PsiElement(IDENTIFIER)('C')
|
||||
PsiWhiteSpace('\n ')
|
||||
ENUM_ENTRY
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiElement(KDOC_TEXT)(' This is X ')
|
||||
PsiElement(KDOC_END)('*/')
|
||||
PsiWhiteSpace('\n ')
|
||||
OBJECT_DECLARATION_NAME
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiElement(KDOC_TEXT)(' This is X ')
|
||||
PsiElement(KDOC_END)('*/')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(IDENTIFIER)('X')
|
||||
PsiWhiteSpace(' ')
|
||||
CLASS_BODY
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
[file:volatile]
|
||||
/**
|
||||
* Doc comment
|
||||
*/
|
||||
class C{}
|
||||
@@ -0,0 +1,31 @@
|
||||
JetFile: DocCommentAfterFileAnnotations.kt
|
||||
FILE_ANNOTATION_LIST
|
||||
ANNOTATION
|
||||
PsiElement(LBRACKET)('[')
|
||||
PsiElement(file)('file')
|
||||
PsiElement(COLON)(':')
|
||||
ANNOTATION_ENTRY
|
||||
CONSTRUCTOR_CALLEE
|
||||
TYPE_REFERENCE
|
||||
USER_TYPE
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('volatile')
|
||||
PsiElement(RBRACKET)(']')
|
||||
PsiWhiteSpace('\n')
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
CLASS
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(KDOC_LEADING_ASTERISK)('*')
|
||||
PsiElement(KDOC_TEXT)(' Doc comment')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(KDOC_END)('*/')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(class)('class')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('C')
|
||||
CLASS_BODY
|
||||
PsiElement(LBRACE)('{')
|
||||
PsiElement(RBRACE)('}')
|
||||
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* Doc comment
|
||||
*/
|
||||
fun foo() {}
|
||||
@@ -0,0 +1,22 @@
|
||||
JetFile: DocCommentForFirstDeclaration.kt
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
FUN
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(KDOC_LEADING_ASTERISK)('*')
|
||||
PsiElement(KDOC_TEXT)(' Doc comment')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(KDOC_END)('*/')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(fun)('fun')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
VALUE_PARAMETER_LIST
|
||||
PsiElement(LPAR)('(')
|
||||
PsiElement(RPAR)(')')
|
||||
PsiWhiteSpace(' ')
|
||||
BLOCK
|
||||
PsiElement(LBRACE)('{')
|
||||
PsiElement(RBRACE)('}')
|
||||
@@ -0,0 +1,3 @@
|
||||
[file:volatile]
|
||||
// class C
|
||||
class C{}
|
||||
@@ -0,0 +1,25 @@
|
||||
JetFile: LineCommentAfterFileAnnotations.kt
|
||||
FILE_ANNOTATION_LIST
|
||||
ANNOTATION
|
||||
PsiElement(LBRACKET)('[')
|
||||
PsiElement(file)('file')
|
||||
PsiElement(COLON)(':')
|
||||
ANNOTATION_ENTRY
|
||||
CONSTRUCTOR_CALLEE
|
||||
TYPE_REFERENCE
|
||||
USER_TYPE
|
||||
REFERENCE_EXPRESSION
|
||||
PsiElement(IDENTIFIER)('volatile')
|
||||
PsiElement(RBRACKET)(']')
|
||||
PsiWhiteSpace('\n')
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
CLASS
|
||||
PsiComment(EOL_COMMENT)('// class C')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(class)('class')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('C')
|
||||
CLASS_BODY
|
||||
PsiElement(LBRACE)('{')
|
||||
PsiElement(RBRACE)('}')
|
||||
@@ -0,0 +1,2 @@
|
||||
// This is foo
|
||||
fun foo() {}
|
||||
@@ -0,0 +1,16 @@
|
||||
JetFile: LineCommentForFirstDeclaration.kt
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
FUN
|
||||
PsiComment(EOL_COMMENT)('// This is foo')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(fun)('fun')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
VALUE_PARAMETER_LIST
|
||||
PsiElement(LPAR)('(')
|
||||
PsiElement(RPAR)(')')
|
||||
PsiWhiteSpace(' ')
|
||||
BLOCK
|
||||
PsiElement(LBRACE)('{')
|
||||
PsiElement(RBRACE)('}')
|
||||
@@ -1,9 +1,9 @@
|
||||
JetFile: Super.kt
|
||||
PsiComment(EOL_COMMENT)('// KT-156 Fix the this<Super> syntax')
|
||||
PsiWhiteSpace('\n')
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
FUN
|
||||
PsiComment(EOL_COMMENT)('// KT-156 Fix the this<Super> syntax')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(fun)('fun')
|
||||
PsiWhiteSpace(' ')
|
||||
PsiElement(IDENTIFIER)('foo')
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
JetFile: MutableArray.kt
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(KDOC_TEXT)('These declarations are "shallow" in the sense that they are not really compiled, only the type-checker uses them')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(KDOC_END)('*/')
|
||||
PsiWhiteSpace('\n\n')
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
CLASS
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(KDOC_TEXT)('These declarations are "shallow" in the sense that they are not really compiled, only the type-checker uses them')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(KDOC_END)('*/')
|
||||
PsiWhiteSpace('\n\n')
|
||||
MODIFIER_LIST
|
||||
PsiElement(open)('open')
|
||||
PsiWhiteSpace(' ')
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
JetFile: AtTags.kt
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiWhiteSpace('\n ')
|
||||
@@ -12,6 +14,4 @@ JetFile: AtTags.kt
|
||||
PsiElement(KDOC_LEADING_ASTERISK)('*')
|
||||
PsiElement(KDOC_TEXT)(' @')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(KDOC_END)('*/')
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
PsiElement(KDOC_END)('*/')
|
||||
@@ -1,5 +1,5 @@
|
||||
JetFile: DocCommentAtBeginningOfFile1.kt
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
<empty list>
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
@@ -1,7 +1,7 @@
|
||||
JetFile: DocCommentAtBeginningOfFile2.kt
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(KDOC_TEXT)('/**')
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
PsiElement(KDOC_TEXT)('/**')
|
||||
@@ -1,7 +1,7 @@
|
||||
JetFile: DocCommentAtBeginningOfFile3.kt
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiWhiteSpace('\n\n')
|
||||
PsiElement(KDOC_TEXT)('fooo')
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
PsiElement(KDOC_TEXT)('fooo')
|
||||
@@ -1,9 +1,9 @@
|
||||
JetFile: DocCommentAtBeginningOfFile4.kt
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiWhiteSpace('\n\n')
|
||||
PsiElement(KDOC_TEXT)('/**foo*/')
|
||||
PsiWhiteSpace('\n\n')
|
||||
PsiElement(KDOC_TEXT)('asdfas')
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
PsiElement(KDOC_TEXT)('asdfas')
|
||||
@@ -1,7 +1,7 @@
|
||||
JetFile: EndOnLeadingAsterisks.kt
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(KDOC_END)('*/')
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
PsiElement(KDOC_END)('*/')
|
||||
@@ -1,7 +1,7 @@
|
||||
JetFile: EndRightAfterText.kt
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiElement(KDOC_TEXT)('text')
|
||||
PsiElement(KDOC_END)('*/')
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
PsiElement(KDOC_END)('*/')
|
||||
@@ -1,7 +1,7 @@
|
||||
JetFile: Incomplete.kt
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(KDOC_TEXT)('contents')
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
PsiElement(KDOC_TEXT)('contents')
|
||||
@@ -1,4 +1,6 @@
|
||||
JetFile: Markdown.kt
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiWhiteSpace('\n ')
|
||||
@@ -15,6 +17,4 @@ JetFile: Markdown.kt
|
||||
PsiElement(KDOC_MARKDOWN_ESCAPED_CHAR)('\]')
|
||||
PsiElement(KDOC_TEXT)(']')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(KDOC_END)('*/')
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
PsiElement(KDOC_END)('*/')
|
||||
@@ -1,4 +1,6 @@
|
||||
JetFile: Simple.kt
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiElement(KDOC_TEXT)(' line 0')
|
||||
@@ -18,6 +20,4 @@ JetFile: Simple.kt
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(KDOC_LEADING_ASTERISK)('**')
|
||||
PsiElement(KDOC_TEXT)(' line 6 ')
|
||||
PsiElement(KDOC_END)('*/')
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
PsiElement(KDOC_END)('*/')
|
||||
@@ -1,10 +1,10 @@
|
||||
JetFile: TextRightAfterLeadAsterisks.kt
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
KDoc
|
||||
PsiElement(KDOC_START)('/**')
|
||||
PsiWhiteSpace('\n')
|
||||
PsiElement(KDOC_LEADING_ASTERISK)('**')
|
||||
PsiElement(KDOC_TEXT)('test')
|
||||
PsiWhiteSpace('\n ')
|
||||
PsiElement(KDOC_END)('*/')
|
||||
PACKAGE_DIRECTIVE
|
||||
<empty list>
|
||||
PsiElement(KDOC_END)('*/')
|
||||
@@ -136,6 +136,18 @@ public class JetParsingTestGenerated extends AbstractJetParsingTest {
|
||||
doParsingTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("DocCommentAfterFileAnnotations.kt")
|
||||
public void testDocCommentAfterFileAnnotations() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/DocCommentAfterFileAnnotations.kt");
|
||||
doParsingTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("DocCommentForFirstDeclaration.kt")
|
||||
public void testDocCommentForFirstDeclaration() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/DocCommentForFirstDeclaration.kt");
|
||||
doParsingTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("DoubleColon.kt")
|
||||
public void testDoubleColon() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/DoubleColon.kt");
|
||||
@@ -292,6 +304,18 @@ public class JetParsingTestGenerated extends AbstractJetParsingTest {
|
||||
doParsingTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("LineCommentAfterFileAnnotations.kt")
|
||||
public void testLineCommentAfterFileAnnotations() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/LineCommentAfterFileAnnotations.kt");
|
||||
doParsingTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("LineCommentForFirstDeclaration.kt")
|
||||
public void testLineCommentForFirstDeclaration() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/LineCommentForFirstDeclaration.kt");
|
||||
doParsingTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("LocalDeclarations.kt")
|
||||
public void testLocalDeclarations() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/LocalDeclarations.kt");
|
||||
|
||||
Reference in New Issue
Block a user