diff --git a/LanguageServer/src/main/java/org/nittalab/dtram/languageserver/model/Token.java b/LanguageServer/src/main/java/org/nittalab/dtram/languageserver/model/Token.java index 567e722..0885491 100644 --- a/LanguageServer/src/main/java/org/nittalab/dtram/languageserver/model/Token.java +++ b/LanguageServer/src/main/java/org/nittalab/dtram/languageserver/model/Token.java @@ -15,12 +15,12 @@ private String text; /** - * A position the token starts + * A position where the token starts at */ private Position start; /** - * A position the token ends + * A position where the token ends at */ private Position end; @@ -45,10 +45,10 @@ /** * Constructs a new token with given properties. * - * @param text - * @param start - * @param end - * @param atomic + * @param text The text of token + * @param start The position where the token starts at + * @param end The position where the token ends at + * @param atomic Whether the token is the minimal block or not * @author Shohei Yamagiwa * @since 0.1 */ @@ -59,6 +59,22 @@ this.atomic = atomic; } + /** + * Constructs a new token with given properties. But {@code end} position will be calculated automatically. + * + * @param text The text of token + * @param start The position where the token starts at + * @param atomic Whether the token is the minimal block or not + * @author Shohei Yamagiwa + * @since 0.1 + */ + public Token(final String text, final Position start, final boolean atomic) { + this.text = text; + this.start = start; + this.end = start.move(0, text.codePointCount(0, text.length()) - 1); + this.atomic = atomic; + } + public String getText() { return text; } @@ -93,7 +109,7 @@ @Override public String toString() { - return text + " " + "starts from " + "line: " + start.getLine() + ", " + "column: " + start.getColumn() + " " + "to" + " " + "line: " + end.getLine() + ", " + "column: " + end.getColumn() + ", " + "isAtomic: " + atomic; + return "\"" + text + "\"" + " " + "starts from " + "line: " + start.getLine() + ", " + "column: " + start.getColumn() + " " + "to" + " " + "line: " + end.getLine() + ", " + "column: " + end.getColumn() + ", " + "isAtomic: " + atomic; } @Override