PositionedNode.txt 1.14 KB
Newer Older
dgelessus's avatar
dgelessus committed
1
/*
Jens Bendisposto's avatar
Jens Bendisposto committed
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
 * (c) 2009 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, 
 * Heinrich Heine Universitaet Duesseldorf
 * This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) 
 * */

package de.hhu.stups.sablecc.patch;

public class PositionedNode {
	private SourcePosition startPos;
	private SourcePosition endPos;

	public SourcePosition getStartPos() {
		/*
		 * Special treatment for tokens because they don't get a position in the
		 * PositionAspect
		 */
		if (this instanceof IToken) {
			final IToken token = (IToken) this;
			return new SourcePosition(token.getLine(), token.getPos());
		}

		return startPos;
	}

	public SourcePosition getEndPos() {
		/*
		 * Special treatment for tokens because they don't get a position in the
		 * PositionAspect
		 */
		if (this instanceof IToken) {
			final IToken token = (IToken) this;
			return new SourcePosition(token.getLine(), token.getPos()
					+ token.getText().length());
		}

		return endPos;
	}

	public void setStartPos(final SourcePosition startPos) {
		this.startPos = startPos;
	}

	public void setEndPos(final SourcePosition endPos) {
		this.endPos = endPos;
	}
}