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

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/ClassFileInfo.java (-6 / +25 lines)
Lines 244-255 Link Here
244
		// TODO (jerome) filter out synthetic members
244
		// TODO (jerome) filter out synthetic members
245
		//                        indexer should not index them as well
245
		//                        indexer should not index them as well
246
		// if ((methodInfo.getModifiers() & IConstants.AccSynthetic) != 0) continue; // skip synthetic
246
		// if ((methodInfo.getModifiers() & IConstants.AccSynthetic) != 0) continue; // skip synthetic
247
		boolean useGenericSignature = true;
247
		char[] signature = methodInfo.getGenericSignature();
248
		char[] signature = methodInfo.getGenericSignature();
248
		if (signature == null) signature = methodInfo.getMethodDescriptor();
249
		if (signature == null) {
250
			useGenericSignature = false;
251
			signature = methodInfo.getMethodDescriptor();
252
		}
253
		String selector = new String(methodInfo.getSelector());
254
		final boolean isConstructor = methodInfo.isConstructor();
255
		if (isConstructor) {
256
			selector = type.getElementName();
257
		}
249
		String[] pNames = null;
258
		String[] pNames = null;
250
		try {
259
		try {
251
			pNames = Signature.getParameterTypes(new String(signature));
260
			pNames = Signature.getParameterTypes(new String(signature));
252
		} catch (IllegalArgumentException e) {
261
			if (isConstructor
262
					&& useGenericSignature
263
					&& type.isMember()
264
					&& !Flags.isStatic(type.getFlags())) {
265
				int length = pNames.length;
266
				System.arraycopy(pNames, 0, (pNames = new String[length + 1]), 1, length);
267
				char[] descriptor = methodInfo.getMethodDescriptor();
268
				final String[] parameterTypes = Signature.getParameterTypes(new String(descriptor));
269
				pNames[0] = parameterTypes[0];
270
			}
271
		}catch (IllegalArgumentException e) {
272
			// protect against malformed .class file (e.g. com/sun/crypto/provider/SunJCE_b.class has a 'a' generic signature)
273
			signature = methodInfo.getMethodDescriptor();
274
			pNames = Signature.getParameterTypes(new String(signature));
275
		} catch (JavaModelException e) {
253
			// protect against malformed .class file (e.g. com/sun/crypto/provider/SunJCE_b.class has a 'a' generic signature)
276
			// protect against malformed .class file (e.g. com/sun/crypto/provider/SunJCE_b.class has a 'a' generic signature)
254
			signature = methodInfo.getMethodDescriptor();
277
			signature = methodInfo.getMethodDescriptor();
255
			pNames = Signature.getParameterTypes(new String(signature));
278
			pNames = Signature.getParameterTypes(new String(signature));
Lines 260-269 Link Here
260
		}
283
		}
261
		char[][] parameterTypes = ClassFile.translatedNames(paramNames);
284
		char[][] parameterTypes = ClassFile.translatedNames(paramNames);
262
		JavaModelManager manager = JavaModelManager.getJavaModelManager();
285
		JavaModelManager manager = JavaModelManager.getJavaModelManager();
263
		String selector = new String(methodInfo.getSelector());
264
		if (methodInfo.isConstructor()) {
265
			selector =type.getElementName();
266
		}
267
		selector =  manager.intern(selector);
286
		selector =  manager.intern(selector);
