From 123574be8842c68a20757ad2b4c3b236aa8f5f88 Mon Sep 17 00:00:00 2001 From: khartlage Date: Sun, 11 Jul 2004 08:33:44 +0000 Subject: [PATCH] fixed NPE in Parser ( function catch() ) --- .../phpdt/internal/compiler/parser/Parser.java | 15 +++++++++------ .../phpdt/internal/compiler/parser/Scanner.java | 3 +++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java index 45fa6e4..264b0ad 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Parser.java @@ -1465,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(); @@ -1485,9 +1490,7 @@ public class Parser //extends PHPParserSuperclass getNextToken(); } } else { - if (token > TokenNameKEYWORD) { - throwSyntaxError("Don't use keyword for function declaration [" + token + "]."); - } + methodDecl.selector = "".toCharArray(); throwSyntaxError("Function name expected after keyword 'function'."); } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java index c1098d5..0544363 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java @@ -2259,6 +2259,9 @@ public class Scanner implements IScanner, ITerminalSymbols { public char[] getSource() { return this.source; } + public static boolean isIdentifierOrKeyword(int token) { + return (token == TokenNameIdentifier) || (token > TokenNameKEYWORD); + } final char[] optimizedCurrentTokenSource1() { //return always the same char[] build only once //optimization at no speed cost of 99.5 % of the singleCharIdentifier -- 1.7.1