public static Constructor getConstructor(Class type, Class[] parameterTypes) { try { Constructor constructor = type.getDeclaredConstructor(parameterTypes); constructor.setAccessible(true); return constructor; } catch (NoSuchMethodException e) { throw new CodeGenerationException(e); } }
public static Object newInstance(final Constructor cstruct, final Object[] args) { boolean flag = cstruct.isAccessible(); try { cstruct.setAccessible(true); Object result = cstruct.newInstance(args); return result; } catch (InstantiationException e) { throw new CodeGenerationException(e); } catch (IllegalAccessException e) { throw new CodeGenerationException(e); } catch (InvocationTargetException e) { throw new CodeGenerationException(e.getTargetException()); } finally { cstruct.setAccessible(flag); } }
public Object run() { try { Class loader = Class.forName("java.lang.ClassLoader"); // JVM crash w/o this DEFINE_CLASS = loader.getDeclaredMethod("defineClass", new Class[]{ String.class, byte[].class, Integer.TYPE, Integer.TYPE, ProtectionDomain.class }); DEFINE_CLASS.setAccessible(true); } catch (ClassNotFoundException e) { throw new CodeGenerationException(e); } catch (NoSuchMethodException e) { throw new CodeGenerationException(e); } return null; } });
private static void setCallbacksHelper(Class type, Callback[] callbacks, String methodName) { // TODO: optimize try { Method setter = getCallbacksSetter(type, methodName); setter.invoke(null, new Object[]{ callbacks }); } catch (NoSuchMethodException e) { throw new IllegalArgumentException(type + " is not an enhanced class"); } catch (IllegalAccessException e) { throw new CodeGenerationException(e); } catch (InvocationTargetException e) { throw new CodeGenerationException(e); } }
/** * Return the <code>MethodProxy</code> used when intercepting the method * matching the given signature. * @param type the class generated by Enhancer * @param sig the signature to match * @return the MethodProxy instance, or null if no applicable matching method is found * @throws IllegalArgumentException if the Class was not created by Enhancer or does not use a MethodInterceptor */ public static MethodProxy find(Class type, Signature sig) { try { Method m = type.getDeclaredMethod(MethodInterceptorGenerator.FIND_PROXY_NAME, MethodInterceptorGenerator.FIND_PROXY_TYPES); return (MethodProxy)m.invoke(null, new Object[]{ sig }); } catch (NoSuchMethodException e) { throw new IllegalArgumentException("Class " + type + " does not use a MethodInterceptor"); } catch (IllegalAccessException e) { throw new CodeGenerationException(e); } catch (InvocationTargetException e) { throw new CodeGenerationException(e); } }
/** Creates a new instance of AddDelegateTransformer */ public AddDelegateTransformer(Class delegateIf[], Class delegateImpl) { try { delegateImpl.getConstructor(new Class[]{ Object.class }); this.delegateIf = delegateIf; this.delegateImpl = delegateImpl; delegateType = Type.getType(delegateImpl); } catch (NoSuchMethodException e) { throw new CodeGenerationException(e); } }
public static Object newProxyInstance(ClassLoader loader, Class[] interfaces, InvocationHandler h) { try { Class clazz = getProxyClass(loader, interfaces); return clazz.getConstructor(new Class[]{ InvocationHandler.class }).newInstance(new Object[]{ h }); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new CodeGenerationException(e); } } }
public static Constructor findConstructor(String desc, ClassLoader loader) { try { int lparen = desc.indexOf('('); String className = desc.substring(0, lparen).trim(); return getClass(className, loader).getConstructor(parseTypes(desc, loader)); } catch (ClassNotFoundException e) { throw new CodeGenerationException(e); } catch (NoSuchMethodException e) { throw new CodeGenerationException(e); } }
public static Method findMethod(String desc, ClassLoader loader) { try { int lparen = desc.indexOf('('); int dot = desc.lastIndexOf('.', lparen); String className = desc.substring(0, dot).trim(); String methodName = desc.substring(dot + 1, lparen).trim(); return getClass(className, loader).getDeclaredMethod(methodName, parseTypes(desc, loader)); } catch (ClassNotFoundException e) { throw new CodeGenerationException(e); } catch (NoSuchMethodException e) { throw new CodeGenerationException(e); } }
private static PropertyDescriptor[] getPropertiesHelper(Class type, boolean read, boolean write) { try { BeanInfo info = Introspector.getBeanInfo(type, Object.class); PropertyDescriptor[] all = info.getPropertyDescriptors(); if (read && write) { return all; } List properties = new ArrayList(all.length); for (int i = 0; i < all.length; i++) { PropertyDescriptor pd = all[i]; if ((read && pd.getReadMethod() != null) || (write && pd.getWriteMethod() != null)) { properties.add(pd); } } return (PropertyDescriptor[])properties.toArray(new PropertyDescriptor[properties.size()]); } catch (IntrospectionException e) { throw new CodeGenerationException(e); } }
throw new CodeGenerationException(e);
public void end_class() { if (!TypeUtils.isInterface(access)) { try { generate(); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new CodeGenerationException(e); } } super.end_class(); }
public static void string_switch(CodeEmitter e, String[] strings, int switchStyle, ObjectSwitchCallback callback) { try { switch (switchStyle) { case Constants.SWITCH_STYLE_TRIE: string_switch_trie(e, strings, callback); break; case Constants.SWITCH_STYLE_HASH: string_switch_hash(e, strings, callback, false); break; case Constants.SWITCH_STYLE_HASHONLY: string_switch_hash(e, strings, callback, true); break; default: throw new IllegalArgumentException("unknown switch style " + switchStyle); } } catch (RuntimeException ex) { throw ex; } catch (Error ex) { throw ex; } catch (Exception ex) { throw new CodeGenerationException(ex); } }
private void addDelegate(Method m) { Method delegate; try { delegate = delegateImpl.getMethod(m.getName(), m.getParameterTypes()); if (!delegate.getReturnType().getName().equals(m.getReturnType().getName())){ throw new IllegalArgumentException("Invalid delegate signature " + delegate); } } catch (NoSuchMethodException e) { throw new CodeGenerationException(e); } final Signature sig = ReflectUtils.getSignature(m); Type[] exceptions = TypeUtils.getTypes(m.getExceptionTypes()); CodeEmitter e = super.begin_method(Constants.ACC_PUBLIC, sig, exceptions); e.load_this(); e.getfield(DELEGATE); e.load_args(); e.invoke_virtual(delegateType, sig); e.return_value(); e.end_method(); } }
throw e; } catch (Exception e) { throw new CodeGenerationException(e);
throw x; } catch (Exception x) { throw new CodeGenerationException(x);
throw e; } catch (Exception e) { throw new CodeGenerationException(e);
throw ex; } catch (Exception ex) { throw new CodeGenerationException(ex);
throw e; } catch (Exception e) { throw new CodeGenerationException(e);
public static Constructor getConstructor(Class type, Class[] parameterTypes) { try { Constructor constructor = type.getDeclaredConstructor(parameterTypes); constructor.setAccessible(true); return constructor; } catch (NoSuchMethodException e) { throw new CodeGenerationException(e); } }