### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java,v retrieving revision 1.158 diff -u -r1.158 TypeDeclaration.java --- compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java 12 May 2009 20:49:56 -0000 1.158 +++ compiler/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java 22 Jun 2009 13:59:27 -0000 @@ -815,15 +815,20 @@ //members if (this.memberTypes != null) { int length = this.memberTypes.length; - for (int i = 0; i < length; i++) - this.memberTypes[i].parseMethods(parser, unit); + for (int i = 0; i < length; i++) { + TypeDeclaration typeDeclaration = this.memberTypes[i]; + typeDeclaration.parseMethods(parser, unit); + this.bits |= (typeDeclaration.bits & ASTNode.HasSyntaxErrors); + } } //methods if (this.methods != null) { int length = this.methods.length; for (int i = 0; i < length; i++) { - this.methods[i].parseStatements(parser, unit); + AbstractMethodDeclaration abstractMethodDeclaration = this.methods[i]; + abstractMethodDeclaration.parseStatements(parser, unit); + this.bits |= (abstractMethodDeclaration.bits & ASTNode.HasSyntaxErrors); } } @@ -835,6 +840,7 @@ switch(fieldDeclaration.getKind()) { case AbstractVariableDeclaration.INITIALIZER: ((Initializer) fieldDeclaration).parseStatements(parser, this, unit); + this.bits |= (fieldDeclaration.bits & ASTNode.HasSyntaxErrors); break; } } Index: compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java,v retrieving revision 1.99 diff -u -r1.99 ASTNode.java --- compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java 13 Feb 2009 21:40:39 -0000 1.99 +++ compiler/org/eclipse/jdt/internal/compiler/ast/ASTNode.java 22 Jun 2009 13:59:27 -0000 @@ -42,7 +42,7 @@ public final static int Bit17 = 0x10000; // compound assigned (reference lhs) | unchecked (msg, alloc, explicit constr call) public final static int Bit18 = 0x20000; // non null (expression) | onDemand (import reference) public final static int Bit19 = 0x40000; // didResolve (parameterized qualified type ref/parameterized single type ref) | empty (javadoc return statement) | needReceiverGenericCast (msg/fieldref) - public final static int Bit20 = 0x80000; + public final static int Bit20 = 0x80000; // contains syntax errors (method declaration, type declaration, field declarations, initializer) public final static int Bit21 = 0x100000; public final static int Bit22 = 0x200000; // parenthesis count (expression) | used (import reference) public final static int Bit23 = 0x400000; // parenthesis count (expression) @@ -226,6 +226,9 @@ // for annotation reference public static final int IsRecovered = Bit6; + // for type declaration, initializer and method declaration + public static final int HasSyntaxErrors = Bit20; + // constants used when checking invocation arguments public static final int INVOCATION_ARGUMENT_OK = 0; public static final int INVOCATION_ARGUMENT_UNCHECKED = 1; Index: codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java,v retrieving revision 1.89 diff -u -r1.89 AssistParser.java --- codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java 7 May 2009 08:49:43 -0000 1.89 +++ codeassist/org/eclipse/jdt/internal/codeassist/impl/AssistParser.java 22 Jun 2009 13:59:27 -0000 @@ -1285,6 +1285,7 @@ } if (this.lastAct == ERROR_ACTION) { + cd.bits |= ASTNode.HasSyntaxErrors; return; } @@ -1352,6 +1353,7 @@ } if (this.lastAct == ERROR_ACTION) { + initializer.bits |= ASTNode.HasSyntaxErrors; return; } @@ -1408,6 +1410,7 @@ } if (this.lastAct == ERROR_ACTION) { + md.bits |= ASTNode.HasSyntaxErrors; return; } Index: compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java,v retrieving revision 1.404 diff -u -r1.404 Parser.java --- compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 18 Jun 2009 08:18:55 -0000 1.404 +++ compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 22 Jun 2009 13:59:27 -0000 @@ -9437,6 +9437,7 @@ checkNonNLSAfterBodyEnd(cd.declarationSourceEnd); if (this.lastAct == ERROR_ACTION) { + cd.bits |= ASTNode.HasSyntaxErrors; initialize(); return; } @@ -9506,6 +9507,7 @@ } if (this.lastAct == ERROR_ACTION) { + field.bits |= ASTNode.HasSyntaxErrors; return; } @@ -9614,6 +9616,7 @@ checkNonNLSAfterBodyEnd(initializer.declarationSourceEnd); if (this.lastAct == ERROR_ACTION) { + initializer.bits |= ASTNode.HasSyntaxErrors; return; } @@ -9677,6 +9680,7 @@ checkNonNLSAfterBodyEnd(md.declarationSourceEnd); if (this.lastAct == ERROR_ACTION) { + md.bits |= ASTNode.HasSyntaxErrors; return; } @@ -9764,11 +9768,14 @@ result = new ASTNode[astLength]; this.astPtr -= astLength; System.arraycopy(this.astStack, this.astPtr + 1, result, 0, astLength); + } else { + // empty class body declaration (like ';' see https://bugs.eclipse.org/bugs/show_bug.cgi?id=280079). + result = new ASTNode[0]; } } boolean containsInitializers = false; TypeDeclaration typeDeclaration = null; - for (int i = 0, max = result.length; i< max; i++) { + for (int i = 0, max = result.length; i < max; i++) { // parse each class body declaration ASTNode node = result[i]; if (node instanceof TypeDeclaration) { @@ -9796,15 +9803,16 @@ break; } } - if (this.lastAct == ERROR_ACTION && (!this.options.performMethodsFullRecovery && !this.options.performStatementsRecovery)) { + if (((node.bits & ASTNode.HasSyntaxErrors) != 0) && (!this.options.performMethodsFullRecovery && !this.options.performStatementsRecovery)) { return null; } } if (containsInitializers) { FieldDeclaration[] fieldDeclarations = typeDeclaration.fields; for (int i = 0, max = fieldDeclarations.length; i < max; i++) { - ((Initializer) fieldDeclarations[i]).parseStatements(this, typeDeclaration , unit); - if (this.lastAct == ERROR_ACTION && (!this.options.performMethodsFullRecovery && !this.options.performStatementsRecovery)) { + Initializer initializer = (Initializer) fieldDeclarations[i]; + initializer.parseStatements(this, typeDeclaration , unit); + if (((initializer.bits & ASTNode.HasSyntaxErrors) != 0) && (!this.options.performMethodsFullRecovery && !this.options.performStatementsRecovery)) { return null; } } Index: compiler/org/eclipse/jdt/internal/compiler/lookup/TagBits.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/TagBits.java,v retrieving revision 1.37 diff -u -r1.37 TagBits.java --- compiler/org/eclipse/jdt/internal/compiler/lookup/TagBits.java 12 May 2009 20:49:56 -0000 1.37 +++ compiler/org/eclipse/jdt/internal/compiler/lookup/TagBits.java 22 Jun 2009 13:59:27 -0000 @@ -27,7 +27,7 @@ long AnonymousTypeMask = LocalTypeMask | IsAnonymousType | ContainsNestedTypeReferences; long IsBinaryBinding = ASTNode.Bit7; - // set for all bindings either represeting a missing type (type), or directly referencing a missing type (field/method/variable) + // set for all bindings either representing a missing type (type), or directly referencing a missing type (field/method/variable) long HasMissingType = ASTNode.Bit8; // for method @@ -60,7 +60,7 @@ // test bit to identify if the type's type variables have been connected long TypeVariablesAreConnected = ASTNode.Bit19; - // set for parameterized type with successfull bound check + // set for parameterized type with successful bound check long PassedBoundCheck = ASTNode.Bit23; // set for parameterized type NOT of the form X #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java,v retrieving revision 1.163 diff -u -r1.163 ASTConverterTestAST3_2.java --- src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java 26 May 2009 17:22:08 -0000 1.163 +++ src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java 22 Jun 2009 13:59:28 -0000 @@ -121,8 +121,8 @@ static { // TESTS_NAMES = new String[] {"test0602"}; -// TESTS_RANGE = new int[] { 670, -1 }; -// TESTS_NUMBERS = new int[] { 709 }; +// TESTS_RANGE = new int[] { 713, -1 }; +// TESTS_NUMBERS = new int[] { 710, 711 }; } public static Test suite() { return buildModelTestSuite(ASTConverterTestAST3_2.class); @@ -10281,4 +10281,120 @@ } } } + /** + * http://dev.eclipse.org/bugs/show_bug.cgi?id=280079 + */ + public void test0710() throws JavaModelException { + final char[] source = (";").toCharArray(); + ASTParser parser = ASTParser.newParser(AST.JLS3); + parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS); + parser.setStatementsRecovery(true); + parser.setSource(source); + ASTNode root = parser.createAST(null); + assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, root.getNodeType()); + TypeDeclaration typeDeclaration = (TypeDeclaration) root; + List bodyDeclarations = typeDeclaration.bodyDeclarations(); + assertEquals("Wrong size", 0, bodyDeclarations.size()); + } + /** + * http://dev.eclipse.org/bugs/show_bug.cgi?id=280079 + */ + public void test0711() throws JavaModelException { + final char[] source = (";void foo() {}").toCharArray(); + ASTParser parser = ASTParser.newParser(AST.JLS3); + parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS); + parser.setStatementsRecovery(true); + parser.setSource(source); + ASTNode root = parser.createAST(null); + assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, root.getNodeType()); + TypeDeclaration typeDeclaration = (TypeDeclaration) root; + List bodyDeclarations = typeDeclaration.bodyDeclarations(); + assertEquals("Wrong size", 1, bodyDeclarations.size()); + } + /** + * http://dev.eclipse.org/bugs/show_bug.cgi?id=280079 + */ + public void test0712() throws JavaModelException { + final char[] source = (";void foo() {};").toCharArray(); + ASTParser parser = ASTParser.newParser(AST.JLS3); + parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS); + parser.setStatementsRecovery(true); + parser.setSource(source); + ASTNode root = parser.createAST(null); + assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, root.getNodeType()); + TypeDeclaration typeDeclaration = (TypeDeclaration) root; + List bodyDeclarations = typeDeclaration.bodyDeclarations(); + assertEquals("Wrong size", 1, bodyDeclarations.size()); + } + /** + * http://dev.eclipse.org/bugs/show_bug.cgi?id=280063 + */ + public void test0713() throws JavaModelException { + final char[] source = (" class MyCommand extends CompoundCommand\n" + + " {\n" + + " public void execute()\n" + + " {\n" + + " // ...\n" + + " appendAndExecute(new AddCommand(...));\n" + + " if (condition) appendAndExecute(new AddCommand(...));\n" + + " }\n" + + " }").toCharArray(); + ASTParser parser = ASTParser.newParser(AST.JLS3); + parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS); + parser.setStatementsRecovery(false); + parser.setSource(source); + ASTNode root = parser.createAST(null); + assertEquals("Not a type declaration", ASTNode.COMPILATION_UNIT, root.getNodeType()); + CompilationUnit unit = (CompilationUnit) root; + assertTrue("No problem reported", unit.getProblems().length != 0); + } + /** + * http://dev.eclipse.org/bugs/show_bug.cgi?id=280063 + */ + public void test0714() throws JavaModelException { + final char[] source = ("class MyCommand extends CommandBase\n" + + " {\n" + + " protected Command subcommand;\n" + + "\n" + + " //...\n" + + "\n" + + " public void execute()\n" + + " {\n" + + " // ...\n" + + " Compound subcommands = new CompoundCommand();\n" + + " subcommands.appendAndExecute(new AddCommand(...));\n" + + " if (condition) subcommands.appendAndExecute(new AddCommand(...));\n" + + " subcommand = subcommands.unwrap();\n" + + " }\n" + + "\n" + + " public void undo()\n" + + " {\n" + + " // ...\n" + + " subcommand.undo();\n" + + " }\n" + + "\n" + + " public void redo()\n" + + " {\n" + + " // ...\n" + + " subcommand.redo();\n" + + " }\n" + + "\n" + + " public void dispose()\n" + + " {\n" + + " // ...\n" + + " if (subcommand != null)\n" + + " {\n" + + " subcommand.dispose();\n" + + " }\n" + + " }\n" + + " }").toCharArray(); + ASTParser parser = ASTParser.newParser(AST.JLS3); + parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS); + parser.setStatementsRecovery(false); + parser.setSource(source); + ASTNode root = parser.createAST(null); + assertEquals("Not a type declaration", ASTNode.COMPILATION_UNIT, root.getNodeType()); + CompilationUnit unit = (CompilationUnit) root; + assertTrue("No problem reported", unit.getProblems().length != 0); + } } \ No newline at end of file