View | Details | Raw Unified | Return to bug 119249
Collapse All | Expand All

(-)dom/org/eclipse/jdt/core/dom/MethodBinding.java (-3 / +9 lines)
Lines 200-213 Link Here
200
			// case of method not in the created AST, or a binary method
200
			// case of method not in the created AST, or a binary method
201
			org.eclipse.jdt.internal.compiler.lookup.MethodBinding original = this.binding.original();
201
			org.eclipse.jdt.internal.compiler.lookup.MethodBinding original = this.binding.original();
202
			String selector = original.isConstructor() ? declaringType.getElementName() : new String(original.selector);
202
			String selector = original.isConstructor() ? declaringType.getElementName() : new String(original.selector);
203
			boolean isBinary = declaringType.isBinary();
204
			ReferenceBinding enclosingType = original.declaringClass.enclosingType();
205
			boolean isInnerBinaryTypeConstructor = isBinary && original.isConstructor() && enclosingType != null;
203
			TypeBinding[] parameters = original.parameters;
206
			TypeBinding[] parameters = original.parameters;
204
			int length = parameters == null ? 0 : parameters.length;
207
			int length = parameters == null ? 0 : parameters.length;
205
			String[] parameterSignatures = new String[length];
208
			int declaringIndex = isInnerBinaryTypeConstructor ? 1 : 0;
209
			String[] parameterSignatures = new String[declaringIndex + length];
210
			if (isInnerBinaryTypeConstructor)
211
				parameterSignatures[0] = new String(enclosingType.genericTypeSignature()).replace('/', '.');
206
			for (int i = 0;  i < length; i++) {
212
			for (int i = 0;  i < length; i++) {
207
				parameterSignatures[i] = new String(parameters[i].genericTypeSignature()).replace('/', '.');
213
				parameterSignatures[declaringIndex + i] = new String(parameters[i].genericTypeSignature()).replace('/', '.');
208
			}
214
			}
209
			IMethod result = declaringType.getMethod(selector, parameterSignatures);
215
			IMethod result = declaringType.getMethod(selector, parameterSignatures);
210
			if (declaringType.isBinary())
216
			if (isBinary)
211
				return (JavaElement) result;
217
				return (JavaElement) result;
212
			IMethod[] methods = null;
218
			IMethod[] methods = null;
