Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2008 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2011 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 10-18
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.jdt.core.tests.model; |
11 |
package org.eclipse.jdt.core.tests.model; |
12 |
|
12 |
|
|
|
13 |
import java.io.IOException; |
14 |
import java.util.HashMap; |
15 |
import java.util.Map; |
16 |
|
13 |
import org.eclipse.core.runtime.CoreException; |
17 |
import org.eclipse.core.runtime.CoreException; |
14 |
import org.eclipse.jdt.core.*; |
18 |
import org.eclipse.jdt.core.*; |
15 |
import org.eclipse.jdt.core.tests.util.Util; |
19 |
import org.eclipse.jdt.core.tests.util.Util; |
|
|
20 |
import org.eclipse.jdt.internal.core.LocalVariable; |
16 |
|
21 |
|
17 |
import junit.framework.Test; |
22 |
import junit.framework.Test; |
18 |
|
23 |
|
Lines 95-101
Link Here
|
95 |
} |
100 |
} |
96 |
static { |
101 |
static { |
97 |
// TESTS_NUMBERS = new int[] { 182, 183 }; |
102 |
// TESTS_NUMBERS = new int[] { 182, 183 }; |
98 |
// TESTS_NAMES = new String[] {"test0177"}; |
103 |
// TESTS_NAMES = new String[] { "testParamAnnotations5" }; |
99 |
} |
104 |
} |
100 |
public static Test suite() { |
105 |
public static Test suite() { |
101 |
return buildModelTestSuite(TypeResolveTests.class); |
106 |
return buildModelTestSuite(TypeResolveTests.class); |
Lines 299-302
Link Here
|
299 |
"p4.A.Inner", |
304 |
"p4.A.Inner", |
300 |
types); |
305 |
types); |
301 |
} |
306 |
} |
|
|
307 |
/** |
308 |
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=334783" |
309 |
*/ |
310 |
public void testParamAnnotations() throws CoreException { |
311 |
try { |
312 |
createJavaProject("P", new String[] {"src"}, new String[] {"JCL15_LIB"}, "bin", "1.5"); |
313 |
String source = "package p;" + |
314 |
"public class X<T> {\n" + |
315 |
" X<String> field;\n" + |
316 |
" @Inject " + |
317 |
" public void Test(@Default String processor) {}" + |
318 |
"}" + |
319 |
"@interface Inject{\n" + |
320 |
"}" + |
321 |
"@interface Default{\n" + |
322 |
"}"; |
323 |
createFolder("/P/src/p"); |
324 |
createFile( |
325 |
"/P/src/p/X.java", |
326 |
source |
327 |
); |
328 |
waitForAutoBuild(); |
329 |
|
330 |
ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); |
331 |
IJavaElement[] variable = ((ICodeAssist) unit).codeSelect(source.indexOf("processor"), "processor".length()); |
332 |
|
333 |
assertEquals(1, variable.length); |
334 |
String annotationString = "@Default [in processor [in Test(String) [in X [in X.java [in p [in src [in P]]]]]]]"; |
335 |
assertEquals(annotationString, ((LocalVariable)variable[0]).getAnnotations()[0].toString()); |
336 |
IType type = unit.getType("X"); |
337 |
|
338 |
IMethod method = type.getMethods()[0]; |
339 |
assertEquals(annotationString, method.getParameterAnnotations()[0][0].toString()); |
340 |
} finally { |
341 |
deleteProject("P"); |
342 |
} |
343 |
} |
344 |
/** |
345 |
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=334783" |
346 |
*/ |
347 |
public void testParamAnnotations2() throws CoreException, IOException { |
348 |
try { |
349 |
IJavaProject project = createJavaProject("P", new String[] {"src"}, new String[] {"JCL15_LIB"}, "bin", "1.5"); |
350 |
String[] pathAndContents = new String[]{"p/X.java", |
351 |
"package p;" + |
352 |
"public class X<T> {\n" + |
353 |
" X<String> field;\n" + |
354 |
" @Inject " + |
355 |
" public void Test(@Default String processor) {}" + |
356 |
"}" + |
357 |
"@interface Inject{\n" + |
358 |
"}" + |
359 |
"@interface Default{\n" + |
360 |
"}"}; |
361 |
addLibrary(project, "lib334783.jar", "libsrc.zip", pathAndContents, JavaCore.VERSION_1_5); |
362 |
|
363 |
waitForAutoBuild(); |
364 |
IPackageFragmentRoot root = project.getPackageFragmentRoot(getFile("/P/lib334783.jar")); |
365 |
IType type = root.getPackageFragment("p").getClassFile("X.class").getType(); |
366 |
String annotationString = "@p.Default [in Test(java.lang.String) [in X [in X.class [in p [in lib334783.jar [in P]]]]]]"; |
367 |
|
368 |
IMethod method = type.getMethods()[1]; |
369 |
assertEquals(annotationString, method.getParameterAnnotations()[0][0].toString()); |
370 |
} finally { |
371 |
deleteProject("P"); |
372 |
} |
373 |
} |
374 |
/** |
375 |
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=334783" |
376 |
*/ |
377 |
public void testParamAnnotations3() throws CoreException { |
378 |
try { |
379 |
createJavaProject("P", new String[] {"src"}, new String[] {"JCL15_LIB"}, "bin", "1.5"); |
380 |
String source = "package p;" + |
381 |
"public class X<T> {\n" + |
382 |
" X<String> field;\n" + |
383 |
" @Inject\n" + |
384 |
" public void Test(int i, @Default @Marker(id=1) String processor, int k) {}\n" + |
385 |
"}\n" + |
386 |
"@interface Inject{\n" + |
387 |
"}\n" + |
388 |
"@interface Marker {\n" + |
389 |
" int id() default 0;\n" + |
390 |
"}\n" + |
391 |
"@interface Default{\n" + |
392 |
"}"; |
393 |
createFolder("/P/src/p"); |
394 |
createFile( |
395 |
"/P/src/p/X.java", |
396 |
source |
397 |
); |
398 |
waitForAutoBuild(); |
399 |
|
400 |
ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); |
401 |
IJavaElement[] variable = ((ICodeAssist) unit).codeSelect(source.indexOf("processor"), "processor".length()); |
402 |
|
403 |
assertEquals(1, variable.length); |
404 |
String annotationString1 = "@Default [in processor [in Test(int, String, int) [in X [in X.java [in p [in src [in P]]]]]]]"; |
405 |
String annotationString2 = "@Marker [in processor [in Test(int, String, int) [in X [in X.java [in p [in src [in P]]]]]]]"; |
406 |
assertEquals(annotationString1, ((LocalVariable)variable[0]).getAnnotations()[0].toString()); |
407 |
IType type = unit.getType("X"); |
408 |
|
409 |
IMethod method = type.getMethods()[0]; |
410 |
IAnnotation[][] parameterAnnotations = method.getParameterAnnotations(); |
411 |
assertEquals("Wrong length", 2, parameterAnnotations[1].length); |
412 |
assertEquals(annotationString1, parameterAnnotations[1][0].toString()); |
413 |
IAnnotation iAnnotation = parameterAnnotations[1][1]; |
414 |
assertEquals(annotationString2, iAnnotation.toString()); |
415 |
IMemberValuePair[] memberValuePairs = iAnnotation.getMemberValuePairs(); |
416 |
assertEquals("Wrong number of pairs", 1, memberValuePairs.length); |
417 |
StringBuffer output = new StringBuffer(); |
418 |
output.append(memberValuePairs[0].getMemberName()); |
419 |
output.append(' '); |
420 |
output.append(memberValuePairs[0].getValue()); |
421 |
assertEquals("Wrong value", "id 1", String.valueOf(output)); |
422 |
assertEquals("Wrong length", 0, parameterAnnotations[0].length); |
423 |
assertEquals("Wrong length", 0, parameterAnnotations[2].length); |
424 |
} finally { |
425 |
deleteProject("P"); |
426 |
} |
427 |
} |
428 |
/** |
429 |
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=334783" |
430 |
*/ |
431 |
public void testParamAnnotations4() throws CoreException, IOException { |
432 |
try { |
433 |
IJavaProject project = createJavaProject("P", new String[] {"src"}, new String[] {"JCL15_LIB"}, "bin", "1.5"); |
434 |
String[] pathAndContents = new String[]{"p/X.java", |
435 |
"package p;" + |
436 |
"public class X<T> {\n" + |
437 |
" X<String> field;\n" + |
438 |
" @Inject @Marker(id=3)" + |
439 |
" public void Test(int i, @Default @Marker(id=1) String processor, int k) {}" + |
440 |
"}", |
441 |
"p/Inject.java", |
442 |
"package p;\n"+ |
443 |
"public @interface Inject{\n" + |
444 |
"}", |
445 |
"p/Marker.java", |
446 |
"package p;\n" + |
447 |
"public @interface Marker {\n" + |
448 |
" int id() default 0;\n" + |
449 |
"}", |
450 |
"p/Default.java", |
451 |
"package p;\n" + |
452 |
"public @interface Default{\n" + |
453 |
"}"}; |
454 |
addLibrary(project, "lib334783_2.jar", "lib334783_2src.zip", pathAndContents, JavaCore.VERSION_1_5); |
455 |
|
456 |
waitForAutoBuild(); |
457 |
IPackageFragmentRoot root = project.getPackageFragmentRoot(getFile("/P/lib334783_2.jar")); |
458 |
IType type = root.getPackageFragment("p").getClassFile("X.class").getType(); |
459 |
String annotationString1 = "@p.Default [in Test(int, java.lang.String, int) [in X [in X.class [in p [in lib334783_2.jar [in P]]]]]]"; |
460 |
String annotationString2 = "@p.Marker [in Test(int, java.lang.String, int) [in X [in X.class [in p [in lib334783_2.jar [in P]]]]]]"; |
461 |
IMethod method = type.getMethods()[1]; |
462 |
IAnnotation[] annotations = method.getAnnotations(); |
463 |
assertEquals("Wrong length", 2, annotations.length); |
464 |
assertEquals("@p.Inject [in Test(int, java.lang.String, int) [in X [in X.class [in p [in lib334783_2.jar [in P]]]]]]", annotations[0].toString()); |
465 |
IAnnotation annotation = annotations[1]; |
466 |
assertEquals("@p.Marker [in Test(int, java.lang.String, int) [in X [in X.class [in p [in lib334783_2.jar [in P]]]]]]", annotation.toString()); |
467 |
IMemberValuePair[] memberValuePairs = annotation.getMemberValuePairs(); |
468 |
assertEquals("Wrong number of pairs", 1, memberValuePairs.length); |
469 |
StringBuffer output = new StringBuffer(); |
470 |
output.append(memberValuePairs[0].getMemberName()); |
471 |
output.append(' '); |
472 |
output.append(memberValuePairs[0].getValue()); |
473 |
assertEquals("Wrong value", "id 3", String.valueOf(output)); |
474 |
IAnnotation[][] parameterAnnotations = method.getParameterAnnotations(); |
475 |
assertEquals("Wrong length", 2, parameterAnnotations[1].length); |
476 |
assertEquals(annotationString1, parameterAnnotations[1][0].toString()); |
477 |
annotation = parameterAnnotations[1][1]; |
478 |
assertEquals(annotationString2, annotation.toString()); |
479 |
memberValuePairs = annotation.getMemberValuePairs(); |
480 |
assertEquals("Wrong number of pairs", 1, memberValuePairs.length); |
481 |
output = new StringBuffer(); |
482 |
output.append(memberValuePairs[0].getMemberName()); |
483 |
output.append(' '); |
484 |
output.append(memberValuePairs[0].getValue()); |
485 |
assertEquals("Wrong value", "id 1", String.valueOf(output)); |
486 |
assertEquals("Wrong length", 0, parameterAnnotations[0].length); |
487 |
assertEquals("Wrong length", 0, parameterAnnotations[2].length); |
488 |
} finally { |
489 |
deleteProject("P"); |
490 |
} |
491 |
} |
492 |
/** |
493 |
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=334783" |
494 |
*/ |
495 |
public void testParamAnnotations5() throws CoreException, IOException { |
496 |
try { |
497 |
IJavaProject project = createJavaProject("P", new String[] {"src"}, new String[] {"JCL15_LIB"}, "bin", "1.5"); |
498 |
String[] pathAndContents = new String[]{"p/X.java", |
499 |
"package p;" + |
500 |
"public class X<T> {\n" + |
501 |
" X<String> field;\n" + |
502 |
" @Inject @Marker(id=3)" + |
503 |
" public void Test(int i, @Default @Marker(id=1) String processor, int k) {}" + |
504 |
"}", |
505 |
"p/Inject.java", |
506 |
"package p;\n"+ |
507 |
"public @interface Inject{\n" + |
508 |
"}", |
509 |
"p/Marker.java", |
510 |
"package p;\n" + |
511 |
"public @interface Marker {\n" + |
512 |
" int id() default 0;\n" + |
513 |
"}", |
514 |
"p/Default.java", |
515 |
"package p;\n" + |
516 |
"public @interface Default{\n" + |
517 |
"}"}; |
518 |
Map options = new HashMap(); |
519 |
options.put(JavaCore.COMPILER_LOCAL_VARIABLE_ATTR, JavaCore.DO_NOT_GENERATE); |
520 |
addLibrary(project, "lib334783_3.jar", "lib334783_3src.zip", pathAndContents, JavaCore.VERSION_1_5, options); |
521 |
|
522 |
waitForAutoBuild(); |
523 |
IPackageFragmentRoot root = project.getPackageFragmentRoot(getFile("/P/lib334783_3.jar")); |
524 |
IType type = root.getPackageFragment("p").getClassFile("X.class").getType(); |
525 |
String annotationString1 = "@p.Default [in Test(int, java.lang.String, int) [in X [in X.class [in p [in lib334783_3.jar [in P]]]]]]"; |
526 |
String annotationString2 = "@p.Marker [in Test(int, java.lang.String, int) [in X [in X.class [in p [in lib334783_3.jar [in P]]]]]]"; |
527 |
IMethod method = type.getMethods()[1]; |
528 |
IAnnotation[] annotations = method.getAnnotations(); |
529 |
assertEquals("Wrong length", 2, annotations.length); |
530 |
assertEquals("@p.Inject [in Test(int, java.lang.String, int) [in X [in X.class [in p [in lib334783_3.jar [in P]]]]]]", annotations[0].toString()); |
531 |
IAnnotation annotation = annotations[1]; |
532 |
assertEquals("@p.Marker [in Test(int, java.lang.String, int) [in X [in X.class [in p [in lib334783_3.jar [in P]]]]]]", annotation.toString()); |
533 |
IMemberValuePair[] memberValuePairs = annotation.getMemberValuePairs(); |
534 |
assertEquals("Wrong number of pairs", 1, memberValuePairs.length); |
535 |
StringBuffer output = new StringBuffer(); |
536 |
output.append(memberValuePairs[0].getMemberName()); |
537 |
output.append(' '); |
538 |
output.append(memberValuePairs[0].getValue()); |
539 |
assertEquals("Wrong value", "id 3", String.valueOf(output)); |
540 |
IAnnotation[][] parameterAnnotations = method.getParameterAnnotations(); |
541 |
assertEquals("Wrong length", 2, parameterAnnotations[1].length); |
542 |
assertEquals(annotationString1, parameterAnnotations[1][0].toString()); |
543 |
annotation = parameterAnnotations[1][1]; |
544 |
assertEquals(annotationString2, annotation.toString()); |
545 |
memberValuePairs = annotation.getMemberValuePairs(); |
546 |
assertEquals("Wrong number of pairs", 1, memberValuePairs.length); |
547 |
output = new StringBuffer(); |
548 |
output.append(memberValuePairs[0].getMemberName()); |
549 |
output.append(' '); |
550 |
output.append(memberValuePairs[0].getValue()); |
551 |
assertEquals("Wrong value", "id 1", String.valueOf(output)); |
552 |
assertEquals("Wrong length", 0, parameterAnnotations[0].length); |
553 |
assertEquals("Wrong length", 0, parameterAnnotations[2].length); |
554 |
} finally { |
555 |
deleteProject("P"); |
556 |
} |
557 |
} |
558 |
/** |
559 |
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=334783" |
560 |
*/ |
561 |
public void testParamAnnotations6() throws CoreException { |
562 |
try { |
563 |
createJavaProject("P", new String[] {"src"}, new String[] {"JCL15_LIB"}, "bin", "1.5"); |
564 |
String source = "package p;" + |
565 |
"public class X<T> {\n" + |
566 |
" X<String> field;\n" + |
567 |
" public void Test() {}" + |
568 |
"}"; |
569 |
createFolder("/P/src/p"); |
570 |
createFile( |
571 |
"/P/src/p/X.java", |
572 |
source |
573 |
); |
574 |
waitForAutoBuild(); |
575 |
|
576 |
ICompilationUnit unit = getCompilationUnit("/P/src/p/X.java"); |
577 |
IType type = unit.getType("X"); |
578 |
IMethod method = type.getMethods()[0]; |
579 |
IAnnotation[][] parameterAnnotations = method.getParameterAnnotations(); |
580 |
assertNotNull(parameterAnnotations); |
581 |
assertEquals("Wrong length", 0, parameterAnnotations.length); |
582 |
} finally { |
583 |
deleteProject("P"); |
584 |
} |
585 |
} |
586 |
/** |
587 |
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=334783" |
588 |
*/ |
589 |
public void testParamAnnotations7() throws CoreException, IOException { |
590 |
try { |
591 |
IJavaProject project = createJavaProject("P", new String[] {"src"}, new String[] {"JCL15_LIB"}, "bin", "1.5"); |
592 |
String[] pathAndContents = new String[]{"p/X.java", |
593 |
"package p;" + |
594 |
"public class X<T> {\n" + |
595 |
" X<String> field;\n" + |
596 |
" public void Test() {}" + |
597 |
"}" |
598 |
}; |
599 |
addLibrary(project, "lib334783.jar", "libsrc.zip", pathAndContents, JavaCore.VERSION_1_5); |
600 |
|
601 |
waitForAutoBuild(); |
602 |
IPackageFragmentRoot root = project.getPackageFragmentRoot(getFile("/P/lib334783.jar")); |
603 |
IType type = root.getPackageFragment("p").getClassFile("X.class").getType(); |
604 |
|
605 |
IMethod method = type.getMethods()[1]; |
606 |
IAnnotation[][] parameterAnnotations = method.getParameterAnnotations(); |
607 |
assertNotNull(parameterAnnotations); |
608 |
assertEquals("Wrong length", 0, parameterAnnotations.length); |
609 |
} finally { |
610 |
deleteProject("P"); |
611 |
} |
612 |
} |
302 |
} |
613 |
} |