org.eclipse.ui.texteditor.spelling.SpellingProblem Java Examples

The following examples show how to use org.eclipse.ui.texteditor.spelling.SpellingProblem. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UiBinderStructuredRegionProcessor.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected boolean isInterestingProblem(SpellingProblem problem) {
  IStructuredDocument doc = (IStructuredDocument) getDocument();
  try {
    ITypedRegion[] partitions = doc.computePartitioning(
        problem.getOffset(), problem.getLength());
    for (ITypedRegion partition : partitions) {
      if (partition.getType().equals(ICSSPartitions.STYLE)) {
        return false;
      }
    }
  } catch (BadLocationException e) {
    // Ignore
  }

  return super.isInterestingProblem(problem);
}
 
Example #2
Source File: JavaSpellingReconcileStrategy.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void accept(SpellingProblem problem) {
	IProblemRequestor requestor= fRequestor;
	if (requestor != null) {
		try {
			int line= getDocument().getLineOfOffset(problem.getOffset()) + 1;
			String word= getDocument().get(problem.getOffset(), problem.getLength());
			boolean dictionaryMatch= false;
			boolean sentenceStart= false;
			if (problem instanceof JavaSpellingProblem) {
				dictionaryMatch= ((JavaSpellingProblem)problem).isDictionaryMatch();
				sentenceStart= ((JavaSpellingProblem) problem).isSentenceStart();
			}
			// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=81514
			IEditorInput editorInput= fEditor.getEditorInput();
			if (editorInput != null) {
				CoreSpellingProblem iProblem= new CoreSpellingProblem(problem.getOffset(), problem.getOffset() + problem.getLength() - 1, line, problem.getMessage(), word, dictionaryMatch, sentenceStart, getDocument(), editorInput.getName());
				requestor.acceptProblem(iProblem);
			}
		} catch (BadLocationException x) {
			// drop this SpellingProblem
		}
	}
}
 
Example #3
Source File: XtextQuickAssistProcessor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.3
 */
protected List<ICompletionProposal> createQuickfixes(IQuickAssistInvocationContext invocationContext, Set<Annotation> applicableAnnotations) {
   	List<ICompletionProposal> result = Lists.newArrayList();
   	ISourceViewer sourceViewer = invocationContext.getSourceViewer();
	IAnnotationModel annotationModel = sourceViewer.getAnnotationModel();
	IXtextDocument xtextDocument = xtextDocumentUtil.getXtextDocument(sourceViewer);
   	for(Annotation annotation : applicableAnnotations) {
		if (annotation instanceof SpellingAnnotation) {
			SpellingProblem spellingProblem = ((SpellingAnnotation) annotation).getSpellingProblem();
			ICompletionProposal[] proposals = spellingProblem.getProposals();
			if (proposals != null) {
				result.addAll(asList(proposals));
			}
		} else {
			final Issue issue = issueUtil.getIssueFromAnnotation(annotation);
			Position pos = annotationModel.getPosition(annotation);
			if (issue != null && pos != null) {
				@SuppressWarnings("deprecation")
				Iterable<IssueResolution> resolutions = getResolutions(issue, xtextDocument);
				if (resolutions.iterator().hasNext()) {
					for (IssueResolution resolution : resolutions) {
						result.add(create(pos, resolution));
					}
				}
			}
		}
	}
   	return result;
   }
 
Example #4
Source File: WordIgnoreProposal.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public final void apply(final IDocument document) {

		final ISpellCheckEngine engine= SpellCheckEngine.getInstance();
		final ISpellChecker checker= engine.getSpellChecker();

		if (checker != null) {
			checker.ignoreWord(fWord);
			ISourceViewer sourceViewer= fContext.getSourceViewer();
			if (sourceViewer != null)
				SpellingProblem.removeAll(sourceViewer, fWord);
		}
	}
 
