/******************************************************************************* * Copyright (c) 2000, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jdt.internal.ui.text.spelling; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.eclipse.core.runtime.Assert; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.contentassist.ICompletionProposal; import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext; import org.eclipse.jface.text.source.TextInvocationContext; import org.eclipse.ui.texteditor.spelling.SpellingProblem; import org.eclipse.jdt.internal.corext.util.Messages; import org.eclipse.jdt.ui.PreferenceConstants; import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal; import org.eclipse.jdt.internal.ui.JavaUIMessages; import org.eclipse.jdt.internal.ui.text.javadoc.IHtmlTagConstants; import org.eclipse.jdt.internal.ui.text.spelling.engine.ISpellCheckEngine; import org.eclipse.jdt.internal.ui.text.spelling.engine.ISpellChecker; import org.eclipse.jdt.internal.ui.text.spelling.engine.ISpellEvent; import org.eclipse.jdt.internal.ui.text.spelling.engine.RankedWordProposal; /** * A {@link SpellingProblem} that adapts a {@link ISpellEvent}. *
* TODO: remove {@link ISpellEvent} notification mechanism *
*/ public class JavaSpellingProblem extends SpellingProblem { /** Spell event */ private ISpellEvent fSpellEvent; /** * The associated document. * * @since 3.3 */ private IDocument fDocument; /** * Initialize with the given spell event. * * @param spellEvent the spell event * @param document the document */ public JavaSpellingProblem(ISpellEvent spellEvent, IDocument document) { Assert.isLegal(document != null); Assert.isLegal(spellEvent != null); fSpellEvent= spellEvent; fDocument= document; } /* * @see org.eclipse.ui.texteditor.spelling.SpellingProblem#getOffset() */ @Override public int getOffset() { return fSpellEvent.getBegin(); } /* * @see org.eclipse.ui.texteditor.spelling.SpellingProblem#getLength() */ @Override public int getLength() { return fSpellEvent.getEnd() - fSpellEvent.getBegin() + 1; } /* * @see org.eclipse.ui.texteditor.spelling.SpellingProblem#getMessage() */ @Override public String getMessage() { if (isSentenceStart() && isDictionaryMatch()) return Messages.format(JavaUIMessages.Spelling_error_case_label, new String[] { fSpellEvent.getWord() }); return Messages.format(JavaUIMessages.Spelling_error_label, new String[] { fSpellEvent.getWord() }); } /* * @see org.eclipse.ui.texteditor.spelling.SpellingProblem#getProposals() */ @Override public ICompletionProposal[] getProposals() { return getProposals(null); } /* * @see org.eclipse.ui.texteditor.spelling.SpellingProblem#getProposals(org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext) * @since 3.4 */ @Override public ICompletionProposal[] getProposals(IQuickAssistInvocationContext context) { String[] arguments= getArguments(); if (arguments == null) return new ICompletionProposal[0]; if (arguments[0].indexOf('&') != -1 && isIgnoringAmpersand()) return new ICompletionProposal[0]; // no proposals for now final int threshold= PreferenceConstants.getPreferenceStore().getInt(PreferenceConstants.SPELLING_PROPOSAL_THRESHOLD); int size= 0; Listtrue
iff the corresponding word was found in the dictionary.
* * NOTE: to be removed, see {@link #getProposals()} *
* * @returntrue
iff the corresponding word was found in the dictionary
*/
public boolean isDictionaryMatch() {
return fSpellEvent.isMatch();
}
/**
* Returns true
iff the corresponding word starts a sentence.
* * NOTE: to be removed, see {@link #getProposals()} *
* * @returntrue
iff the corresponding word starts a sentence
*/
public boolean isSentenceStart() {
return fSpellEvent.isStart();
}
}