@Override public void check(IDocument document, IRegion[] regions, SpellingContext context, ISpellingProblemCollector collector, IProgressMonitor monitor) { JLanguageTool.setDataBroker(new EclipseRessourceDataBroker()); JLanguageTool langTool = new JLanguageTool(new AmericanEnglish()); if (langTool.getLanguage() == null) { return; } for (IRegion region : regions) { AnnotatedTextBuilder textBuilder = new AnnotatedTextBuilder(); List<RuleMatch> matches; try { MarkupUtil.populateBuilder(textBuilder, document.get(region.getOffset(), region.getLength())); matches = langTool.check(textBuilder.build()); processMatches(collector, matches); } catch (IOException | BadLocationException e) { e.printStackTrace(); } } }
/** * Tdestings * * @param collector * @param matches */ private void processMatches(ISpellingProblemCollector collector, List<RuleMatch> matches) { WorkspaceModifyOperation workspaceRunnable = new WorkspaceModifyOperation() { @Override protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { // TODO deleteMarkers(); matches.forEach(match -> { collector.accept(new LTSpellingProblem(match)); addMarker(match); }); } }; try { workspaceRunnable.run(null); } catch (InvocationTargetException | InterruptedException e) { e.printStackTrace(); } }
@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) { // System.out.println("==document:" + document); // System.out.println(context.getContentType()); // for (IRegion item : regions) { // System.out.println(item.getOffset() + "," + item.getLength()); // } if (JavaCore.JAVA_SOURCE_CONTENT_TYPE .equals(context.getContentType().getId())) { // System.out.println("checking use " + javaSpellingEngine); javaSpellingEngine.check(document, regions, context, collector, monitor); } else { // System.out.println("check with super.*"); super.check(document, regions, context, collector, monitor); } }
/** * Check the given document regions only for those regions that are in the default document * partition. */ @Override protected void check(IDocument doc, IRegion[] regions, ISpellChecker checker, ISpellingProblemCollector collector, IProgressMonitor monitor) { Filter filter = new Filter(); try { regions = filter.exec(doc, regions); } catch (BadLocationException | BadPartitioningException e) { Log.error("Failed to filter doc partitions: " + e.getMessage()); } super.check(doc, 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 IReconciler getReconciler(final ISourceViewer sourceViewer) { if (fPreferenceStore == null || !fPreferenceStore.getBoolean(SpellingService.PREFERENCE_SPELLING_ENABLED)) { return null; } SpellingService spellingService = EditorsUI.getSpellingService(); if (spellingService.getActiveSpellingEngineDescriptor(fPreferenceStore) == null) { return null; } IReconcilingStrategy strategy = new SpellingReconcileStrategy(sourceViewer, spellingService) { @Override protected ISpellingProblemCollector createSpellingProblemCollector() { final ISpellingProblemCollector collector = super.createSpellingProblemCollector(); return new ISpellingProblemCollector() { public void accept(SpellingProblem problem) { int offset = problem.getOffset(); int length = problem.getLength(); if (sourceViewer == null) { return; } IDocument document = sourceViewer.getDocument(); if (document == null) { return; } String text; try { text = document.get(offset, length); } catch (BadLocationException e) { return; } if (new de.darwinspl.preferences.resource.dwprofile.ui.DwprofileIgnoredWordsFilter().ignoreWord(text)) { return; } collector.accept(problem); } public void beginCollecting() { collector.beginCollecting(); } public void endCollecting() { collector.endCollecting(); } }; } }; MonoReconciler reconciler = new MonoReconciler(strategy, false); reconciler.setDelay(500); return reconciler; }
public IReconciler getReconciler(final ISourceViewer sourceViewer) { if (fPreferenceStore == null || !fPreferenceStore.getBoolean(SpellingService.PREFERENCE_SPELLING_ENABLED)) { return null; } SpellingService spellingService = EditorsUI.getSpellingService(); if (spellingService.getActiveSpellingEngineDescriptor(fPreferenceStore) == null) { return null; } IReconcilingStrategy strategy = new SpellingReconcileStrategy(sourceViewer, spellingService) { @Override protected ISpellingProblemCollector createSpellingProblemCollector() { final ISpellingProblemCollector collector = super.createSpellingProblemCollector(); return new ISpellingProblemCollector() { public void accept(SpellingProblem problem) { int offset = problem.getOffset(); int length = problem.getLength(); if (sourceViewer == null) { return; } IDocument document = sourceViewer.getDocument(); if (document == null) { return; } String text; try { text = document.get(offset, length); } catch (BadLocationException e) { return; } if (new eu.hyvar.feature.expression.resource.hyexpression.ui.HyexpressionIgnoredWordsFilter().ignoreWord(text)) { return; } collector.accept(problem); } public void beginCollecting() { collector.beginCollecting(); } public void endCollecting() { collector.endCollecting(); } }; } }; MonoReconciler reconciler = new MonoReconciler(strategy, false); reconciler.setDelay(500); return reconciler; }
public IReconciler getReconciler(final ISourceViewer sourceViewer) { if (fPreferenceStore == null || !fPreferenceStore.getBoolean(SpellingService.PREFERENCE_SPELLING_ENABLED)) { return null; } SpellingService spellingService = EditorsUI.getSpellingService(); if (spellingService.getActiveSpellingEngineDescriptor(fPreferenceStore) == null) { return null; } IReconcilingStrategy strategy = new SpellingReconcileStrategy(sourceViewer, spellingService) { @Override protected ISpellingProblemCollector createSpellingProblemCollector() { final ISpellingProblemCollector collector = super.createSpellingProblemCollector(); return new ISpellingProblemCollector() { public void accept(SpellingProblem problem) { int offset = problem.getOffset(); int length = problem.getLength(); if (sourceViewer == null) { return; } IDocument document = sourceViewer.getDocument(); if (document == null) { return; } String text; try { text = document.get(offset, length); } catch (BadLocationException e) { return; } if (new eu.hyvar.context.contextValidity.resource.hyvalidityformula.ui.HyvalidityformulaIgnoredWordsFilter().ignoreWord(text)) { return; } collector.accept(problem); } public void beginCollecting() { collector.beginCollecting(); } public void endCollecting() { collector.endCollecting(); } }; } }; MonoReconciler reconciler = new MonoReconciler(strategy, false); reconciler.setDelay(500); return reconciler; }
public IReconciler getReconciler(final ISourceViewer sourceViewer) { if (fPreferenceStore == null || !fPreferenceStore.getBoolean(SpellingService.PREFERENCE_SPELLING_ENABLED)) { return null; } SpellingService spellingService = EditorsUI.getSpellingService(); if (spellingService.getActiveSpellingEngineDescriptor(fPreferenceStore) == null) { return null; } IReconcilingStrategy strategy = new SpellingReconcileStrategy(sourceViewer, spellingService) { @Override protected ISpellingProblemCollector createSpellingProblemCollector() { final ISpellingProblemCollector collector = super.createSpellingProblemCollector(); return new ISpellingProblemCollector() { public void accept(SpellingProblem problem) { int offset = problem.getOffset(); int length = problem.getLength(); if (sourceViewer == null) { return; } IDocument document = sourceViewer.getDocument(); if (document == null) { return; } String text; try { text = document.get(offset, length); } catch (BadLocationException e) { return; } if (new eu.hyvar.dataValues.resource.hydatavalue.ui.HydatavalueIgnoredWordsFilter().ignoreWord(text)) { return; } collector.accept(problem); } public void beginCollecting() { collector.beginCollecting(); } public void endCollecting() { collector.endCollecting(); } }; } }; MonoReconciler reconciler = new MonoReconciler(strategy, false); reconciler.setDelay(500); return reconciler; }
public IReconciler getReconciler(final ISourceViewer sourceViewer) { if (fPreferenceStore == null || !fPreferenceStore.getBoolean(SpellingService.PREFERENCE_SPELLING_ENABLED)) { return null; } SpellingService spellingService = EditorsUI.getSpellingService(); if (spellingService.getActiveSpellingEngineDescriptor(fPreferenceStore) == null) { return null; } IReconcilingStrategy strategy = new SpellingReconcileStrategy(sourceViewer, spellingService) { @Override protected ISpellingProblemCollector createSpellingProblemCollector() { final ISpellingProblemCollector collector = super.createSpellingProblemCollector(); return new ISpellingProblemCollector() { public void accept(SpellingProblem problem) { int offset = problem.getOffset(); int length = problem.getLength(); if (sourceViewer == null) { return; } IDocument document = sourceViewer.getDocument(); if (document == null) { return; } String text; try { text = document.get(offset, length); } catch (BadLocationException e) { return; } if (new eu.hyvar.feature.mapping.resource.hymapping.ui.HymappingIgnoredWordsFilter().ignoreWord(text)) { return; } collector.accept(problem); } public void beginCollecting() { collector.beginCollecting(); } public void endCollecting() { collector.endCollecting(); } }; } }; MonoReconciler reconciler = new MonoReconciler(strategy, false); reconciler.setDelay(500); return reconciler; }
public IReconciler getReconciler(final ISourceViewer sourceViewer) { if (fPreferenceStore == null || !fPreferenceStore.getBoolean(SpellingService.PREFERENCE_SPELLING_ENABLED)) { return null; } SpellingService spellingService = EditorsUI.getSpellingService(); if (spellingService.getActiveSpellingEngineDescriptor(fPreferenceStore) == null) { return null; } IReconcilingStrategy strategy = new SpellingReconcileStrategy(sourceViewer, spellingService) { @Override protected ISpellingProblemCollector createSpellingProblemCollector() { final ISpellingProblemCollector collector = super.createSpellingProblemCollector(); return new ISpellingProblemCollector() { public void accept(SpellingProblem problem) { int offset = problem.getOffset(); int length = problem.getLength(); if (sourceViewer == null) { return; } IDocument document = sourceViewer.getDocument(); if (document == null) { return; } String text; try { text = document.get(offset, length); } catch (BadLocationException e) { return; } if (new eu.hyvar.feature.constraint.resource.hyconstraints.ui.HyconstraintsIgnoredWordsFilter().ignoreWord(text)) { return; } collector.accept(problem); } public void beginCollecting() { collector.beginCollecting(); } public void endCollecting() { collector.endCollecting(); } }; } }; MonoReconciler reconciler = new MonoReconciler(strategy, false); reconciler.setDelay(500); return reconciler; }
public IReconciler getReconciler(final ISourceViewer sourceViewer) { if (fPreferenceStore == null || !fPreferenceStore.getBoolean(SpellingService.PREFERENCE_SPELLING_ENABLED)) { return null; } SpellingService spellingService = EditorsUI.getSpellingService(); if (spellingService.getActiveSpellingEngineDescriptor(fPreferenceStore) == null) { return null; } IReconcilingStrategy strategy = new SpellingReconcileStrategy(sourceViewer, spellingService) { @Override protected ISpellingProblemCollector createSpellingProblemCollector() { final ISpellingProblemCollector collector = super.createSpellingProblemCollector(); return new ISpellingProblemCollector() { public void accept(SpellingProblem problem) { int offset = problem.getOffset(); int length = problem.getLength(); if (sourceViewer == null) { return; } IDocument document = sourceViewer.getDocument(); if (document == null) { return; } String text; try { text = document.get(offset, length); } catch (BadLocationException e) { return; } if (new eu.hyvar.mspl.manifest.resource.hymanifest.ui.HymanifestIgnoredWordsFilter().ignoreWord(text)) { return; } collector.accept(problem); } public void beginCollecting() { collector.beginCollecting(); } public void endCollecting() { collector.endCollecting(); } }; } }; MonoReconciler reconciler = new MonoReconciler(strategy, false); reconciler.setDelay(500); return reconciler; }
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(); }
@Override public void check(IDocument document, IRegion[] regions, SpellingContext context, ISpellingProblemCollector collector, IProgressMonitor monitor) { super.check(document, regions, context, collector, 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);
/** * 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= Activator.getDefault().getPreferenceStore().getInt(PreferenceConstants.SPELLING_PROBLEMS_THRESHOLD); }