JavaParser Source Viewer

Home|JavaParser/com/github/javaparser/printer/lexicalpreservation/TokenTextElement.java
1/*
2 * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser.
3 * Copyright (C) 2011, 2013-2020 The JavaParser Team.
4 *
5 * This file is part of JavaParser.
6 *
7 * JavaParser can be used either under the terms of
8 * a) the GNU Lesser General Public License as published by
9 *     the Free Software Foundation, either version 3 of the License, or
10 *     (at your option) any later version.
11 * b) the terms of the Apache License
12 *
13 * You should have received a copy of both licenses in LICENCE.LGPL and
14 * LICENCE.APACHE. Please refer to those files for details.
15 *
16 * JavaParser is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU Lesser General Public License for more details.
20 */
21
22package com.github.javaparser.printer.lexicalpreservation;
23
24import com.github.javaparser.JavaToken;
25import com.github.javaparser.Range;
26import com.github.javaparser.JavaToken.Kind;
27import com.github.javaparser.ast.Node;
28
29import java.util.Optional;
30
31class TokenTextElement extends TextElement {
32    private final JavaToken token;
33
34    TokenTextElement(JavaToken token) {
35        this.token = token;
36    }
37
38    TokenTextElement(int tokenKindString text) {
39        this(new JavaToken(tokenKindtext));
40    }
41
42    TokenTextElement(int tokenKind) {
43        this(new JavaToken(tokenKind));
44    }
45
46    @Override
47    String expand() {
48        return token.getText();
49    }
50
51    // Visible for testing
52    String getText() {
53        return token.getText();
54    }
55
56    int getTokenKind() {
57        return token.getKind();
58    }
59
60    public JavaToken getToken() {
61        return token;
62    }
63
64    @Override
65    public boolean equals(Object o) {
66        if (this == o) return true;
67        if (o == null || getClass() != o.getClass()) return false;
68
69        TokenTextElement that = (TokenTextElemento;
70
71        return token.equals(that.token);
72    }
73
74    @Override
75    public int hashCode() {
76        return token.hashCode();
77    }
78
79    @Override
80    public String toString() {
81        return token.toString();
82    }
83
84    @Override
85    boolean isToken(int tokenKind) {
86        return token.getKind() == tokenKind;
87    }
88
89    @Override
90    boolean isNode(Node node) {
91        return false;
92    }
93
94    @Override
95    public boolean isWhiteSpace() {
96        return token.getCategory().isWhitespace();
97    }
98
99    @Override
100    public boolean isSpaceOrTab() {
101        return token.getCategory().isWhitespaceButNotEndOfLine();
102    }
103
104    @Override
105    public boolean isComment() {
106        return token.getCategory().isComment();
107    }
108    
109    @Override
110    public boolean isSeparator() {
111        return token.getCategory().isSeparator();
112    }
113
114    @Override
115    public boolean isNewline() {
116        return token.getCategory().isEndOfLine();
117    }
118
119    @Override
120    public boolean isChildOfClass(Class<? extends NodenodeClass) {
121        return false;
122    }
123    
124    @Override
125    public boolean isIdentifier() {
126        return getToken().getCategory().isIdentifier();
127    }
128
129    @Override
130    public boolean isLiteral() {
131        return getToken().getCategory().isLiteral();
132    }
133    
134    @Override
135    public boolean isPrimitive() {
136        return Kind.valueOf(getTokenKind()).isPrimitive();
137    }
138
139    @Override
140    Optional<RangegetRange() {
141        return token.getRange();
142    }
143}
144
MembersX
TokenTextElement:getText
TokenTextElement:isSpaceOrTab
TokenTextElement:equals:Block:that
TokenTextElement:isLiteral
TokenTextElement:isSeparator
TokenTextElement:isIdentifier
TokenTextElement:getRange
TokenTextElement:toString
TokenTextElement:isNode
TokenTextElement:getToken
TokenTextElement:isChildOfClass
TokenTextElement:hashCode
TokenTextElement:isToken
TokenTextElement:isComment
TokenTextElement:equals
TokenTextElement:getTokenKind
TokenTextElement:isWhiteSpace
TokenTextElement:isPrimitive
TokenTextElement:token
TokenTextElement:expand
TokenTextElement:TokenTextElement
TokenTextElement:isNewline
Members
X