下面列出了怎么用org.eclipse.ui.texteditor.spelling.ISpellingProblemCollector的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void reconcile(IRegion region) {
if (getAnnotationModel() == null) {
return;
}
try {
currentRegion = region;
if (region instanceof ITypedRegion && !contentTypes.contains(((ITypedRegion) region).getType())) {
ISpellingProblemCollector collector = createSpellingProblemCollector();
collector.beginCollecting();
collector.endCollecting();
} else {
super.reconcile(region);
}
} finally {
currentRegion = null;
}
}
@Override
public void check(IDocument document, IRegion[] regions,
SpellingContext context, ISpellingProblemCollector collector,
IProgressMonitor monitor) {
ISpellingEngine engine = getEngine(context.getContentType());
if (engine == null){
engine = getEngine(TEXT_CONTENT_TYPE);
}
if (engine != null){
engine.check(document, regions, context, collector, monitor);
}
}
@Override
protected void check(IDocument document, IRegion[] regions, ISpellChecker checker, ISpellingProblemCollector collector, IProgressMonitor monitor) {
SpellEventListener listener= new SpellEventListener(collector, document);
for (int i= 0; i < regions.length; i++) {
if (monitor != null && monitor.isCanceled())
return;
if (listener.isProblemsThresholdReached())
return;
checker.execute(listener, new SpellCheckIterator(document, regions[i], checker.getLocale()));
}
}
public void check(IDocument document, IRegion[] regions, SpellingContext context, ISpellingProblemCollector collector, IProgressMonitor monitor) {
if (collector != null) {
final ISpellCheckEngine spellingEngine= SpellCheckEngine.getInstance();
ISpellChecker checker= spellingEngine.getSpellChecker();
if (checker != null)
check(document, regions, checker, collector, monitor);
}
}
@Override
protected void check(IDocument document, IRegion[] regions,
ISpellChecker checker, ISpellingProblemCollector collector,
IProgressMonitor monitor) {
try {
List<IRegion> regionList = new ArrayList<IRegion>();
for (int i = 0; i < regions.length; i++) {
IRegion region = regions[i];
// Compute the GWT partitioning so we can identify JSNI blocks
ITypedRegion[] partitions = TextUtilities.computePartitioning(
document, GWTPartitions.GWT_PARTITIONING, region.getOffset(),
region.getLength(), false);
// Spelling engine should ignore all JSNI block regions
for (int j = 0; j < partitions.length; j++) {
ITypedRegion partition = partitions[j];
if (!GWTPartitions.JSNI_METHOD.equals(partition.getType())) {
regionList.add(partition);
}
}
}
super.check(document,
regionList.toArray(new IRegion[regionList.size()]), checker,
collector, monitor);
} catch (BadLocationException e) {
// Ignore: the document has been changed in another thread and will be
// checked again (our super class JavaSpellingEngine does the same).
}
}
@Override
public void check(IDocument document, IRegion[] regions,
SpellingContext context, ISpellingProblemCollector collector,
IProgressMonitor monitor) {
if (JavaCore.JAVA_SOURCE_CONTENT_TYPE.equals(context.getContentType().getId())) {
gwtEngine.check(document, regions, context, collector, monitor);
} else {
super.check(document, regions, context, collector, monitor);
}
}
@Override
protected ISpellingProblemCollector createSpellingProblemCollector() {
IAnnotationModel model = getAnnotationModel();
if (model == null) {
return null;
}
return new SpellingProblemCollector(model);
}
public void check(IDocument document, IRegion[] regions, SpellingContext context, ISpellingProblemCollector collector, IProgressMonitor monitor) {
ISpellingEngine engine= getEngine(context.getContentType());
if (engine == null)
engine= getEngine(TEXT_CONTENT_TYPE);
if (engine != null)
engine.check(document, regions, context, collector, monitor);
}
@Override
protected void check(IDocument document, IRegion[] regions, ISpellChecker checker, ISpellingProblemCollector collector, IProgressMonitor monitor) {
SpellEventListener listener= new SpellEventListener(collector, document);
for (int i= 0; i < regions.length; i++) {
if (monitor != null && monitor.isCanceled())
return;
if (listener.isProblemsThresholdReached())
return;
checker.execute(listener, new SpellCheckIterator(document, regions[i], checker.getLocale()));
}
}
public void check(IDocument document, IRegion[] regions, SpellingContext context, ISpellingProblemCollector collector, IProgressMonitor monitor) {
if (collector != null) {
final ISpellCheckEngine spellingEngine= SpellCheckEngine.getInstance();
ISpellChecker checker= spellingEngine.getSpellChecker();
if (checker != null)
check(document, regions, checker, collector, monitor);
}
}
public void check(IDocument document, IRegion[] regions, SpellingContext context,
ISpellingProblemCollector collector, IProgressMonitor monitor) {
if (ignore == null) {
ignore = new HashSet<String>();
}
IProject project = getProject(document);
String lang = DEFAULT_LANG;
if (project != null) {
lang = TexlipseProperties.getProjectProperty(project, TexlipseProperties.LANGUAGE_PROPERTY);
}
//Get spellchecker for the correct language
SpellChecker spellCheck = getSpellChecker(lang);
if (spellCheck == null) return;
if (collector instanceof TeXSpellingProblemCollector) {
((TeXSpellingProblemCollector) collector).setRegions(regions);
}
try {
spellCheck.addSpellCheckListener(this);
for (final IRegion r : regions) {
errors = new LinkedList<SpellCheckEvent>();
int roffset = r.getOffset();
//Create a new wordfinder and initialize it
TexlipseWordFinder wf = new TexlipseWordFinder();
wf.setIgnoreComments(TexlipsePlugin.getDefault().getPreferenceStore().getBoolean(TexlipseProperties.SPELLCHECKER_IGNORE_COMMENTS));
wf.setIgnoreMath(TexlipsePlugin.getDefault().getPreferenceStore().getBoolean(TexlipseProperties.SPELLCHECKER_IGNORE_MATH));
spellCheck.checkSpelling(new StringWordTokenizer(
document.get(roffset, r.getLength()), wf));
for (SpellCheckEvent error : errors) {
SpellingProblem p = new TexSpellingProblem(error, roffset, lang);
collector.accept(p);
}
}
spellCheck.removeSpellCheckListener(this);
} catch (BadLocationException e) {
e.printStackTrace();
}
}
@Override
protected ISpellingProblemCollector createSpellingProblemCollector() {
return new SpellingProblemCollector();
}
/**
* Initialize with the given spelling problem collector.
*
* @param collector the spelling problem collector
* @param document the document
*/
public SpellEventListener(ISpellingProblemCollector collector, IDocument document) {
fCollector= collector;
fDocument= document;
fProblemsThreshold= 100;
}
/**
* Spell checks the given document regions with the given arguments.
*
* @param document the document
* @param regions the regions
* @param checker the spell checker
* @param collector the spelling problem collector
* @param monitor the progress monitor, can be <code>null</code>
*/
protected abstract void check(IDocument document, IRegion[] regions, ISpellChecker checker, ISpellingProblemCollector collector, IProgressMonitor monitor);
/**
* Initialize with the given spelling problem collector.
*
* @param collector the spelling problem collector
* @param document the document
*/
public SpellEventListener(ISpellingProblemCollector collector, IDocument document) {
fCollector= collector;
fDocument= document;
fProblemsThreshold= PreferenceConstants.getPreferenceStore().getInt(PreferenceConstants.SPELLING_PROBLEMS_THRESHOLD);
}
/**
* Spell checks the given document regions with the given arguments.
*
* @param document the document
* @param regions the regions
* @param checker the spell checker
* @param collector the spelling problem collector
* @param monitor the progress monitor, can be <code>null</code>
*/
protected abstract void check(IDocument document, IRegion[] regions, ISpellChecker checker, ISpellingProblemCollector collector, IProgressMonitor monitor);