1) Fixed calculation of the new indentation method of splitted strings.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / text / JavaHeuristicScanner.java
index 6bea251..e68f3c2 100644 (file)
@@ -13,13 +13,16 @@ package net.sourceforge.phpdt.internal.ui.text;
 import java.util.Arrays;
 
 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
+import net.sourceforge.phpeclipse.phpeditor.php.PHPDocumentPartitioner;
 
-import org.eclipse.jface.text.Assert;
+//incastrix
+//import org.eclipse.jface.text.Assert;
+import org.eclipse.core.runtime.Assert;
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
+//import org.eclipse.jface.text.IRegion;
 import org.eclipse.jface.text.ITypedRegion;
-import org.eclipse.jface.text.Region;
+//import org.eclipse.jface.text.Region;
 import org.eclipse.jface.text.TextUtilities;
 
 /**
@@ -327,8 +330,10 @@ public class JavaHeuristicScanner implements Symbols {
         *            the document to scan.
         */
        public JavaHeuristicScanner(IDocument document) {
+//             this(document, IPHPPartitions.PHP_PARTITIONING,
+//                             IDocument.DEFAULT_CONTENT_TYPE);
                this(document, IPHPPartitions.PHP_PARTITIONING,
-                               IDocument.DEFAULT_CONTENT_TYPE);
+                               PHPDocumentPartitioner.PHP_SCRIPT_CODE);
        }
 
        /**
@@ -380,7 +385,25 @@ public class JavaHeuristicScanner implements Symbols {
                case QUESTIONMARK:
                        return TokenQUESTIONMARK;
                case EQUAL:
+                       try {
+                               if (fDocument.getChar(fPos) == '>') {
+                                       fPos++;
+                                       return TokenOTHER;
+                               }
+                       } catch (BadLocationException e) {
+                       }
                        return TokenEQUAL;
+               case '<':
+                       try {
+                               if (fDocument.get(fPos, 4).equalsIgnoreCase("?php")) {
+                                       fPos += 4;
+                                       return TokenEOF;
+                               } else if (fDocument.getChar(fPos) == '?') {
+                                       fPos++;
+                                       return TokenEOF;
+                               }
+                       } catch (BadLocationException e) {
+                       }
                }
 
                // else
@@ -451,6 +474,18 @@ public class JavaHeuristicScanner implements Symbols {
                        return TokenQUESTIONMARK;
                case EQUAL:
                        return TokenEQUAL;
+               case '>':
+                       try {
+                               switch (fDocument.getChar(fPos)) {
+                               case '=':
+                                       fPos--;
+                                       return TokenOTHER;
+                               case '?':
+                                       fPos--;
+                                       return TokenEOF;
+                               }
+                       } catch (BadLocationException e) {
+                       }
                }
 
                // else
@@ -644,16 +679,16 @@ public class JavaHeuristicScanner implements Symbols {
         * @return a region describing the surrounding block, or <code>null</code>
         *         if none can be found
         */
-       public IRegion findSurroundingBlock(int offset) {
-               if (offset < 1 || offset >= fDocument.getLength())
-                       return null;
-
-               int begin = findOpeningPeer(offset - 1, LBRACE, RBRACE);
-               int end = findClosingPeer(offset, LBRACE, RBRACE);
-               if (begin == NOT_FOUND || end == NOT_FOUND)
-                       return null;
-               return new Region(begin, end + 1 - begin);
-       }
+//     public IRegion findSurroundingBlock(int offset) {
+//             if (offset < 1 || offset >= fDocument.getLength())
+//                     return null;
+//
+//             int begin = findOpeningPeer(offset - 1, LBRACE, RBRACE);
+//             int end = findClosingPeer(offset, LBRACE, RBRACE);
+//             if (begin == NOT_FOUND || end == NOT_FOUND)
+//                     return null;
+//             return new Region(begin, end + 1 - begin);
+//     }
 
        /**
         * Finds the smallest position in <code>fDocument</code> such that the
@@ -673,9 +708,9 @@ public class JavaHeuristicScanner implements Symbols {
         *         <code>bound</code>) that resides in a Java partition, or
         *         <code>NOT_FOUND</code> if none can be found
         */
