### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: dom/org/eclipse/jdt/core/dom/DefaultASTVisitor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/DefaultASTVisitor.java,v retrieving revision 1.4 diff -u -r1.4 DefaultASTVisitor.java --- dom/org/eclipse/jdt/core/dom/DefaultASTVisitor.java 29 Mar 2006 02:54:51 -0000 1.4 +++ dom/org/eclipse/jdt/core/dom/DefaultASTVisitor.java 24 Nov 2006 11:08:17 -0000 @@ -95,6 +95,12 @@ public boolean visit(EmptyStatement node) { return visitNode(node); } + public boolean visit(EnumConstantDeclaration node) { + return visitNode(node); + } + public boolean visit(EnumDeclaration node) { + return visitNode(node); + } public boolean visit(ExpressionStatement node) { return visitNode(node); } @@ -309,6 +315,12 @@ public void endVisit(EmptyStatement node) { endVisitNode(node); } + public void endVisit(EnumConstantDeclaration node) { + endVisitNode(node); + } + public void endVisit(EnumDeclaration node) { + endVisitNode(node); + } public void endVisit(ExpressionStatement node) { endVisitNode(node); } #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest.java,v retrieving revision 1.74 diff -u -r1.74 ASTConverterJavadocTest.java --- src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest.java 17 Nov 2006 16:11:16 -0000 1.74 +++ src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest.java 24 Nov 2006 11:08:19 -0000 @@ -114,7 +114,7 @@ // Run test cases subset COPY_DIR = false; System.err.println("WARNING: only subset of tests will be executed!!!"); - suite.addTest(new ASTConverterJavadocTest("testBug70892_JLS3")); + suite.addTest(new ASTConverterJavadocTest("testBug165525")); return suite; } @@ -3415,4 +3415,61 @@ assertEquals("Comment should be javadoc", comment.getNodeType(), ASTNode.JAVADOC); } } + + /** + * @bug 165525: [comments] ASTParser excludes trailing line comments from extended range of fields in enums + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=165525" + */ + public void testBug165525() throws JavaModelException { + workingCopies = new ICompilationUnit[1]; + workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b165525/Test.java", + "package javadoc.b165525;\n" + + "public enum Test {\n" + + " ENUM_CONST_1(\"String constant 1\") //$NON-NLS-1$\n" + + " , ENUM_CONST_2(\"String constant 2\") //$NON-NLS-1$\n" + + " ;\n" + + " Test(String x) {\n" + + " }\n" + + " String a = \"a\"; //$NON-NLS-1$\n" + + " String b = \"b\"; //$NON-NLS-1$\n" + + "}\n" + ); + System.out.println(workingCopies[0].getSource()); + CompilationUnit compilUnit = (CompilationUnit) runConversion(AST.JLS3, workingCopies[0], true); + verifyWorkingCopiesComments(); + if (docCommentSupport.equals(JavaCore.ENABLED)) { + // Verify comment type + List unitComments = compilUnit.getCommentList(); + assertEquals("Wrong number of comments", 4, unitComments.size()); + + // Verify extension of first enum declaration constant + Comment comment = (Comment) unitComments.get(0); + EnumDeclaration enumDeclaration = (EnumDeclaration) compilUnit.types().get(0); + EnumConstantDeclaration constantDeclaration = (EnumConstantDeclaration) enumDeclaration.enumConstants().get(0); + int declarationEnd = constantDeclaration.getStartPosition() + compilUnit.getExtendedLength(constantDeclaration) - 1; + int commentEnd = comment.getStartPosition() + comment.getLength() - 1; + assumeEquals("Enum constant declaration "+constantDeclaration+" does not have the correct length", commentEnd, declarationEnd); + + // Verify extension of second enum declaration constant + comment = (Comment) unitComments.get(1); + constantDeclaration = (EnumConstantDeclaration) enumDeclaration.enumConstants().get(1); + declarationEnd = constantDeclaration.getStartPosition() + compilUnit.getExtendedLength(constantDeclaration) - 1; + commentEnd = comment.getStartPosition() + comment.getLength() - 1; + assumeEquals("Enum constant declaration "+constantDeclaration+" does not have the correct length", commentEnd, declarationEnd); + + // Verify extension of first field declaration + comment = (Comment) unitComments.get(2); + FieldDeclaration fieldDeclaration = (FieldDeclaration) enumDeclaration.bodyDeclarations().get(1); + declarationEnd = fieldDeclaration.getStartPosition() + compilUnit.getExtendedLength(fieldDeclaration) - 1; + commentEnd = comment.getStartPosition() + comment.getLength() - 1; + assumeEquals("Enum constant declaration "+constantDeclaration+" does not have the correct length", commentEnd, declarationEnd); + + // Verify extension of second field declaration + comment = (Comment) unitComments.get(3); + fieldDeclaration = (FieldDeclaration) enumDeclaration.bodyDeclarations().get(2); + declarationEnd = fieldDeclaration.getStartPosition() + compilUnit.getExtendedLength(fieldDeclaration) - 1; + commentEnd = comment.getStartPosition() + comment.getLength() - 1; + assumeEquals("Enum constant declaration "+constantDeclaration+" does not have the correct length", commentEnd, declarationEnd); + } + } }