Fixed bug passing default partition type to scanner when entering
authormusk <musk>
Sun, 6 Apr 2003 20:27:17 +0000 (20:27 +0000)
committermusk <musk>
Sun, 6 Apr 2003 20:27:17 +0000 (20:27 +0000)
text in a line with a partition delimiter

net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java

index f571e39..1d502f3 100644 (file)
@@ -6,7 +6,7 @@
  * Created on 05.03.2003
  *
  * @author Stefan Langer (musk)
- * @version $Revision: 1.13 $
+ * @version $Revision: 1.14 $
  */
 package net.sourceforge.phpeclipse.phpeditor.php;
 
@@ -65,32 +65,46 @@ public class PHPPartitionScanner implements IPartitionTokenScanner {
     return token;
   }
 
-  /* (non-Javadoc)
-   * @see org.eclipse.jface.text.rules.IPartitionTokenScanner#setPartialRange(org.eclipse.jface.text.IDocument, int, int, java.lang.String, int)
-   */
-  public void setPartialRange(
+/* (non-Javadoc)
+ * @see org.eclipse.jface.text.rules.IPartitionTokenScanner#setPartialRange(org.eclipse.jface.text.IDocument, int, int, java.lang.String, int)
+ */
+public void setPartialRange(
     IDocument document,
     int offset,
     int length,
     String contentType,
-    int partitionOffset) {
+    int partitionOffset)
+{
     this.setRange(document, offset, length);
-    if (DEBUG) {
-      System.out.println(
-        "PartialRange: contentType="
-          + contentType
-          + " partitionOffset="
-          + partitionOffset);
+    if (DEBUG)
+    {
+        System.out.println(
+            "PartialRange: contentType="
+                + contentType
+                + " partitionOffset="
+                + partitionOffset);
     }
-
-    if (this.tokens.containsKey(contentType))
-      fContentType = contentType;
+       
+       if(offset == partitionOffset)
+       {
+               try
+        {
+            fContentType = fDocument.getContentType(offset);
+        }
+        catch (BadLocationException e)
+        {
+            //should never happen
+        }
+       }
+    else if (this.tokens.containsKey(contentType))
+        fContentType = contentType;
     // TODO Calculate previouse contenttype
-    if (partitionOffset > -1) {
-      partitionBorder = false;
-      fTokenOffset = partitionOffset;
+    if (partitionOffset > -1)
+    {
+        partitionBorder = false;
+        fTokenOffset = partitionOffset;
     }
-  }
+}
 
   /* (non-Javadoc)
    * @see org.eclipse.jface.text.rules.ITokenScanner#getTokenLength()
@@ -106,154 +120,183 @@ public class PHPPartitionScanner implements IPartitionTokenScanner {
     return fTokenOffset;
   }
 
-  /* (non-Javadoc)
-   * @see org.eclipse.jface.text.rules.ITokenScanner#nextToken()
-   */
-  public IToken nextToken() {
+/* (non-Javadoc)
+ * @see org.eclipse.jface.text.rules.ITokenScanner#nextToken()
+ */
+public IToken nextToken()
+{
     int c;
 
     // check if we are not allready at the end of the
     // file
-    if ((c = read()) == ICharacterScanner.EOF) {
-      partitionBorder = false;
-      return Token.EOF;
-    } else
-      unread();
-
-    if (partitionBorder) {
-      fTokenOffset = fOffset;
-      partitionBorder = false;
+    if ((c = read()) == ICharacterScanner.EOF)
+    {
+        partitionBorder = false;
+        return Token.EOF;
     }
+    else
+        unread();
 
-    while ((c = read()) != ICharacterScanner.EOF) {
-      switch (c) {
-        case '<' :
-          if (fContentType
-            != IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT
-            && checkPattern(new char[] { '?', 'p', 'h', 'p' }, true)) {
-            if (fContentType != IPHPPartitionScannerConstants.PHP
-              && fOffset - 5 > 0) {
-              fOffset -= 5;
-              IToken token = getToken(fContentType);
-              // save previouse contenttype
-              fPrevContentType = fContentType;
-
-              fContentType = IPHPPartitionScannerConstants.PHP;
-
-              return token;
-            } else
-              fContentType = IPHPPartitionScannerConstants.PHP;
-
-            // remember offset of this partition
-            fTokenOffset = fOffset - 5;
-          } else if (fContentType != IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT
-              && (checkPattern(new char[] { '?', ' ' }, false)
-                || checkPattern(new char[] { '?', '\r' }, false)
-                || checkPattern(new char[] { '?', '\n' }, false))) {
-            if (fContentType != IPHPPartitionScannerConstants.PHP
-              && fOffset - 3 > 0) {
-              fOffset -= 3;
-              IToken token = getToken(fContentType);
-              // save previouse contenttype
-              fPrevContentType = fContentType;
-
-              fContentType = IPHPPartitionScannerConstants.PHP;
-
-              return token;
-            } else
-              fContentType = IPHPPartitionScannerConstants.PHP;
-
-            // remember offset of this partition
-            fTokenOffset = fOffset - 3;
-          } else if (checkPattern(new char[] { '!', '-', '-' })) {
-            // return previouse partition
-            if (fContentType
-              != IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT
-              && fOffset - 4 > 0) {
-              fOffset -= 4;
-              IToken token = getToken(fContentType);
-
-              fContentType =
-                IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT;
-              return token;
-            } else
-              fContentType =
-                IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT;
-
-            fTokenOffset = fOffset - 4;
-          }
-          break;
-        case '?' :
-          if (fContentType == IPHPPartitionScannerConstants.PHP) {
-            if ((c = read()) == '>') {
-              // TODO Actually calculate the previouse contenttype from the document
-              if (fPrevContentType != null)
-                fContentType = fPrevContentType;
-              else
-                fContentType = IPHPPartitionScannerConstants.HTML;
-              partitionBorder = true;
-              return getToken(IPHPPartitionScannerConstants.PHP);
-            } else if (c != ICharacterScanner.EOF)
-              unread();
-          }
-          break;
-        case '-' :
-          if (fContentType
-            == IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT
-            && checkPattern(new char[] { '-', '>' })) {
-            fContentType = IPHPPartitionScannerConstants.HTML;
-            partitionBorder = true;
-            return getToken(
-              IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT);
-          }
-          break;
-        case '/' :
-          if ((c = read()) == '*') { // MULTINE COMMENT JAVASCRIPT, CSS, PHP
-            if (fContentType == IPHPPartitionScannerConstants.PHP
-              && fOffset - 2 > 0) {
-              fOffset -= 2;
-              IToken token = getToken(fContentType);
-
-              fContentType =
-                IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT;
-
-              return token;
-            } else if (
-              fContentType
-                == IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT) {
-
-              fTokenOffset = fOffset - 2;
-            }
-
-          } else if (c != ICharacterScanner.EOF)
-            unread();
-          break;
-        case '*' :
-          if ((c = read()) == '/') {
-            if (fContentType
-              == IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT) {
-              fContentType = IPHPPartitionScannerConstants.PHP;
-              partitionBorder = true;
-
-              return getToken(
-                IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT);
-            } else if (
-              fContentType
-                == IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT) {
-            } else if (
-              fContentType
-                == IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT) {
-            }
-          } else if (c != ICharacterScanner.EOF)
-            unread();
-          break;
-      }
+    if (partitionBorder)
+    {
+        fTokenOffset = fOffset;
+        partitionBorder = false;
     }
 
-    // end of file reached but we have to return the
+    while ((c = read()) != ICharacterScanner.EOF)
+    {
+        switch (c)
+        {
+            case '<' :
+                if (fContentType
+                    != IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT
+                    && checkPattern(new char[] { '?', 'p', 'h', 'p' }, true))
+                {
+                    if (fContentType != IPHPPartitionScannerConstants.PHP
+                        && fOffset - 5 > 0)
+                    {
+                        fOffset -= 5;
+                        IToken token = getToken(fContentType);
+                        // save previouse contenttype
+                        fPrevContentType = fContentType;
+
+                        fContentType = IPHPPartitionScannerConstants.PHP;
+
+                        return token;
+                    }
+                    else
+                        fContentType = IPHPPartitionScannerConstants.PHP;
+
+                    // remember offset of this partition
+                    fTokenOffset = fOffset - 5;
+                }
+                else if (
+                    fContentType
+                        != IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT
+                    && checkPattern(new char[] { '?' }, false))
+                {
+                    if (fContentType != IPHPPartitionScannerConstants.PHP
+                        && fOffset - 2 > 0)
+                    {
+                        fOffset -= 2;
+                            IToken token = getToken(fContentType);
+                // save previouse contenttype
+                        fPrevContentType =
+                        fContentType;
+                            fContentType = IPHPPartitionScannerConstants.PHP;
+                            return token;
+                            }
+                    else
+                        fContentType = IPHPPartitionScannerConstants.PHP;
+            // remember offset of this partition
+                        fTokenOffset =
+                    fOffset - 3;
+                            }
+                else if (checkPattern(new char[] { '!', '-', '-' }))
+                { // return previouse partition
+                if (
+                    fContentType
+                        != IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT
+                    && fOffset - 4 > 0)
+                    {
+                        fOffset -= 4;
+                            IToken token = getToken(fContentType);
+                            fContentType =
+                                IPHPPartitionScannerConstants
+                                    .HTML_MULTILINE_COMMENT;
+                            return token;
+                            }
+                    else
+                        fContentType =
+                            IPHPPartitionScannerConstants
+                                .HTML_MULTILINE_COMMENT;
+                            fTokenOffset = fOffset - 4;
+                            }
+                break; case '?' :
+                if (fContentType == IPHPPartitionScannerConstants.PHP)
+                {
+                    if ((c = read()) == '>')
+                    { // TODO Actually calculate the previouse contenttype from the document
+                    if (
+                        fPrevContentType
+                        != null)
+                            fContentType = fPrevContentType; else
+                                fContentType =
+                                    IPHPPartitionScannerConstants.HTML;
+                                    partitionBorder = true;
+                                    return getToken(
+                                        IPHPPartitionScannerConstants.PHP);
+                                    }
+                    else if (c != ICharacterScanner.EOF)
+                        unread(); }
+                break; case '-' :
+                if (fContentType
+                    == IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT
+                    && checkPattern(new char[] { '-', '>' }))
+                {
+                    fContentType = IPHPPartitionScannerConstants.HTML;
+                        partitionBorder = true;
+                        return getToken(
+                            IPHPPartitionScannerConstants
+                                .HTML_MULTILINE_COMMENT);
+                        }
+                break; case '/' :
+                if ((c = read()) == '*')
+                { // MULTINE COMMENT JAVASCRIPT, CSS, PHP
+                if (
+                    fContentType == IPHPPartitionScannerConstants.PHP
+                    && fOffset - 2 > 0)
+                    {
+                        fOffset -= 2;
+                            IToken token = getToken(fContentType);
+                            fContentType =
+                                IPHPPartitionScannerConstants
+                                    .PHP_MULTILINE_COMMENT;
+                            return token;
+                            }
+                    else if (
+                        fContentType
+                            == IPHPPartitionScannerConstants
+                                .PHP_MULTILINE_COMMENT)
+                    {
+
+                        fTokenOffset = fOffset - 2; }
+
+                }
+                else if (c != ICharacterScanner.EOF)
+                    unread(); break; case '*' :
+                        if ((c = read()) == '/')
+                        {
+                            if (fContentType
+                                == IPHPPartitionScannerConstants
+                                    .PHP_MULTILINE_COMMENT)
+                            {
+                                fContentType =
+                                    IPHPPartitionScannerConstants.PHP;
+                                    partitionBorder = true;
+                                    return getToken(
+                                        IPHPPartitionScannerConstants
+                                            .PHP_MULTILINE_COMMENT);
+                                    }
+                            else if (
+                                fContentType
+                                    == IPHPPartitionScannerConstants
+                                        .CSS_MULTILINE_COMMENT)
+                            {
+                            }
+                            else if (
+                                fContentType
+                                    == IPHPPartitionScannerConstants
+                                        .JS_MULTILINE_COMMENT)
+                            {
+                            }
+                        }
+                        else if (c != ICharacterScanner.EOF)
+                            unread(); break; }
+    } // end of file reached but we have to return the
     // last partition.
     return getToken(fContentType);
-  }
+        }
   /* (non-Javadoc)
    * @see org.eclipse.jface.text.rules.ITokenScanner#setRange(org.eclipse.jface.text.IDocument, int, int)
    */