summaryrefslogtreecommitdiffstats
path: root/bcel-builder/testsrc/org/aspectj/apache/bcel/classfile/tests/GenericsErasureTesting.java
blob: f0e5de738bc416943a3b7b5c3276c63d9a9517a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* *******************************************************************
 * Copyright (c) 2005 Contributors
 * All rights reserved. 
 * This program and the accompanying materials are made available 
 * under the terms of the Eclipse Public License v1.0 
 * which accompanies this distribution and is available at 
 * http://www.eclipse.org/legal/epl-v10.html 
 *  
 * Contributors: 
 *     Andy Clement (IBM)     initial implementation 
 * ******************************************************************/
package org.aspectj.apache.bcel.classfile.tests;

import org.aspectj.apache.bcel.classfile.Attribute;
import org.aspectj.apache.bcel.classfile.JavaClass;
import org.aspectj.apache.bcel.classfile.Method;
import org.aspectj.apache.bcel.classfile.Signature;

/**
 * Should be possible to recover original declared signatures after erasure by using
 * the signature attribute.
 */
public class GenericsErasureTesting extends BcelTestCase {
	
	
	public void testLoadingGenerics() throws ClassNotFoundException {
		JavaClass clazz = getClassFromJar("ErasureTestData");
		Method m = getMethod(clazz,"getData");
		String sig = m.getDeclaredSignature();
		System.err.println(getSignatureAttribute(clazz,"getData"));
		System.err.println(sig);
		assertTrue("Incorrect: "+sig,sig.equals("()Ljava/util/Vector<Ljava/lang/String;>;"));
	}
	
	
	// helper methods below
	
	public Signature getSignatureAttribute(JavaClass clazz,String name) {
		Method m = getMethod(clazz,name);
		Attribute[] as = m.getAttributes();
		for (int i = 0; i < as.length; i++) {
			Attribute attribute = as[i];
			if (attribute.getName().equals("Signature")) {
				return (Signature)attribute;
			}
		}
		return null;
	}
	
}