JavaParser Source Viewer

Home|JavaParser/com/github/javaparser/printer/lexicalpreservation/ChildTextElement.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.Range;
25import com.github.javaparser.ast.Node;
26import com.github.javaparser.ast.comments.Comment;
27
28import java.util.Optional;
29
30/**
31 * Represent the position of a child node in the NodeText of its parent.
32 */
33class ChildTextElement extends TextElement {
34    private final Node child;
35
36    ChildTextElement(Node child) {
37        this.child = child;
38    }
39
40    String expand() {
41        return LexicalPreservingPrinter.print(child);
42    }
43
44    Node getChild() {
45        return child;
46    }
47
48    @Override
49    boolean isToken(int tokenKind) {
50        return false;
51    }
52
53    @Override
54    boolean isNode(Node node) {
55        return node == child;
56    }
57
58    NodeText getNodeTextForWrappedNode() {
59        return LexicalPreservingPrinter.getOrCreateNodeText(child);
60    }
61
62    @Override
63    public boolean equals(Object o) {
64        if (this == o) return true;
65        if (o == null || getClass() != o.getClass()) return false;
66
67        ChildTextElement that = (ChildTextElemento;
68
69        return child.equals(that.child);
70
71    }
72
73    @Override
74    public int hashCode() {
75        return child.hashCode();
76    }
77
78    @Override
79    public String toString() {
80        return "ChildTextElement{" + child + '}';
81    }
82
83    @Override
84    public boolean isWhiteSpace() {
85        return false;
86    }
87
88    @Override
89    public boolean isSpaceOrTab() {
90        return false;
91    }
92
93    @Override
94    public boolean isNewline() {
95        return false;
96    }
97
98    @Override
99    public boolean isComment() {
100        return child instanceof Comment;
101    }
102    
103    @Override
104    public boolean isSeparator() {
105        return false;
106    }
107    
108    @Override
109    public boolean isIdentifier() {
110        return false;
111    }
112    
113    @Override
114    public boolean isPrimitive() {
115        return false;
116    }
117
118    @Override
119    public boolean isLiteral() {
120        return false;
121    }
122
123    @Override
124    public boolean isChildOfClass(Class<? extends NodenodeClass) {
125        return nodeClass.isInstance(child);
126    }
127
128    @Override
129    Optional<RangegetRange() {
130        return child.getRange();
131    }
132}
133
MembersX
ChildTextElement:isSpaceOrTab
ChildTextElement:ChildTextElement
ChildTextElement:isNewline
ChildTextElement:isNode
ChildTextElement:isWhiteSpace
ChildTextElement:isSeparator
ChildTextElement:isIdentifier
ChildTextElement:hashCode
ChildTextElement:getChild
ChildTextElement:child
ChildTextElement:isToken
ChildTextElement:isLiteral
ChildTextElement:toString
ChildTextElement:isPrimitive
ChildTextElement:isComment
ChildTextElement:getNodeTextForWrappedNode
ChildTextElement:equals
ChildTextElement:getRange
ChildTextElement:expand
ChildTextElement:isChildOfClass
ChildTextElement:equals:Block:that
Members
X