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.

TestJava5ReflectionBasedReferenceTypeDelegate.java 3.3KB

пре 18 година
пре 18 година
пре 18 година
пре 15 година
пре 15 година
пре 18 година
пре 15 година
пре 15 година
пре 15 година
пре 15 година
пре 15 година
пре 15 година
пре 18 година
пре 15 година
пре 18 година
пре 15 година
пре 18 година
пре 15 година
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. * Andrew Clement Initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver;
  13. import junit.framework.Test;
  14. import junit.framework.TestSuite;
  15. import org.aspectj.weaver.reflect.ReflectionBasedReferenceTypeDelegateTest;
  16. public class TestJava5ReflectionBasedReferenceTypeDelegate extends ReflectionBasedReferenceTypeDelegateTest {
  17. public static Test suite() {
  18. TestSuite suite = new TestSuite("TestJava5ReflectionBasedReferenceTypeDelegate");
  19. suite.addTestSuite(TestJava5ReflectionBasedReferenceTypeDelegate.class);
  20. return suite;
  21. }
  22. /**
  23. * Let's play about with a generic type and ensure we can work with it in a reflective world.
  24. */
  25. public void testResolveGeneric() {
  26. UnresolvedType collectionType = UnresolvedType.forName("java.util.Collection");
  27. world.resolve(collectionType).getRawType().resolve(world);
  28. ResolvedMember[] methods = world.resolve(collectionType).getDeclaredMethods();
  29. int i = findMethod("toArray", 1, methods);
  30. assertTrue("Couldn't find 'toArray' in the set of methods? ", i != -1);
  31. // String expectedSignature = "java.lang.Object[] java.util.Collection.toArray(java.lang.Object[])";
  32. String expectedSignature = "([Ljava/lang/Object;)[Ljava/lang/Object;";
  33. assertTrue("Expected signature of '" + expectedSignature + "' but it was '" + methods[i].getSignatureErased(), methods[i]
  34. .getSignatureErased().equals(expectedSignature));
  35. }
  36. /**
  37. * Can we resolve the dreaded Enum type...
  38. */
  39. public void testResolveEnum() {
  40. ResolvedType enumType = world.resolve("java.lang.Enum");
  41. assertTrue("Should be the raw type but is " + enumType.typeKind, enumType.isRawType());
  42. ResolvedType theGenericEnumType = enumType.getGenericType();
  43. assertTrue("Should have a type variable ", theGenericEnumType.getTypeVariables().length > 0);
  44. TypeVariable tv = theGenericEnumType.getTypeVariables()[0];
  45. String expected = "TypeVar E extends java.lang.Enum<E>";
  46. assertTrue("Type variable should be '" + expected + "' but is '" + tv + "'", tv.toString().equals(expected));
  47. }
  48. public void testResolveClass() {
  49. world.resolve("java.lang.Class").getGenericType();
  50. }
  51. public void testGenericInterfaceSuperclass_ReflectionWorldResolution() {
  52. UnresolvedType javaUtilMap = UnresolvedType.forName("java.util.Map");
  53. ReferenceType rawType = (ReferenceType) world.resolve(javaUtilMap);
  54. assertTrue("Should be the raw type ?!? " + rawType.getTypekind(), rawType.isRawType());
  55. ReferenceType genericType = (ReferenceType) rawType.getGenericType();
  56. assertTrue("Should be the generic type ?!? " + genericType.getTypekind(), genericType.isGenericType());
  57. ResolvedType rt = rawType.getSuperclass();
  58. assertTrue("Superclass for Map raw type should be Object but was " + rt, rt.equals(UnresolvedType.OBJECT));
  59. ResolvedType rt2 = genericType.getSuperclass();
  60. assertTrue("Superclass for Map generic type should be Object but was " + rt2, rt2.equals(UnresolvedType.OBJECT));
  61. }
  62. }