KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2007 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 com.ibm.icu.text.BreakIterator;
14
15 import java.util.Locale JavaDoc;
16
17 import org.eclipse.jface.text.IDocument;
18 import org.eclipse.jface.text.IRegion;
19
20
21 /**
22  * Iterator to spell check Java properties files
23  * where '&' is ignored.
24  *
25  * @since 3.3
26  */

27 public class PropertiesFileSpellCheckIterator extends SpellCheckIterator {
28
29     public PropertiesFileSpellCheckIterator(IDocument document, IRegion region, Locale JavaDoc locale) {
30         super(document, region, locale);
31     }
32
33     /*
34      * @see org.eclipse.jdt.internal.ui.text.spelling.SpellCheckIterator#next()
35      */

36     public final Object JavaDoc next() {
37         int previous= -1;
38         String JavaDoc token= nextToken();
39         while (fSuccessor != BreakIterator.DONE && (token == null || fContent.charAt(fNext) == '&')) {
40             if (token != null) {
41                 if (previous == -1)
42                     previous= fPrevious;
43                 String JavaDoc nextToken= nextToken();
44                 if (nextToken != null)
45                     token= token + nextToken.substring(1);
46                 else
47                     token= token + '&';
48             } else
49                 token= nextToken();
50
51         }
52
53         if (previous != -1)
54             fPrevious= previous;
55
56         if (token != null && token.length() > 1 && token.startsWith("&")) { //$NON-NLS-1$
57
token= token.substring(1);
58             
59             // Add characters in front of '&'
60
while (fPrevious > 0 && !Character.isWhitespace(fContent.charAt(fPrevious - 1)) && fContent.charAt(fPrevious - 1) != '=') {
61                 token= fContent.charAt(fPrevious - 1) + token;
62                 fPrevious--;
63             }
64                 
65         }
66
67         fLastToken= token;
68
69         return token;
70     }
71
72 }
73
Popular Tags