### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.model Index: workspace/AttachSourceTests/.classpath =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/workspace/AttachSourceTests/.classpath,v retrieving revision 1.8 diff -u -r1.8 .classpath --- workspace/AttachSourceTests/.classpath 21 Sep 2004 15:57:01 -0000 1.8 +++ workspace/AttachSourceTests/.classpath 20 Oct 2005 19:32:46 -0000 @@ -8,6 +8,7 @@ + Index: src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java,v retrieving revision 1.36 diff -u -r1.36 CompilationUnitTests.java --- src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java 13 Oct 2005 09:07:59 -0000 1.36 +++ src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java 20 Oct 2005 19:32:46 -0000 @@ -82,7 +82,7 @@ // All specified tests which do not belong to the class are skipped... static { // TESTS_PREFIX = "testBug"; -// TESTS_NAMES = new String[] { "testGetChildrenForCategory02" }; +// TESTS_NAMES = new String[] { "test110172" }; // TESTS_NUMBERS = new int[] { 13 }; // TESTS_RANGE = new int[] { 16, -1 }; } @@ -1006,4 +1006,137 @@ deleteFile("/P/src/X.java"); } } +public void test110172() throws CoreException { + try { + String source = + "/**\n" + + " * Class X javadoc \n" + + " */\n" + + "public class X {\n" + + " /**\n" + + " * Javadoc for initializer\n" + + " */\n" + + " static {\n" + + " }\n" + + " \n" + + " /**\n" + + " * Javadoc for field f \n" + + " */\n" + + " public int f;\n" + + " \n" + + " /**\n" + + " * Javadoc for method foo\n" + + " */\n" + + " public void foo(int i, long l, String s) {\n" + + " }\n" + + " \n" + + " /**\n" + + " * Javadoc for member type A\n" + + " */\n" + + " public class A {\n" + + " }\n" + + "\n" + + " /**\n" + + " * Javadoc for constructor X(int)\n" + + " */\n" + + " X(int i) {\n" + + " }\n" + + " \n" + + " /**\n" + + " * Javadoc for f3\n" + + " */\n" + + " /*\n" + + " * Not a javadoc comment\n" + + " */\n" + + " /**\n" + + " * Real javadoc for f3\n" + + " */\n" + + " public String f3;\n" + + " \n" + + " public int f2;\n" + + " \n" + + " public void foo2() {\n" + + " }\n" + + " \n" + + " public class B {\n" + + " }\n" + + "\n" + + " X() {\n" + + " }\n" + + " \n" + + " {\n" + + " }\n" + + "}"; + createFile("/P/src/X.java", source); + IType type = getCompilationUnit("/P/src/X.java").getType("X"); + IJavaElement[] members = type.getChildren(); + final int length = members.length; + assertEquals("Wrong number", 11, length); + for (int i = 0; i < length; i++) { + final IJavaElement element = members[i]; + assertTrue(element instanceof IMember); + final ISourceRange javadocRange = ((IMember) element).getJavadocRange(); + final String elementName = element.getElementName(); + if ("f".equals(elementName)) { + assertNotNull("No javadoc source range", javadocRange); + final int start = javadocRange.getOffset(); + final int end = javadocRange.getLength() + start - 1; + String javadocSource = source.substring(start, end); + assertTrue("Wrong javadoc", javadocSource.indexOf("field f") != -1); + } else if ("foo".equals(elementName)) { + assertNotNull("No javadoc source range", javadocRange); + final int start = javadocRange.getOffset(); + final int end = javadocRange.getLength() + start - 1; + String javadocSource = source.substring(start, end); + assertTrue("Wrong javadoc", javadocSource.indexOf("method foo") != -1); + } else if ("A".equals(elementName)) { + assertNotNull("No javadoc source range", javadocRange); + final int start = javadocRange.getOffset(); + final int end = javadocRange.getLength() + start - 1; + String javadocSource = source.substring(start, end); + assertTrue("Wrong javadoc", javadocSource.indexOf("member type A") != -1); + } else if ("X".equals(elementName)) { + // need treatment for the two constructors + assertTrue("Not an IMethod", element instanceof IMethod); + IMethod method = (IMethod) element; + switch(method.getNumberOfParameters()) { + case 0 : + assertNull("Has a javadoc source range", javadocRange); + break; + case 1: + assertNotNull("No javadoc source range", javadocRange); + final int start = javadocRange.getOffset(); + final int end = javadocRange.getLength() + start - 1; + String javadocSource = source.substring(start, end); + assertTrue("Wrong javadoc", javadocSource.indexOf("constructor") != -1); + } + } else if ("f3".equals(elementName)) { + assertNotNull("No javadoc source range", javadocRange); + final int start = javadocRange.getOffset(); + final int end = javadocRange.getLength() + start - 1; + String javadocSource = source.substring(start, end); + assertTrue("Wrong javadoc", javadocSource.indexOf("Real") != -1); + } else if ("f2".equals(elementName)) { + assertNull("Has a javadoc source range", javadocRange); + } else if ("foo2".equals(elementName)) { + assertNull("Has a javadoc source range", javadocRange); + } else if ("B".equals(elementName)) { + assertNull("Has a javadoc source range", javadocRange); + } else if (element instanceof IInitializer) { + IInitializer initializer = (IInitializer) element; + if (Flags.isStatic(initializer.getFlags())) { + assertNotNull("No javadoc source range", javadocRange); + final int start = javadocRange.getOffset(); + final int end = javadocRange.getLength() + start - 1; + String javadocSource = source.substring(start, end); + assertTrue("Wrong javadoc", javadocSource.indexOf("initializer") != -1); + } else { + assertNull("Has a javadoc source range", javadocRange); + } + } + } + } finally { + deleteFile("/P/src/X.java"); + } +} } Index: src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java,v retrieving revision 1.36 diff -u -r1.36 AttachSourceTests.java --- src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java 8 Jun 2005 09:03:20 -0000 1.36 +++ src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java 20 Oct 2005 19:32:46 -0000 @@ -21,8 +21,6 @@ import org.eclipse.core.runtime.Path; import org.eclipse.jdt.core.*; import org.eclipse.jdt.core.dom.*; -import org.eclipse.jdt.core.dom.AST; -import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.core.JarPackageFragmentRoot; import org.eclipse.jdt.internal.core.util.Util; @@ -34,6 +32,15 @@ * - don't hardcode positions */ public class AttachSourceTests extends ModifyingResourceTests { + static { +// TESTS_NAMES = new String[] { "testRootPath13" }; +// TESTS_NUMBERS = new int[] { 5 }; +// TESTS_RANGE = new int[] { 169, 180 }; + } + + public static Test suite() { + return buildTestSuite(AttachSourceTests.class); + } /** @deprecated using deprecated code */ private static final int AST_INTERNAL_JLS2 = AST.JLS2; @@ -45,9 +52,6 @@ public AttachSourceTests(String name) { super(name); } -public static Test suite() { - return new Suite(AttachSourceTests.class); -} public ASTNode runConversion(IClassFile classFile, boolean resolveBindings) { ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS2); parser.setSource(classFile); @@ -868,5 +872,84 @@ attachSource(root, null, null); // detach source root.close(); } - +/** + * http://bugs.eclipse.org/bugs/show_bug.cgi?id=110172 + */ +public void testRootPath13() throws JavaModelException { + IJavaProject project = this.getJavaProject("/AttachSourceTests"); + IPackageFragmentRoot root = project.getPackageFragmentRoot(this.getFile("/AttachSourceTests/test6.jar")); + assertTrue("Root doesn't exist", root.exists()); + attachSource(root, "/AttachSourceTests/test6src.zip", null); + + try { + // check the javadoc source range in a class file + IClassFile cf = root.getPackageFragment("p1.p2").getClassFile("X.class"); + assertNotNull(cf); + final String source = cf.getSource(); + assertNotNull("No source", source); + IJavaElement[] children = cf.getChildren(); + assertEquals("Wrong number of children", 1, children.length); + IJavaElement element = children[0]; + assertTrue("Not a type", element instanceof IType); + IType type = (IType) element; + IJavaElement[] members = type.getChildren(); + final int length = members.length; + assertEquals("Wrong number", 9, length); + for (int i = 0; i < length; i++) { + element = members[i]; + assertTrue(element instanceof IMember); + final ISourceRange javadocRange = ((IMember) element).getJavadocRange(); + final String elementName = element.getElementName(); + if ("f".equals(elementName)) { + assertNotNull("No javadoc source range", javadocRange); + final int start = javadocRange.getOffset(); + final int end = javadocRange.getLength() + start - 1; + String javadocSource = source.substring(start, end); + assertTrue("Wrong javadoc", javadocSource.indexOf("field f") != -1); + } else if ("foo".equals(elementName)) { + assertNotNull("No javadoc source range", javadocRange); + final int start = javadocRange.getOffset(); + final int end = javadocRange.getLength() + start - 1; + String javadocSource = source.substring(start, end); + assertTrue("Wrong javadoc", javadocSource.indexOf("method foo") != -1); + } else if ("A".equals(elementName)) { + assertNotNull("No javadoc source range", javadocRange); + final int start = javadocRange.getOffset(); + final int end = javadocRange.getLength() + start - 1; + String javadocSource = source.substring(start, end); + assertTrue("Wrong javadoc", javadocSource.indexOf("member type A") != -1); + } else if ("X".equals(elementName)) { + // need treatment for the two constructors + assertTrue("Not an IMethod", element instanceof IMethod); + IMethod method = (IMethod) element; + switch(method.getNumberOfParameters()) { + case 0 : + assertNull("Has a javadoc source range", javadocRange); + break; + case 1: + assertNotNull("No javadoc source range", javadocRange); + final int start = javadocRange.getOffset(); + final int end = javadocRange.getLength() + start - 1; + String javadocSource = source.substring(start, end); + assertTrue("Wrong javadoc", javadocSource.indexOf("constructor") != -1); + } + } else if ("f3".equals(elementName)) { + assertNotNull("No javadoc source range", javadocRange); + final int start = javadocRange.getOffset(); + final int end = javadocRange.getLength() + start - 1; + String javadocSource = source.substring(start, end); + assertTrue("Wrong javadoc", javadocSource.indexOf("Real") != -1); + } else if ("f2".equals(elementName)) { + assertNull("Has a javadoc source range", javadocRange); + } else if ("foo2".equals(elementName)) { + assertNull("Has a javadoc source range", javadocRange); + } else if ("B".equals(elementName)) { + assertNull("Has a javadoc source range", javadocRange); + } + } + } finally { + attachSource(root, null, null); // detach source + root.close(); + } +} } Index: workspace/AttachSourceTests/test6src.zip =================================================================== RCS file: workspace/AttachSourceTests/test6src.zip diff -N workspace/AttachSourceTests/test6src.zip --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ workspace/AttachSourceTests/test6src.zip 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,13 @@ +PK +¨nT3p1/PK +¨nT3p1/p2/PK +¨pT3??Dt… p1/p2/X.java…‘1oƒ0…g?ünLPTT2fJ»uèÐ.¬Žc§n +gÁ%R[õ¿×†‹¨Q%?Nw÷½{<¼Tò¤Áßßùj'r‘—E!r(àÑɾ‡ÞåEQAl–"÷烳 +O¿Ež +D?'^5Ø?m-Yéì—î†a@³ž$62?á?}f°±ÚÁÀ8Š(Ÿµ-?Ù?ìŸgMoPÄt•Ñ Ú¡¿ŠvÛ¸ +¼RgCÕ¯§¾nh7Ý}z +û¥üÈþ*rKCaÛSwVê:ZY'¡ztö¿³MLÉãg$?éW)lÝÒd‹×^´tik!ÅßÁq˜-§< +¾š÷®‰V«™çY “@êù—áùPK +¨nT3íAp1/PK +¨nT3íA!p1/p2/PK +¨pT3??Dt… ¤?Ep1/p2/X.javaPKŸw Index: workspace/AttachSourceTests/test6.jar =================================================================== RCS file: workspace/AttachSourceTests/test6.jar diff -N workspace/AttachSourceTests/test6.jar --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ workspace/AttachSourceTests/test6.jar 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,26 @@ +PK +rqT3 META-INF/þÊPK +qqT3ò C¿^jMETA-INF/MANIFEST.MFóMÌËLK-.Ñ +K-*ÎÌϳR0Ô3àårÌCq,HLÎHUŠ%ÍôLy¹œ‹RKRSt?*AêMôŒâ +,u“ Œ4‚Kó|3“‹ò‹+‹KRs‹<ó’õ4y¹x¹PK +CoT3p1/PK +CoT3p1/p2/PK + qT3‹!Žqp1/p2/X$A.class=?MKÃ@†ßibbÓøU¿õ$ôÐVhT¼)B)BÐC%ôº‰‹Ý’nJ’ +þ,"xðø£ÄÙÊÂ̼³ïì>óû÷ý`€ +Bsq,®‚IgèÂ&lÏÄ›R¡_ƒ§x&“’à”SUt.ØÖÞ®ÇﺜÊR%l¸UZ•w¿»rô"‚=Ê^¤ ¾?ul¬n/j‚°åc +çPiù¸œÇ2q* í0KD‰\]7m@h…+TðÆÙ2Oä½2g20ÜLð µÌG©( +Y¸8"¸õ?†8ãÏ-^ž÷4œ] ÒÄ„Ícu?Àë¡Õ?ÿÄæ«Ï šN±ÃѯjmìV÷{UÜÇAÕ5oâôPK + qT3Žzgåqp1/p2/X$B.class=?MKÃ@†ßIbbÓøU¿½ =´oŠ‡!è¡zÝÄÅn‰IIRÁŸåAþ”8»„²03ïì;»Ïüþ}ÿâăEh-.ÂÅe8íŽ<8„í¹xa&ò—ð1™Ë´&¸õLUÝs¶F?÷šëÉ{^Ïd­R6ܨ\Õ·„ ·rôc‚3.ž¥A€ulì^?n?°` +.çHåòaùšÈòI$™$t¢"Y,J¥uÓt4¡­PÀŸË2•wJ;ÜéPs3Á}žËrœ‰ª’•‡#‚× h„SþÜæåyOMÀÙŒ&&Ôh>«+X|ð…öà웬,ž?™ÑŽŽ?©}t°kî÷LÜÇ?éê7q úPK + qT3êVrœ}™ +p1/p2/X.classuPÉNÂP=?©Rë, ÎÓ5¡š8$BbRBt¡!l ­©­)ÕÿreâÂð£Œç=Š’¨‹;Ÿ{îÉýø|{Pƶ†„€ö¸o>V̶†”Àô½ýl›žíßš—?{§ ˆÍHôª³ÍÀUºþí‘œT’½ (”¬ÆoÈNK Un?©¦ë;O'¼¶;ž#)ƒ®íµìЕuÜLEwn_ ÛŒÅñŠpi­Aã,sìúntJlÉÚiéHbÁ@EJ)©ƒD]úUðv?sWÒfÚe)NÀ°|ß ëžÝï;} +k<_Ú>#ý™†Í‘V?­6@j>.ɘF†Ÿ‡1³ªN1Ó1No°²hi9}¡K`‚>Ã?Ç$ý.áru +Ó€Êfâ9‚9nÈlž$.Ç­í £œ¥w_Qø¡ÖUsƒàMEŸ€¾éÓ1½À"Š1Õž:ñ‡ÂŠ¢0b5CŠÜ÷bUý£á€G†XR~+Œ³ÌV9_§ÉÏnA|PK +rqT3 íAMETA-INF/þÊPK +qqT3ò C¿^j¤?+META-INF/MANIFEST.MFPK +CoT3íA»p1/PK +CoT3íAÜp1/p2/PK + qT3‹!Žq¤?p1/p2/X$A.classPK + qT3Žzgåq¤?@p1/p2/X$B.classPK + qT3êVrœ}™ +¤?p1/p2/X.classPK—'