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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java (-1 / +59 lines)
Lines 86-91 Link Here
86
		"  }\n" +
86
		"  }\n" +
87
		"  void foo(int i, X<Object[]> x) {\n" +
87
		"  void foo(int i, X<Object[]> x) {\n" +
88
		"  }\n" +
88
		"  }\n" +
89
		"  void foo(boolean b, X<? extends X> x) {\n" +
90
		"  }\n" +
91
		"  void foo(float f, X<?> x) {\n" +
92
		"  }\n" +
93
		"  void foo(Y<? extends Integer, ? extends Object> y) {\n" +
94
		"  }\n" +
95
		"  void foo(Z.Inner<Object> inner) {\n" +
96
		"  }\n" +
97
		"  void foo(AType<Object> t) {\n" +
98
		"  }\n" +
99
		"}\n" +
100
		"class Y<K, V> {\n" +
101
		"}\n" +
102
		"class Z {\n" +
103
		"  class Inner<E> {\n" +
104
		"  }\n" +
105
		"}\n" +
106
		"class AType<E> {\n" + // type name containing character 'T'
89
		"}"
107
		"}"
90
	};
108
	};
91
	IJavaProject project = getJavaProject("AttachSourceTests");
109
	IJavaProject project = getJavaProject("AttachSourceTests");
Lines 333-339 Link Here
333
 * Ensures that the source of a generic method can be retrieved.
351
 * Ensures that the source of a generic method can be retrieved.
