From: bananeweizen Date: Sun, 29 Jan 2006 22:47:34 +0000 (+0000) Subject: suppress "variable not initialized" error for break statements. In switch-case statem... X-Git-Url: http://secure.phpeclipse.com suppress "variable not initialized" error for break statements. In switch-case statements it is recommended to have a break statement in each case (even after return), so you don't get different code, if you later remove the return statement. --- 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 a9fdbb2..d82979c 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 @@ -428,8 +428,13 @@ public class Parser implements ITerminalSymbols, CompilerModifiers, ParserBasicI if (branchStatement && statement != null) { // reportSyntaxError("Unreachable code", statement.sourceStart, // statement.sourceEnd); - problemReporter.unreachableCode(new String(scanner.getCurrentIdentifierSource()), statement.sourceStart, + if (! (statement instanceof BreakStatement)) { + /* don't give an error for break statement following return statement + Technically it's unreachable code, but in switch-case it's recommended to + avoid accidental fall-through later when editing the code */ + problemReporter.unreachableCode(new String(scanner.getCurrentIdentifierSource()), statement.sourceStart, statement.sourceEnd, referenceContext, compilationUnit.compilationResult); + } } if ((token == TokenNameRBRACE) || (token == TokenNamecase) || (token == TokenNamedefault) || (token == TokenNameelse) || (token == TokenNameelseif) || (token == TokenNameendif) || (token == TokenNameendfor)