1 | /******************************************************************************* |
---|---|
2 | * Copyright (c) 2000, 2009 IBM Corporation and others. |
3 | * |
4 | * This program and the accompanying materials |
5 | * are made available under the terms of the Eclipse Public License 2.0 |
6 | * which accompanies this distribution, and is available at |
7 | * https://www.eclipse.org/legal/epl-2.0/ |
8 | * |
9 | * SPDX-License-Identifier: EPL-2.0 |
10 | * |
11 | * Contributors: |
12 | * IBM Corporation - initial API and implementation |
13 | *******************************************************************************/ |
14 | |
15 | package org.eclipse.jdt.core.dom; |
16 | |
17 | /** |
18 | * Error message used to report potential errors found during the AST parsing |
19 | * or name resolution. Instances of this class are immutable. |
20 | * |
21 | * @since 2.0 |
22 | */ |
23 | public class Message { |
24 | |
25 | /** |
26 | * The message. |
27 | */ |
28 | private String message; |
29 | |
30 | /** |
31 | * The character index into the original source string, or -1 if none. |
32 | */ |
33 | private int startPosition; |
34 | |
35 | /** |
36 | * The length in characters of the original source file indicating |
37 | * where the source fragment corresponding to this message ends. |
38 | */ |
39 | private int length; |
40 | |
41 | /** |
42 | * Creates a message. |
43 | * |
44 | * @param message the localized message reported by the compiler |
45 | * @param startPosition the 0-based character index into the |
46 | * original source file, or <code>-1</code> if no source position |
47 | * information is to be recorded for this message |
48 | * @throws IllegalArgumentException if the message is null |
49 | * @throws IllegalArgumentException if the startPosition is lower than -1. |
50 | */ |
51 | public Message(String message, int startPosition) { |
52 | if (message == null) { |
53 | throw new IllegalArgumentException(); |
54 | } |
55 | if (startPosition < -1) { |
56 | throw new IllegalArgumentException(); |
57 | } |
58 | this.message = message; |
59 | this.startPosition = startPosition; |
60 | this.length = 0; |
61 | } |
62 | |
63 | /** |
64 | * Creates a message. |
65 | * |
66 | * @param message the localized message reported by the compiler |
67 | * @param startPosition the 0-based character index into the |
68 | * original source file, or <code>-1</code> if no source position |
69 | * information is to be recorded for this message |
70 | * @param length the length in character of the original source file indicating |
71 | * where the source fragment corresponding to this message ends. 0 or a negative number |
72 | * if none. A negative number will be converted to a 0-length. |
73 | * @throws IllegalArgumentException if the message is null |
74 | * @throws IllegalArgumentException if the startPosition is lower than -1. |
75 | */ |
76 | public Message(String message, int startPosition, int length) { |
77 | if (message == null) { |
78 | throw new IllegalArgumentException(); |
79 | } |
80 | if (startPosition < -1) { |
81 | throw new IllegalArgumentException(); |
82 | } |
83 | this.message = message; |
84 | this.startPosition = startPosition; |
85 | if (length <= 0) { |
86 | this.length = 0; |
87 | } else { |
88 | this.length = length; |
89 | } |
90 | } |
91 | |
92 | /** |
93 | * Returns the localized message. |
94 | * |
95 | * @return the localized message |
96 | */ |
97 | public String getMessage() { |
98 | return this.message; |
99 | } |
100 | |
101 | /** |
102 | * Returns the character index into the original source file. |
103 | * |
104 | * @return the 0-based character index, or <code>-1</code> |
105 | * if no source position information is recorded for this |
106 | * message |
107 | * @deprecated Use {@link #getStartPosition()} instead. |
108 | * @see #getLength() |
109 | */ |
110 | public int getSourcePosition() { |
111 | return getStartPosition(); |
112 | } |
113 | |
114 | /** |
115 | * Returns the character index into the original source file. |
116 | * |
117 | * @return the 0-based character index, or <code>-1</code> |
118 | * if no source position information is recorded for this |
119 | * message |
120 | * @see #getLength() |
121 | */ |
122 | public int getStartPosition() { |
123 | return this.startPosition; |
124 | } |
125 | |
126 | /** |
127 | * Returns the length in characters of the original source file indicating |
128 | * where the source fragment corresponding to this message ends. |
129 | * |
130 | * @return a length, or <code>0</code> |
131 | * if no source length information is recorded for this message |
132 | * @see #getStartPosition() |
133 | */ |
134 | public int getLength() { |
135 | return this.length; |
136 | } |
137 | } |
138 |
Members