334
 * (regression test for bug 129317 Outline view inconsistent with code
352
 * (regression test for bug 129317 Outline view inconsistent with code
335
 */
353
 */
336
public void _testGeneric3() throws JavaModelException {
354
public void testGeneric3() throws JavaModelException {
337
	IMethod method = this.genericType.getMethod("foo", new String[] {"I", "Lgeneric.X<[Ljava.lang.Object;>;"});
355
	IMethod method = this.genericType.getMethod("foo", new String[] {"I", "Lgeneric.X<[Ljava.lang.Object;>;"});
338
	assertSourceEquals(
356
	assertSourceEquals(
339
		"Unexpected source",
357
		"Unexpected source",
Lines 341-346 Link Here
341
		"  }",
359
		"  }",
342
		method.getSource());
360
		method.getSource());
343
}
361
}
362
public void testGeneric4() throws JavaModelException {
363
	IMethod method = this.genericType.getMethod("foo", new String[] {"Z", "Lgeneric.X<+Lgeneric.X;>;"});
364
	assertSourceEquals(
365
		"Unexpected source",
366
		"void foo(boolean b, X<? extends X> x) {\n" + 
367
		"  }",
368
		method.getSource());
369
}
370
public void testGeneric5() throws JavaModelException {
371
	IMethod method = this.genericType.getMethod("foo", new String[] {"F", "Lgeneric.X<*>;"});
372
	assertSourceEquals(
373
		"Unexpected source",
374
		"void foo(float f, X<?> x) {\n" + 
375
		"  }",
376
		method.getSource());
377
}
378
public void testGeneric6() throws JavaModelException {
379
	IMethod method = this.genericType.getMethod("foo", new String[] {"Lgeneric.Y<+Ljava.lang.Integer;+Ljava.lang.Object;>;"});
380
	assertSourceEquals(
381
		"Unexpected source",
382
		"void foo(Y<? extends Integer, ? extends Object> y) {\n" + 
383
		"  }",
384
		method.getSource());
385
}
386
public void testGeneric7() throws JavaModelException {
387
	IMethod method = this.genericType.getMethod("foo", new String[] {"Lgeneric.Z.Inner<Ljava.lang.Object;>;"});
388
	assertSourceEquals(
389
		"Unexpected source",
390
		"void foo(Z.Inner<Object> inner) {\n" + 
391
		"  }",
392
		method.getSource());
393
}
394
public void testGeneric8() throws JavaModelException {
395
	IMethod method = this.genericType.getMethod("foo", new String[] {"Lgeneric.AType<Ljava.lang.Object;>;"});
396
	assertSourceEquals(
397
		"Unexpected source",
398
		"void foo(AType<Object> t) {\n" + 
399
		"  }",
400
		method.getSource());
401
}
344
/**
402
/**
345
 * Ensures that name ranges exists for BinaryMembers that have
403
 * Ensures that name ranges exists for BinaryMembers that have
346
 * mapped source.
404
 * mapped source.
(-)model/org/eclipse/jdt/internal/core/SourceMapper.java (-56 / +115 lines)
Lines 307-320 Link Here
307
			return CharOperation.NO_STRINGS;
307
			return CharOperation.NO_STRINGS;
308
		String[] typeSigs = new String[n];
308
		String[] typeSigs = new String[n];
309
		for (int i = 0; i < n; ++i) {
309
		for (int i = 0; i < n; ++i) {
310
			String typeSig = Signature.createTypeSignature(typeNames[i], false);
310
			char[] typeSig = Signature.createCharArrayTypeSignature(typeNames[i], false);
311
			int lastIndex = typeSig.lastIndexOf('.');
311
			
312
			if (lastIndex == -1) {
312
			// transforms signatures that contains a qualification into unqualified signatures
313
				typeSigs[i] = typeSig;
313
			// e.g. "QX<+QMap.Entry;>;" becomes "QX<+QEntry;>;"
314
			StringBuffer simpleTypeSig = null;
315
			int start = 0;
316
			int dot = -1;
317
			int length = typeSig.length;
318
			for (int j = 0; j < length; j++) {
319
				switch (typeSig[j]) {
320
					case Signature.C_UNRESOLVED:
321
						if (simpleTypeSig != null)
322
							simpleTypeSig.append(typeSig, start, j-start);
323
						start = j;
324
						break;
325
					case Signature.C_DOT:
326
						dot = j;
327
						break;
328
					case Signature.C_GENERIC_START:
329
					case Signature.C_NAME_END:
330
						if (dot > start) {
331
							if (simpleTypeSig == null)
332
								simpleTypeSig = new StringBuffer().append(typeSig, 0, start);
333
							simpleTypeSig.append(Signature.C_UNRESOLVED);
334
							simpleTypeSig.append(typeSig, dot+1, j-dot-1);
335
							start = j;
336
						}
337
						break;
338
				}
339
			}
340
			if (simpleTypeSig == null) {
341
				typeSigs[i] = new String(typeSig);
314
			} else {
342
			} else {
315
				int arrayEnd = 0;
343
				simpleTypeSig.append(typeSig, start, length-start);
316
				while(typeSig.charAt(arrayEnd) == Signature.C_ARRAY) arrayEnd++;
344
				typeSigs[i] = simpleTypeSig.toString();
317
				typeSigs[i] = typeSig.substring(0, arrayEnd) + Signature.C_UNRESOLVED + typeSig.substring(lastIndex + 1, typeSig.length());
318
			}
345
			}
319
		}
346
		}
320
		return typeSigs;
347
		return typeSigs;
Lines 1071-1125 Link Here
1071
		String[] qualifiedParameterTypes = method.getParameterTypes();
1098
		String[] qualifiedParameterTypes = method.getParameterTypes();
1072
		String[] unqualifiedParameterTypes = new String[qualifiedParameterTypes.length];
1099
		String[] unqualifiedParameterTypes = new String[qualifiedParameterTypes.length];
1073
		for (int i = 0; i < qualifiedParameterTypes.length; i++) {
1100
		for (int i = 0; i < qualifiedParameterTypes.length; i++) {
1074
			StringBuffer unqualifiedName = new StringBuffer();
1101
			StringBuffer unqualifiedTypeSig = new StringBuffer();
1075
			String qualifiedName = qualifiedParameterTypes[i];
1102
			getUnqualifiedTypeSignature(qualifiedParameterTypes[i], 0/*start*/, qualifiedParameterTypes[i].length(), unqualifiedTypeSig, noDollar);
1076
			int count = 0;
1103
			unqualifiedParameterTypes[i] = unqualifiedTypeSig.toString();
1077
			while (qualifiedName.charAt(count) == Signature.C_ARRAY) {
1104
			hasDollar |= unqualifiedParameterTypes[i].lastIndexOf('$') != -1;
1078
				unqualifiedName.append(Signature.C_ARRAY);
1079
				++count;
1080
			}
1081
			char currentChar = qualifiedName.charAt(count);
1082
			if (currentChar == Signature.C_RESOLVED || currentChar == Signature.C_TYPE_VARIABLE) {
1083
				unqualifiedName.append(Signature.C_UNRESOLVED);
1084
				String simpleName = Signature.getSimpleName(qualifiedName.substring(count+1));
1085
				int lastDollar = simpleName.lastIndexOf('$');
1086
				hasDollar |= lastDollar != -1;
1087
				int start = noDollar ? lastDollar + 1 : 0;
1088
				boolean sigStart = false;
1089
				for (int j = start, length = simpleName.length(); j < length; j++) {
1090
					char current = simpleName.charAt(j);
1091
					switch (current) {
1092
						case Signature.C_SUPER:
1093
						case Signature.C_EXTENDS:
1094
						case Signature.C_GENERIC_START:
1095
						case Signature.C_NAME_END:
1096
							unqualifiedName.append(current);
1097
							sigStart = true;
1098
							break;
1099
						default:
1100
							if (sigStart) {
1101
								switch(current) {
1102
									case Signature.C_TYPE_VARIABLE :
1103
										unqualifiedName.append(Signature.C_UNRESOLVED);
1104
										break;
1105
									case Signature.C_GENERIC_END :
1106
									case Signature.C_STAR :
1107
										unqualifiedName.append(current);
1108
										break;
1109
									default:
1110
										unqualifiedName.append(Signature.C_UNRESOLVED);
1111
										unqualifiedName.append(current);
1112
								}
1113
								sigStart = false;
1114
							} else {
1115
								unqualifiedName.append(current);
1116
							}
1117
					}
1118
				}
1119
			} else {
1120
				unqualifiedName.append(qualifiedName.substring(count, qualifiedName.length()));
1121
			}
1122
			unqualifiedParameterTypes[i] = unqualifiedName.toString();
1123
		}
