Partially fixed highlight bug for php block in html comment.
authormusk <musk>
Tue, 1 Apr 2003 18:53:19 +0000 (18:53 +0000)
committermusk <musk>
Tue, 1 Apr 2003 18:53:19 +0000 (18:53 +0000)
Added defaultcontenttype to legal types as intermediate partition.
Added DEBUG Flag to partitionscanner.
PARTITIONBORDER Bug still exists! Problem probably lies in DefaultPartitioner

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

index fbc20df..6ce08f4 100644 (file)
@@ -52,7 +52,7 @@ import org.eclipse.swt.graphics.RGB;
  */
 public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
 
-  public static final String HTML_DEFAULT = IDocument.DEFAULT_CONTENT_TYPE;
+  public static final String HTML_DEFAULT = IPHPPartitionScannerConstants.HTML; //IDocument.DEFAULT_CONTENT_TYPE;
   
   private PHPEditor fEditor;
   
@@ -147,7 +147,7 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
 public String[] getConfiguredContentTypes(ISourceViewer sourceViewer)
 {
     return new String[] {
-        IDocument.DEFAULT_CONTENT_TYPE,
+       IDocument.DEFAULT_CONTENT_TYPE,
         IPHPPartitionScannerConstants.PHP,
         IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT,
         IPHPPartitionScannerConstants.HTML,
@@ -262,7 +262,7 @@ public String[] getConfiguredContentTypes(ISourceViewer sourceViewer)
 //    reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
 //    reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
 
-    dr = new DefaultDamagerRepairer(PHPEditorEnvironment.getPHPCodeScanner());
+       dr = new DefaultDamagerRepairer(PHPEditorEnvironment.getPHPCodeScanner());
     reconciler.setDamager(dr, IPHPPartitionScannerConstants.PHP);
     reconciler.setRepairer(dr, IPHPPartitionScannerConstants.PHP);
 
index 8e2485d..92badac 100644 (file)
@@ -6,7 +6,7 @@
  * Created on 05.03.2003
  *
  * @author Stefan Langer (musk)
- * @version $Revision: 1.10 $
+ * @version $Revision: 1.11 $
  */
 package net.sourceforge.phpeclipse.phpeditor.php;
 
@@ -20,23 +20,16 @@ import org.eclipse.jface.text.rules.*;
  */
 public class PHPPartitionScanner implements IPartitionTokenScanner
 {
-//    private final int HTML = 0;
-//    private final int PHP = 1;
-//    private final int JS = 2;
-//    private final int CSS = 4;
-//    private final int COMMENT = 5;
-//    private final int HTMLCOMMENT = 6;
-
+    private static final boolean DEBUG = false;
     private IDocument fDocument = null;
     private int fOffset = -1;
-//    private int fLastOffset = -1;
     private String fContentType = IPHPPartitionScannerConstants.HTML;
-       
-       private boolean partitionBorder = false;
+    private String fPrevContentType;
+
+    private boolean partitionBorder = false;
     private int fTokenOffset;
     private int fEnd = -1;
     private int fLength;
-    //private int fState = HTML;
     private Map tokens = new HashMap();
 
     public PHPPartitionScanner()
@@ -53,35 +46,58 @@ public class PHPPartitionScanner implements IPartitionTokenScanner
         this.tokens.put(
             IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT,
             new Token(IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT));
+        this.tokens.put(
+            IDocument.DEFAULT_CONTENT_TYPE,
+            new Token(IDocument.DEFAULT_CONTENT_TYPE));
     }
 
     private IToken getToken(String type)
     {
-        fLength = fOffset-fTokenOffset;
-               IToken token = (IToken)this.tokens.get(type);
-               Assert.isNotNull(token, "Token for type \"" + type + "\" not found!");
-               return token;
+        fLength = fOffset - fTokenOffset;
+        IToken token = (IToken) this.tokens.get(type);
+        Assert.isNotNull(token, "Token for type \"" + type + "\" not found!");
+        if (DEBUG)
+        {
+            System.out.println(
+                "Partition: fTokenOffset="
+                    + fTokenOffset
+                    + " fContentType="
+                    + fContentType
+                    + " fLength="
+                    + fLength);
+        }
+        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(
-    IDocument document,
-    int offset,
-    int length,
-    String contentType,
-    int partitionOffset)
-{
-       this.setRange(document, offset, length);
-       if(this.tokens.containsKey(contentType))
-               fContentType = contentType;
-    if (partitionOffset > -1)
+    /* (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)
     {
-       partitionBorder = false;
-        fTokenOffset = partitionOffset;
+        this.setRange(document, offset, length);
+        if (DEBUG)
+        {
+            System.out.println(
+                "PartialRange: contentType="
+                    + contentType
+                    + " partitionOffset="
+                    + partitionOffset);
+        }
+
+        if (this.tokens.containsKey(contentType))
+            fContentType = contentType;
+        // TODO Calculate previouse contenttype
+        if (partitionOffset > -1)
+        {
+            partitionBorder = false;
+            fTokenOffset = partitionOffset;
+        }
     }
-}
 
     /* (non-Javadoc)
      * @see org.eclipse.jface.text.rules.ITokenScanner#getTokenLength()
@@ -95,8 +111,8 @@ public void setPartialRange(
      * @see org.eclipse.jface.text.rules.ITokenScanner#getTokenOffset()
      */
     public int getTokenOffset()
-    {  
-       return fTokenOffset;
+    {
+        return fTokenOffset;
     }
 
     /* (non-Javadoc)
@@ -127,14 +143,18 @@ public void setPartialRange(
             switch (c)
             {
                 case '<' :
-                    if (fContentType != IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT && checkPattern(new char[] { '?', 'p', 'h', 'p' }, true))
+                    if (fContentType
+                        != IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT
+                        && checkPattern(new char[] { '?', 'p', 'h', 'p' }, true))
                     {
-
-                        if (fContentType != IPHPPartitionScannerConstants.PHP
+                                               if (fContentType != IPHPPartitionScannerConstants.PHP
                             && fOffset - 5 > 0)
                         {
                             fOffset -= 5;
                             IToken token = getToken(fContentType);
+                            // save previouse contenttype
+                                                       fPrevContentType = fContentType;
+                     
                             fContentType = IPHPPartitionScannerConstants.PHP;
 
                             return token;
@@ -155,6 +175,7 @@ public void setPartialRange(
                         {
                             fOffset -= 4;
                             IToken token = getToken(fContentType);
+
                             fContentType =
                                 IPHPPartitionScannerConstants
                                     .HTML_MULTILINE_COMMENT;
@@ -172,12 +193,15 @@ public void setPartialRange(
                     if (fContentType == IPHPPartitionScannerConstants.PHP)
                     {
                         if ((c = read()) == '>')
-                        {
-                            fContentType = IPHPPartitionScannerConstants.HTML;
+                        {      // 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)
+                        else if (c != ICharacterScanner.EOF)
                             unread();
                     }
                     break;
@@ -194,13 +218,14 @@ public void setPartialRange(
                     }
                     break;
                 case '/' :
-                    if ((c=read()) == '*')
+                    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;
@@ -217,7 +242,7 @@ public void setPartialRange(
                         }
 
                     }
-                    else if(c != ICharacterScanner.EOF)
+                    else if (c != ICharacterScanner.EOF)
                         unread();
                     break;
                 case '*' :
@@ -229,6 +254,7 @@ public void setPartialRange(
                         {
                             fContentType = IPHPPartitionScannerConstants.PHP;
                             partitionBorder = true;
+
                             return getToken(
                                 IPHPPartitionScannerConstants
                                     .PHP_MULTILINE_COMMENT);
@@ -246,7 +272,7 @@ public void setPartialRange(
                         {
                         }
                     }
-                    else if(c != ICharacterScanner.EOF)
+                    else if (c != ICharacterScanner.EOF)
                         unread();
                     break;
             }
@@ -261,23 +287,29 @@ public void setPartialRange(
      */
     public void setRange(IDocument document, int offset, int length)
     {
+        if (DEBUG)
+        {
+            System.out.println(
+                "SET RANGE: offset=" + offset + " length=" + length);
+        }
+
         fDocument = document;
         fOffset = offset;
         fTokenOffset = offset;
-        fLength = 0;    
+        fLength = 0;
         fEnd = fOffset + length;
-               //partitionBorder = false;
+        //partitionBorder = false;
     }
 
     private int read()
     {
         try
         {
-                       if (fOffset < fEnd)
+            if (fOffset < fEnd)
             {
-                               return fDocument.getChar(fOffset++);
+                return fDocument.getChar(fOffset++);
             }
-                       return ICharacterScanner.EOF;
+            return ICharacterScanner.EOF;
         }
         catch (BadLocationException e)
         {
@@ -308,31 +340,38 @@ public void setPartialRange(
      */
     private boolean checkPattern(char[] pattern, boolean ignoreCase)
     {
-       int prevOffset = fOffset;
+        int prevOffset = fOffset;
         for (int i = 0; i < pattern.length; i++)
         {
             int c = read();
-                       
-                       if(c == ICharacterScanner.EOF || !letterEquals(c, pattern[i], ignoreCase))
+
+            if (c == ICharacterScanner.EOF
+                || !letterEquals(c, pattern[i], ignoreCase))
             {
-               fOffset = prevOffset;
+                fOffset = prevOffset;
                 return false;
             }
         }
 
         return true;
     }
-    
+
     private boolean letterEquals(int test, char letter, boolean ignoreCase)
     {
-       if(test == letter)
-               return true;
-       else if(ignoreCase && Character.isLowerCase(letter) && test == Character.toUpperCase(letter))
-               return true;
-       else if(ignoreCase && Character.isUpperCase(letter) && test == Character.toLowerCase(letter))
-               return true;
-       
-       return false;
+        if (test == letter)
+            return true;
+        else if (
+            ignoreCase
+                && Character.isLowerCase(letter)
+                && test == Character.toUpperCase(letter))
+            return true;
+        else if (
+            ignoreCase
+                && Character.isUpperCase(letter)
+                && test == Character.toLowerCase(letter))
+            return true;
+
+        return false;
     }
-    
+
 }