Put comments and whitespaces under body in script files

It's more consistent to normal function body for IDE.
Doc comments in file beginning are now sticks to declarations
correctly.
Moving declarations at the end of scripts is fixed
This commit is contained in:
Nikolay Krasko
2017-08-03 16:27:38 +03:00
parent 8de6017e53
commit 8d226594ff
11 changed files with 84 additions and 14 deletions
@@ -30,6 +30,8 @@ import org.jetbrains.kotlin.lexer.KtTokens;
import static org.jetbrains.kotlin.KtNodeTypes.*;
import static org.jetbrains.kotlin.lexer.KtTokens.*;
import static org.jetbrains.kotlin.parsing.KotlinParsing.AnnotationParsingMode.*;
import static org.jetbrains.kotlin.parsing.KotlinWhitespaceAndCommentsBindersKt.PRECEDING_ALL_BINDER;
import static org.jetbrains.kotlin.parsing.KotlinWhitespaceAndCommentsBindersKt.TRAILING_ALL_BINDER;
public class KotlinParsing extends AbstractKotlinParsing {
private static final Logger LOG = Logger.getInstance(KotlinParsing.class);
@@ -174,7 +176,11 @@ public class KotlinParsing extends AbstractKotlinParsing {
checkForUnexpectedSymbols();
blockMarker.done(BLOCK);
blockMarker.setCustomEdgeTokenBinders(PRECEDING_ALL_BINDER, TRAILING_ALL_BINDER);
scriptMarker.done(SCRIPT);
scriptMarker.setCustomEdgeTokenBinders(PRECEDING_ALL_BINDER, TRAILING_ALL_BINDER);
fileMarker.done(KT_FILE);
}
@@ -113,4 +113,17 @@ object DoNotBindAnything : WhitespacesAndCommentsBinder {
tokens: List<IElementType>, atStreamEdge: Boolean, getter: WhitespacesAndCommentsBinder.TokenTextGetter): Int {
return 0
}
}
}
class BindAll(val isTrailing: Boolean) : WhitespacesAndCommentsBinder {
override fun getEdgePosition(
tokens: List<IElementType>, atStreamEdge: Boolean, getter: WhitespacesAndCommentsBinder.TokenTextGetter): Int {
return if (!isTrailing) 0 else tokens.size
}
}
@JvmField
val PRECEDING_ALL_BINDER: WhitespacesAndCommentsBinder = BindAll(false)
@JvmField
val TRAILING_ALL_BINDER: WhitespacesAndCommentsBinder = BindAll(true)