Skip to content

Commit

Permalink
Finalized TokenType
Browse files Browse the repository at this point in the history
  • Loading branch information
jhy committed Nov 28, 2023
1 parent 244db10 commit 03df8ce
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/main/java/org/jsoup/parser/Token.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -67,7 +68,7 @@ static final class Doctype extends Token {
boolean forceQuirks = false;

Doctype() {
type = TokenType.Doctype;
super(TokenType.Doctype);
}

@Override
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -408,7 +408,7 @@ Token reset() {
}

Comment() {
type = TokenType.Comment;
super(TokenType.Comment);
}

String getData() {
Expand Down Expand Up @@ -449,8 +449,7 @@ static class Character extends Token implements Cloneable {
private String data;

Character() {
super();
type = TokenType.Character;
super(TokenType.Character);
}

@Override
Expand Down Expand Up @@ -498,7 +497,7 @@ public String toString() {

final static class EOF extends Token {
EOF() {
type = Token.TokenType.EOF;
super(Token.TokenType.EOF);
}

@Override
Expand Down

0 comments on commit 03df8ce

Please sign in to comment.