fixed NPE in Parser ( function catch() )
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / parser / Parser.java
index e99fb28..264b0ad 100644 (file)
@@ -19,6 +19,7 @@ import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
 import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities;
 import net.sourceforge.phpdt.internal.compiler.util.Util;
+import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
 import net.sourceforge.phpeclipse.internal.compiler.ast.AstNode;
 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
@@ -69,12 +70,15 @@ public class Parser //extends PHPParserSuperclass
   //private boolean phpMode;
   protected int modifiers;
   protected int modifiersSourceStart;
+//  protected IdentifierIndexManager indexManager;
+  
   protected Parser(ProblemReporter problemReporter) {
     this.problemReporter = problemReporter;
     this.options = problemReporter.options;
     this.currentPHPString = 0;
     //         PHPParserSuperclass.fileToParse = fileToParse;
     this.phpList = null;
+//    this.indexManager = null;
     this.str = "";
     this.token = TokenNameEOF;
     //    this.chIndx = 0;
@@ -88,6 +92,7 @@ public class Parser //extends PHPParserSuperclass
     this.currentPHPString = 0;
     //    PHPParserSuperclass.fileToParse = fileToParse;
     this.phpList = null;
+//    this.indexManager = null;
     this.str = "";
     this.token = TokenNameEOF;
     this.phpEnd = false;
@@ -219,9 +224,13 @@ public class Parser //extends PHPParserSuperclass
     scanner.setPHPMode(false);
   }
   protected void initialize(boolean phpMode) {
+    initialize(phpMode, null);
+  }
+  protected void initialize(boolean phpMode, IdentifierIndexManager indexManager) {
     compilationUnit = null;
     referenceContext = null;
     includesList = new ArrayList();
+//    this.indexManager = indexManager;
     this.str = "";
     this.token = TokenNameEOF;
     //    this.chIndx = 0;
@@ -851,6 +860,7 @@ public class Parser //extends PHPParserSuperclass
     } else if (token == TokenNamefunction) {
       MethodDeclaration methodDecl = new MethodDeclaration(this.compilationUnit.compilationResult);
       methodDecl.declarationSourceStart = scanner.getCurrentTokenStartPosition();
+      methodDecl.modifiers = AccDefault;
       getNextToken();
       functionDefinition(methodDecl);
       return;
@@ -1249,7 +1259,8 @@ public class Parser //extends PHPParserSuperclass
       getNextToken();
       class_variable_declaration(declarationSourceStart, list);
     } else if (token == TokenNameconst) {
-      class_constant_declaration();
+      checkAndSetModifiers(AccFinal|AccPublic);
+      class_constant_declaration(declarationSourceStart, list);
       if (token != TokenNameSEMICOLON) {
         throwSyntaxError("';' expected after class const declaration.");
       }
@@ -1272,21 +1283,8 @@ public class Parser //extends PHPParserSuperclass
         class_variable_declaration(declarationSourceStart, list);
       }
     }
-    //    if (token == TokenNamefunction) {
-    //      MethodDeclaration methodDecl = new MethodDeclaration(
-    //          this.compilationUnit.compilationResult);
-    //      methodDecl.declarationSourceStart = scanner
-    //          .getCurrentTokenStartPosition();
-    //      getNextToken();
-    //      functionDefinition(methodDecl);
-    //    } else if (token == TokenNamevar) {
-    //      getNextToken();
-    //      classProperty();
-    //    } else {
-    //      throwSyntaxError("'function' or 'var' expected.");
-    //    }
   }
-  private void class_constant_declaration() {
+  private void class_constant_declaration(int declarationSourceStart, ArrayList list) {
     // class_constant_declaration ',' T_STRING '=' static_scalar
     // | T_CONST T_STRING '=' static_scalar
     if (token != TokenNameconst) {
@@ -1298,6 +1296,14 @@ public class Parser //extends PHPParserSuperclass
       if (token != TokenNameIdentifier) {
         throwSyntaxError("Identifier expected in class const declaration.");
       }
+      FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner.getCurrentIdentifierSource(), scanner
+          .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
+      fieldDeclaration.modifiers = this.modifiers;
+      fieldDeclaration.declarationSourceStart = declarationSourceStart;
+      fieldDeclaration.declarationSourceEnd = scanner.getCurrentTokenEndPosition();
+      fieldDeclaration.modifiersSourceStart = declarationSourceStart;
+      //        fieldDeclaration.type
+      list.add(fieldDeclaration);
       getNextToken();
       if (token != TokenNameEQUAL) {
         throwSyntaxError("'=' expected in class const declaration.");
@@ -1385,9 +1391,12 @@ public class Parser //extends PHPParserSuperclass
     // | class_variable_declaration ',' T_VARIABLE '=' static_scalar
     // | T_VARIABLE
     // | T_VARIABLE '=' static_scalar
+    char[] classVariable;
     do {
       if (token == TokenNameVariable) {
-        FieldDeclaration fieldDeclaration = new FieldDeclaration(scanner.getCurrentIdentifierSource(), scanner
+        classVariable = scanner.getCurrentIdentifierSource();
+      //  indexManager.addIdentifierInformation('v', classVariable, buf, -1, -1);
+        FieldDeclaration fieldDeclaration = new FieldDeclaration(classVariable, scanner
             .getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
         fieldDeclaration.modifiers = this.modifiers;
         fieldDeclaration.declarationSourceStart = declarationSourceStart;
@@ -1456,10 +1465,15 @@ public class Parser //extends PHPParserSuperclass
     if (token == TokenNameAND) {
       getNextToken();
     }
-    if (token == TokenNameIdentifier) {
-      methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
-      methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
+    methodDecl.sourceStart = scanner.getCurrentTokenStartPosition();
+    methodDecl.sourceEnd = scanner.getCurrentTokenEndPosition();
+    if (Scanner.isIdentifierOrKeyword(token)) {
       methodDecl.selector = scanner.getCurrentIdentifierSource();
+      if (token > TokenNameKEYWORD) {
+        reportSyntaxWarning("Don't use keyword for function declaration [" + scanner.toStringAction(token) + "].",
+          scanner.getCurrentTokenStartPosition(), scanner.getCurrentTokenEndPosition());
+//        throwSyntaxError("Don't use keyword for function declaration [" + scanner.toStringAction(token) + "].");
+      }
       getNextToken();
       if (token == TokenNameLPAREN) {
         getNextToken();
@@ -1476,9 +1490,7 @@ public class Parser //extends PHPParserSuperclass
         getNextToken();
       }
     } else {
-      if (token > TokenNameKEYWORD) {
-        throwSyntaxError("Don't use keyword for function declaration [" + token + "].");
-      }
+      methodDecl.selector = "<undefined>".toCharArray();
       throwSyntaxError("Function name expected after keyword 'function'.");
     }
   }