jaroslav@355: /** jaroslav@355: * Back 2 Browser Bytecode Translator jaroslav@355: * Copyright (C) 2012 Jaroslav Tulach jaroslav@355: * jaroslav@355: * This program is free software: you can redistribute it and/or modify jaroslav@355: * it under the terms of the GNU General Public License as published by jaroslav@355: * the Free Software Foundation, version 2 of the License. jaroslav@355: * jaroslav@355: * This program is distributed in the hope that it will be useful, jaroslav@355: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@355: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@355: * GNU General Public License for more details. jaroslav@355: * jaroslav@355: * You should have received a copy of the GNU General Public License jaroslav@355: * along with this program. Look for COPYING file in the top folder. jaroslav@355: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@355: */ jaroslav@355: package org.apidesign.bck2brwsr.tck; jaroslav@355: jaroslav@1378: import java.lang.reflect.InvocationHandler; jaroslav@392: import java.lang.reflect.Method; jaroslav@1376: import java.lang.reflect.Proxy; jaroslav@355: import org.apidesign.bck2brwsr.vmtest.Compare; jaroslav@355: import org.apidesign.bck2brwsr.vmtest.VMTest; jaroslav@355: import org.testng.annotations.Factory; jaroslav@355: jaroslav@355: /** jaroslav@355: * jaroslav@355: * @author Jaroslav Tulach jaroslav@355: */ jaroslav@1378: public class ProxyTest { jaroslav@1378: @Compare public String generateAnnotation() throws Exception { jaroslav@1378: class InvHandler implements InvocationHandler { jaroslav@1378: @Override jaroslav@1378: public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { jaroslav@1378: return "Joe Hacker"; jaroslav@1378: } jaroslav@1378: } jaroslav@1378: Anno anno = (Anno) Proxy.newProxyInstance( jaroslav@1378: Anno.class.getClassLoader(), jaroslav@1378: new Class[] { Anno.class }, jaroslav@1378: new InvHandler() jaroslav@1378: ); jaroslav@1378: return anno.name(); jaroslav@1378: } jaroslav@1378: jaroslav@1378: @Compare public int getPrimitiveType() throws Exception { jaroslav@1378: class InvHandler implements InvocationHandler { jaroslav@1378: @Override jaroslav@1378: public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { jaroslav@1378: return 40; jaroslav@1378: } jaroslav@1378: } jaroslav@1378: Anno anno = (Anno) Proxy.newProxyInstance( jaroslav@1378: Anno.class.getClassLoader(), jaroslav@1378: new Class[] { Anno.class }, jaroslav@1378: new InvHandler() jaroslav@1378: ); jaroslav@1378: return 2 + anno.age(); jaroslav@412: } jaroslav@412: jaroslav@1378: public static @interface Anno { jaroslav@1378: public String name(); jaroslav@1378: public int age(); jaroslav@448: } jaroslav@448: jaroslav@355: @Factory jaroslav@355: public static Object[] create() { jaroslav@1378: return VMTest.create(ProxyTest.class); jaroslav@355: } jaroslav@355: }