1105
		}
1124
		
1106
		
1125
		IJavaElement[] result = new IJavaElement[2];
1107
		IJavaElement[] result = new IJavaElement[2];
Lines 1131-1136 Link Here
1131
		}
1113
		}
1132
		return result;
1114
		return result;
1133
	}
1115
	}
1116
1117
	private int getUnqualifiedTypeSignature(String qualifiedTypeSig, int start, int length, StringBuffer unqualifiedTypeSig, boolean noDollar) {
1118
		char firstChar = qualifiedTypeSig.charAt(start);
1119
		int end = start + 1;
1120
		boolean sigStart = false;
1121
		firstPass: for (int i = start; i < length; i++) {
1122
			char current = qualifiedTypeSig.charAt(i);
1123
			switch (current) {
1124
				case Signature.C_ARRAY :
1125
				case Signature.C_SUPER:
1126
				case Signature.C_EXTENDS:
1127
					unqualifiedTypeSig.append(current);
1128
					start = i + 1;
1129
					end = start + 1;
1130
					firstChar = qualifiedTypeSig.charAt(start);
1131
					break;
1132
				case Signature.C_RESOLVED :
1133
				case Signature.C_UNRESOLVED :
1134
				case Signature.C_TYPE_VARIABLE :
1135
					if (!sigStart) {
1136
						start = ++i;
1137
						sigStart = true;
1138
					}
1139
					break;
1140
				case Signature.C_NAME_END:
1141
				case Signature.C_GENERIC_START :
1142
					end = i;
1143
					break firstPass;
1144
				case Signature.C_STAR :
1145
					unqualifiedTypeSig.append(current);
1146
					start = i + 1;
1147
					end = start + 1;
1148
					firstChar = qualifiedTypeSig.charAt(start);
1149
					break;
1150
				case Signature.C_GENERIC_END :
1151
					return i;
1152
				case Signature.C_DOT:
1153
					start = ++i;
1154
					break;
1155
			}
1156
		}
1157
		switch (firstChar) {
1158
			case Signature.C_RESOLVED :
1159
			case Signature.C_UNRESOLVED :
1160
			case Signature.C_TYPE_VARIABLE :
1161
				unqualifiedTypeSig.append(Signature.C_UNRESOLVED);
1162
				if (noDollar) {
1163
					int lastDollar = qualifiedTypeSig.lastIndexOf('$', end);
1164
					if (lastDollar > start)
1165
						start = lastDollar + 1;
1166
				}
1167
				for (int i = start; i < length; i++) {
1168
					char current = qualifiedTypeSig.charAt(i);
1169
					switch (current) {
1170
						case Signature.C_GENERIC_START:
1171
							unqualifiedTypeSig.append(current);
1172
							i++;
1173
							do {
1174
								i = getUnqualifiedTypeSignature(qualifiedTypeSig, i, length, unqualifiedTypeSig, noDollar);
1175
							} while (qualifiedTypeSig.charAt(i) != Signature.C_GENERIC_END);
1176
							unqualifiedTypeSig.append(Signature.C_GENERIC_END);
1177
							break;
1178
						case Signature.C_NAME_END:
1179
							unqualifiedTypeSig.append(current);
1180
							return i + 1;
1181
						default:
1182
							unqualifiedTypeSig.append(current);
1183
							break;
1184
					}
1185
				}
1186
				return length;
1187
			default :
1188
				// primitive type or wildcard
1189
				unqualifiedTypeSig.append(qualifiedTypeSig.substring(start, end));
1190
				return end;
1191
		}
1192
	}
1134
		
1193
		
1135
	/**
1194
	/**
1136
	 * Maps the given source code to the given binary type and its children.
1195
	 * Maps the given source code to the given binary type and its children.

Return to bug 129317