View | Details | Raw Unified | Return to bug 110172 | Differences between
and this patch

Collapse All | Expand All

(-)workspace/AttachSourceTests/.classpath (+1 lines)
Lines 8-13 Link Here
8
    <classpathentry kind="lib" path="test2.jar"/>    
8
    <classpathentry kind="lib" path="test2.jar"/>    
9
    <classpathentry kind="lib" path="test4.jar"/>    
9
    <classpathentry kind="lib" path="test4.jar"/>    
10
    <classpathentry kind="lib" path="test5.jar"/>    
10
    <classpathentry kind="lib" path="test5.jar"/>    
11
    <classpathentry kind="lib" path="test6.jar"/>
11
    <classpathentry kind="lib" path="lib"/>
12
    <classpathentry kind="lib" path="lib"/>
12
    <classpathentry kind="src" path="src" output="src"/>
13
    <classpathentry kind="src" path="src" output="src"/>
13
    <classpathentry kind="var" path="JCL_LIB"/>
14
    <classpathentry kind="var" path="JCL_LIB"/>
(-)src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java (-1 / +134 lines)
Lines 82-88 Link Here
82
// All specified tests which do not belong to the class are skipped...
82
// All specified tests which do not belong to the class are skipped...
83
static {
83
static {
84
//	TESTS_PREFIX = "testBug";
84
//	TESTS_PREFIX = "testBug";
85
//	TESTS_NAMES = new String[] { "testGetChildrenForCategory02" };
85
//	TESTS_NAMES = new String[] { "test110172" };
86
//	TESTS_NUMBERS = new int[] { 13 };
86
//	TESTS_NUMBERS = new int[] { 13 };
87
//	TESTS_RANGE = new int[] { 16, -1 };
87
//	TESTS_RANGE = new int[] { 16, -1 };
88
}
88
}
Lines 1006-1009 Link Here
1006
		deleteFile("/P/src/X.java");
1006
		deleteFile("/P/src/X.java");
1007
	}
1007
	}
