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.

GenericsErasureTesting.java 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Andy Clement (IBM) initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.apache.bcel.classfile.tests;
  13. import org.aspectj.apache.bcel.classfile.Attribute;
  14. import org.aspectj.apache.bcel.classfile.JavaClass;
  15. import org.aspectj.apache.bcel.classfile.Method;
  16. import org.aspectj.apache.bcel.classfile.Signature;
  17. /**
  18. * Should be possible to recover original declared signatures after erasure by using
  19. * the signature attribute.
  20. */
  21. public class GenericsErasureTesting extends BcelTestCase {
  22. public void testLoadingGenerics() throws ClassNotFoundException {
  23. JavaClass clazz = getClassFromJar("ErasureTestData");
  24. Method m = getMethod(clazz,"getData");
  25. String sig = m.getDeclaredSignature();
  26. System.err.println(getSignatureAttribute(clazz,"getData"));
  27. System.err.println(sig);
  28. assertTrue("Incorrect: "+sig,sig.equals("()Ljava/util/Vector<Ljava/lang/String;>;"));
  29. }
  30. // helper methods below
  31. public Signature getSignatureAttribute(JavaClass clazz,String name) {
  32. Method m = getMethod(clazz,name);
  33. Attribute[] as = m.getAttributes();
  34. for (Attribute attribute : as) {
  35. if (attribute.getName().equals("Signature")) {
  36. return (Signature) attribute;
  37. }
  38. }
  39. return null;
  40. }
  41. }