Example #5
Source File: AddWordProposal.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public final void apply(final IDocument document) {

		final ISpellCheckEngine engine= SpellCheckEngine.getInstance();
		final ISpellChecker checker= engine.getSpellChecker();

		if (checker == null)
			return;

		if (!checker.acceptsWords()) {
			final Shell shell;
			if (fContext != null && fContext.getSourceViewer() != null)
				shell= fContext.getSourceViewer().getTextWidget().getShell();
			else
				shell= WorkbenchUtils.getWorkbenchWindowShell();

			if (!canAskToConfigure() || !askUserToConfigureUserDictionary(shell))
				return;

			String[] preferencePageIds= new String[] { "org.eclipse.ui.editors.preferencePages.Spelling" }; //$NON-NLS-1$
			PreferencesUtil.createPreferenceDialogOn(shell, preferencePageIds[0], preferencePageIds, null).open();
		}

		if (checker.acceptsWords()) {
			checker.addWord(fWord);
			if (fContext != null && fContext.getSourceViewer() != null)
				SpellingProblem.removeAll(fContext.getSourceViewer(), fWord);
		}
	}
 
Example #6
Source File: WordIgnoreProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public final void apply(final IDocument document) {

		final ISpellCheckEngine engine= SpellCheckEngine.getInstance();
		final ISpellChecker checker= engine.getSpellChecker();

		if (checker != null) {
			checker.ignoreWord(fWord);
			ISourceViewer sourceViewer= fContext.getSourceViewer();
			if (sourceViewer != null)
				SpellingProblem.removeAll(sourceViewer, fWord);
		}
	}
 
Example #7
Source File: AddWordProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public final void apply(final IDocument document) {

		final ISpellCheckEngine engine= SpellCheckEngine.getInstance();
		final ISpellChecker checker= engine.getSpellChecker();

		if (checker == null)
			return;

		if (!checker.acceptsWords()) {
			final Shell shell;
			if (fContext != null && fContext.getSourceViewer() != null)
				shell= fContext.getSourceViewer().getTextWidget().getShell();
			else
				shell= JavaPlugin.getActiveWorkbenchShell();

			if (!canAskToConfigure() || !askUserToConfigureUserDictionary(shell))
				return;

			String[] preferencePageIds= new String[] { "org.eclipse.ui.editors.preferencePages.Spelling" }; //$NON-NLS-1$
			PreferencesUtil.createPreferenceDialogOn(shell, preferencePageIds[0], preferencePageIds, null).open();
		}

		if (checker.acceptsWords()) {
			checker.addWord(fWord);
			if (fContext != null && fContext.getSourceViewer() != null)
				SpellingProblem.removeAll(fContext.getSourceViewer(), fWord);
		}
	}
 
Example #8
Source File: AddToDictProposal.java    From texlipse with Eclipse Public License 1.0 4 votes vote down vote up
public void apply(IDocument document) {
    TexSpellDictionary dict = TexSpellingEngine.getDict(fLang);
    dict.addWord(ferror.getInvalidWord());
    SpellingProblem.removeAll(fviewer, ferror.getInvalidWord());
}
 
Example #9
Source File: IgnoreProposal.java    From texlipse with Eclipse Public License 1.0 4 votes vote down vote up
public void apply(IDocument document) {
    fIgnore.add(fWord);
    SpellingProblem.removeAll(fViewer, fWord);
}
 
Example #10
Source File: TexSpellingEngine.java    From texlipse with Eclipse Public License 1.0 4 votes vote down vote up
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();
    }
}
 
Example #11
Source File: TeXSpellingReconcileStrategy.java    From texlipse with Eclipse Public License 1.0 4 votes vote down vote up
public void accept(SpellingProblem problem) {
    fAddAnnotations.put(new SpellingAnnotation(problem), new Position(problem.getOffset(), problem.getLength()));
}
 
Example #12
Source File: CommitCommentArea.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
public void accept(SpellingProblem problem) {
  fAddAnnotations.put(new Annotation(SPELLING_ERROR, false, problem.getMessage()), 
      new Position(problem.getOffset(), problem.getLength()));
}
 
Example #13
Source File: MultiRegionSpellingReconcileStrategy.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
public void accept(SpellingProblem problem) {
	fAddAnnotations.put(new SpellingAnnotation(problem), new Position(problem.getOffset(), problem.getLength()));
}
 
Example #14
Source File: PyReconciler.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void accept(SpellingProblem problem) {
    fAddAnnotations
            .put(new SpellingAnnotation(problem), new Position(problem.getOffset(), problem.getLength()));
}