### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core 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.405 diff -u -r1.405 Parser.java --- compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 22 Jun 2009 14:00:52 -0000 1.405 +++ compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 26 Aug 2009 22:55:39 -0000 @@ -1657,17 +1657,18 @@ int op = this.intStack[this.intPtr--] ; //<--the encoded operator this.expressionPtr -- ; this.expressionLengthPtr -- ; + Expression expression = this.expressionStack[this.expressionPtr+1]; this.expressionStack[this.expressionPtr] = (op != EQUAL ) ? new CompoundAssignment( this.expressionStack[this.expressionPtr] , - this.expressionStack[this.expressionPtr+1], + expression, op, - this.scanner.startPosition - 1) : + expression.sourceEnd): new Assignment( this.expressionStack[this.expressionPtr] , - this.expressionStack[this.expressionPtr+1], - this.scanner.startPosition - 1); + expression, + expression.sourceEnd); if (this.pendingRecoveredType != null) { // Used only in statements recovery. Index: eval/org/eclipse/jdt/internal/eval/CodeSnippetParser.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/eval/org/eclipse/jdt/internal/eval/CodeSnippetParser.java,v retrieving revision 1.67 diff -u -r1.67 CodeSnippetParser.java --- eval/org/eclipse/jdt/internal/eval/CodeSnippetParser.java 7 Mar 2009 01:08:09 -0000 1.67 +++ eval/org/eclipse/jdt/internal/eval/CodeSnippetParser.java 26 Aug 2009 22:55:39 -0000 @@ -325,10 +325,11 @@ finallyBlock.sourceEnd = end; finallyBlock.statements = new Statement[varCount]; for (int i = 0; i < varCount; i++){ + SingleNameReference nameRef = new SingleNameReference(this.evaluationContext.localVariableNames[i], position); finallyBlock.statements[i] = new Assignment( new SingleNameReference(CharOperation.concat(LOCAL_VAR_PREFIX, this.evaluationContext.localVariableNames[i]), position), - new SingleNameReference(this.evaluationContext.localVariableNames[i], position), - (int) position); + nameRef, + nameRef.sourceEnd); } tryStatement.finallyBlock = finallyBlock; #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/dom/ConverterTestSetup.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ConverterTestSetup.java,v retrieving revision 1.61 diff -u -r1.61 ConverterTestSetup.java --- src/org/eclipse/jdt/core/tests/dom/ConverterTestSetup.java 28 Apr 2009 17:46:03 -0000 1.61 +++ src/org/eclipse/jdt/core/tests/dom/ConverterTestSetup.java 26 Aug 2009 22:55:45 -0000 @@ -541,6 +541,13 @@ return (ASTNode) unit.types().get(typeIndex); } + protected void checkSourceRange(int start, int length, String expectedContents, String source) { + assertTrue("length == 0", length != 0); //$NON-NLS-1$ //$NON-NLS-2$ + assertTrue("start == -1", start != -1); //$NON-NLS-1$ + String actualContentsString = source.substring(start, start + length); + assertSourceEquals("Unexpected source", Util.convertToIndependantLineDelimiter(expectedContents), Util.convertToIndependantLineDelimiter(actualContentsString)); + } + protected void checkSourceRange(ASTNode node, String expectedContents, String source) { assertNotNull("The node is null", node); //$NON-NLS-1$ assertTrue("The node(" + node.getClass() + ").getLength() == 0", node.getLength() != 0); //$NON-NLS-1$ //$NON-NLS-2$ Index: src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java,v retrieving revision 1.288 diff -u -r1.288 ASTConverter15Test.java --- src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java 17 Aug 2009 17:45:43 -0000 1.288 +++ src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java 26 Aug 2009 22:55:45 -0000 @@ -47,7 +47,7 @@ } static { -// TESTS_NUMBERS = new int[] { 334 }; +// TESTS_NUMBERS = new int[] { 337 }; // TESTS_RANGE = new int[] { 325, -1 }; // TESTS_NAMES = new String[] {"test0204"}; } @@ -10802,4 +10802,45 @@ IVariableBinding variableBinding = (IVariableBinding) memberValuePair.getValue(); assertEquals("Wrong field", "CLASS", variableBinding.getName()); } + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=287701 + */ + public void test0337() throws JavaModelException { + String contents = + "public class X {\n" + + " void m() {\n" + + " int x= 1 ;\n" + + " int y= - 1 , z=0 ;\n" + + " // Assignment nodes too long:\n" + + " int a= x = 2 ;\n" + + " System.out.print( x=1 );\n" + + " java.util.Arrays.asList( x = 1 /*bla*/ , x= 2\n" + + " // comment \n" + + " );\n" + + " }\n" + + "}\n" + + ""; + this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/); + CompilationUnit unit= (CompilationUnit) buildAST( + contents, + this.workingCopy, + true, + true, + true); + ASTNode node = getASTNode(unit, 0, 0, 2); + checkSourceRange(node, "int a= x = 2 ;", contents); + VariableDeclarationFragment fragment = (VariableDeclarationFragment) ((VariableDeclarationStatement) node).fragments().get(0); + checkSourceRange(fragment, "a= x = 2", contents); + node = getASTNode(unit, 0, 0, 3); + Expression expression = (Expression) ((MethodInvocation) ((ExpressionStatement) node).getExpression()).arguments().get(0); + checkSourceRange(expression, "x=1", contents); + node = getASTNode(unit, 0, 0, 4); + List arguments = ((MethodInvocation) ((ExpressionStatement) node).getExpression()).arguments(); + ASTNode node2 = (ASTNode) arguments.get(0); + checkSourceRange(node2, "x = 1", contents); + checkSourceRange((ASTNode) arguments.get(1), "x= 2", contents); + int extendedLength = unit.getExtendedLength(node2); + int extendedStartPosition = unit.getExtendedStartPosition(node2); + checkSourceRange(extendedStartPosition, extendedLength, "x = 1 /*bla*/", contents); + } } \ No newline at end of file