Introduce a field "stringValue" used by the new method getString() that read a string...
authorkpouer <kpouer>
Fri, 24 Jan 2003 11:40:19 +0000 (11:40 +0000)
committerkpouer <kpouer>
Fri, 24 Jan 2003 11:40:19 +0000 (11:40 +0000)
The variable in outline will now show their initial value
I also think the bug 670086 with the error on save is fixed (by catching a SyntaxError in parseDeclarations())

I still have a bug : when you change the initial value of a field, the outline will not detect it

net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/phpparser/PHPParser.java

index bcc7ba9..110dd8f 100644 (file)
@@ -14,19 +14,16 @@ import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Hashtable;
-import java.util.Stack;
 
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
 import net.sourceforge.phpeclipse.phpeditor.PHPString;
-import net.sourceforge.phpeclipse.phpeditor.PHPParserAction;
 import net.sourceforge.phpeclipse.phpeditor.php.PHPKeywords;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IMarker;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.action.IAction;
 import org.eclipse.ui.texteditor.MarkerUtilities;
 
 public class PHPParser extends PHPKeywords {
@@ -63,6 +60,8 @@ public class PHPParser extends PHPKeywords {
 
   Long longNumber;
   Double doubleNumber;
+
+  String stringValue;
   private boolean phpMode;
 
   final static int TT_EOF = 0;
@@ -883,73 +882,14 @@ public class PHPParser extends PHPKeywords {
               continue;
 
             } else if (ch == '"') {
-              // read string until end
-              boolean openString = true;
-              while (str.length() > chIndx) {
-                ch = str.charAt(chIndx++);
-                if (ch == '\\') {
-                  if (str.length() > chIndx) {
-                    ch = str.charAt(chIndx++);
-                  }
-                } else if (ch == '"') {
-                  openString = false;
-                  break;
-                } else if (ch == '\n') {
-                  rowCount++;
-                  columnCount = chIndx;
-                }
-              }
-              if (openString) {
-                throwSyntaxError("Open string character '\"' at end of file.");
-              }
-              token = TT_INTERPOLATED_STRING;
+              getString('"',TT_INTERPOLATED_STRING,"Open string character '\"' at end of file.");
               return;
             } else if (ch == '\'') {
-              // read string until end
-              boolean openString = true;
-              int startRow = rowCount;
-              while (str.length() > chIndx) {
-                ch = str.charAt(chIndx++);
-                if (ch == '\\') {
-                  if (str.length() > chIndx) {
-                    ch = str.charAt(chIndx++);
-                  }
-                } else if (ch == '\'') {
-                  openString = false;
-                  break;
-                } else if (ch == '\n') {
-                  rowCount++;
-                  columnCount = chIndx;
-                }
-              }
-              if (openString) {
-                throwSyntaxError("Open string character \"'\" at end of file.", startRow);
-              }
-              token = TT_STRING_CONSTANT;
+              getString('\'',TT_STRING_CONSTANT,"Open string character \"'\" at end of file.");
               return;
             } else if (ch == '`') {
-              // read string until end
-              boolean openString = true;
-              int startRow = rowCount;
-              while (str.length() > chIndx) {
-                ch = str.charAt(chIndx++);
-                if (ch == '\\') {
-                  if (str.length() > chIndx) {
-                    ch = str.charAt(chIndx++);
-                  }
-                } else if (ch == '`') {
-                  openString = false;
-                  break;
-                } else if (ch == '\n') {
-                  rowCount++;
-                  columnCount = chIndx;
-                }
-              }
-              if (openString) {
-                throwSyntaxError("Open string character \"`\" at end of file.", startRow);
-              }
+              getString('`',TT_STRING_CONSTANT,"Open string character \"`\" at end of file.");
               setMarker("Other string delimiters prefered (found \"`\").", rowCount, PHPParser.INFO);
-              token = TT_STRING_CONSTANT;
               return;
             }
 
@@ -1331,6 +1271,7 @@ public class PHPParser extends PHPKeywords {
     //    }
   }
 
+
   private void getIdentifier() {
     StringBuffer ident = new StringBuffer();
 
@@ -1446,6 +1387,45 @@ public class PHPParser extends PHPKeywords {
     }
   }
 
+  /**
+   * Get a String.
+   * @param openChar the opening char ('\'', '"', '`')
+   * @param typeString the type of string {@link #TT_STRING_CONSTANT},{@link #TT_INTERPOLATED_STRING}
+   * @param errorMsg the error message in case of parse error in the string
+   */
+  private void getString(final char openChar, final int typeString, final String errorMsg) {
+    StringBuffer sBuffer = new StringBuffer();
+    boolean openString = true;
+    int startRow = rowCount;
+    while (str.length() > chIndx) {
+      ch = str.charAt(chIndx++);
+      if (ch == '\\') {
+        sBuffer.append(ch);
+        if (str.length() > chIndx) {
+          ch = str.charAt(chIndx++);
+          sBuffer.append(ch);
+        }
+      } else if (ch == openChar) {
+        openString = false;
+        break;
+      } else if (ch == '\n') {
+        rowCount++;
+        columnCount = chIndx;
+      } else {
+        sBuffer.append(ch);
+      }
+    }
+    if (openString) {
+      if (typeString == TT_STRING_CONSTANT) {
+        throwSyntaxError(errorMsg, startRow);
+      } else {
+        throwSyntaxError(errorMsg);
+      }
+    }
+    token = typeString;
+    stringValue = sBuffer.toString();
+  }
+
   public void htmlParserTester(String input) {
     int lineNumber = 1;
     int startLineNumber = 1;
@@ -1791,6 +1771,7 @@ public class PHPParser extends PHPKeywords {
     //   PHPClassDeclaration current = (PHPClassDeclaration) stack.peek();
     PHPClassDeclaration temp;
     int counter = 0;
+    String oldIdentifier;
     IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
     try {
       while (token != TT_EOF && token != TT_UNDEFINED) {
@@ -1800,9 +1781,30 @@ public class PHPParser extends PHPKeywords {
         } else if (token == TT_var) {
           getNextToken();
           if (token == TT_VARIABLE && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_VAR)) {
-            outlineInfo.addVariable(identifier);
-            current.add(new PHPVarDeclaration(current, identifier, chIndx - identifier.length()));
             getNextToken();
+            outlineInfo.addVariable(identifier);
+            if (token != TT_SEMICOLON) {
+              oldIdentifier = identifier;
+              getNextToken();
+              switch (token) {
+                case TT_VARIABLE            : current.add(new PHPVarDeclaration(current, oldIdentifier, chIndx - identifier.length(),identifier));
+                                              break;
+                case TT_IDENTIFIER          : current.add(new PHPVarDeclaration(current, oldIdentifier, chIndx - identifier.length(),identifier));
+                                              break;
+                case TT_DOUBLE_NUMBER       : current.add(new PHPVarDeclaration(current, oldIdentifier + doubleNumber, chIndx - identifier.length(),doubleNumber.toString()));
+                                              break;
+                case TT_INT_NUMBER          : current.add(new PHPVarDeclaration(current, oldIdentifier, chIndx - identifier.length(),longNumber.toString()));
+                                              break;
+                case TT_INTERPOLATED_STRING : current.add(new PHPVarDeclaration(current, oldIdentifier, chIndx - identifier.length(),stringValue));
+                                              break;
+                case TT_STRING_CONSTANT     : current.add(new PHPVarDeclaration(current, oldIdentifier, chIndx - identifier.length(),stringValue));
+                                              break;
+                default                     : current.add(new PHPVarDeclaration(current, oldIdentifier, chIndx - identifier.length()));
+                                              break;
+              }
+            } else {
+              current.add(new PHPVarDeclaration(current, identifier, chIndx - identifier.length()));
+            }
           }
         } else if (token == TT_function) {
           getNextToken();
@@ -1842,6 +1844,11 @@ public class PHPParser extends PHPKeywords {
         }
       }
     } catch (CoreException e) {
+    } catch (SyntaxError sytaxErr) {
+      try {
+        setMarker(sytaxErr.getMessage(), sytaxErr.getLine(), ERROR);
+      } catch (CoreException e) {
+      }
     }
   }