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 |
} |