### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/dom/ASTConverterTest2.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest2.java,v retrieving revision 1.183 diff -u -r1.183 ASTConverterTest2.java --- src/org/eclipse/jdt/core/tests/dom/ASTConverterTest2.java 16 Aug 2007 14:59:30 -0000 1.183 +++ src/org/eclipse/jdt/core/tests/dom/ASTConverterTest2.java 20 Sep 2007 19:10:36 -0000 @@ -43,7 +43,7 @@ static { // TESTS_NAMES = new String[] {"test0578"}; -// TESTS_NUMBERS = new int[] { 606 }; +// TESTS_NUMBERS = new int[] { 608 }; } public static Test suite() { return buildModelTestSuite(ASTConverterTest2.class); @@ -5501,8 +5501,20 @@ " }\n" + "}" ); - ASTNode cu = buildAST(null, workingCopy, false, true); - assertNotNull("Should get an AST", cu); + ASTNode node = buildAST(null, workingCopy, false, true); + assertNotNull("Should get an AST", node); + assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); + node = getASTNode((CompilationUnit) node, 0, 0, 0); + assertEquals("Not a for statement", ASTNode.FOR_STATEMENT, node.getNodeType()); + ForStatement forStatement = (ForStatement) node; + List initializers = forStatement.initializers(); + assertEquals("Wrong size", 1, initializers.size()); + VariableDeclarationExpression expression = (VariableDeclarationExpression) initializers.get(0); + List fragments = expression.fragments(); + assertEquals("Wrong size", 1, fragments.size()); + VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0); + assertEquals("Wrong name", "i", fragment.getName().getIdentifier()); + assertTrue("Should be a recovered fragment", isRecovered(expression)); } finally { if (workingCopy != null) workingCopy.discardWorkingCopy(); #P org.eclipse.jdt.core Index: dom/org/eclipse/jdt/core/dom/ASTRecoveryPropagator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTRecoveryPropagator.java,v retrieving revision 1.5 diff -u -r1.5 ASTRecoveryPropagator.java --- dom/org/eclipse/jdt/core/dom/ASTRecoveryPropagator.java 10 Apr 2006 14:02:46 -0000 1.5 +++ dom/org/eclipse/jdt/core/dom/ASTRecoveryPropagator.java 20 Sep 2007 19:10:38 -0000 @@ -359,6 +359,26 @@ } } + public void endVisit(ForStatement node) { + endVisitNode(node); + List initializers = node.initializers(); + if (initializers.size() == 1) { + Expression expression = (Expression) initializers.get(0); + if (expression.getNodeType() == ASTNode.VARIABLE_DECLARATION_EXPRESSION) { + VariableDeclarationExpression variableDeclarationExpression = (VariableDeclarationExpression) expression; + List fragments = variableDeclarationExpression.fragments(); + for (int i = 0, max = fragments.size(); i 0 - && stmts[index - 1] instanceof org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) { - org.eclipse.jdt.internal.compiler.ast.LocalDeclaration local1 = (org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) stmts[index - 1]; - org.eclipse.jdt.internal.compiler.ast.LocalDeclaration local2 = (org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) stmts[index]; - if (local2.name == RecoveryScanner.FAKE_IDENTIFIER) // workaround for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=199668 - return; - if (local1.declarationSourceStart == local2.declarationSourceStart) { - // we have a multiple local declarations - // We retrieve the existing VariableDeclarationStatement to add the new VariableDeclarationFragment - VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) blockStatements.get(blockStatements.size() - 1); - variableDeclarationStatement.fragments().add(convertToVariableDeclarationFragment((org.eclipse.jdt.internal.compiler.ast.LocalDeclaration)stmts[index])); - } else { - // we can create a new FieldDeclaration - blockStatements.add(convertToVariableDeclarationStatement((org.eclipse.jdt.internal.compiler.ast.LocalDeclaration)stmts[index])); - } + && stmts[index - 1] instanceof org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) { + org.eclipse.jdt.internal.compiler.ast.LocalDeclaration local1 = (org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) stmts[index - 1]; + org.eclipse.jdt.internal.compiler.ast.LocalDeclaration local2 = (org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) stmts[index]; + if (local1.declarationSourceStart == local2.declarationSourceStart) { + // we have a multiple local declarations + // We retrieve the existing VariableDeclarationStatement to add the new VariableDeclarationFragment + VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) blockStatements.get(blockStatements.size() - 1); + variableDeclarationStatement.fragments().add(convertToVariableDeclarationFragment((org.eclipse.jdt.internal.compiler.ast.LocalDeclaration)stmts[index])); + } else { + // we can create a new FieldDeclaration + blockStatements.add(convertToVariableDeclarationStatement((org.eclipse.jdt.internal.compiler.ast.LocalDeclaration)stmts[index])); + } } else { // we can create a new FieldDeclaration blockStatements.add(convertToVariableDeclarationStatement((org.eclipse.jdt.internal.compiler.ast.LocalDeclaration)stmts[index])); @@ -1739,16 +1737,11 @@ // we know that we have at least one initialization if (initializations[0] instanceof org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) { org.eclipse.jdt.internal.compiler.ast.LocalDeclaration initialization = (org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) initializations[0]; - if (initialization.name == RecoveryScanner.FAKE_IDENTIFIER) { // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=199668) - return null; - } VariableDeclarationExpression variableDeclarationExpression = convertToVariableDeclarationExpression(initialization); int initializationsLength = initializations.length; for (int i = 1; i < initializationsLength; i++) { initialization = (org.eclipse.jdt.internal.compiler.ast.LocalDeclaration)initializations[i]; - if (initialization.name != RecoveryScanner.FAKE_IDENTIFIER) { // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=199668) - variableDeclarationExpression.fragments().add(convertToVariableDeclarationFragment(initialization)); - } + variableDeclarationExpression.fragments().add(convertToVariableDeclarationFragment(initialization)); } if (initializationsLength != 1) { int start = variableDeclarationExpression.getStartPosition(); @@ -2380,8 +2373,6 @@ } if (statement instanceof org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) { org.eclipse.jdt.internal.compiler.ast.LocalDeclaration localDeclaration = (org.eclipse.jdt.internal.compiler.ast.LocalDeclaration)statement; - if (localDeclaration.name == RecoveryScanner.FAKE_IDENTIFIER) // workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=199668 - return null; return convertToVariableDeclarationStatement(localDeclaration); } if (statement instanceof org.eclipse.jdt.internal.compiler.ast.AssertStatement) {