### 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.346 diff -u -r1.346 Parser.java --- compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 29 Mar 2006 02:47:34 -0000 1.346 +++ compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java 21 Jun 2006 14:30:14 -0000 @@ -1369,7 +1369,7 @@ this.expressionStack[this.expressionPtr], this.expressionStack[this.expressionPtr + 1]); } - exp.sourceEnd = this.endPosition; + exp.sourceEnd = this.endStatementPosition; } protected void consumeArrayCreationExpressionWithInitializer() { // ArrayCreationWithArrayInitializer ::= 'new' PrimitiveType DimWithOrWithOutExprs ArrayInitializer @@ -1392,7 +1392,7 @@ length); arrayAllocation.sourceStart = this.intStack[this.intPtr--]; if (arrayAllocation.initializer == null) { - arrayAllocation.sourceEnd = this.endPosition; + arrayAllocation.sourceEnd = this.endStatementPosition; } else { arrayAllocation.sourceEnd = arrayAllocation.initializer.sourceEnd ; } @@ -1416,7 +1416,7 @@ length); arrayAllocation.sourceStart = this.intStack[this.intPtr--]; if (arrayAllocation.initializer == null) { - arrayAllocation.sourceEnd = this.endPosition; + arrayAllocation.sourceEnd = this.endStatementPosition; } else { arrayAllocation.sourceEnd = arrayAllocation.initializer.sourceEnd ; } #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.96 diff -u -r1.96 ASTConverterTestAST3_2.java --- src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java 8 Jun 2006 13:09:33 -0000 1.96 +++ src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java 21 Jun 2006 14:30:22 -0000 @@ -7801,5 +7801,149 @@ if (workingCopy != null) workingCopy.discardWorkingCopy(); } - } + } + + /** + * http://dev.eclipse.org/bugs/show_bug.cgi?id=147877 + */ + public void test0648() throws JavaModelException { + ICompilationUnit workingCopy = null; + try { + String contents = + "public class X {\n" + + " public void foo(int[] a) {\n" + + " int i = a[0];\n" + + " }\n" + + "}"; + workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/); + ASTNode node = buildAST( + contents, + workingCopy, + false, + true); + assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); + CompilationUnit unit = (CompilationUnit) node; + assertProblemsSize(unit, 0); + node = getASTNode(unit, 0, 0, 0); + assertEquals("Not a vaviable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType()); + VariableDeclarationStatement statement = (VariableDeclarationStatement) node; + List fragments = statement.fragments(); + assertEquals("Wrong size", 1, fragments.size()); + VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0); + Expression expression = fragment.getInitializer(); + assertNotNull("No initializer", expression); + checkSourceRange(expression, "a[0]", contents); + } finally { + if (workingCopy != null) + workingCopy.discardWorkingCopy(); + } + } + + /** + * http://dev.eclipse.org/bugs/show_bug.cgi?id=147877 + */ + public void test0649() throws JavaModelException { + ICompilationUnit workingCopy = null; + try { + String contents = + "public class X {\n" + + " public void foo(int[] a) {\n" + + " int i = a[0\\u005D;\n" + + " }\n" + + "}"; + workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/); + ASTNode node = buildAST( + contents, + workingCopy, + false, + true); + assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); + CompilationUnit unit = (CompilationUnit) node; + assertProblemsSize(unit, 0); + node = getASTNode(unit, 0, 0, 0); + assertEquals("Not a vaviable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType()); + VariableDeclarationStatement statement = (VariableDeclarationStatement) node; + List fragments = statement.fragments(); + assertEquals("Wrong size", 1, fragments.size()); + VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0); + Expression expression = fragment.getInitializer(); + assertNotNull("No initializer", expression); + checkSourceRange(expression, "a[0\\u005D", contents); + } finally { + if (workingCopy != null) + workingCopy.discardWorkingCopy(); + } + } + + /** + * http://dev.eclipse.org/bugs/show_bug.cgi?id=147877 + */ + public void test0650() throws JavaModelException { + ICompilationUnit workingCopy = null; + try { + String contents = + "public class X {\n" + + " public void foo(int[] a) {\n" + + " int[] i = new int[0];\n" + + " }\n" + + "}"; + workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/); + ASTNode node = buildAST( + contents, + workingCopy, + false, + true); + assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); + CompilationUnit unit = (CompilationUnit) node; + assertProblemsSize(unit, 0); + node = getASTNode(unit, 0, 0, 0); + assertEquals("Not a vaviable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType()); + VariableDeclarationStatement statement = (VariableDeclarationStatement) node; + List fragments = statement.fragments(); + assertEquals("Wrong size", 1, fragments.size()); + VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0); + Expression expression = fragment.getInitializer(); + assertNotNull("No initializer", expression); + checkSourceRange(expression, "new int[0]", contents); + } finally { + if (workingCopy != null) + workingCopy.discardWorkingCopy(); + } + } + + /** + * http://dev.eclipse.org/bugs/show_bug.cgi?id=147877 + */ + public void test0651() throws JavaModelException { + ICompilationUnit workingCopy = null; + try { + String contents = + "public class X {\n" + + " public void foo(int[] a) {\n" + + " int[] i = new int[0\\u005D;\n" + + " }\n" + + "}"; + workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/); + ASTNode node = buildAST( + contents, + workingCopy, + false, + true); + assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); + CompilationUnit unit = (CompilationUnit) node; + assertProblemsSize(unit, 0); + node = getASTNode(unit, 0, 0, 0); + assertEquals("Not a vaviable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType()); + VariableDeclarationStatement statement = (VariableDeclarationStatement) node; + List fragments = statement.fragments(); + assertEquals("Wrong size", 1, fragments.size()); + VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0); + Expression expression = fragment.getInitializer(); + assertNotNull("No initializer", expression); + checkSourceRange(expression, "new int[0\\u005D", contents); + } finally { + if (workingCopy != null) + workingCopy.discardWorkingCopy(); + } + } } \ No newline at end of file