KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 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 org.eclipse.core.runtime.IProgressMonitor;
14
15 import org.eclipse.jface.text.BadLocationException;
16 import org.eclipse.jface.text.IDocument;
17 import org.eclipse.jface.text.IRegion;
18 import org.eclipse.jface.text.ITypedRegion;
19 import org.eclipse.jface.text.TextUtilities;
20
21 import org.eclipse.ui.texteditor.spelling.ISpellingProblemCollector;
22
23 import org.eclipse.jdt.ui.PreferenceConstants;
24 import org.eclipse.jdt.ui.text.IJavaPartitions;
25
26 import org.eclipse.jdt.internal.ui.JavaPlugin;
27 import org.eclipse.jdt.internal.ui.text.spelling.engine.ISpellChecker;
28
29
30 /**
31  * Java spelling engine
32  *
33  * @since 3.1
34  */

35 public class JavaSpellingEngine extends SpellingEngine {
36     
37     /*
38      * XXX: To be made public in 3.4,
39      * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=186117
40      */

41     public static final String JavaDoc SPELLING_IGNORE_JAVA_STRINGS= "spelling_ignore_java_stringsr"; //$NON-NLS-1$;
42

43     /*
44      * @see org.eclipse.jdt.internal.ui.text.spelling.SpellingEngine#check(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IRegion[], org.eclipse.jdt.internal.ui.text.spelling.engine.ISpellChecker, org.eclipse.ui.texteditor.spelling.ISpellingProblemCollector, org.eclipse.core.runtime.IProgressMonitor)
45      */

46     protected void check(IDocument document, IRegion[] regions, ISpellChecker checker, ISpellingProblemCollector collector, IProgressMonitor monitor) {
47         SpellEventListener listener= new SpellEventListener(collector, document);
48         boolean isIgnoringJavaStrings= PreferenceConstants.getPreferenceStore().getBoolean(SPELLING_IGNORE_JAVA_STRINGS);
49         try {
50             checker.addListener(listener);
51             try {
52                 for (int i= 0; i < regions.length; i++) {
53                     IRegion region= regions[i];
54                     ITypedRegion[] partitions= TextUtilities.computePartitioning(document, IJavaPartitions.JAVA_PARTITIONING, region.getOffset(), region.getLength(), false);
55                     for (int index= 0; index < partitions.length; index++) {
56                         if (monitor != null && monitor.isCanceled())
57                             return;
58
59                         if (listener.isProblemsThresholdReached())
60                             return;
61
62                         ITypedRegion partition= partitions[index];
63                         final String JavaDoc type= partition.getType();
64                         
65                         if (isIgnoringJavaStrings && type.equals(IJavaPartitions.JAVA_STRING))
66                             continue;
67                         
68                         if (!type.equals(IDocument.DEFAULT_CONTENT_TYPE) && !type.equals(IJavaPartitions.JAVA_CHARACTER))
69                             checker.execute(new SpellCheckIterator(document, partition, checker.getLocale()));
70                     }
71                 }
72             } catch (BadLocationException x) {
73                 JavaPlugin.log(x);
74             }
75         } finally {
76             checker.removeListener(listener);
77         }
78     }
79 }
80
Popular Tags