268
		for (int j= 0; j < pNames.length; j++) {
287
		for (int j= 0; j < pNames.length; j++) {
269
			pNames[j]= manager.intern(new String(parameterTypes[j]));
288
			pNames[j]= manager.intern(new String(parameterTypes[j]));
(-)src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java (-11 / +41 lines)
Lines 36-42 Link Here
36
*/
36
*/
37
public class AttachSourceTests extends ModifyingResourceTests {
37
public class AttachSourceTests extends ModifyingResourceTests {
38
	static {
38
	static {
39
//		TESTS_NAMES = new String[] { "testClassFileBuffer" };
39
//		TESTS_NAMES = new String[] { "testConstructorAccess" };
40
//		TESTS_NUMBERS = new int[] { 5 };
40
//		TESTS_NUMBERS = new int[] { 5 };
41
//		TESTS_RANGE = new int[] { 169, 180 };
41
//		TESTS_RANGE = new int[] { 169, 180 };
42
	}
42
	}
Lines 127-132 Link Here
127
		"  }\n" +
127
		"  }\n" +
128
		"}\n" +
128
		"}\n" +
129
		"class AType<E> {\n" + // type name containing character 'T'
129
		"class AType<E> {\n" + // type name containing character 'T'
130
		"}",
131
		"Container.java",
132
		"public class Container {\n" + 
133
		"	class Inner<S> {\n" + 
134
		"		Inner(String st, Class<S> s) {\n" + 
135
		"			super();\n" + 
136
		"		}\n" + 
137
		"	}\n" + 
130
		"}"
138
		"}"
131
	};
139
	};
132
	addLibrary("generic.jar", "genericsrc.zip", pathAndContents, JavaCore.VERSION_1_5);
140
	addLibrary("generic.jar", "genericsrc.zip", pathAndContents, JavaCore.VERSION_1_5);
Lines 951-957 Link Here
951
}
959
}
952
960
953
/*
961
/*
954
 * Ensures that having a project as source attachement finds the source
962
 * Ensures that having a project as source attachment finds the source
955
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=65186)
963
 * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=65186)
956
 */
964
 */
957
public void testProjectAsSourceAttachment() throws CoreException {
965
public void testProjectAsSourceAttachment() throws CoreException {
Lines 1062-1068 Link Here
1062
	root.close();
1070
	root.close();
1063
}
1071
}
1064
/**
1072
/**
1065
 * Attach a jar with a source attachement that doesn't contain the source folders
1073
 * Attach a jar with a source attachment that doesn't contain the source folders
1066
 */
1074
 */
1067
public void testRootPath4() throws JavaModelException {
1075
public void testRootPath4() throws JavaModelException {
1068
	IJavaProject project = getJavaProject("/AttachSourceTests");
1076
	IJavaProject project = getJavaProject("/AttachSourceTests");
Lines 1079-1085 Link Here
1079
	root.close();
1087
	root.close();
1080
}
1088
}
1081
/**
1089
/**
1082
 * Attach a jar with a source attachement that doesn't contain the source folders
1090
 * Attach a jar with a source attachment that doesn't contain the source folders
1083
 */
1091
 */
1084
public void testRootPath5() throws JavaModelException {
1092
public void testRootPath5() throws JavaModelException {
1085
	IJavaProject project = getJavaProject("/AttachSourceTests");
1093
	IJavaProject project = getJavaProject("/AttachSourceTests");
Lines 1104-1110 Link Here
1104
	root.close();
1112
	root.close();
1105
}
1113
}
1106
/**
1114
/**
1107
 * Attach a jar with a source attachement that doesn't contain the source folders
1115
 * Attach a jar with a source attachment that doesn't contain the source folders
1108
 */
1116
 */
1109
public void testRootPath6() throws JavaModelException {
1117
public void testRootPath6() throws JavaModelException {
1110
	IJavaProject project = getJavaProject("/AttachSourceTests");
1118
	IJavaProject project = getJavaProject("/AttachSourceTests");
Lines 1129-1135 Link Here
1129
	root.close();
1137
	root.close();
1130
}
1138
}
1131
/**
1139
/**
1132
 * Attach a jar with a source attachement that doesn't contain the source folders
1140
 * Attach a jar with a source attachment that doesn't contain the source folders
1133
 */
1141
 */
