1 11 12 package org.eclipse.jdt.internal.ui.text.spelling; 13 14 import org.eclipse.core.runtime.IProgressMonitor; 15 16 import org.eclipse.jface.text.IDocument; 17 import org.eclipse.jface.text.IRegion; 18 19 import org.eclipse.ui.texteditor.spelling.ISpellingEngine; 20 import org.eclipse.ui.texteditor.spelling.ISpellingProblemCollector; 21 import org.eclipse.ui.texteditor.spelling.SpellingContext; 22 23 import org.eclipse.jdt.ui.PreferenceConstants; 24 25 import org.eclipse.jdt.internal.ui.text.spelling.engine.ISpellCheckEngine; 26 import org.eclipse.jdt.internal.ui.text.spelling.engine.ISpellChecker; 27 import org.eclipse.jdt.internal.ui.text.spelling.engine.ISpellEvent; 28 import org.eclipse.jdt.internal.ui.text.spelling.engine.ISpellEventListener; 29 30 35 public abstract class SpellingEngine implements ISpellingEngine { 36 37 46 public final static String SPELLING_PROBLEMS_THRESHOLD= "spelling_problems_threshold"; 48 49 53 protected static class SpellEventListener implements ISpellEventListener { 54 55 56 private ISpellingProblemCollector fCollector; 57 58 62 private IDocument fDocument; 63 64 private int fProblemsThreshold; 65 private int fProblemCount; 66 67 73 public SpellEventListener(ISpellingProblemCollector collector, IDocument document) { 74 fCollector= collector; 75 fDocument= document; 76 fProblemsThreshold= PreferenceConstants.getPreferenceStore().getInt(SpellingEngine.SPELLING_PROBLEMS_THRESHOLD); 77 } 78 79 82 public void handle(ISpellEvent event) { 83 if (isProblemsThresholdReached()) 84 return; 85 fProblemCount++; 86 fCollector.accept(new JavaSpellingProblem(event, fDocument)); 87 } 88 89 boolean isProblemsThresholdReached() { 90 return fProblemCount >= fProblemsThreshold; 91 } 92 } 93 94 97 public void check(IDocument document, IRegion[] regions, SpellingContext context, ISpellingProblemCollector collector, IProgressMonitor monitor) { 98 if (collector != null) { 99 final ISpellCheckEngine spellingEngine= SpellCheckEngine.getInstance(); 100 ISpellChecker checker= spellingEngine.getSpellChecker(); 101 if (checker != null) 102 check(document, regions, checker, collector, monitor); 103 } 104 } 105 106 115 protected abstract void check(IDocument document, IRegion[] regions, ISpellChecker checker, ISpellingProblemCollector collector, IProgressMonitor monitor); 116 117 } 118 | Popular Tags |