From 03df8cede945507c103249250d758eea72629cc2 Mon Sep 17 00:00:00 2001 From: Jonathan Hedley Date: Tue, 28 Nov 2023 13:47:10 +1100 Subject: [PATCH] Finalized TokenType --- src/main/java/org/jsoup/parser/Token.java | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/jsoup/parser/Token.java b/src/main/java/org/jsoup/parser/Token.java index 8c0133c53a..d79fefcdea 100644 --- a/src/main/java/org/jsoup/parser/Token.java +++ b/src/main/java/org/jsoup/parser/Token.java @@ -16,11 +16,12 @@ * Parse tokens for the Tokeniser. */ abstract class Token { - TokenType type; + final TokenType type; // used in switches in TreeBuilder vs .getClass() static final int Unset = -1; private int startPos, endPos = Unset; // position in CharacterReader this token was read from - private Token() { + private Token(TokenType type) { + this.type = type; } String tokenType() { @@ -67,7 +68,7 @@ static final class Doctype extends Token { boolean forceQuirks = false; Doctype() { - type = TokenType.Doctype; + super(TokenType.Doctype); } @Override @@ -127,7 +128,8 @@ static abstract class Tag extends Token { final boolean trackSource; int attrNameStart, attrNameEnd, attrValStart, attrValEnd; - Tag(TreeBuilder treeBuilder) { + Tag(TokenType type, TreeBuilder treeBuilder) { + super(type); this.treeBuilder = treeBuilder; this.trackSource = treeBuilder.trackSourceRange; } @@ -353,8 +355,7 @@ final static class StartTag extends Tag { // TreeBuilder is provided so if tracking, can get line / column positions for Range; and can dedupe as we go StartTag(TreeBuilder treeBuilder) { - super(treeBuilder); - type = TokenType.StartTag; + super(TokenType.StartTag, treeBuilder); } @Override @@ -383,8 +384,7 @@ public String toString() { final static class EndTag extends Tag{ EndTag(TreeBuilder treeBuilder) { - super(treeBuilder); - type = TokenType.EndTag; + super(TokenType.EndTag, treeBuilder); } @Override @@ -408,7 +408,7 @@ Token reset() { } Comment() { - type = TokenType.Comment; + super(TokenType.Comment); } String getData() { @@ -449,8 +449,7 @@ static class Character extends Token implements Cloneable { private String data; Character() { - super(); - type = TokenType.Character; + super(TokenType.Character); } @Override @@ -498,7 +497,7 @@ public String toString() { final static class EOF extends Token { EOF() { - type = Token.TokenType.EOF; + super(Token.TokenType.EOF); } @Override