You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MemberTestCase15.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* *******************************************************************
  2. * Copyright (c) 2005 Contributors.
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Adrian Colyer Initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver;
  13. import org.aspectj.weaver.bcel.BcelWorld;
  14. import junit.framework.TestCase;
  15. /**
  16. * @author colyer
  17. *
  18. */
  19. public class MemberTestCase15 extends TestCase {
  20. public void testCanBeParameterizedRegularMethod() {
  21. BcelWorld world = new BcelWorld();
  22. ResolvedType javaLangClass = world.resolve(UnresolvedType.forName("java/lang/Class"));
  23. ResolvedMember[] methods = javaLangClass.getDeclaredMethods();
  24. ResolvedMember getAnnotations = null;
  25. for (int i = 0; i < methods.length; i++) {
  26. if (methods[i].getName().equals("getAnnotations")) {
  27. getAnnotations = methods[i];
  28. break;
  29. }
  30. }
  31. if (getAnnotations != null) { // so can run on non-Java 5
  32. // System.out.println("got it");
  33. assertFalse(getAnnotations.canBeParameterized());
  34. }
  35. }
  36. public void testCanBeParameterizedGenericMethod() {
  37. BcelWorld world = new BcelWorld();
  38. world.setBehaveInJava5Way(true);
  39. ResolvedType javaLangClass = world.resolve(UnresolvedType.forName("java.lang.Class"));
  40. javaLangClass = javaLangClass.getGenericType();
  41. if (javaLangClass == null) return; // for < 1.5
  42. ResolvedMember[] methods = javaLangClass.getDeclaredMethods();
  43. ResolvedMember asSubclass = null;
  44. for (int i = 0; i < methods.length; i++) {
  45. if (methods[i].getName().equals("asSubclass")) {
  46. asSubclass = methods[i];
  47. break;
  48. }
  49. }
  50. if (asSubclass != null) { // so can run on non-Java 5
  51. // System.out.println("got it");
  52. assertTrue(asSubclass.canBeParameterized());
  53. }
  54. }
  55. public void testCanBeParameterizedMethodInGenericType() {
  56. BcelWorld world = new BcelWorld();
  57. world.setBehaveInJava5Way(true);
  58. ResolvedType javaUtilList = world.resolve(UnresolvedType.forName("java.util.List"));
  59. javaUtilList = javaUtilList.getGenericType();
  60. if (javaUtilList == null) return; // for < 1.5
  61. ResolvedMember[] methods = javaUtilList.getDeclaredMethods();
  62. ResolvedMember add = null;
  63. for (int i = 0; i < methods.length; i++) {
  64. if (methods[i].getName().equals("add")) {
  65. add = methods[i];
  66. break;
  67. }
  68. }
  69. if (add != null) { // so can run on non-Java 5
  70. // System.out.println("got it");
  71. assertTrue(add.canBeParameterized());
  72. }
  73. }
  74. }