-       public int findNonWhitespaceForward(int position, int bound) {
-               return scanForward(position, bound, fNonWSDefaultPart);
-       }
+//     public int findNonWhitespaceForward(int position, int bound) {
+//             return scanForward(position, bound, fNonWSDefaultPart);
+//     }
 
        /**
         * Finds the smallest position in <code>fDocument</code> such that the
@@ -716,9 +751,9 @@ public class JavaHeuristicScanner implements Symbols {
         *         <code>position</code>] that resides in a Java partition, or
         *         <code>NOT_FOUND</code> if none can be found
         */
-       public int findNonWhitespaceBackward(int position, int bound) {
-               return scanBackward(position, bound, fNonWSDefaultPart);
-       }
+//     public int findNonWhitespaceBackward(int position, int bound) {
+//             return scanBackward(position, bound, fNonWSDefaultPart);
+//     }
 
        /**
         * Finds the lowest position <code>p</code> in <code>fDocument</code>
@@ -752,6 +787,15 @@ public class JavaHeuristicScanner implements Symbols {
                        while (fPos < bound) {
 
                                fChar = fDocument.getChar(fPos);
+                               // omit closing tag
+                               if (fChar == '?') {
+                                       if (fPos < fDocument.getLength() - 1) {
+                                               if (fDocument.get(fPos - 1, 2).equalsIgnoreCase("?>")) {
+                                                       fPos++;
+                                                       return NOT_FOUND;
+                                               }
+                                       }
+                               }
                                if (condition.stop(fChar, fPos, true))
                                        return fPos;
 
@@ -781,9 +825,9 @@ public class JavaHeuristicScanner implements Symbols {
         *         <code>position</code>] that resides in a Java partition, or
         *         <code>NOT_FOUND</code> if none can be found
         */
-       public int scanForward(int position, int bound, char ch) {
-               return scanForward(position, bound, new CharacterMatch(ch));
-       }
+//     public int scanForward(int position, int bound, char ch) {
+//             return scanForward(position, bound, new CharacterMatch(ch));
+//     }
 
        /**
         * Finds the lowest position in <code>fDocument</code> such that the
@@ -805,9 +849,9 @@ public class JavaHeuristicScanner implements Symbols {
         *         <code>bound</code>) that resides in a Java partition, or
         *         <code>NOT_FOUND</code> if none can be found
         */
-       public int scanForward(int position, int bound, char[] chars) {
-               return scanForward(position, bound, new CharacterMatch(chars));
-       }
+//     public int scanForward(int position, int bound, char[] chars) {
+//             return scanForward(position, bound, new CharacterMatch(chars));
+//     }
 
        /**
         * Finds the highest position <code>p</code> in <code>fDocument</code>
@@ -841,6 +885,22 @@ public class JavaHeuristicScanner implements Symbols {
                        while (fPos > bound) {
 
                                fChar = fDocument.getChar(fPos);
+                               // omit opening tag
+                               if (fChar == 'p' || fChar == 'P') {
+                                       if (fPos >= 4) {
+                                               if (fDocument.get(fPos - 4, 5).equalsIgnoreCase("<?php")) {
+                                                       fPos -= 4;
+                                                       return NOT_FOUND;
+                                               }
+                                       }
+                               } else if (fChar == '?') {
+                                       if (fPos >= 1) {
+                                               if (fDocument.get(fPos - 1, 2).equalsIgnoreCase("<?")) {
+                                                       fPos--;
+                                                       return NOT_FOUND;
+                                               }
+                                       }
+                               }
                                if (condition.stop(fChar, fPos, false))
                                        return fPos;
 
@@ -871,9 +931,9 @@ public class JavaHeuristicScanner implements Symbols {
         *         <code>position</code>] that resides in a Java partition, or
         *         <code>NOT_FOUND</code> if none can be found
         */
-       public int scanBackward(int position, int bound, char ch) {
-               return scanBackward(position, bound, new CharacterMatch(ch));
-       }
+//     public int scanBackward(int position, int bound, char ch) {
+//             return scanBackward(position, bound, new CharacterMatch(ch));
+//     }
 
        /**
         * Finds the highest position in <code>fDocument</code> such that the
@@ -895,9 +955,9 @@ public class JavaHeuristicScanner implements Symbols {
         *         <code>position</code>] that resides in a Java partition, or
         *         <code>NOT_FOUND</code> if none can be found
         */
-       public int scanBackward(int position, int bound, char[] chars) {
-               return scanBackward(position, bound, new CharacterMatch(chars));
-       }
+//     public int scanBackward(int position, int bound, char[] chars) {
+//             return scanBackward(position, bound, new CharacterMatch(chars));
+//     }
 
        /**
         * Checks whether <code>position</code> resides in a default (Java)