213
			try {
219
			try {
(-)model/org/eclipse/jdt/internal/core/SourceMapper.java (-3 / +12 lines)
Lines 687-696 Link Here
687
			this.memberNameRange[typeDepth] =
687
			this.memberNameRange[typeDepth] =
688
				new SourceRange(methodInfo.nameSourceStart, methodInfo.nameSourceEnd - methodInfo.nameSourceStart + 1);
688
				new SourceRange(methodInfo.nameSourceStart, methodInfo.nameSourceEnd - methodInfo.nameSourceStart + 1);
689
			this.memberDeclarationStart[typeDepth] = methodInfo.declarationStart;
689
			this.memberDeclarationStart[typeDepth] = methodInfo.declarationStart;
690
			this.methodParameterTypes[typeDepth] = methodInfo.parameterTypes;
691
			this.methodParameterNames[typeDepth] = methodInfo. parameterNames;
692
			
693
			IType currentType = this.types[typeDepth];
690
			IType currentType = this.types[typeDepth];
691
			char[][] parameterTypes = methodInfo.parameterTypes;
692
			if (parameterTypes != null && methodInfo.isConstructor && currentType.getDeclaringType() != null) {
693
				int length = parameterTypes.length;
694
				char[][] newParameterTypes = new char[length+1][];
695
				newParameterTypes[0] = currentType.getDeclaringType().getElementName().toCharArray();
696
				System.arraycopy(parameterTypes, 0, newParameterTypes, 1, length);
697
				this.methodParameterTypes[typeDepth] = newParameterTypes;
698
			} else {
699
				this.methodParameterTypes[typeDepth] = parameterTypes;
700
			}
701
			this.methodParameterNames[typeDepth] = methodInfo.parameterNames;
702
			
694
			IMethod method = currentType.getMethod(
703
			IMethod method = currentType.getMethod(
695
					this.memberName[typeDepth],
704
					this.memberName[typeDepth],
696
					convertTypeNamesToSigs(this.methodParameterTypes[typeDepth]));
705
					convertTypeNamesToSigs(this.methodParameterTypes[typeDepth]));
(-)src/org/eclipse/jdt/core/tests/model/AttachSourceTests.java (-36 / +72 lines)
Lines 33-39 Link Here
33
*/
33
*/
34
public class AttachSourceTests extends ModifyingResourceTests {
34
public class AttachSourceTests extends ModifyingResourceTests {
35
	static {
35
	static {
36
//		TESTS_NAMES = new String[] { "testRootPath13" };
36
//		TESTS_NAMES = new String[] { "testClassFileGetElementAt04" };
37
//		TESTS_NUMBERS = new int[] { 5 };
37
//		TESTS_NUMBERS = new int[] { 5 };
38
//		TESTS_RANGE = new int[] { 169, 180 };
38
//		TESTS_RANGE = new int[] { 169, 180 };
39
	}
39
	}
Lines 109-114 Link Here
109
		"    }\n" +
109
		"    }\n" +
110
		"  }\n" +
110
		"  }\n" +
111
		"  class V {\n" +
111
		"  class V {\n" +
112
		"    V(String s) {\n" +
113
		"    }\n" +
112
		"  }\n" +
114
		"  }\n" +
113
		"}"
115
		"}"
114
	};
116
	};
Lines 218-246 Link Here
218
/**
220
/**
219
 * Ensure that a class file with an attached source can retrieve its children given a source index.
221
 * Ensure that a class file with an attached source can retrieve its children given a source index.
220
 */
222
 */
221
public void testClassFileGetElementAt() throws JavaModelException {
223
public void testClassFileGetElementAt01() throws JavaModelException {
222
	IClassFile cf = this.pkgFragmentRoot.getPackageFragment("x.y").getClassFile("A.class");
224
	IClassFile classFile = this.pkgFragmentRoot.getPackageFragment("x.y").getClassFile("A.class");
223
	IJavaElement elt = null;
225
	String source = classFile.getSource();
224
	
226
	IJavaElement element = classFile.getElementAt(source.indexOf("class A"));
225
	elt = cf.getElementAt(15);
227
	assertElementEquals(
226
	assertTrue("should have found \"A\"",
228
		"Unexpected element",
227
		elt != null &&
229
		"A [in A.class [in x.y [in attach.jar [in AttachSourceTests]]]]",
228
		elt.getElementType() == IJavaElement.TYPE &&
230
		element);
229
		elt.getElementName().equals("A"));
231
}
230
	
232
/**
231
	elt = cf.getElementAt(53);
233
 * Ensure that a class file with an attached source can retrieve its children given a source index.
232
	assertTrue("should have found \"public A()\"",
234
 */
233
		elt != null &&
235
public void testClassFileGetElementAt02() throws JavaModelException {
234
		elt.getElementType() == IJavaElement.METHOD &&
236
	IClassFile classFile = this.pkgFragmentRoot.getPackageFragment("x.y").getClassFile("A.class");
235
		elt.getElementName().equals("A"));
237
	String source = classFile.getSource();
236
238
	IJavaElement element = classFile.getElementAt(source.indexOf("public A"));
237
	elt = cf.getElementAt(72);
239
	assertElementEquals(
238
	assertTrue("should have found \"public void foo()\"",
240
		"Unexpected element",
239
		elt != null &&
241
		"A() [in A [in A.class [in x.y [in attach.jar [in AttachSourceTests]]]]]",
240
		elt.getElementType() == IJavaElement.METHOD &&
242
		element);
241
		elt.getElementName().equals("foo"));
243
}
244
/**
245
 * Ensure that a class file with an attached source can retrieve its children given a source index.
246
 */
247
public void testClassFileGetElementAt03() throws JavaModelException {
248
	IClassFile classFile = this.pkgFragmentRoot.getPackageFragment("x.y").getClassFile("A.class");
249
	String source = classFile.getSource();
250
	IJavaElement element = classFile.getElementAt(source.indexOf("void foo"));
251
	assertElementEquals(
252
		"Unexpected element",
253
		"foo() [in A [in A.class [in x.y [in attach.jar [in AttachSourceTests]]]]]",
254
		element);
242
}
255
}
243
/*
256
/*
257
 * Ensure that a constructor of a binary member type can be retrieved with its source position.
258
 * (regression test for bug 119249 codeResolve, search, etc. don't work on constructor of binary inner class)
259
 */
260
public void testClassFileGetElementAt04() throws JavaModelException {
261
	IClassFile classFile = this.innerClasses.getClassFile("X$V.class");
262
	String source = classFile.getSource();
263
	IJavaElement element = classFile.getElementAt(source.indexOf("V(String s)"));
264
	assertElementEquals(
265
		"Unexpected element",
266
		"V(inner.X, java.lang.String) [in V [in X$V.class [in inner [in innerClasses.jar [in AttachSourceTests]]]]]",
267
		element);
268
}/*
244
 * Ensures that the source of a .class file is implicetely attached when prj=src=bin
269
 * Ensures that the source of a .class file is implicetely attached when prj=src=bin
245
 * (regression test for bug 41444 [navigation] error dialog on opening class file)
270
 * (regression test for bug 41444 [navigation] error dialog on opening class file)
246
 */
271
 */
Lines 300-319 Link Here
300
 * Ensures that name ranges exists for BinaryMembers that have
325
 * Ensures that name ranges exists for BinaryMembers that have
301
 * mapped source.
326
 * mapped source.
302
 */
327
 */
303
public void testGetNameRange() throws JavaModelException {
328
public void testGetNameRange01() throws JavaModelException {
304
	IClassFile cf = this.pkgFragmentRoot.getPackageFragment("x.y").getClassFile("A.class");
329
	IClassFile classFile = this.pkgFragmentRoot.getPackageFragment("x.y").getClassFile("A.class");
305
	IMethod method = cf.getType().getMethod("foo", null);
330
	IMethod method = classFile.getType().getMethod("foo", null);
306
	assertTrue("method name range not correct", method.getNameRange().getOffset() != -1 && method.getNameRange().getLength() != 0);
331
	assertSourceEquals("Unexpected name source", "foo", getNameSource(classFile.getSource(), method));
307
332
}
308
	IClassFile objectCF = this.pkgFragmentRoot.getPackageFragment("x.y").getClassFile("A.class");
333
/**
309
	ISourceRange range= objectCF.getType().getNameRange();
334
 * Ensures that name ranges exists for BinaryMembers that have
310
	int start, end;
335
 * mapped source.
311
	start= range.getOffset();
336
 */
312
	end= start + range.getLength() - 1;
337
public void testGetNameRange02() throws JavaModelException {
313
338
	IClassFile classFile = this.pkgFragmentRoot.getPackageFragment("x.y").getClassFile("A.class");
314
	assertTrue("source code does not exist for the entire attached compilation unit", start != -1 && end != -1);
339
	assertSourceEquals("Unexpected name source", "A", getNameSource(classFile.getSource(), classFile.getType()));
315
	String source= objectCF.getSource().substring(start, end + 1);
340
}
316
	assertSourceEquals("name should be 'A'", "A", source);
341
/*
342
 * Ensure that the name range for a constructor of a binary member type is correct.
343
 * (regression test for bug 119249 codeResolve, search, etc. don't work on constructor of binary inner class)
344
 */
345
public void testGetNameRange03() throws JavaModelException {
346
	IClassFile classFile = this.innerClasses.getClassFile("X$V.class");
347
	IMethod constructor = classFile.getType().getMethod("V", new String[] {"Linner.X;", "Ljava.lang.String;"});
348
	assertSourceEquals("Unexpected name source", "V", getNameSource(classFile.getSource(), constructor));
317
}
349
}
318
/**
350
/**
319
 * Retrieves the source attachment paths for jar root.
351
 * Retrieves the source attachment paths for jar root.
Lines 366-371 Link Here
366
		"    }\n" + 
398
		"    }\n" + 
367
		"  }\n" + 
399
		"  }\n" + 
368
		"  class V {\n" + 
400
		"  class V {\n" + 
401
		"    V(String s) {\n" + 
402
		"    }\n" + 
369
		"  }\n" + 
403
		"  }\n" + 
370
		"}",
404
		"}",
371
		type.getSource());
405
		type.getSource());
Lines 444-449 Link Here
444
	assertSourceEquals(
478
	assertSourceEquals(
445
		"Unexpected source",
479
		"Unexpected source",
446
		"class V {\n" + 
480
		"class V {\n" + 
481
		"    V(String s) {\n" + 
482
		"    }\n" + 
447
		"  }",
483
		"  }",
448
		type.getSource());
484
		type.getSource());
449
}
485
}
(-)src/org/eclipse/jdt/core/tests/model/GetSourceTests.java (-8 lines)
Lines 209-222 Link Here
209
		}
209
		}
210
	}
210
	}
211
	
211
	
212
	private String getNameSource(String cuSource, IJavaElement element) throws JavaModelException {
213
		ISourceRange nameRange = element instanceof ITypeParameter ? ((ITypeParameter) element).getNameRange() : ((IMember) element).getNameRange();
214
		int start = nameRange.getOffset();
215
		int end = start+nameRange.getLength();
216
		String actualSource = start >= 0 && end >= start ? cuSource.substring(start, end) : "";
217
		return actualSource;
218
	}
219
220
	/*
212
	/*
221
	 * Ensures the name range for a type parameter is correct.
213
	 * Ensures the name range for a type parameter is correct.
222
	 */
214
	 */
(-)src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java (+7 lines)
Lines 1395-1400 Link Here
1395
		ISourceReference cu = getCompilationUnit(cuPath);
1395
		ISourceReference cu = getCompilationUnit(cuPath);
1396
		return getLocalVariable(cu, selectAt, selection);
1396
		return getLocalVariable(cu, selectAt, selection);
1397
	}
