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.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 (int i = 0; i < as.length; i++) {
  35. Attribute attribute = as[i];
  36. if (attribute.getName().equals("Signature")) {
  37. return (Signature)attribute;
  38. }
  39. }
  40. return null;
  41. }
  42. }