Skip to main content
summaryrefslogtreecommitdiffstats
blob: fa002da3fed2210dbc7faaddce44dbeb5acb4b7b (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
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
/*******************************************************************************
 * Copyright (c) 2000, 2009 IBM Corporation and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.jdt.core.dom;

/**
 * Error message used to report potential errors found during the AST parsing
 * or name resolution. Instances of this class are immutable.
 *
 * @since 2.0
 */
public class Message {

	/**
	 * The message.
	 */
	private String message;

	/**
	 * The character index into the original source string, or -1 if none.
	 */
	private int startPosition;

	/**
	 * The length in characters of the original source file indicating
	 * where the source fragment corresponding to this message ends.
	 */
	private int length;

	/**
	 * Creates a message.
	 *
	 * @param message the localized message reported by the compiler
	 * @param startPosition the 0-based character index into the
	 *    original source file, or <code>-1</code> if no source position
	 *    information is to be recorded for this message
	 * @throws IllegalArgumentException if the message is null
	 * @throws IllegalArgumentException if the startPosition is lower than -1.
	 */
	public Message(String message, int startPosition) {
		if (message == null) {
			throw new IllegalArgumentException();
		}
		if (startPosition < -1) {
			throw new IllegalArgumentException();
		}
		this.message = message;
		this.startPosition = startPosition;
		this.length = 0;
	}

	/**
	 * Creates a message.
	 *
	 * @param message the localized message reported by the compiler
	 * @param startPosition the 0-based character index into the
	 *    original source file, or <code>-1</code> if no source position
	 *    information is to be recorded for this message
	 * @param length the length in character of the original source file indicating
	 * 	  where the source fragment corresponding to this message ends. 0 or a negative number
	 *    if none. A negative number will be converted to a 0-length.
	 * @throws IllegalArgumentException if the message is null
	 * @throws IllegalArgumentException if the startPosition is lower than -1.
	 */
	public Message(String message, int startPosition, int length) {
		if (message == null) {
			throw new IllegalArgumentException();
		}
		if (startPosition < -1) {
			throw new IllegalArgumentException();
		}
		this.message = message;
		this.startPosition = startPosition;
		if (length <= 0) {
			this.length = 0;
		} else {
			this.length = length;
		}
	}

	/**
	 * Returns the localized message.
	 *
	 * @return the localized message
	 */
	public String getMessage() {
		return this.message;
	}

	/**
	 * Returns the character index into the original source file.
	 *
	 * @return the 0-based character index, or <code>-1</code>
	 *    if no source position information is recorded for this
	 *    message
	 * @deprecated Use {@link #getStartPosition()} instead.
	 * @see #getLength()
	 */
	public int getSourcePosition() {
		return getStartPosition();
	}

	/**
	 * Returns the character index into the original source file.
	 *
	 * @return the 0-based character index, or <code>-1</code>
	 *    if no source position information is recorded for this
	 *    message
	 * @see #getLength()
	 */
	public int getStartPosition() {
		return this.startPosition;
	}

	/**
	 * Returns the length in characters of the original source file indicating
	 * where the source fragment corresponding to this message ends.
	 *
	 * @return a length, or <code>0</code>
	 *    if no source length information is recorded for this message
	 * @see #getStartPosition()
	 */
	public int getLength() {
		return this.length;
	}
}

Back to the top