1 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 35 public class JavaSpellingEngine extends SpellingEngine { 36 37 41 public static final String SPELLING_IGNORE_JAVA_STRINGS= "spelling_ignore_java_stringsr"; 43 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 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 |