A massive organize imports and formatting of the sources using default Eclipse code...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / text / spelling / engine / DefaultSpellChecker.java
index 3453691..2b4da35 100644 (file)
@@ -26,19 +26,20 @@ import org.eclipse.jface.preference.IPreferenceStore;
 public class DefaultSpellChecker implements ISpellChecker {
 
        /** Array of url prefixes */
-       public static final String[] URL_PREFIXES= new String[] { "http://", "https://", "www.", "ftp://", "ftps://", "news://", "mailto://" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
+       public static final String[] URL_PREFIXES = new String[] {
+                       "http://", "https://", "www.", "ftp://", "ftps://", "news://", "mailto://" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
 
        /**
         * Does this word contain digits?
         * 
         * @param word
-        *                   The word to check
-        * @return <code>true</code> iff this word contains digits, <code>false></code>
-        *               otherwise
+        *            The word to check
+        * @return <code>true</code> iff this word contains digits,
+        *         <code>false></code> otherwise
         */
        protected static boolean isDigits(final String word) {
 
-               for (int index= 0; index < word.length(); index++) {
+               for (int index = 0; index < word.length(); index++) {
 
                        if (Character.isDigit(word.charAt(index)))
                                return true;
@@ -50,30 +51,31 @@ public class DefaultSpellChecker implements ISpellChecker {
         * Does this word contain mixed-case letters?
         * 
         * @param word
-        *                   The word to check
+        *            The word to check
         * @param sentence
-        *                   <code>true</code> iff the specified word starts a new
-        *                   sentence, <code>false</code> otherwise
-        * @return <code>true</code> iff the contains mixed-case letters, <code>false</code>
-        *               otherwise
+        *            <code>true</code> iff the specified word starts a new
+        *            sentence, <code>false</code> otherwise
+        * @return <code>true</code> iff the contains mixed-case letters,
+        *         <code>false</code> otherwise
         */
-       protected static boolean isMixedCase(final String word, final boolean sentence) {
+       protected static boolean isMixedCase(final String word,
+                       final boolean sentence) {
 
-               final int length= word.length();
-               boolean upper= Character.isUpperCase(word.charAt(0));
+               final int length = word.length();
+               boolean upper = Character.isUpperCase(word.charAt(0));
 
                if (sentence && upper && (length > 1))
-                       upper= Character.isUpperCase(word.charAt(1));
+                       upper = Character.isUpperCase(word.charAt(1));
 
                if (upper) {
 
-                       for (int index= length - 1; index > 0; index--) {
+                       for (int index = length - 1; index > 0; index--) {
                                if (Character.isLowerCase(word.charAt(index)))
                                        return true;
                        }
                } else {
 
-                       for (int index= length - 1; index > 0; index--) {
+                       for (int index = length - 1; index > 0; index--) {
                                if (Character.isUpperCase(word.charAt(index)))
                                        return true;
                        }
@@ -85,13 +87,13 @@ public class DefaultSpellChecker implements ISpellChecker {
         * Does this word contain upper-case letters only?
         * 
         * @param word
-        *                   The word to check
+        *            The word to check
         * @return <code>true</code> iff this word only contains upper-case
-        *               letters, <code>false</code> otherwise
+        *         letters, <code>false</code> otherwise
         */
        protected static boolean isUpperCase(final String word) {
 
-               for (int index= word.length() - 1; index >= 0; index--) {
+               for (int index = word.length() - 1; index >= 0; index--) {
 
                        if (Character.isLowerCase(word.charAt(index)))
                                return false;
@@ -103,13 +105,13 @@ public class DefaultSpellChecker implements ISpellChecker {
         * Does this word look like an URL?
         * 
         * @param word
-        *                   The word to check
-        * @return <code>true</code> iff this word looks like an URL, <code>false</code>
-        *               otherwise
+        *            The word to check
+        * @return <code>true</code> iff this word looks like an URL,
+        *         <code>false</code> otherwise
         */
        protected static boolean isUrl(final String word) {
 
-               for (int index= 0; index < URL_PREFIXES.length; index++) {
+               for (int index = 0; index < URL_PREFIXES.length; index++) {
 
                        if (word.startsWith(URL_PREFIXES[index]))
                                return true;
@@ -121,18 +123,19 @@ public class DefaultSpellChecker implements ISpellChecker {
         * The dictionaries to use for spell-checking. Synchronized to avoid
         * concurrent modifications.
         */
-       private final Set fDictionaries= Collections.synchronizedSet(new HashSet());
+       private final Set fDictionaries = Collections
+                       .synchronizedSet(new HashSet());
 
        /**
         * The words to be ignored. Synchronized to avoid concurrent modifications.
         */
-       private final Set fIgnored= Collections.synchronizedSet(new HashSet());
+       private final Set fIgnored = Collections.synchronizedSet(new HashSet());
 
        /**
         * The spell event listeners. Synchronized to avoid concurrent
         * modifications.
         */
-       private final Set fListeners= Collections.synchronizedSet(new HashSet());
+       private final Set fListeners = Collections.synchronizedSet(new HashSet());
 
        /**
         * The preference store. Assumes the <code>IPreferenceStore</code>
@@ -144,10 +147,10 @@ public class DefaultSpellChecker implements ISpellChecker {
         * Creates a new default spell-checker.
         * 
         * @param store
-        *                   The preference store for this spell-checker
+        *            The preference store for this spell-checker
         */
        public DefaultSpellChecker(final IPreferenceStore store) {
-               fPreferences= store;
+               fPreferences = store;
        }
 
        /*
@@ -165,23 +168,23 @@ public class DefaultSpellChecker implements ISpellChecker {
                // synchronizing is necessary as this is a write access
                fListeners.add(listener);
        }
-       
+
        /*
         * @see net.sourceforge.phpdt.ui.text.spelling.engine.ISpellChecker#acceptsWords()
         */
        public boolean acceptsWords() {
-               // synchronizing might not be needed here since acceptWords is 
+               // synchronizing might not be needed here since acceptWords is
                // a read-only access and only called in the same thread as
                // the modifing methods add/checkWord (?)
                Set copy;
                synchronized (fDictionaries) {
-                       copy= new HashSet(fDictionaries);
+                       copy = new HashSet(fDictionaries);
                }
-               
-               ISpellDictionary dictionary= null;
-               for (final Iterator iterator= copy.iterator(); iterator.hasNext();) {
 
-                       dictionary= (ISpellDictionary)iterator.next();
+               ISpellDictionary dictionary = null;
+               for (final Iterator iterator = copy.iterator(); iterator.hasNext();) {
+
+                       dictionary = (ISpellDictionary) iterator.next();
                        if (dictionary.acceptsWords())
                                return true;
                }
@@ -195,16 +198,16 @@ public class DefaultSpellChecker implements ISpellChecker {
                // synchronizing is necessary as this is a write access
                Set copy;
                synchronized (fDictionaries) {
-                       copy= new HashSet(fDictionaries);
+                       copy = new HashSet(fDictionaries);
                }
 
-               final String addable= word.toLowerCase();
+               final String addable = word.toLowerCase();
                fIgnored.add(addable);
 
-               ISpellDictionary dictionary= null;
-               for (final Iterator iterator= copy.iterator(); iterator.hasNext();) {
+               ISpellDictionary dictionary = null;
+               for (final Iterator iterator = copy.iterator(); iterator.hasNext();) {
 
-                       dictionary= (ISpellDictionary)iterator.next();
+                       dictionary = (ISpellDictionary) iterator.next();
                        dictionary.addWord(addable);
                }
        }
@@ -222,38 +225,51 @@ public class DefaultSpellChecker implements ISpellChecker {
         */
        public void execute(final ISpellCheckIterator iterator) {
 
-               final boolean ignoreDigits= fPreferences.getBoolean(ISpellCheckPreferenceKeys.SPELLING_IGNORE_DIGITS);
-               final boolean ignoreMixed= fPreferences.getBoolean(ISpellCheckPreferenceKeys.SPELLING_IGNORE_MIXED);
-               final boolean ignoreSentence= fPreferences.getBoolean(ISpellCheckPreferenceKeys.SPELLING_IGNORE_SENTENCE);
-               final boolean ignoreUpper= fPreferences.getBoolean(ISpellCheckPreferenceKeys.SPELLING_IGNORE_UPPER);
-               final boolean ignoreURLS= fPreferences.getBoolean(ISpellCheckPreferenceKeys.SPELLING_IGNORE_URLS);
+               final boolean ignoreDigits = fPreferences
+                               .getBoolean(ISpellCheckPreferenceKeys.SPELLING_IGNORE_DIGITS);
+               final boolean ignoreMixed = fPreferences
+                               .getBoolean(ISpellCheckPreferenceKeys.SPELLING_IGNORE_MIXED);
+               final boolean ignoreSentence = fPreferences
+                               .getBoolean(ISpellCheckPreferenceKeys.SPELLING_IGNORE_SENTENCE);
+               final boolean ignoreUpper = fPreferences
+                               .getBoolean(ISpellCheckPreferenceKeys.SPELLING_IGNORE_UPPER);
+               final boolean ignoreURLS = fPreferences
+                               .getBoolean(ISpellCheckPreferenceKeys.SPELLING_IGNORE_URLS);
 
-               String word= null;
-               boolean starts= false;
+               String word = null;
+               boolean starts = false;
 
                while (iterator.hasNext()) {
 
-                       word= (String)iterator.next();
+                       word = (String) iterator.next();
                        if (word != null) {
 
-                               // synchronizing is necessary as this is called inside the reconciler
+                               // synchronizing is necessary as this is called inside the
+                               // reconciler
                                if (!fIgnored.contains(word)) {
 
-                                       starts= iterator.startsSentence();
+                                       starts = iterator.startsSentence();
                                        if (!isCorrect(word)) {
-                                           
-                                           boolean isMixed=  isMixedCase(word, true);
-                                           boolean isUpper= isUpperCase(word);
-                                           boolean isDigits= isDigits(word);
-                                           boolean isURL= isUrl(word);
-                        
-                                           if ( !ignoreMixed && isMixed || !ignoreUpper && isUpper || !ignoreDigits && isDigits || !ignoreURLS && isURL || !(isMixed || isUpper || isDigits || isURL))                         
-                                               fireEvent(new SpellEvent(this, word, iterator.getBegin(), iterator.getEnd(), starts, false));
+
+                                               boolean isMixed = isMixedCase(word, true);
+                                               boolean isUpper = isUpperCase(word);
+                                               boolean isDigits = isDigits(word);
+                                               boolean isURL = isUrl(word);
+
+                                               if (!ignoreMixed && isMixed || !ignoreUpper && isUpper
+                                                               || !ignoreDigits && isDigits || !ignoreURLS
+                                                               && isURL
+                                                               || !(isMixed || isUpper || isDigits || isURL))
+                                                       fireEvent(new SpellEvent(this, word, iterator
+                                                                       .getBegin(), iterator.getEnd(), starts,
+                                                                       false));
 
                                        } else {
 
-                                               if (!ignoreSentence && starts && Character.isLowerCase(word.charAt(0)))
-                                                       fireEvent(new SpellEvent(this, word, iterator.getBegin(), iterator.getEnd(), true, true));
+                                               if (!ignoreSentence && starts
+                                                               && Character.isLowerCase(word.charAt(0)))
+                                                       fireEvent(new SpellEvent(this, word, iterator
+                                                                       .getBegin(), iterator.getEnd(), true, true));
                                        }
                                }
                        }
@@ -264,16 +280,16 @@ public class DefaultSpellChecker implements ISpellChecker {
         * Fires the specified event.
         * 
         * @param event
-        *                   Event to fire
+        *            Event to fire
         */
        protected final void fireEvent(final ISpellEvent event) {
                // synchronizing is necessary as this is called from execute
                Set copy;
                synchronized (fListeners) {
-                       copy= new HashSet(fListeners);
+                       copy = new HashSet(fListeners);
                }
-               for (final Iterator iterator= copy.iterator(); iterator.hasNext();) {
-                       ((ISpellEventListener)iterator.next()).handle(event);
+               for (final Iterator iterator = copy.iterator(); iterator.hasNext();) {
+                       ((ISpellEventListener) iterator.next()).handle(event);
                }
        }
 
@@ -281,21 +297,21 @@ public class DefaultSpellChecker implements ISpellChecker {
         * @see org.eclipse.spelling.done.ISpellChecker#getProposals(java.lang.String,boolean)
         */
        public Set getProposals(final String word, final boolean sentence) {
-               
-               // synchronizing might not be needed here since getProposals is 
+
+               // synchronizing might not be needed here since getProposals is
                // a read-only access and only called in the same thread as
                // the modifing methods add/removeDictionary (?)
                Set copy;
                synchronized (fDictionaries) {
-                       copy= new HashSet(fDictionaries);
+                       copy = new HashSet(fDictionaries);
                }
 
-               ISpellDictionary dictionary= null;
-               final HashSet proposals= new HashSet();
+               ISpellDictionary dictionary = null;
+               final HashSet proposals = new HashSet();
 
-               for (final Iterator iterator= copy.iterator(); iterator.hasNext();) {
+               for (final Iterator iterator = copy.iterator(); iterator.hasNext();) {
 
-                       dictionary= (ISpellDictionary)iterator.next();
+                       dictionary = (ISpellDictionary) iterator.next();
                        proposals.addAll(dictionary.getProposals(word, sentence));
                }
                return proposals;
@@ -316,16 +332,16 @@ public class DefaultSpellChecker implements ISpellChecker {
                // synchronizing is necessary as this is called from execute
                Set copy;
                synchronized (fDictionaries) {
-                       copy= new HashSet(fDictionaries);
+                       copy = new HashSet(fDictionaries);
                }
 
                if (fIgnored.contains(word.toLowerCase()))
                        return true;
 
-               ISpellDictionary dictionary= null;
-               for (final Iterator iterator= copy.iterator(); iterator.hasNext();) {
+               ISpellDictionary dictionary = null;
+               for (final Iterator iterator = copy.iterator(); iterator.hasNext();) {
 
-                       dictionary= (ISpellDictionary)iterator.next();
+                       dictionary = (ISpellDictionary) iterator.next();
                        if (dictionary.isCorrect(word))
                                return true;
                }