1134
public void testRootPath7() throws JavaModelException {
1142
public void testRootPath7() throws JavaModelException {
1135
	IJavaProject project = getJavaProject("/AttachSourceTests");
1143
	IJavaProject project = getJavaProject("/AttachSourceTests");
Lines 1162-1168 Link Here
1162
	root.close();
1170
	root.close();
1163
}
1171
}
1164
/**
1172
/**
1165
 * Attach a jar with a source attachement that contains the source folders
1173
 * Attach a jar with a source attachment that contains the source folders
1166
 */
1174
 */
1167
public void testRootPath8() throws JavaModelException {
1175
public void testRootPath8() throws JavaModelException {
1168
	IJavaProject project = getJavaProject("/AttachSourceTests");
1176
	IJavaProject project = getJavaProject("/AttachSourceTests");
Lines 1195-1201 Link Here
1195
	root.close();
1203
	root.close();
1196
}
1204
}
1197
/**
1205
/**
1198
 * Attach a jar with a source attachement that contains the source folders
1206
 * Attach a jar with a source attachment that contains the source folders
1199
 */
1207
 */
1200
public void testRootPath9() throws JavaModelException {
1208
public void testRootPath9() throws JavaModelException {
1201
	IJavaProject project = getJavaProject("/AttachSourceTests");
1209
	IJavaProject project = getJavaProject("/AttachSourceTests");
Lines 1228-1234 Link Here
1228
	root.close();
1236
	root.close();
1229
}
1237
}
1230
/**
1238
/**
1231
 * Attach a jar with a source attachement that is itself
1239
 * Attach a jar with a source attachment that is itself
1232
 */
1240
 */
1233
public void testRootPath10() throws JavaModelException {
1241
public void testRootPath10() throws JavaModelException {
1234
	IJavaProject project = getJavaProject("/AttachSourceTests");
1242
	IJavaProject project = getJavaProject("/AttachSourceTests");
Lines 1279-1286 Link Here
1279
	root.close();
1287
	root.close();
1280
}
1288
}
1281
/**
1289
/**
1282
 * Attach a jar with a source attachement that is itself. The jar contains 2 root paths for the same class file.
1290
 * Attach a jar with a source attachment that is itself. The jar contains 2 root paths for the same class file.
1283
 * (regression test for bug 74014 prefix path for source attachements - automatic detection does not seem to work)
1291
 * (regression test for bug 74014 prefix path for source attachments - automatic detection does not seem to work)
1284
 */
1292
 */
1285
public void testRootPath12() throws JavaModelException {
1293
public void testRootPath12() throws JavaModelException {
1286
	IJavaProject project = getJavaProject("/AttachSourceTests");
1294
	IJavaProject project = getJavaProject("/AttachSourceTests");
Lines 1514-1517 Link Here
1514
	IBuffer buffer2 = classFile.getBuffer();
1522
	IBuffer buffer2 = classFile.getBuffer();
1515
	assertTrue("Same buffer is not reused", buffer2 == buffer);
1523
	assertTrue("Same buffer is not reused", buffer2 == buffer);
1516
}
1524
}
1525
/**
1526
 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=242029
1527
 */
1528
public void testConstructorAccess() throws JavaModelException {
1529
	IJavaProject project = this.getJavaProject("/AttachSourceTests");
1530
	IPackageFragmentRoot root = project.getPackageFragmentRoot(getFile("/AttachSourceTests/generic.jar"));
1531
	attachSource(root, "/AttachSourceTests/genericsrc.zip", null);
1532
	
1533
	IClassFile cf = root.getPackageFragment("").getClassFile("Container$Inner.class");
1534
	final IType type = cf.getType();
1535
	final IMethod[] methods = type.getMethods();
1536
	assertEquals("wrong size", 1, methods.length);
1537
	assertTrue("Not a constructor", methods[0].isConstructor());
1538
	assertSourceEquals(
1539
		"Unexpected source for generic constructor",
1540
		"Inner(String st, Class<S> s) {\n" + 
1541
		"			super();\n" + 
1542
		"		}",
1543
		methods[0].getSource());
1544
	attachSource(root, null, null); // detach source
1545
	root.close();
1546
}
1517
}
1547
}

Return to bug 321276