KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > core > dom > Message


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jdt.core.dom;
13
14 /**
15  * Error message used to report potential errors found during the AST parsing
16  * or name resolution. Instances of this class are immutable.
17  *
18  * @since 2.0
19  */

20 public class Message {
21     
22     /**
23      * The message.
24      */

25     private String JavaDoc message;
26     
27     /**
28      * The character index into the original source string, or -1 if none.
29      */

30     private int startPosition;
31     
32     /**
33      * The length in characters of the original source file indicating
34      * where the source fragment corresponding to this message ends.
35      */

36     private int length;
37     
38     /**
39      * Creates a message.
40      *
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.
47      */

48     public Message(String JavaDoc message, int startPosition) {
49         if (message == null) {
50             throw new IllegalArgumentException JavaDoc();
51         }
52         if (startPosition < -1) {
53             throw new IllegalArgumentException JavaDoc();
54         }
55         this.message = message;
56         this.startPosition = startPosition;
57         this.length = 0;
58     }
59
60     /**
61      * Creates a message.
62      *
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.
72      */

73     public Message(String JavaDoc message, int startPosition, int length) {
74         if (message == null) {
75             throw new IllegalArgumentException JavaDoc();
76         }
77         if (startPosition < -1) {
78             throw new IllegalArgumentException JavaDoc();
79         }
80         this.message = message;
81         this.startPosition = startPosition;
82         if (length <= 0) {
83             this.length = 0;
84         } else {
85             this.length = length;
86         }
87     }
88     
89     /**
90      * Returns the localized message.
91      *
92      * @return the localized message
93      */

94     public String JavaDoc getMessage() {
95         return message;
96     }
97     
98     /**
99      * Returns the character index into the original source file.
100      *
101      * @return the 0-based character index, or <code>-1</code>
102      * if no source position information is recorded for this
103      * message
104      * @deprecated Use getStartPosition() instead.
105      * @see #getLength()
106      */

107     public int getSourcePosition() {
108         return getStartPosition();
109     }
110
111     /**
112      * Returns the character index into the original source file.
113      *
114      * @return the 0-based character index, or <code>-1</code>
115      * if no source position information is recorded for this
116      * message
117      * @see #getLength()
118      */

119     public int getStartPosition() {
120         return startPosition;
121     }
122     
123     /**
124      * Returns the length in characters of the original source file indicating
125      * where the source fragment corresponding to this message ends.
126      *
127      * @return a length, or <code>0</code>
128      * if no source length information is recorded for this message
129      * @see #getStartPosition()
130      */

131     public int getLength() {
132         return length;
133     }
134 }
135
Popular Tags