1008
}
1008
}
1009
public void test110172() throws CoreException {
1010
	try {
1011
		String source =
1012
			"/**\n" +
1013
			" * Class X javadoc \n" +
1014
			" */\n" +
1015
			"public class X {\n" +
1016
			"	/**\n" +
1017
			"	 * Javadoc for initializer\n" +
1018
			"	 */\n" +
1019
			"	static {\n" +
1020
			"	}\n" +
1021
			"	\n" +
1022
			"	 /**\n" +
1023
			"	  * Javadoc for field f \n" +
1024
			"	  */\n" +
1025
			"	public int f;\n" +
1026
			"	\n" +
1027
			"	/**\n" +
1028
			"	 * Javadoc for method foo\n" +
1029
			"	 */\n" +
1030
			"	public void foo(int i, long l, String s) {\n" +
1031
			"	}\n" +
1032
			"	\n" +
1033
			"	/**\n" +
1034
			"	 * Javadoc for member type A\n" +
1035
			"	 */\n" +
1036
			"	public class A {\n" +
1037
			"	}\n" +
1038
			"\n" +
1039
			"	/**\n" +
1040
			"	 * Javadoc for constructor X(int)\n" +
1041
			"	 */\n" +
1042
			"	X(int i) {\n" +
1043
			"	}\n" +
1044
			"	\n" +
1045
			"	/**\n" +
1046
			"	 * Javadoc for f3\n" +
1047
			"	 */\n" +
1048
			"	/*\n" +
1049
			"	 * Not a javadoc comment\n" +
1050
			"	 */\n" +
1051
			"	/**\n" +
1052
			"	 * Real javadoc for f3\n" +
1053
			"	 */\n" +
1054
			"	public String f3;\n" +
1055
			"	\n" +
1056
			"	public int f2;\n" +
1057
			"	\n" +
1058
			"	public void foo2() {\n" +
1059
			"	}\n" +
1060
			"	\n" +
1061
			"	public class B {\n" +
1062
			"	}\n" +
1063
			"\n" +
1064
			"	X() {\n" +
1065
			"	}\n" +
1066
			"	\n" +
1067
			"	{\n" +
1068
			"	}\n" +
1069
			"}";
1070
		createFile("/P/src/X.java", source);
1071
		IType type = getCompilationUnit("/P/src/X.java").getType("X");
1072
		IJavaElement[] members = type.getChildren();
1073
		final int length = members.length;
1074
		assertEquals("Wrong number", 11, length);
1075
		for (int i = 0; i < length; i++) {
1076
			final IJavaElement element = members[i];
1077
			assertTrue(element instanceof IMember);
1078
			final ISourceRange javadocRange = ((IMember) element).getJavadocRange();
1079
			final String elementName = element.getElementName();
1080
			if ("f".equals(elementName)) {
1081
				assertNotNull("No javadoc source range", javadocRange);
1082
				final int start = javadocRange.getOffset();
1083
				final int end = javadocRange.getLength() + start - 1;
1084
				String javadocSource = source.substring(start, end);
1085
				assertTrue("Wrong javadoc", javadocSource.indexOf("field f") != -1);
1086
			} else if ("foo".equals(elementName)) {
1087
				assertNotNull("No javadoc source range", javadocRange);
1088
				final int start = javadocRange.getOffset();
1089
				final int end = javadocRange.getLength() + start - 1;
1090
				String javadocSource = source.substring(start, end);
1091
				assertTrue("Wrong javadoc", javadocSource.indexOf("method foo") != -1);
1092
			} else if ("A".equals(elementName)) {
1093
				assertNotNull("No javadoc source range", javadocRange);
1094
				final int start = javadocRange.getOffset();
1095
				final int end = javadocRange.getLength() + start - 1;
1096
				String javadocSource = source.substring(start, end);
1097
				assertTrue("Wrong javadoc", javadocSource.indexOf("member type A") != -1);
1098
			} else if ("X".equals(elementName)) {
1099
				// need treatment for the two constructors
1100
				assertTrue("Not an IMethod", element instanceof IMethod);
1101
				IMethod method = (IMethod) element;
1102
				switch(method.getNumberOfParameters()) {
1103
					case 0 :
1104
						assertNull("Has a javadoc source range", javadocRange);
1105
						break;
1106
					case 1:
1107
						assertNotNull("No javadoc source range", javadocRange);
1108
						final int start = javadocRange.getOffset();
1109
						final int end = javadocRange.getLength() + start - 1;
1110
						String javadocSource = source.substring(start, end);
1111
						assertTrue("Wrong javadoc", javadocSource.indexOf("constructor") != -1);
1112
				}
1113
			} else if ("f3".equals(elementName)) {
1114
				assertNotNull("No javadoc source range", javadocRange);
1115
				final int start = javadocRange.getOffset();
1116
				final int end = javadocRange.getLength() + start - 1;
1117
				String javadocSource = source.substring(start, end);
1118
				assertTrue("Wrong javadoc", javadocSource.indexOf("Real") != -1);
1119
			} else if ("f2".equals(elementName)) {
1120
				assertNull("Has a javadoc source range", javadocRange);
1121
			} else if ("foo2".equals(elementName)) {
1122
				assertNull("Has a javadoc source range", javadocRange);
1123
			} else if ("B".equals(elementName)) {
1124
				assertNull("Has a javadoc source range", javadocRange);
1125
			} else if (element instanceof IInitializer) {
1126
				IInitializer initializer = (IInitializer) element;
1127
				if (Flags.isStatic(initializer.getFlags())) {
1128
					assertNotNull("No javadoc source range", javadocRange);
1129
					final int start = javadocRange.getOffset();
1130
					final int end = javadocRange.getLength() + start - 1;
1131
					String javadocSource = source.substring(start, end);
1132
					assertTrue("Wrong javadoc", javadocSource.indexOf("initializer") != -1);
1133
				} else {
1134
					assertNull("Has a javadoc source range", javadocRange);
1135
				}
1136
			}
1137
		}
1138
	} finally {
1139
		deleteFile("/P/src/X.java");
1140
	}
1141
}
1009
}
1142
}
(-)src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java (-6 / +89 lines)
Lines 21-28 Link Here
21
import org.eclipse.core.runtime.Path;
21
import org.eclipse.core.runtime.Path;
22
import org.eclipse.jdt.core.*;
22
import org.eclipse.jdt.core.*;
23
import org.eclipse.jdt.core.dom.*;
23
import org.eclipse.jdt.core.dom.*;
24
import org.eclipse.jdt.core.dom.AST;
25
import org.eclipse.jdt.core.dom.ASTNode;
26
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
24
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
27
import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
25
import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
28
import org.eclipse.jdt.internal.core.util.Util;
26
import org.eclipse.jdt.internal.core.util.Util;
Lines 34-39 Link Here
34
 * - don't hardcode positions
32
 * - don't hardcode positions
