org.eclipse.ui.texteditor.spelling.ISpellingProblemCollector#org.eclipse.ui.texteditor.spelling.SpellingProblem源码实例Demo

下面列出了org.eclipse.ui.texteditor.spelling.ISpellingProblemCollector#org.eclipse.ui.texteditor.spelling.SpellingProblem 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@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);
}
 
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
		}
	}
}
 
源代码3 项目: xtext-eclipse   文件: XtextQuickAssistProcessor.java
/**
 * @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;
   }
 
源代码4 项目: xds-ide   文件: WordIgnoreProposal.java
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);
		}
	}
 
源代码5 项目: xds-ide   文件: AddWordProposal.java
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);
		}
	}
 
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);
		}
	}
 
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);
		}
	}
 
源代码8 项目: texlipse   文件: AddToDictProposal.java
public void apply(IDocument document) {
    TexSpellDictionary dict = TexSpellingEngine.getDict(fLang);
    dict.addWord(ferror.getInvalidWord());
    SpellingProblem.removeAll(fviewer, ferror.getInvalidWord());
}
 
源代码9 项目: texlipse   文件: IgnoreProposal.java
public void apply(IDocument document) {
    fIgnore.add(fWord);
    SpellingProblem.removeAll(fViewer, fWord);
}
 
源代码10 项目: texlipse   文件: TexSpellingEngine.java
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();
    }
}
 
源代码11 项目: texlipse   文件: TeXSpellingReconcileStrategy.java
public void accept(SpellingProblem problem) {
    fAddAnnotations.put(new SpellingAnnotation(problem), new Position(problem.getOffset(), problem.getLength()));
}
 
源代码12 项目: APICloud-Studio   文件: CommitCommentArea.java
public void accept(SpellingProblem problem) {
  fAddAnnotations.put(new Annotation(SPELLING_ERROR, false, problem.getMessage()), 
      new Position(problem.getOffset(), problem.getLength()));
}
 
public void accept(SpellingProblem problem) {
	fAddAnnotations.put(new SpellingAnnotation(problem), new Position(problem.getOffset(), problem.getLength()));
}
 
源代码14 项目: Pydev   文件: PyReconciler.java
@Override
public void accept(SpellingProblem problem) {
    fAddAnnotations
            .put(new SpellingAnnotation(problem), new Position(problem.getOffset(), problem.getLength()));
}