Always assign shebang comment to same position before package
This commit is contained in:
@@ -231,8 +231,8 @@ public class KotlinParsing extends AbstractKotlinParsing {
|
||||
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(DoNotBindAnything.INSTANCE, null);
|
||||
// Need to skip everything but shebang comment to allow comments at the start of the file to be bound to the first declaration.
|
||||
packageDirective.setCustomEdgeTokenBinders(BindFirstShebangWithWhitespaceOnly.INSTANCE, null);
|
||||
}
|
||||
|
||||
parseImportDirectives();
|
||||
|
||||
+11
@@ -115,6 +115,17 @@ object DoNotBindAnything : WhitespacesAndCommentsBinder {
|
||||
}
|
||||
}
|
||||
|
||||
object BindFirstShebangWithWhitespaceOnly : WhitespacesAndCommentsBinder {
|
||||
override fun getEdgePosition(
|
||||
tokens: List<IElementType>, atStreamEdge: Boolean, getter: WhitespacesAndCommentsBinder.TokenTextGetter): Int {
|
||||
if (tokens.firstOrNull() == KtTokens.SHEBANG_COMMENT) {
|
||||
return if (tokens.getOrNull(1) == KtTokens.WHITE_SPACE) 2 else 1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
class BindAll(val isTrailing: Boolean) : WhitespacesAndCommentsBinder {
|
||||
override fun getEdgePosition(
|
||||
tokens: List<IElementType>, atStreamEdge: Boolean, getter: WhitespacesAndCommentsBinder.TokenTextGetter): Int {
|
||||
|
||||
Reference in New Issue
Block a user