Attach preceding line comments to property accessors (KT-25417)

#KT-25417 Fixed
This commit is contained in:
Nikolay Krasko
2018-07-30 14:48:41 +03:00
parent e3462a2999
commit 449069b1b7
5 changed files with 74 additions and 5 deletions
@@ -1472,7 +1472,7 @@ public class KotlinParsing extends AbstractKotlinParsing {
errorUntil("Accessor body expected", TokenSet.orSet(ACCESSOR_FIRST_OR_PROPERTY_END, TokenSet.create(LBRACE, LPAR, EQ))); errorUntil("Accessor body expected", TokenSet.orSet(ACCESSOR_FIRST_OR_PROPERTY_END, TokenSet.create(LBRACE, LPAR, EQ)));
} }
else { else {
closeDeclarationWithCommentBinders(getterOrSetter, PROPERTY_ACCESSOR, false); closeDeclarationWithCommentBinders(getterOrSetter, PROPERTY_ACCESSOR, true);
return accessorKind; return accessorKind;
} }
} }
@@ -1508,7 +1508,7 @@ public class KotlinParsing extends AbstractKotlinParsing {
parseFunctionBody(); parseFunctionBody();
closeDeclarationWithCommentBinders(getterOrSetter, PROPERTY_ACCESSOR, false); closeDeclarationWithCommentBinders(getterOrSetter, PROPERTY_ACCESSOR, true);
return accessorKind; return accessorKind;
} }
+6
View File
@@ -71,3 +71,9 @@ var prop: Int // Int
set(value) {} // this is setter set(value) {} // this is setter
val prop2: Int get = 1 // prop2 val prop2: Int get = 1 // prop2
var prop3: Int // Int
// this comment is for getter
get() = 1
// this comment is for setter
set(value) {}
+39
View File
@@ -473,3 +473,42 @@ KtFile: CommentsBinding.kt
PsiElement(INTEGER_LITERAL)('1') PsiElement(INTEGER_LITERAL)('1')
PsiWhiteSpace(' ') PsiWhiteSpace(' ')
PsiComment(EOL_COMMENT)('// prop2') PsiComment(EOL_COMMENT)('// prop2')
PsiWhiteSpace('\n\n')
PROPERTY
PsiElement(var)('var')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('prop3')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('Int')
PsiWhiteSpace(' ')
PsiComment(EOL_COMMENT)('// Int')
PsiWhiteSpace('\n ')
PROPERTY_ACCESSOR
PsiComment(EOL_COMMENT)('// this comment is for getter')
PsiWhiteSpace('\n ')
PsiElement(get)('get')
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('1')
PsiWhiteSpace('\n ')
PROPERTY_ACCESSOR
PsiComment(EOL_COMMENT)('// this comment is for setter')
PsiWhiteSpace('\n ')
PsiElement(set)('set')
PsiElement(LPAR)('(')
VALUE_PARAMETER_LIST
VALUE_PARAMETER
PsiElement(IDENTIFIER)('value')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiElement(RBRACE)('}')
+12
View File
@@ -38,3 +38,15 @@ class EmptyProperties {
*/ */
set(value) {} set(value) {}
} }
var prop: Int // Int
get() = 1 // this is getter
set(value) {} // this is setter
val prop2: Int get = 1 // prop2
var prop3: Int // Int
// this comment is for getter
get() = 1
// this comment is for setter
set(value) {}
+12
View File
@@ -41,3 +41,15 @@ class EmptyProperties {
*/ */
set(value) {} set(value) {}
} }
var prop: Int // Int
get() = 1 // this is getter
set(value) {} // this is setter
val prop2: Int get = 1 // prop2
var prop3: Int // Int
// this comment is for getter
get() = 1
// this comment is for setter
set(value) {}