### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: dom/org/eclipse/jdt/core/dom/ASTConverter.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java,v retrieving revision 1.271 diff -u -r1.271 ASTConverter.java --- dom/org/eclipse/jdt/core/dom/ASTConverter.java 27 Mar 2010 02:26:04 -0000 1.271 +++ dom/org/eclipse/jdt/core/dom/ASTConverter.java 15 Nov 2010 18:03:26 -0000 @@ -926,9 +926,11 @@ Expression lhs = convert(expression.lhs); assignment.setLeftHandSide(lhs); assignment.setOperator(Assignment.Operator.ASSIGN); - assignment.setRightHandSide(convert(expression.expression)); + Expression rightHandSide = convert(expression.expression); + assignment.setRightHandSide(rightHandSide); int start = lhs.getStartPosition(); - assignment.setSourceRange(start, expression.sourceEnd - start + 1); + int end = rightHandSide.getStartPosition() + rightHandSide.getLength() - 1; + assignment.setSourceRange(start, end - start + 1); return assignment; } #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/dom/ASTConverterRecoveryTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterRecoveryTest.java,v retrieving revision 1.16 diff -u -r1.16 ASTConverterRecoveryTest.java --- src/org/eclipse/jdt/core/tests/dom/ASTConverterRecoveryTest.java 17 Jun 2009 06:44:27 -0000 1.16 +++ src/org/eclipse/jdt/core/tests/dom/ASTConverterRecoveryTest.java 15 Nov 2010 18:03:26 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2009 IBM Corporation and others. + * Copyright (c) 2006, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -45,7 +45,7 @@ static { // TESTS_NAMES = new String[] {"test0003"}; -// TESTS_NUMBERS = new int[] { 624 }; +// TESTS_NUMBERS = new int[] { 19 }; } public static Test suite() { return buildModelTestSuite(ASTConverterRecoveryTest.class); @@ -992,4 +992,47 @@ "Syntax error, insert \") Statement\" to complete BlockStatements\n", result); } + public void test0019() throws JavaModelException { + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/Converter/src/test/X.java", + "package test;\n"+ + "public class X {\n"+ + " void foo() {\n" + + " field= new Object() {hash};\n" + + " }\n" + + "}\n"); + + char[] source = this.workingCopies[0].getSource().toCharArray(); + ASTNode result = runConversion(AST.JLS3, this.workingCopies[0], true, true); + + assertASTNodeEquals( + "package test;\n" + + "public class X {\n" + + " void foo(){\n" + + " field=new Object(){\n" + + " }\n" + + ";\n" + + " }\n" + + "}\n", + result); + + ASTNode node = getASTNode((CompilationUnit) result, 0, 0); + assertNotNull(node); + assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$ + MethodDeclaration methodDeclaration = (MethodDeclaration) node; + Block block = methodDeclaration.getBody(); + List statements = block.statements(); + assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$ + Statement statement = (Statement) statements.get(0); + assertTrue("Not an expression statement", statement.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$ + ExpressionStatement expressionStatement = (ExpressionStatement) statement; + checkSourceRange(expressionStatement, "field= new Object() {hash};", source); //$NON-NLS-1$ + Expression expression = expressionStatement.getExpression(); + assertTrue("Not an assignment", expression.getNodeType() == ASTNode.ASSIGNMENT); //$NON-NLS-1$ + Assignment assignment = (Assignment) expression; + Expression anonymousClassDeclaration = assignment.getRightHandSide(); + checkSourceRange(anonymousClassDeclaration, "new Object() {hash}", source); //$NON-NLS-1$ + checkSourceRange(assignment, "field= new Object() {hash}", source); //$NON-NLS-1$ + } }