added class fields to outline
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / parser / Scanner.java
index ea1f9c0..bfbb4d7 100644 (file)
@@ -13,6 +13,7 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Stack;
+
 import net.sourceforge.phpdt.core.compiler.CharOperation;
 import net.sourceforge.phpdt.core.compiler.IScanner;
 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
@@ -52,11 +53,11 @@ public class Scanner implements IScanner, ITerminalSymbols {
   //when == 0 ==> no unicode in the current token
   public boolean unicodeAsBackSlash = false;
   public boolean scanningFloatLiteral = false;
-  //support for /** comments
-  //public char[][] comments = new char[10][];
-  public int[] commentStops = new int[10];
-  public int[] commentStarts = new int[10];
-  public int commentPtr = -1; // no comment test with commentPtr value -1
+//support for /** comments
+       public int[] commentStops = new int[10];
+       public int[] commentStarts = new int[10];
+       public int commentPtr = -1; // no comment test with commentPtr value -1
+       protected int lastCommentLinePosition = -1;
   //diet parsing support - jump over some method body when requested
   public boolean diet = false;
   //support for the poor-line-debuggers ....
@@ -1482,6 +1483,7 @@ public class Scanner implements IScanner, ITerminalSymbols {
                 int test;
                 if ((startChar == '#') || (test = getNextChar('/', '*')) == 0) {
                   //line comment
+                       this.lastCommentLinePosition = this.currentPosition;
                   int endPositionForLineComment = 0;
                   try { //get the next char
                     currentCharacter = source[currentPosition++];
@@ -1524,6 +1526,7 @@ public class Scanner implements IScanner, ITerminalSymbols {
                     //                    } //jump over the \\
                     boolean isUnicode = false;
                     while (currentCharacter != '\r' && currentCharacter != '\n') {
+                       this.lastCommentLinePosition = this.currentPosition;
                       if (currentCharacter == '?') {
                         if (getNextChar('>')) {
                           startPosition = currentPosition - 2;
@@ -1581,7 +1584,8 @@ public class Scanner implements IScanner, ITerminalSymbols {
                     } else {
                       endPositionForLineComment = currentPosition - 1;
                     }
-                    recordComment(false);
+//                    recordComment(false);
+                    recordComment(TokenNameCOMMENT_LINE);
                     if (this.taskTags != null) checkTaskTag(this.startPosition, this.currentPosition);
                                        if ((currentCharacter == '\r')
                         || (currentCharacter == '\n')) {
@@ -1685,7 +1689,13 @@ public class Scanner implements IScanner, ITerminalSymbols {
                       //                          currentPosition++;
                       //                      } //jump over the \\
                     }
-                    recordComment(isJavadoc);
+                    //recordComment(isJavadoc);
+                    if (isJavadoc) {
+                       recordComment(TokenNameCOMMENT_PHPDOC);
+                    } else {
+                       recordComment(TokenNameCOMMENT_BLOCK);
+                    }
+                    
                     if (tokenizeComments) {
                       if (isJavadoc)
                         return TokenNameCOMMENT_PHPDOC;
@@ -1733,11 +1743,44 @@ public class Scanner implements IScanner, ITerminalSymbols {
     }
     return TokenNameEOF;
   }
+  
+  private int getInlinedHTML(int start) throws InvalidInputException {
+       int token = getInlinedHTMLToken(start);
+       if (token == TokenNameINLINE_HTML) {
+//             Stack stack = new Stack();
+//             // scan html for errors
+//             Source inlinedHTMLSource = new Source(new String(source, startPosition, currentPosition - startPosition));
+//             int lastPHPEndPos=0;
+//             for (Iterator i=inlinedHTMLSource.getNextTagIterator(0); i.hasNext();) {
+//                 Tag tag=(Tag)i.next();
+//                 
+//                 if (tag instanceof StartTag) {
+//                     StartTag startTag=(StartTag)tag;
+//                   //  System.out.println("startTag: "+tag);
+//                     if (startTag.isServerTag()) {
+//                       // TODO : what to do with a server tag ? 
+//                     } else {
+//                         // do whatever with HTML start tag
+//                         // use startTag.getElement() to find the element corresponding
+//                         // to this start tag which may be useful if you implement code
+//                         // folding etc
+//                             stack.push(startTag);
+//                     }
+//                 } else {
+//                     EndTag endTag=(EndTag)tag;
+//                     StartTag stag = (StartTag) stack.peek();
+////                 System.out.println("endTag: "+tag);
+//                     // do whatever with HTML end tag.
+//                 }
+//             }
+       }
+       return token;
+  }
   /**
    * @return @throws
    *         InvalidInputException
    */
-  private int getInlinedHTML(int start) throws InvalidInputException {
+  private int getInlinedHTMLToken(int start) throws InvalidInputException {
     //    int htmlPosition = start;
     if (currentPosition > source.length) {
       currentPosition = source.length;
@@ -2558,26 +2601,48 @@ public class Scanner implements IScanner, ITerminalSymbols {
       }
     }
   }
-  public final void recordComment(boolean isJavadoc) {
-    // a new annotation comment is recorded
-    try {
-      commentStops[++commentPtr] = isJavadoc
-          ? currentPosition
-          : -currentPosition;
-    } catch (IndexOutOfBoundsException e) {
-      int oldStackLength = commentStops.length;
-      int[] oldStack = commentStops;
-      commentStops = new int[oldStackLength + 30];
-      System.arraycopy(oldStack, 0, commentStops, 0, oldStackLength);
-      commentStops[commentPtr] = isJavadoc ? currentPosition : -currentPosition;
-      //grows the positions buffers too
-      int[] old = commentStarts;
-      commentStarts = new int[oldStackLength + 30];
-      System.arraycopy(old, 0, commentStarts, 0, oldStackLength);
-    }
-    //the buffer is of a correct size here
-    commentStarts[commentPtr] = startPosition;
-  }
+  public void recordComment(int token) {
+       // compute position
+       int stopPosition = this.currentPosition;
+       switch (token) {
+               case TokenNameCOMMENT_LINE:
+                       stopPosition = -this.lastCommentLinePosition;
+                       break;
+               case TokenNameCOMMENT_BLOCK:
+                       stopPosition = -this.currentPosition;
+                       break;
+       }
+
+       // a new comment is recorded
+       int length = this.commentStops.length;
+       if (++this.commentPtr >=  length) {
+               System.arraycopy(this.commentStops, 0, this.commentStops = new int[length + 30], 0, length);
+               //grows the positions buffers too
+               System.arraycopy(this.commentStarts, 0, this.commentStarts = new int[length + 30], 0, length);
+       }
+       this.commentStops[this.commentPtr] = stopPosition;
+       this.commentStarts[this.commentPtr] = this.startPosition;
+}
+//  public final void recordComment(boolean isJavadoc) {
+//    // a new annotation comment is recorded
+//    try {
+//      commentStops[++commentPtr] = isJavadoc
+//          ? currentPosition
+//          : -currentPosition;
+//    } catch (IndexOutOfBoundsException e) {
+//      int oldStackLength = commentStops.length;
+//      int[] oldStack = commentStops;
+//      commentStops = new int[oldStackLength + 30];
+//      System.arraycopy(oldStack, 0, commentStops, 0, oldStackLength);
+//      commentStops[commentPtr] = isJavadoc ? currentPosition : -currentPosition;
+//      //grows the positions buffers too
+//      int[] old = commentStarts;
+//      commentStarts = new int[oldStackLength + 30];
+//      System.arraycopy(old, 0, commentStarts, 0, oldStackLength);
+//    }
+//    //the buffer is of a correct size here
+//    commentStarts[commentPtr] = startPosition;
+//  }
   public void resetTo(int begin, int end) {
     //reset the scanner to a given position where it may rescan again
     diet = false;