Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9d0310236632b4465b5515aa671d104f616108da (plain) (blame)
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
/*******************************************************************************
 * Copyright (c) 2003, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 * IBM Corporation - initial API and implementation
 *******************************************************************************/
/*
 * Created on Nov 11, 2003
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package org.eclipse.jst.common.internal.annotations.core;

/**
 * A string, and the range it was taken from in the source file. The range is inclusive. (ie, with
 * source "ABCD", the beginning and end for the Token "BC" would be (1,2) )
 * 
 * @author Pat Kelley
 * 
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class Token {
	private String text;
	private int beginning;
	private int end;



	/**
	 * @return Position in original source of the first character of this token.
	 */
	public int getBeginning() {
		return beginning;
	}

	/**
	 * @return Position in the original source of the last character of this token.
	 */
	public int getEnd() {
		return end;
	}

	/**
	 * @return The token string.
	 */
	public String getText() {
		return text;
	}

	/**
	 * @param i
	 *            A source position
	 */
	public void setBeginning(int i) {
		beginning = i;
	}

	/**
	 * @param i
	 *            A source position.
	 */
	public void setEnd(int i) {
		end = i;
	}

	/**
	 * @param string
	 */
	public void setText(String string) {
		text = string;
	}

	public int length() {
		return text.length();
	}

	/**
	 * Tests whether <code>srcPos</code> comes immediately after the last character in this token.
	 * 
	 * @param srcPos
	 *            A position in the original source the token came from.
	 * @return true if srcPos comes immediately after this token.
	 */
	public boolean immediatelyPrecedes(int srcPos) {
		return end + 1 == srcPos;
	}

	/**
	 * Tests whether srcPos is within the original source range range of the token.
	 * 
	 * @param srcPos
	 * @return
	 */
	public boolean contains(int srcPos) {
		return srcPos >= beginning && srcPos <= end;
	}
}

Back to the top