1397
	}
1398
	protected String getNameSource(String cuSource, IJavaElement element) throws JavaModelException {
1399
		ISourceRange nameRange = element instanceof ITypeParameter ? ((ITypeParameter) element).getNameRange() : ((IMember) element).getNameRange();
1400
		int start = nameRange.getOffset();
1401
		int end = start+nameRange.getLength();
1402
		String actualSource = start >= 0 && end >= start ? cuSource.substring(start, end) : "";
1403
		return actualSource;
1404
	}
1398
	/**
1405
	/**
1399
	 * Returns the specified package fragment in the given project and root, or
1406
	 * Returns the specified package fragment in the given project and root, or
1400
	 * <code>null</code> if it does not exist.
1407
	 * <code>null</code> if it does not exist.
(-)src/org/eclipse/jdt/core/tests/dom/ASTModelBridgeTests.java (-1 / +31 lines)
Lines 36-42 Link Here
36
	// All specified tests which do not belong to the class are skipped...
36
	// All specified tests which do not belong to the class are skipped...
37
	static {
37
	static {
38
//		TESTS_PREFIX =  "testBug86380";
38
//		TESTS_PREFIX =  "testBug86380";
39
//		TESTS_NAMES = new String[] { "testLocalType2" };
39
		TESTS_NAMES = new String[] { "testBinaryMemberTypeConstructor" };
40
//		TESTS_NUMBERS = new int[] { 83230 };
40
//		TESTS_NUMBERS = new int[] { 83230 };
41
//		TESTS_RANGE = new int[] { 83304, -1 };
41
//		TESTS_RANGE = new int[] { 83304, -1 };
42
		}
42
		}
Lines 95-100 Link Here
95
				"    new Member() {};\n" +
95
				"    new Member() {};\n" +
96
				"  }\n" +
96
				"  }\n" +
97
				"}",
97
				"}",
98
				"p/W.java",
99
				"package p;\n" +
100
				"public class W {\n" +
101
				"  class Member {\n" +
102
				"    /*start*/Member(String s) {\n" +
103
				"    }/*end*/\n" +
104
				"  }\n" +
105
				"}",
98
				"Z.java",
106
				"Z.java",
99
				"public class Z {\n" +
107
				"public class Z {\n" +
100
				"  /*start*/class Member {\n" +
108
				"  /*start*/class Member {\n" +
Lines 239-244 Link Here
239
	}
