1 /*******************************************************************************
2 * Copyright (c) 2000, 2006 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
12 package net.sourceforge.phpdt.core.dom;
15 * Error message used to report potential errors found during the AST parsing
16 * or name resolution. Instances of this class are immutable.
20 public class Message {
25 private String message;
28 * The character index into the original source string, or -1 if none.
30 private int startPosition;
33 * The length in characters of the original source file indicating
34 * where the source fragment corresponding to this message ends.
41 * @param message the localized message reported by the compiler
42 * @param startPosition the 0-based character index into the
43 * original source file, or <code>-1</code> if no source position
44 * information is to be recorded for this message
45 * @throws IllegalArgumentException if the message is null
46 * @throws IllegalArgumentException if the startPosition is lower than -1.
48 public Message(String message, int startPosition) {
49 if (message == null) {
50 throw new IllegalArgumentException();
52 if (startPosition < -1) {
53 throw new IllegalArgumentException();
55 this.message = message;
56 this.startPosition = startPosition;
63 * @param message the localized message reported by the compiler
64 * @param startPosition the 0-based character index into the
65 * original source file, or <code>-1</code> if no source position
66 * information is to be recorded for this message
67 * @param length the length in character of the original source file indicating
68 * where the source fragment corresponding to this message ends. 0 or a negative number
69 * if none. A negative number will be converted to a 0-length.
70 * @throws IllegalArgumentException if the message is null
71 * @throws IllegalArgumentException if the startPosition is lower than -1.
73 public Message(String message, int startPosition, int length) {
74 if (message == null) {
75 throw new IllegalArgumentException();
77 if (startPosition < -1) {
78 throw new IllegalArgumentException();
80 this.message = message;
81 this.startPosition = startPosition;
90 * Returns the localized message.
92 * @return the localized message
94 public String getMessage() {
99 * Returns the character index into the original source file.
101 * @return the 0-based character index, or <code>-1</code>
102 * if no source position information is recorded for this
104 * @deprecated Use {@link #getStartPosition()} instead.
107 public int getSourcePosition() {
108 return getStartPosition();
112 * Returns the character index into the original source file.
114 * @return the 0-based character index, or <code>-1</code>
115 * if no source position information is recorded for this
119 public int getStartPosition() {
120 return startPosition;
124 * Returns the length in characters of the original source file indicating
125 * where the source fragment corresponding to this message ends.
127 * @return a length, or <code>0</code>
128 * if no source length information is recorded for this message
129 * @see #getStartPosition()
131 public int getLength() {