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 / SpellCheckIterator.java
index f420cd7..022cabf 100644 (file)
@@ -30,7 +30,8 @@ import org.eclipse.jface.text.TextUtilities;
  * 
  * @since 3.0
  */
-public class SpellCheckIterator implements ISpellCheckIterator, IJavaDocTagConstants, IHtmlTagConstants {
+public class SpellCheckIterator implements ISpellCheckIterator,
+               IJavaDocTagConstants, IHtmlTagConstants {
 
        /** The content of the region */
        private final String fContent;
@@ -39,10 +40,10 @@ public class SpellCheckIterator implements ISpellCheckIterator, IJavaDocTagConst
        private final String fDelimiter;
 
        /** The last token */
-       private String fLastToken= null;
+       private String fLastToken = null;
 
        /** The next break */
-       private int fNext= 1;
+       private int fNext = 1;
 
        /** The offset of the region */
        private final int fOffset;
@@ -51,13 +52,13 @@ public class SpellCheckIterator implements ISpellCheckIterator, IJavaDocTagConst
        private int fPredecessor;
 
        /** The previous break */
-       private int fPrevious= 0;
+       private int fPrevious = 0;
 
        /** The sentence breaks */
-       private final LinkedList fSentenceBreaks= new LinkedList();
+       private final LinkedList fSentenceBreaks = new LinkedList();
 
        /** Does the current word start a sentence? */
-       private boolean fStartsSentence= false;
+       private boolean fStartsSentence = false;
 
        /** The successor break */
        private int fSuccessor;
@@ -69,42 +70,44 @@ public class SpellCheckIterator implements ISpellCheckIterator, IJavaDocTagConst
         * Creates a new spell check iterator.
         * 
         * @param document
-        *                   The document containing the specified partition
+        *            The document containing the specified partition
         * @param region
-        *                   The region to spell-check
+        *            The region to spell-check
         * @param locale
-        *                   The locale to use for spell-checking
+        *            The locale to use for spell-checking
         */
-       public SpellCheckIterator(final IDocument document, final IRegion region, final Locale locale) {
+       public SpellCheckIterator(final IDocument document, final IRegion region,
+                       final Locale locale) {
 
-               fOffset= region.getOffset();
-               fWordIterator= BreakIterator.getWordInstance(locale);
-               fDelimiter= TextUtilities.getDefaultLineDelimiter(document);
+               fOffset = region.getOffset();
+               fWordIterator = BreakIterator.getWordInstance(locale);
+               fDelimiter = TextUtilities.getDefaultLineDelimiter(document);
 
                String content;
                try {
 
-                       content= document.get(region.getOffset(), region.getLength());
+                       content = document.get(region.getOffset(), region.getLength());
                        if (content.startsWith(NLSElement.TAG_PREFIX))
-                               content= ""; //$NON-NLS-1$
+                               content = ""; //$NON-NLS-1$
 
                } catch (Exception exception) {
-                       content= ""; //$NON-NLS-1$
+                       content = ""; //$NON-NLS-1$
                }
-               fContent= content;
+               fContent = content;
 
                fWordIterator.setText(content);
-               fPredecessor= fWordIterator.first();
-               fSuccessor= fWordIterator.next();
+               fPredecessor = fWordIterator.first();
+               fSuccessor = fWordIterator.next();
 
-               final BreakIterator iterator= BreakIterator.getSentenceInstance(locale);
+               final BreakIterator iterator = BreakIterator
+                               .getSentenceInstance(locale);
                iterator.setText(content);
 
-               int offset= iterator.current();
+               int offset = iterator.current();
                while (offset != BreakIterator.DONE) {
 
                        fSentenceBreaks.add(new Integer(offset));
-                       offset= iterator.next();
+                       offset = iterator.next();
                }
        }
 
@@ -133,22 +136,22 @@ public class SpellCheckIterator implements ISpellCheckIterator, IJavaDocTagConst
         * Does the specified token consist of at least one letter and digits only?
         * 
         * @param begin
-        *                   The begin index
+        *            The begin index
         * @param end
-        *                   The end index
-        * @return <code>true</code> iff the token consists of digits and at
-        *               least one letter only, <code>false</code> otherwise
+        *            The end index
+        * @return <code>true</code> iff the token consists of digits and at least
+        *         one letter only, <code>false</code> otherwise
         */
        protected final boolean isAlphaNumeric(final int begin, final int end) {
 
-               char character= 0;
+               char character = 0;
 
-               boolean letter= false;
-               for (int index= begin; index < end; index++) {
+               boolean letter = false;
+               for (int index = begin; index < end; index++) {
 
-                       character= fContent.charAt(index);
+                       character = fContent.charAt(index);
                        if (Character.isLetter(character))
-                               letter= true;
+                               letter = true;
 
                        if (!Character.isLetterOrDigit(character))
                                return false;
@@ -160,15 +163,15 @@ public class SpellCheckIterator implements ISpellCheckIterator, IJavaDocTagConst
         * Was the last token a Javadoc tag tag?
         * 
         * @param tags
-        *                   The javadoc tags to check
-        * @return <code>true</code> iff the last token was a Javadoc tag, <code>false</code>
-        *               otherwise
+        *            The javadoc tags to check
+        * @return <code>true</code> iff the last token was a Javadoc tag,
+        *         <code>false</code> otherwise
         */
        protected final boolean isJavadocToken(final String[] tags) {
 
                if (fLastToken != null) {
 
-                       for (int index= 0; index < tags.length; index++) {
+                       for (int index = 0; index < tags.length; index++) {
 
                                if (fLastToken.equals(tags[index]))
                                        return true;
@@ -182,14 +185,16 @@ public class SpellCheckIterator implements ISpellCheckIterator, IJavaDocTagConst
         * characters?
         * 
         * @param begin
-        *                   The begin index
+        *            The begin index
         * @return <code>true</code> iff the token is a single letter token,
-        *               <code>false</code> otherwise
+        *         <code>false</code> otherwise
         */
        protected final boolean isSingleLetter(final int begin) {
 
                if (begin > 0 && begin < fContent.length() - 1)
-                       return Character.isWhitespace(fContent.charAt(begin - 1)) && Character.isLetter(fContent.charAt(begin)) && Character.isWhitespace(fContent.charAt(begin + 1));
+                       return Character.isWhitespace(fContent.charAt(begin - 1))
+                                       && Character.isLetter(fContent.charAt(begin))
+                                       && Character.isWhitespace(fContent.charAt(begin + 1));
 
                return false;
        }
@@ -198,15 +203,16 @@ public class SpellCheckIterator implements ISpellCheckIterator, IJavaDocTagConst
         * Does the specified token look like an URL?
         * 
         * @param begin
-        *                   The begin index
-        * @return <code>true</code> iff this token look like an URL, <code>false</code>
-        *               otherwise
+        *            The begin index
+        * @return <code>true</code> iff this token look like an URL,
+        *         <code>false</code> otherwise
         */
        protected final boolean isUrlToken(final int begin) {
 
-               for (int index= 0; index < DefaultSpellChecker.URL_PREFIXES.length; index++) {
+               for (int index = 0; index < DefaultSpellChecker.URL_PREFIXES.length; index++) {
 
-                       if (fContent.startsWith(DefaultSpellChecker.URL_PREFIXES[index], begin))
+                       if (fContent.startsWith(DefaultSpellChecker.URL_PREFIXES[index],
+                                       begin))
                                return true;
                }
                return false;
@@ -216,15 +222,15 @@ public class SpellCheckIterator implements ISpellCheckIterator, IJavaDocTagConst
         * Does the specified token consist of whitespace only?
         * 
         * @param begin
-        *                   The begin index
+        *            The begin index
         * @param end
-        *                   The end index
+        *            The end index
         * @return <code>true</code> iff the token consists of whitespace only,
-        *               <code>false</code> otherwise
+        *         <code>false</code> otherwise
         */
        protected final boolean isWhitespace(final int begin, final int end) {
 
-               for (int index= begin; index < end; index++) {
+               for (int index = begin; index < end; index++) {
 
                        if (!Character.isWhitespace(fContent.charAt(index)))
                                return false;
@@ -237,11 +243,11 @@ public class SpellCheckIterator implements ISpellCheckIterator, IJavaDocTagConst
         */
        public final Object next() {
 
-               String token= nextToken();
+               String token = nextToken();
                while (token == null && fSuccessor != BreakIterator.DONE)
-                       token= nextToken();
+                       token = nextToken();
 
-               fLastToken= token;
+               fLastToken = token;
 
                return token;
        }
@@ -251,10 +257,10 @@ public class SpellCheckIterator implements ISpellCheckIterator, IJavaDocTagConst
         */
        protected final void nextBreak() {
 
-               fNext= fSuccessor;
-               fPredecessor= fSuccessor;
+               fNext = fSuccessor;
+               fPredecessor = fSuccessor;
 
-               fSuccessor= fWordIterator.next();
+               fSuccessor = fWordIterator.next();
        }
 
        /**
@@ -270,57 +276,63 @@ public class SpellCheckIterator implements ISpellCheckIterator, IJavaDocTagConst
         * Determines the next token to be spell-checked.
         * 
         * @return The next token to be spell-checked, or <code>null</code> iff
-        *               the next token is not a candidate for spell-checking.
+        *         the next token is not a candidate for spell-checking.
         */
        protected String nextToken() {
 
-               String token= null;
+               String token = null;
 
-               fPrevious= fPredecessor;
-               fStartsSentence= false;
+               fPrevious = fPredecessor;
+               fStartsSentence = false;
 
                nextBreak();
 
-               boolean update= false;
+               boolean update = false;
                if (fNext - fPrevious > 0) {
 
-                       if (fSuccessor != BreakIterator.DONE && fContent.charAt(fPrevious) == JAVADOC_TAG_PREFIX) {
+                       if (fSuccessor != BreakIterator.DONE
+                                       && fContent.charAt(fPrevious) == JAVADOC_TAG_PREFIX) {
 
                                nextBreak();
                                if (Character.isLetter(fContent.charAt(fPrevious + 1))) {
-                                       update= true;
-                                       token= fContent.substring(fPrevious, fNext);
+                                       update = true;
+                                       token = fContent.substring(fPrevious, fNext);
                                } else
-                                       fPredecessor= fNext;
+                                       fPredecessor = fNext;
 
-                       } else if (fSuccessor != BreakIterator.DONE && fContent.charAt(fPrevious) == HTML_TAG_PREFIX && (Character.isLetter(fContent.charAt(fNext)) || fContent.charAt(fNext) == '/')) {
+                       } else if (fSuccessor != BreakIterator.DONE
+                                       && fContent.charAt(fPrevious) == HTML_TAG_PREFIX
+                                       && (Character.isLetter(fContent.charAt(fNext)) || fContent
+                                                       .charAt(fNext) == '/')) {
 
                                if (fContent.startsWith(HTML_CLOSE_PREFIX, fPrevious))
                                        nextBreak();
 
                                nextBreak();
 
-                               if (fSuccessor != BreakIterator.DONE && fContent.charAt(fNext) == HTML_TAG_POSTFIX) {
+                               if (fSuccessor != BreakIterator.DONE
+                                               && fContent.charAt(fNext) == HTML_TAG_POSTFIX) {
 
                                        nextBreak();
                                        if (fSuccessor != BreakIterator.DONE) {
-                                               update= true;
-                                               token= fContent.substring(fPrevious, fNext);
+                                               update = true;
+                                               token = fContent.substring(fPrevious, fNext);
                                        }
                                }
-                       } else if (!isWhitespace(fPrevious, fNext) && isAlphaNumeric(fPrevious, fNext)) {
+                       } else if (!isWhitespace(fPrevious, fNext)
+                                       && isAlphaNumeric(fPrevious, fNext)) {
 
                                if (isUrlToken(fPrevious))
                                        skipTokens(fPrevious, ' ');
                                else if (isJavadocToken(JAVADOC_PARAM_TAGS))
-                                       fLastToken= null;
+                                       fLastToken = null;
                                else if (isJavadocToken(JAVADOC_REFERENCE_TAGS)) {
-                                       fLastToken= null;
+                                       fLastToken = null;
                                        skipTokens(fPrevious, fDelimiter.charAt(0));
                                } else if (fNext - fPrevious > 1 || isSingleLetter(fPrevious))
-                                       token= fContent.substring(fPrevious, fNext);
+                                       token = fContent.substring(fPrevious, fNext);
 
-                               update= true;
+                               update = true;
                        }
                }
 
@@ -328,10 +340,11 @@ public class SpellCheckIterator implements ISpellCheckIterator, IJavaDocTagConst
 
                        if (fPrevious >= nextSentence()) {
 
-                               while (fSentenceBreaks.size() > 0 && fPrevious >= nextSentence())
+                               while (fSentenceBreaks.size() > 0
+                                               && fPrevious >= nextSentence())
                                        fSentenceBreaks.removeFirst();
 
-                               fStartsSentence= (fLastToken == null) || (token != null);
+                               fStartsSentence = (fLastToken == null) || (token != null);
                        }
                }
                return token;
@@ -348,25 +361,25 @@ public class SpellCheckIterator implements ISpellCheckIterator, IJavaDocTagConst
         * Skip the tokens until the stop character is reached.
         * 
         * @param begin
-        *                   The begin index
+        *            The begin index
         * @param stop
-        *                   The stop character
+        *            The stop character
         */
        protected final void skipTokens(final int begin, final char stop) {
 
-               int end= begin;
+               int end = begin;
 
                while (end < fContent.length() && fContent.charAt(end) != stop)
                        end++;
 
                if (end < fContent.length()) {
 
-                       fNext= end;
-                       fPredecessor= fNext;
+                       fNext = end;
+                       fPredecessor = fNext;
 
-                       fSuccessor= fWordIterator.following(fNext);
+                       fSuccessor = fWordIterator.following(fNext);
                } else
-                       fSuccessor= BreakIterator.DONE;
+                       fSuccessor = BreakIterator.DONE;
        }
 
        /*