1) Fixed calculation of the new indentation method of splitted strings.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / text / FastJavaPartitionScanner.java
index 559dc88..a4239ba 100644 (file)
@@ -12,7 +12,9 @@ package net.sourceforge.phpdt.internal.ui.text;
 
 import net.sourceforge.phpeclipse.ui.text.rules.AbstractPartitioner;
 
-import org.eclipse.jface.text.Assert;
+//incastrix
+//import org.eclipse.jface.text.Assert;
+import org.eclipse.core.runtime.Assert;
 import org.eclipse.jface.text.IDocument;
 import org.eclipse.jface.text.rules.ICharacterScanner;
 import org.eclipse.jface.text.rules.IPartitionTokenScanner;
@@ -23,7 +25,8 @@ import org.eclipse.jface.text.rules.Token;
  * This scanner recognizes the JavaDoc comments, Java multi line comments, Java
  * single line comments, Java strings.
  */
-public class FastJavaPartitionScanner implements IPartitionTokenScanner, IPHPPartitions {
+public class FastJavaPartitionScanner implements IPartitionTokenScanner,
+               IPHPPartitions {
 
        // states
        private static final int PHP = 0;
@@ -43,29 +46,40 @@ public class FastJavaPartitionScanner implements IPartitionTokenScanner, IPHPPar
        // beginning of prefixes and postfixes
        private static final int NONE = 0;
 
-       private static final int BACKSLASH = 1; // postfix for STRING_DQ and CHARACTER
+       private static final int BACKSLASH = 1; // postfix for STRING_DQ and
+                                                                                       // CHARACTER
 
-       private static final int SLASH = 2; // prefix for SINGLE_LINE or MULTI_LINE or
-                                                                                                                                                       // JAVADOC
+       private static final int SLASH = 2; // prefix for SINGLE_LINE or MULTI_LINE
+                                                                               // or
 
-       private static final int SLASH_STAR = 3; // prefix for MULTI_LINE_COMMENT or
-                                                                                                                                                                               // JAVADOC
+       // JAVADOC
 
-       private static final int SLASH_STAR_STAR = 4; // prefix for MULTI_LINE_COMMENT
-                                                                                                                                                                                               // or JAVADOC
+       private static final int SLASH_STAR = 3; // prefix for MULTI_LINE_COMMENT
+                                                                                               // or
+
+       // JAVADOC
+
+       private static final int SLASH_STAR_STAR = 4; // prefix for
+                                                                                                       // MULTI_LINE_COMMENT
+
+       // or JAVADOC
 
        private static final int STAR = 5; // postfix for MULTI_LINE_COMMENT or
-                                                                                                                                                       // JAVADOC
+
+       // JAVADOC
 
        private static final int CARRIAGE_RETURN = 6; // postfix for STRING_DQ,
-                                                                                                                                                                                               // CHARACTER and
-                                                                                                                                                                                               // SINGLE_LINE_COMMENT
+
+       // CHARACTER and
+       // SINGLE_LINE_COMMENT
 
        // private static final int HEREDOC = 7;
 
        /** The scanner. */
-       private final BufferedDocumentScanner fScanner = new BufferedDocumentScanner(1000); // faster
-                                                                                                                                                                                                                                                                                                                                                       // implementation
+       private final BufferedDocumentScanner fScanner = new BufferedDocumentScanner(
+                       1000); // faster
+
+       // implementation
 
        /** The offset of the last returned token. */
        private int fTokenOffset;
@@ -89,8 +103,10 @@ public class FastJavaPartitionScanner implements IPartitionTokenScanner, IPHPPar
 
        private int fJavaLength;
 
-       private final IToken[] fTokens = new IToken[] { new Token(null), new Token(PHP_SINGLELINE_COMMENT),
-                       new Token(PHP_MULTILINE_COMMENT), new Token(PHP_PHPDOC_COMMENT), new Token(PHP_STRING_DQ), new Token(PHP_STRING_SQ),
+       private final IToken[] fTokens = new IToken[] { new Token(null),
+                       new Token(PHP_SINGLELINE_COMMENT),
+                       new Token(PHP_MULTILINE_COMMENT), new Token(PHP_PHPDOC_COMMENT),
+                       new Token(PHP_STRING_DQ), new Token(PHP_STRING_SQ),
                        new Token(PHP_STRING_HEREDOC) };
 
        public FastJavaPartitionScanner(boolean emulate) {
@@ -108,7 +124,8 @@ public class FastJavaPartitionScanner implements IPartitionTokenScanner, IPHPPar
 
                // emulate JavaPartitionScanner
                if (fEmulate) {
-                       if (fJavaOffset != -1 && fTokenOffset + fTokenLength != fJavaOffset + fJavaLength) {
+                       if (fJavaOffset != -1
+                                       && fTokenOffset + fTokenLength != fJavaOffset + fJavaLength) {
                                fTokenOffset += fTokenLength;
                                return fTokens[PHP];
                        } else {
@@ -200,10 +217,11 @@ public class FastJavaPartitionScanner implements IPartitionTokenScanner, IPHPPar
                                                fScanner.unread();
                                                fScanner.unread();
                                                return postFix(fState);
-                                       }
-                                       else {
+                                       } else {
                                                // bug #1404228: Crash on <?php // comment ?>
-                                               fScanner.unread();
+                                               if (nextch != ICharacterScanner.EOF) {
+                                                       fScanner.unread();
+                                               }
                                        }
                                }
 
@@ -295,7 +313,8 @@ public class FastJavaPartitionScanner implements IPartitionTokenScanner, IPHPPar
                                case '*':
                                        if (fLast == SLASH) {
                                                if (fTokenLength - getLastLength(fLast) > 0)
-                                                       return preFix(PHP, MULTI_LINE_COMMENT, SLASH_STAR, 2);
+                                                       return preFix(PHP, MULTI_LINE_COMMENT, SLASH_STAR,
+                                                                       2);
                                                else {
                                                        preFix(PHP, MULTI_LINE_COMMENT, SLASH_STAR, 2);
                                                        fTokenOffset += fTokenLength;
@@ -496,9 +515,11 @@ public class FastJavaPartitionScanner implements IPartitionTokenScanner, IPHPPar
                return fTokens[state];
        }
 
-       private final IToken preFix(int state, int newState, int last, int prefixLength) {
+       private final IToken preFix(int state, int newState, int last,
+                       int prefixLength) {
                // emulate JavaPartitionScanner
-               if (fEmulate && state == PHP && (fTokenLength - getLastLength(fLast) > 0)) {
+               if (fEmulate && state == PHP
+                               && (fTokenLength - getLastLength(fLast) > 0)) {
                        fTokenLength -= getLastLength(fLast);
                        fJavaOffset = fTokenOffset;
                        fJavaLength = fTokenLength;
@@ -552,7 +573,8 @@ public class FastJavaPartitionScanner implements IPartitionTokenScanner, IPHPPar
         * @see IPartitionTokenScanner#setPartialRange(IDocument, int, int, String,
         *      int)
         */
-       public void setPartialRange(IDocument document, int offset, int length, String contentType, int partitionOffset) {
+       public void setPartialRange(IDocument document, int offset, int length,
+                       String contentType, int partitionOffset) {
                fScanner.setRange(document, offset, length);
                setRange(document, offset, length);
                fTokenOffset = partitionOffset;