35
*/
33
*/
36
public class AttachSourceTests extends ModifyingResourceTests {
34
public class AttachSourceTests extends ModifyingResourceTests {
35
	static {
36
//		TESTS_NAMES = new String[] { "testRootPath13" };
37
//		TESTS_NUMBERS = new int[] { 5 };
38
//		TESTS_RANGE = new int[] { 169, 180 };
39
	}
40
41
	public static Test suite() {
42
		return buildTestSuite(AttachSourceTests.class);
43
	}
37
44
38
	/** @deprecated using deprecated code */
45
	/** @deprecated using deprecated code */
39
	private static final int AST_INTERNAL_JLS2 = AST.JLS2;
46
	private static final int AST_INTERNAL_JLS2 = AST.JLS2;
Lines 45-53 Link Here
45
public AttachSourceTests(String name) {
52
public AttachSourceTests(String name) {
46
	super(name);
53
	super(name);
47
}
54
}
48
public static Test suite() {
49
	return new Suite(AttachSourceTests.class);
50
}
51
public ASTNode runConversion(IClassFile classFile, boolean resolveBindings) {
55
public ASTNode runConversion(IClassFile classFile, boolean resolveBindings) {
52
	ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS2);
56
	ASTParser parser = ASTParser.newParser(AST_INTERNAL_JLS2);
53
	parser.setSource(classFile);
57
	parser.setSource(classFile);
Lines 868-872 Link Here
868
	attachSource(root, null, null); // detach source
872
	attachSource(root, null, null); // detach source
869
	root.close();
873
	root.close();
870
}
874
}
871
875
/**
876
 * http://bugs.eclipse.org/bugs/show_bug.cgi?id=110172
877
 */
878
public void testRootPath13() throws JavaModelException {
879
	IJavaProject project = this.getJavaProject("/AttachSourceTests");
880
	IPackageFragmentRoot root = project.getPackageFragmentRoot(this.getFile("/AttachSourceTests/test6.jar"));
881
	assertTrue("Root doesn't exist", root.exists());
882
	attachSource(root, "/AttachSourceTests/test6src.zip", null);
883
	
884
	try {
885
		// check the javadoc source range in a class file
886
		IClassFile cf = root.getPackageFragment("p1.p2").getClassFile("X.class");
887
		assertNotNull(cf);
888
		final String source = cf.getSource();
889
		assertNotNull("No source", source);
890
		IJavaElement[] children = cf.getChildren();
891
		assertEquals("Wrong number of children", 1, children.length);
892
		IJavaElement element = children[0];
893
		assertTrue("Not a type", element instanceof IType);
894
		IType type = (IType) element;
895
		IJavaElement[] members = type.getChildren();
896
		final int length = members.length;
897
		assertEquals("Wrong number", 9, length);
898
		for (int i = 0; i < length; i++) {
899
			element = members[i];
900
			assertTrue(element instanceof IMember);
901
			final ISourceRange javadocRange = ((IMember) element).getJavadocRange();
902
			final String elementName = element.getElementName();
903
			if ("f".equals(elementName)) {
904
				assertNotNull("No javadoc source range", javadocRange);
905
				final int start = javadocRange.getOffset();
906
				final int end = javadocRange.getLength() + start - 1;
907
				String javadocSource = source.substring(start, end);
908
				assertTrue("Wrong javadoc", javadocSource.indexOf("field f") != -1);
909
			} else if ("foo".equals(elementName)) {
910
				assertNotNull("No javadoc source range", javadocRange);
911
				final int start = javadocRange.getOffset();
912
				final int end = javadocRange.getLength() + start - 1;
913
				String javadocSource = source.substring(start, end);
914
				assertTrue("Wrong javadoc", javadocSource.indexOf("method foo") != -1);
915
			} else if ("A".equals(elementName)) {
916
				assertNotNull("No javadoc source range", javadocRange);
917
				final int start = javadocRange.getOffset();
918
				final int end = javadocRange.getLength() + start - 1;
919
				String javadocSource = source.substring(start, end);
920
				assertTrue("Wrong javadoc", javadocSource.indexOf("member type A") != -1);
921
			} else if ("X".equals(elementName)) {
922
				// need treatment for the two constructors
923
				assertTrue("Not an IMethod", element instanceof IMethod);
924
				IMethod method = (IMethod) element;
925
				switch(method.getNumberOfParameters()) {
926
					case 0 :
927
						assertNull("Has a javadoc source range", javadocRange);
928
						break;
929
					case 1:
930
						assertNotNull("No javadoc source range", javadocRange);
931
						final int start = javadocRange.getOffset();
932
						final int end = javadocRange.getLength() + start - 1;
933
						String javadocSource = source.substring(start, end);
934
						assertTrue("Wrong javadoc", javadocSource.indexOf("constructor") != -1);
935
				}
936
			} else if ("f3".equals(elementName)) {
937
				assertNotNull("No javadoc source range", javadocRange);
938
				final int start = javadocRange.getOffset();
939
				final int end = javadocRange.getLength() + start - 1;
940
				String javadocSource = source.substring(start, end);
941
				assertTrue("Wrong javadoc", javadocSource.indexOf("Real") != -1);
942
			} else if ("f2".equals(elementName)) {
943
				assertNull("Has a javadoc source range", javadocRange);
944
			} else if ("foo2".equals(elementName)) {
945
				assertNull("Has a javadoc source range", javadocRange);
946
			} else if ("B".equals(elementName)) {
947
				assertNull("Has a javadoc source range", javadocRange);
948
			}
949
		}
950
	} finally {
951
		attachSource(root, null, null); // detach source
952
		root.close();
953
	}
954
}
872
}
955
}
(-)workspace/AttachSourceTests/test6src.zip (+13 lines)
Added Link Here
1
PK
2
¨nT3p1/PK
3
¨nT3p1/p2/PK
4
¨pT3??Dt…p1/p2/X.java…‘1oƒ0…g?ünLPTT2fJ»uèÐ.¬Žc§n
5
gÁ%R[õ¿×†‹¨Q%?Nw÷½{<¼Tò¤Áßßùj'r‘—E!r(àÑɾ‡ÞåEQAl–"÷烳
6
O¿Ež
7
D?'^5Ø?m-Yéì—î†a@³ž$62?á?}f°±ÚÁÀ8Š(Ÿµ-?Ù?ìŸgMoPÄt•ÑÚ¡¿ŠvÛ¸
8
¼RgCÕ¯§¾nh7Ý}z
9
û¥üÈþ*rKCaÛSwVê:ZY'¡ztö¿³MLÉãg$?éW)lÝÒd‹×^´tik!ÅßÁq˜-§<
10
¾š÷®‰V«™çY “@êù—áùPK
11
¨nT3íAp1/PK
12
¨nT3íA!p1/p2/PK
13
¨pT3??Dt…¤?Ep1/p2/X.javaPKŸw
(-)workspace/AttachSourceTests/test6.jar (+26 lines)
Added Link Here
1
PK
2
rqT3	META-INF/þÊPK
3
qqT3òC¿^jMETA-INF/MANIFEST.MFóMÌËLK-.Ñ
4
K-*ÎÌϳR0Ô3àårÌCq,HLÎHUŠ%ÍôLy¹œ‹RKRSt?*AêMôŒâ
5
,u“Œ4‚Kó|3“‹ò‹+‹KRs‹<ó’õ4y¹x¹PK
6
CoT3p1/PK
7
CoT3p1/p2/PK
8
qT3‹!Žqp1/p2/X$A.class=?MKÃ@†ßibbÓøU¿õ$ôÐVhT¼)B)BÐC%ôº‰‹Ý’nJ’
9
þ,"xðø£ÄÙÊÂ̼³ïì>óû÷ý`€
10
Bsq,®‚IgèÂ&lÏěR¡_ƒ§x&“’à”SUt.ØÖÞ®ÇﺜÊR%l¸UZ•w¿»rô"‚=Ê^¤¾?ul¬n/j‚°åc
11
çPiù¸œÇ2q*	í0KD‰\]7m@h…+TðÆÙ2Oä½2g20ÜLð µÌG©(
12
Y¸8"¸õ?†8ãÏ-^ž÷4œ] ÒĄÍcu?Àë¡Õ?ÿÄæ«Ï šN±ÃѯjmìV÷{UÜÇAÕ5oâôPK
13
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?°`
14
.çHåòaùšÈòI$™$t¢"Y,J¥uÓt4¡­PÀŸË2•wJ;ÜéPs3Á}žËrœ‰ª’•‡#‚×h„SþÜæåyOMÀٌ&&Ôh>«+X|ð…öà웬,ž?™ÑŽŽ?©}t°kî÷LÜÇ?éê7qúPK
15
qT3êVrœ}™
16
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À°|ß	ëžÝï;}
17
k<_Ú>#ý™†Í‘V?­6@j>.ɘF†Ÿ‡1³ªN1Ó1No°²hi9}¡K`‚>Ã?Ç$ý.áru
18
ӀÊfâ9‚9nÈlž$.Ç­í	£œ¥w_Qø¡ÖUsƒàMEŸ€¾éÓ1½À"Š1՞:ñ‡ÂŠ¢0b5CŠÜ÷bUý£á€G†XR~+Œ³ÌV9_§ÉÏnA|PK
19
rqT3	íAMETA-INF/þÊPK
20
qqT3òC¿^j¤?+META-INF/MANIFEST.MFPK
21
CoT3íA»p1/PK
22
CoT3íAÜp1/p2/PK
23
qT3‹!Žq¤?p1/p2/X$A.classPK
24
qT3Žzgåq¤?@p1/p2/X$B.classPK
25
qT3êVrœ}™
26
¤?p1/p2/X.classPK—'

Return to bug 110172