247
	}
240
	
248
	
241
	/*
249
	/*
250
	 * Ensures that the IJavaElement of an IBinding representing a constructor of a binary member type is correct.
251
	 * (regression test for bug 119249 codeResolve, search, etc. don't work on constructor of binary inner class)
252
	 */
253
	public void testBinaryMemberTypeConstructor() throws JavaModelException {
254
		IClassFile classFile = getClassFile("P", "/P/lib.jar", "p", "W$Member.class");
255
		String source = classFile.getSource();
256
		MarkerInfo markerInfo = new MarkerInfo(source);
257
		markerInfo.astStarts = new int[] {source.indexOf("/*start*/") + "/*start*/".length()};
258
		markerInfo.astEnds = new int[] {source.indexOf("/*end*/")};
259
		ASTNode node = buildAST(markerInfo, classFile);
260
		IBinding binding = ((MethodDeclaration) node).resolveBinding();
261
		assertNotNull("No binding", binding);
262
		IJavaElement element = binding.getJavaElement();
263
		assertElementEquals(
264
			"Unexpected Java element",
265
			"Member(p.W, java.lang.String) [in Member [in W$Member.class [in p [in lib.jar [in P]]]]]",
266
			element
267
		);
268
		assertTrue("Element should exist", element.exists());
269
	}
270
	
271
	/*
242
	 * Ensures that the IJavaElement of an IBinding representing a type coming from a class file is correct.
272
	 * Ensures that the IJavaElement of an IBinding representing a type coming from a class file is correct.
243
	 */
273
	 */
244
	public void testBinaryType() throws JavaModelException {
274
	public void testBinaryType() throws JavaModelException {

Return to bug 119249