summaryrefslogtreecommitdiffstats
path: root/parser/html/java/javaparser/src/japa/parser/ast/Node.java
blob: b91762f5b1b2cf463dfc03cf84ed0a8481e2b9bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
 * Copyright (C) 2007 Júlio Vilmar Gesser.
 *
 * This file is part of Java 1.5 parser and Abstract Syntax Tree.
 *
 * Java 1.5 parser and Abstract Syntax Tree is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Java 1.5 parser and Abstract Syntax Tree is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Java 1.5 parser and Abstract Syntax Tree.  If not, see <http://www.gnu.org/licenses/>.
 */
/*
 * Created on 05/10/2006
 */
package japa.parser.ast;

import japa.parser.ast.visitor.DumpVisitor;
import japa.parser.ast.visitor.GenericVisitor;
import japa.parser.ast.visitor.VoidVisitor;

/**
 * Abstract class for all nodes of the AST.
 * 
 * @author Julio Vilmar Gesser
 */
public abstract class Node {

    private int beginLine;

    private int beginColumn;

    private int endLine;

    private int endColumn;

    /**
     * This attribute can store additional information from semantic analysis.
     */
    private Object data;

    public Node() {
    }

    public Node(int beginLine, int beginColumn, int endLine, int endColumn) {
        this.beginLine = beginLine;
        this.beginColumn = beginColumn;
        this.endLine = endLine;
        this.endColumn = endColumn;
    }

    /**
     * Accept method for visitor support.
     * 
     * @param <R>
     *            the type the return value of the visitor
     * @param <A>
     *            the type the argument passed for the visitor
     * @param v
     *            the visitor implementation
     * @param arg
     *            any value relevant for the visitor
     * @return the result of the visit
     */
    public abstract <R, A> R accept(GenericVisitor<R, A> v, A arg);

    /**
     * Accept method for visitor support.
     * 
     * @param <A>
     *            the type the argument passed for the visitor
     * @param v
     *            the visitor implementation
     * @param arg
     *            any value relevant for the visitor
     */
    public abstract <A> void accept(VoidVisitor<A> v, A arg);

    /**
     * Return the begin column of this node.
     * 
     * @return the begin column of this node
     */
    public final int getBeginColumn() {
        return beginColumn;
    }

    /**
     * Return the begin line of this node.
     * 
     * @return the begin line of this node
     */
    public final int getBeginLine() {
        return beginLine;
    }

    /**
     * Use this to retrieve additional information associated to this node.
     */
    public final Object getData() {
        return data;
    }

    /**
     * Return the end column of this node.
     * 
     * @return the end column of this node
     */
    public final int getEndColumn() {
        return endColumn;
    }

    /**
     * Return the end line of this node.
     * 
     * @return the end line of this node
     */
    public final int getEndLine() {
        return endLine;
    }

    /**
     * Sets the begin column of this node.
     * 
     * @param beginColumn
     *            the begin column of this node
     */
    public final void setBeginColumn(int beginColumn) {
        this.beginColumn = beginColumn;
    }

    /**
     * Sets the begin line of this node.
     * 
     * @param beginLine
     *            the begin line of this node
     */
    public final void setBeginLine(int beginLine) {
        this.beginLine = beginLine;
    }

    /**
     * Use this to store additional information to this node.
     */
    public final void setData(Object data) {
        this.data = data;
    }

    /**
     * Sets the end column of this node.
     * 
     * @param endColumn
     *            the end column of this node
     */
    public final void setEndColumn(int endColumn) {
        this.endColumn = endColumn;
    }

    /**
     * Sets the end line of this node.
     * 
     * @param endLine
     *            the end line of this node
     */
    public final void setEndLine(int endLine) {
        this.endLine = endLine;
    }

    /**
     * Return the String representation of this node.
     * 
     * @return the String representation of this node
     */
    @Override
    public final String toString() {
        DumpVisitor visitor = new DumpVisitor();
        accept(visitor, null);
        return visitor.getSource();
    }

}