KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > text > spelling > CoreSpellingProblem


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

11 package org.eclipse.jdt.internal.ui.text.spelling;
12
13 import org.eclipse.jface.text.BadLocationException;
14 import org.eclipse.jface.text.IDocument;
15 import org.eclipse.jface.text.IRegion;
16
17 import org.eclipse.jdt.core.compiler.CategorizedProblem;
18
19 /**
20  * Spelling problem to be accepted by problem requesters.
21  *
22  * @since 3.1
23  */

24 public class CoreSpellingProblem extends CategorizedProblem {
25
26     // spelling 'marker type' name. Only virtual as spelling problems are never persisted in markers.
27
// marker type is used in the quickFixProcessor extension point
28
public static final String JavaDoc MARKER_TYPE= "org.eclipse.jdt.internal.spelling"; //$NON-NLS-1$
29

30     /** The end offset of the problem */
31     private int fSourceEnd= 0;
32
33     /** The line number of the problem */
34     private int fLineNumber= 1;
35
36     /** The start offset of the problem */
37     private int fSourceStart= 0;
38
39     /** The description of the problem */
40     private String JavaDoc fMessage;
41
42     /** The misspelled word */
43     private String JavaDoc fWord;
44
45     /** Was the word found in the dictionary? */
46     private boolean fMatch;
47
48     /** Does the word start a new sentence? */
49     private boolean fSentence;
50
51     /** The associated document */
52     private IDocument fDocument;
53
54     /** The originating file name */
55     private String JavaDoc fOrigin;
56
57     /**
58      * Initialize with the given parameters.
59      *
60      * @param start the start offset
61      * @param end the end offset
62      * @param line the line
63      * @param message the message
64      * @param word the word
65      * @param match <code>true</code> iff the word was found in the dictionary
66      * @param sentence <code>true</code> iff the word starts a sentence
67      * @param document the document
68      * @param origin the originating file name
69      */

70     public CoreSpellingProblem(int start, int end, int line, String JavaDoc message, String JavaDoc word, boolean match, boolean sentence, IDocument document, String JavaDoc origin) {
71         super();
72         fSourceStart= start;
73         fSourceEnd= end;
74         fLineNumber= line;
75         fMessage= message;
76         fWord= word;
77         fMatch= match;
78         fSentence= sentence;
79         fDocument= document;
80         fOrigin= origin;
81     }
82     /*
83      * @see org.eclipse.jdt.core.compiler.IProblem#getArguments()
84      */

85     public String JavaDoc[] getArguments() {
86
87         String JavaDoc prefix= ""; //$NON-NLS-1$
88
String JavaDoc postfix= ""; //$NON-NLS-1$
89

90         try {
91
92             IRegion line= fDocument.getLineInformationOfOffset(fSourceStart);
93
94             prefix= fDocument.get(line.getOffset(), fSourceStart - line.getOffset());
95             postfix= fDocument.get(fSourceEnd + 1, line.getOffset() + line.getLength() - fSourceEnd);
96
97         } catch (BadLocationException exception) {
98             // Do nothing
99
}
100         return new String JavaDoc[] { fWord, prefix, postfix, fSentence ? Boolean.toString(true) : Boolean.toString(false), fMatch ? Boolean.toString(true) : Boolean.toString(false) };
101     }
102
103     /*
104      * @see org.eclipse.jdt.core.compiler.IProblem#getID()
105      */

106     public int getID() {
107         return JavaSpellingReconcileStrategy.SPELLING_PROBLEM_ID;
108     }
109
110     /*
111      * @see org.eclipse.jdt.core.compiler.IProblem#getMessage()
112      */

113     public String JavaDoc getMessage() {
114         return fMessage;
115     }
116
117     /*
118      * @see org.eclipse.jdt.core.compiler.IProblem#getOriginatingFileName()
119      */

120     public char[] getOriginatingFileName() {
121         return fOrigin.toCharArray();
122     }
123
124     /*
125      * @see org.eclipse.jdt.core.compiler.IProblem#getSourceEnd()
126      */

127     public int getSourceEnd() {
128         return fSourceEnd;
129     }
130
131     /*
132      * @see org.eclipse.jdt.core.compiler.IProblem#getSourceLineNumber()
133      */

134     public int getSourceLineNumber() {
135         return fLineNumber;
136     }
137
138     /*
139      * @see org.eclipse.jdt.core.compiler.IProblem#getSourceStart()
140      */

141     public int getSourceStart() {
142         return fSourceStart;
143     }
144
145     /*
146      * @see org.eclipse.jdt.core.compiler.IProblem#isError()
147      */

148     public boolean isError() {
149         return false;
150     }
151
152     /*
153      * @see org.eclipse.jdt.core.compiler.IProblem#isWarning()
154      */

155     public boolean isWarning() {
156         return true;
157     }
158
159     /*
160      * @see org.eclipse.jdt.core.compiler.IProblem#setSourceStart(int)
161      */

162     public void setSourceStart(int sourceStart) {
163         fSourceStart= sourceStart;
164     }
165
166     /*
167      * @see org.eclipse.jdt.core.compiler.IProblem#setSourceEnd(int)
168      */

169     public void setSourceEnd(int sourceEnd) {
170         fSourceEnd= sourceEnd;
171     }
172
173     /*
174      * @see org.eclipse.jdt.core.compiler.IProblem#setSourceLineNumber(int)
175      */

176     public void setSourceLineNumber(int lineNumber) {
177         fLineNumber= lineNumber;
178     }
179     
180     /*
181      * @see org.eclipse.jdt.core.compiler.CategorizedProblem#getCategoryID()
182      */

183     public int getCategoryID() {
184         return CAT_JAVADOC;
185     }
186     
187     /*
188      * @see org.eclipse.jdt.core.compiler.CategorizedProblem#getMarkerType()
189      */

190     public String JavaDoc getMarkerType() {
191         return MARKER_TYPE;
192     }
193 }
194
Popular Tags