X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/spelling/SpellReconcileStrategy.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/spelling/SpellReconcileStrategy.java index ef18470..9074743 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/spelling/SpellReconcileStrategy.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/spelling/SpellReconcileStrategy.java @@ -42,7 +42,8 @@ import org.eclipse.ui.texteditor.ITextEditor; * * @since 3.0 */ -public class SpellReconcileStrategy implements IReconcilingStrategy, IReconcilingStrategyExtension, ISpellEventListener { +public class SpellReconcileStrategy implements IReconcilingStrategy, + IReconcilingStrategyExtension, ISpellEventListener { /** * Spelling problem to be accepted by problem requestors. @@ -50,22 +51,22 @@ public class SpellReconcileStrategy implements IReconcilingStrategy, IReconcilin public class SpellProblem implements IProblem { /** The id of the problem */ - public static final int Spelling= 0x80000000; + public static final int Spelling = 0x80000000; /** The end offset of the problem */ - private int fEnd= 0; + private int fEnd = 0; /** The line number of the problem */ - private int fLine= 1; + private int fLine = 1; /** Was the word found in the dictionary? */ private boolean fMatch; /** Does the word start a new sentence? */ - private boolean fSentence= false; + private boolean fSentence = false; /** The start offset of the problem */ - private int fStart= 0; + private int fStart = 0; /** The word which caused the problem */ private final String fWord; @@ -74,10 +75,10 @@ public class SpellReconcileStrategy implements IReconcilingStrategy, IReconcilin * Creates a new spelling problem * * @param word - * The word which caused the problem + * The word which caused the problem */ protected SpellProblem(final String word) { - fWord= word; + fWord = word; } /* @@ -85,20 +86,29 @@ public class SpellReconcileStrategy implements IReconcilingStrategy, IReconcilin */ public String[] getArguments() { - String prefix= ""; //$NON-NLS-1$ - String postfix= ""; //$NON-NLS-1$ + String prefix = ""; //$NON-NLS-1$ + String postfix = ""; //$NON-NLS-1$ try { - final IRegion line= fDocument.getLineInformationOfOffset(fStart); + final IRegion line = fDocument + .getLineInformationOfOffset(fStart); - prefix= fDocument.get(line.getOffset(), fStart - line.getOffset()); - postfix= fDocument.get(fEnd + 1, line.getOffset() + line.getLength() - fEnd); + prefix = fDocument.get(line.getOffset(), fStart + - line.getOffset()); + postfix = fDocument.get(fEnd + 1, line.getOffset() + + line.getLength() - fEnd); } catch (BadLocationException exception) { // Do nothing } - return new String[] { fWord, prefix, postfix, fSentence ? Boolean.toString(true) : Boolean.toString(false), fMatch ? Boolean.toString(true) : Boolean.toString(false)}; + return new String[] { + fWord, + prefix, + postfix, + fSentence ? Boolean.toString(true) : Boolean + .toString(false), + fMatch ? Boolean.toString(true) : Boolean.toString(false) }; } /* @@ -114,9 +124,13 @@ public class SpellReconcileStrategy implements IReconcilingStrategy, IReconcilin public String getMessage() { if (fSentence && fMatch) - return MessageFormat.format(PHPUIMessages.getString("Spelling.error.case.label"), new String[] { fWord }); //$NON-NLS-1$ + return MessageFormat + .format( + PHPUIMessages + .getString("Spelling.error.case.label"), new String[] { fWord }); //$NON-NLS-1$ - return MessageFormat.format(PHPUIMessages.getString("Spelling.error.label"), new String[] { fWord }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + return MessageFormat.format(PHPUIMessages + .getString("Spelling.error.label"), new String[] { fWord }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } /* @@ -150,8 +164,8 @@ public class SpellReconcileStrategy implements IReconcilingStrategy, IReconcilin /** * Was the problem word found in the dictionary? * - * @return true iff the word was found, false - * otherwise + * @return true iff the word was found, + * false otherwise */ public final boolean isDictionaryMatch() { return fMatch; @@ -167,8 +181,8 @@ public class SpellReconcileStrategy implements IReconcilingStrategy, IReconcilin /** * Does the problem word start a new sentence? * - * @return true iff it starts a new sentence, false - * otherwise + * @return true iff it starts a new sentence, + * false otherwise */ public final boolean isSentenceStart() { return fSentence; @@ -185,54 +199,54 @@ public class SpellReconcileStrategy implements IReconcilingStrategy, IReconcilin * Sets whether the problem word was found in the dictionary. * * @param match - * true iff the word was found, false - * otherwise + * true iff the word was found, + * false otherwise */ public final void setDictionaryMatch(final boolean match) { - fMatch= match; + fMatch = match; } /** * Sets whether the problem word starts a new sentence. * * @param sentence - * true iff the word starts a new sentence, - * false otherwise. + * true iff the word starts a new sentence, + * false otherwise. */ public final void setSentenceStart(final boolean sentence) { - fSentence= sentence; + fSentence = sentence; } /* * @see net.sourceforge.phpdt.core.compiler.IProblem#setSourceEnd(int) */ public final void setSourceEnd(final int end) { - fEnd= end; + fEnd = end; } /* * @see net.sourceforge.phpdt.core.compiler.IProblem#setSourceLineNumber(int) */ public final void setSourceLineNumber(final int line) { - fLine= line; + fLine = line; } /* * @see net.sourceforge.phpdt.core.compiler.IProblem#setSourceStart(int) */ public final void setSourceStart(final int start) { - fStart= start; + fStart = start; } } - /** The document to operate on */ - private IDocument fDocument= null; + /** The document to operate on */ + private IDocument fDocument = null; /** The text editor to operate on */ private final ITextEditor fEditor; /** The current locale */ - private Locale fLocale= SpellCheckEngine.getDefaultLocale(); + private Locale fLocale = SpellCheckEngine.getDefaultLocale(); /** The partitioning of the document */ private final String fPartitioning; @@ -247,18 +261,19 @@ public class SpellReconcileStrategy implements IReconcilingStrategy, IReconcilin * Creates a new comment reconcile strategy. * * @param editor - * The text editor to operate on + * The text editor to operate on * @param partitioning - * The partitioning of the document + * The partitioning of the document * @param store - * The preference store to get the preferences from + * The preference store to get the preferences from */ - public SpellReconcileStrategy(final ITextEditor editor, final String partitioning, final IPreferenceStore store) { - fEditor= editor; - fPartitioning= partitioning; - fPreferences= store; + public SpellReconcileStrategy(final ITextEditor editor, + final String partitioning, final IPreferenceStore store) { + fEditor = editor; + fPartitioning = partitioning; + fPreferences = store; - updateProblemRequestor(); + updateProblemRequestor(); } /** @@ -268,7 +283,8 @@ public class SpellReconcileStrategy implements IReconcilingStrategy, IReconcilin */ public Locale getLocale() { - final String locale= fPreferences.getString(ISpellCheckPreferenceKeys.SPELLING_LOCALE); + final String locale = fPreferences + .getString(ISpellCheckPreferenceKeys.SPELLING_LOCALE); if (locale.equals(fLocale.toString())) return fLocale; @@ -282,22 +298,23 @@ public class SpellReconcileStrategy implements IReconcilingStrategy, IReconcilin * @see net.sourceforge.phpdt.internal.ui.text.spelling.engine.ISpellEventListener#handle(net.sourceforge.phpdt.internal.ui.text.spelling.engine.ISpellEvent) */ public void handle(final ISpellEvent event) { - + if (fRequestor != null) { - - final SpellProblem problem= new SpellProblem(event.getWord()); - + + final SpellProblem problem = new SpellProblem(event.getWord()); + problem.setSourceStart(event.getBegin()); problem.setSourceEnd(event.getEnd()); problem.setSentenceStart(event.isStart()); problem.setDictionaryMatch(event.isMatch()); - + try { - problem.setSourceLineNumber(fDocument.getLineOfOffset(event.getBegin()) + 1); + problem.setSourceLineNumber(fDocument.getLineOfOffset(event + .getBegin()) + 1); } catch (BadLocationException x) { // Do nothing } - + fRequestor.acceptProblem(problem); } } @@ -320,30 +337,40 @@ public class SpellReconcileStrategy implements IReconcilingStrategy, IReconcilin */ public void reconcile(final IRegion region) { - if (fPreferences.getBoolean(ISpellCheckPreferenceKeys.SPELLING_CHECK_SPELLING) && fRequestor != null) { + if (fPreferences + .getBoolean(ISpellCheckPreferenceKeys.SPELLING_CHECK_SPELLING) + && fRequestor != null) { try { fRequestor.beginReporting(); - ITypedRegion partition= null; - final ITypedRegion[] partitions= TextUtilities.computePartitioning(fDocument, fPartitioning, 0, fDocument.getLength(), false); + ITypedRegion partition = null; + final ITypedRegion[] partitions = TextUtilities + .computePartitioning(fDocument, fPartitioning, 0, + fDocument.getLength(), false); - final Locale locale= getLocale(); - final ISpellCheckEngine engine= SpellCheckEngine.getInstance(); + final Locale locale = getLocale(); + final ISpellCheckEngine engine = SpellCheckEngine.getInstance(); - final ISpellChecker checker= engine.createSpellChecker(locale, fPreferences); + final ISpellChecker checker = engine.createSpellChecker(locale, + fPreferences); if (checker != null) { try { checker.addListener(this); - - for (int index= 0; index < partitions.length; index++) { - partition= partitions[index]; - if (!partition.getType().equals(IDocument.DEFAULT_CONTENT_TYPE) && - !partition.getType().equals(PHPDocumentPartitioner.PHP_SCRIPT_CODE)) - checker.execute(new SpellCheckIterator(fDocument, partition, locale)); + + for (int index = 0; index < partitions.length; index++) { + partition = partitions[index]; + if (!partition.getType().equals( + IDocument.DEFAULT_CONTENT_TYPE) + && !partition + .getType() + .equals( + PHPDocumentPartitioner.PHP_SCRIPT_CODE)) + checker.execute(new SpellCheckIterator( + fDocument, partition, locale)); } - + } finally { checker.removeListener(this); } @@ -360,8 +387,8 @@ public class SpellReconcileStrategy implements IReconcilingStrategy, IReconcilin * @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#setDocument(org.eclipse.jface.text.IDocument) */ public final void setDocument(final IDocument document) { - fDocument= document; - + fDocument = document; + updateProblemRequestor(); } @@ -378,7 +405,9 @@ public class SpellReconcileStrategy implements IReconcilingStrategy, IReconcilin * @since 3.0 */ private void updateProblemRequestor() { - final IAnnotationModel model= fEditor.getDocumentProvider().getAnnotationModel(fEditor.getEditorInput()); - fRequestor= (model instanceof IProblemRequestor) ? (IProblemRequestor) model : null; + final IAnnotationModel model = fEditor.getDocumentProvider() + .getAnnotationModel(fEditor.getEditorInput()); + fRequestor = (model instanceof IProblemRequestor) ? (IProblemRequestor) model + : null; } }