private void processInterface(Class interfaceClass) { Class[] interfaces = interfaceClass.getInterfaces(); for (int i = 0; i < interfaces.length; i++) addInterfaceToQueue(interfaces[i]); Method[] methods = interfaceClass.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { MethodSignature sig = new MethodSignature(methods[i]); _interfaceMethods.add(sig); } }
public void processClass(Class beanClass) { Class[] interfaces = beanClass.getInterfaces(); for (int i = 0; i < interfaces.length; i++) addInterfaceToQueue(interfaces[i]); Method[] methods = beanClass.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { Method m = methods[i]; int modifiers = m.getModifiers(); if (Modifier.isStatic(modifiers) || !Modifier.isPublic(modifiers)) continue; MethodSignature sig = new MethodSignature(m); _allMethods.add(sig); } }
/** * Adds a <code>toString()</code> method to a class that returns a fixed, pre-computed value. * * @param classFab * ClassFab used to construct the new class. * @param toStringResult * fixed result to be returned by the method. */ public static void addToStringMethod(ClassFab classFab, String toStringResult) { StringBuffer buffer = new StringBuffer("return "); buffer.append(QUOTE); buffer.append(toStringResult); buffer.append(QUOTE); buffer.append(";"); classFab.addMethod(Modifier.PUBLIC, new MethodSignature(String.class, "toString", null, null), buffer.toString()); }
public static void createSimpleMutator(EnhancementOperation op, String fieldName, String propertyName, Class propertyType, Location location) { String methodName = createMutatorMethodName(propertyName); op.addMethod(Modifier.PUBLIC, new MethodSignature(void.class, methodName, new Class[] { propertyType }, null), fieldName + " = $1;", location); }
public static void createSimpleAccessor(EnhancementOperation op, String fieldName, String propertyName, Class propertyType, Location location) { String methodName = op.getAccessorMethodName(propertyName); op.addMethod( Modifier.PUBLIC, new MethodSignature(propertyType, methodName, null, null), "return " + fieldName + ";", location); }
public static void createSimpleAccessor(EnhancementOperation op, String fieldName, String propertyName, Class propertyType, Location location) { String methodName = op.getAccessorMethodName(propertyName); op.addMethod( Modifier.PUBLIC, new MethodSignature(propertyType, methodName, null, null), "return " + fieldName + ";", location); }
/** @since 1.1 */ private void processMethod(Method m, Map map) { _toString |= ClassFabUtils.isToString(m); MethodSignature sig = new MethodSignature(m); String uid = sig.getUniqueId(); MethodSignature existing = (MethodSignature) map.get(uid); if (existing == null || sig.isOverridingSignatureOf(existing)) map.put(uid, sig); }
public static void createSimpleMutator(EnhancementOperation op, String fieldName, String propertyName, Class propertyType, Location location) { String methodName = createMutatorMethodName(propertyName); op.addMethod(Modifier.PUBLIC, new MethodSignature(void.class, methodName, new Class[] { propertyType }, null), fieldName + " = $1;", location); }
public void performEnhancement(EnhancementOperation op, IComponentSpecification spec, Method method, Location location) { Class<?> type = method.getReturnType(); if (type.equals(void.class)) throw new ApplicationRuntimeException( "Cached annotation cannot be used with a method that returns void"); String fieldName = "_$cached$" + method.getName(); MethodSignature signature = new MethodSignature(method); op.addField(fieldName, type); BodyBuilder builder = createCacheMethod(signature, fieldName); op.addMethod(Modifier.PUBLIC, signature, builder.toString(), location); extendCleanupAfterRender(op, fieldName); }
/** @since 1.1 */ private void addSerializable(String pointId) { _classFab.addInterface(Serializable.class); BodyBuilder bb = new BodyBuilder(); bb.add( "return {0}.getServiceSerializationSupport().getServiceTokenForService(\"{1}\");", ServiceSerializationHelper.class.getName(), pointId); MethodSignature sig = new MethodSignature(Object.class, "writeReplace", null, null); _classFab.addMethod(Modifier.PRIVATE, sig, bb.toString()); }
MethodSignature sig = new MethodSignature(propertyType, op .getAccessorMethodName(propertyName), null, null);
public void injectAsset(EnhancementOperation op, String assetName, String propertyName, Location location) { Defense.notNull(op, "op"); Defense.notNull(assetName, "assetName"); Defense.notNull(propertyName, "propertyName"); Class propertyType = EnhanceUtils.extractPropertyType(op, propertyName, null); op.claimReadonlyProperty(propertyName); if (!propertyType.isAssignableFrom(IAsset.class)) throw new ApplicationRuntimeException(EnhanceMessages .incompatiblePropertyType(propertyName, propertyType, IAsset.class)); String methodName = op.getAccessorMethodName(propertyName); MethodSignature sig = new MethodSignature(propertyType, methodName, null, null); String code = "return getAsset(\"" + assetName + "\");"; op.addMethod(Modifier.PUBLIC, sig, code, location); }
public void injectBean(EnhancementOperation op, String beanName, String propertyName, Location location) { Defense.notNull(op, "op"); Defense.notNull(beanName, "beanName"); Defense.notNull(propertyName, "propertyName"); op.claimReadonlyProperty(propertyName); Class propertyType = EnhanceUtils.extractPropertyType(op, propertyName, null); String methodName = op.getAccessorMethodName(propertyName); MethodSignature sig = new MethodSignature(propertyType, methodName, null, null); // i.e. // return (foo.bar.Baz) getBeans().getBean("baz"); op.addMethod(Modifier.PUBLIC, sig, "return (" + ClassFabUtils.getJavaClassName(propertyType) + ") getBeans().getBean(\"" + beanName + "\");", location); }
public void injectBean(EnhancementOperation op, String beanName, String propertyName, Location location) { Defense.notNull(op, "op"); Defense.notNull(beanName, "beanName"); Defense.notNull(propertyName, "propertyName"); op.claimReadonlyProperty(propertyName); Class propertyType = EnhanceUtils.extractPropertyType(op, propertyName, null); String methodName = op.getAccessorMethodName(propertyName); MethodSignature sig = new MethodSignature(propertyType, methodName, null, null); // i.e. // return (foo.bar.Baz) getBeans().getBean("baz"); op.addMethod(Modifier.PUBLIC, sig, "return (" + ClassFabUtils.getJavaClassName(propertyType) + ") getBeans().getBean(\"" + beanName + "\");", location); }
/** * We construct a method that always goes through this service model's * {@link #getServiceImplementationForCurrentThread())} method. */ private static void addServiceAccessor(ClassFab classFab, String serviceModelMethodName, ServicePoint servicePoint) { Class serviceInterface = servicePoint.getServiceInterface(); classFab.addField(SERVICE_ACCESSOR_METHOD_NAME, serviceInterface); BodyBuilder builder = new BodyBuilder(); builder.begin(); builder.add("return ("); builder.add(serviceInterface.getName()); builder.add(") _serviceModel."); builder.add(serviceModelMethodName); builder.add("();"); builder.end(); classFab.addMethod(Modifier.PRIVATE | Modifier.FINAL, new MethodSignature(serviceInterface, SERVICE_ACCESSOR_METHOD_NAME, null, null), builder.toString()); } }
private void addMutator(EnhancementOperation op, String propertyName, Class propertyType, String fieldName, boolean persistent, Location location) { String methodName = EnhanceUtils.createMutatorMethodName(propertyName); BodyBuilder body = new BodyBuilder(); body.begin(); if (persistent) { body.add("org.apache.tapestry.Tapestry#fireObservedChange(this, "); body.addQuoted(propertyName); body.addln(", ($w) $1);"); } body.addln(fieldName + " = $1;"); body.end(); MethodSignature sig = new MethodSignature(void.class, methodName, new Class[] { propertyType }, null); op.addMethod(Modifier.PUBLIC, sig, body.toString(), location); }
private void addMutator(EnhancementOperation op, String propertyName, Class propertyType, String fieldName, boolean persistent, Location location) { String methodName = EnhanceUtils.createMutatorMethodName(propertyName); BodyBuilder body = new BodyBuilder(); body.begin(); if (persistent) { body.add("org.apache.tapestry.Tapestry#fireObservedChange(this, "); body.addQuoted(propertyName); body.addln(", ($w) $1);"); } body.addln(fieldName + " = $1;"); body.end(); MethodSignature sig = new MethodSignature(void.class, methodName, new Class[] { propertyType }, null); op.addMethod(Modifier.PUBLIC, sig, body.toString(), location); }
public void injectObject(EnhancementOperation op, String objectReference, String propertyName, Location location) { Defense.notNull(op, "op"); Defense.notNull(propertyName, "propertyName"); Defense.notNull(objectReference, "objectReference"); Class propertyType = op.getPropertyType(propertyName); if (propertyType == null) propertyType = Object.class; op.claimReadonlyProperty(propertyName); Object injectedValue = _provider.obtainValue(objectReference, location); if (injectedValue == null) throw new ApplicationRuntimeException(EnhanceMessages .locatedValueIsNull(objectReference), location, null); if (!propertyType.isInstance(injectedValue)) throw new ApplicationRuntimeException(EnhanceMessages.incompatibleInjectType(objectReference, injectedValue, propertyType), location, null); String fieldName = op.addInjectedField("_$" + propertyName, propertyType, injectedValue); String methodName = EnhanceUtils.createAccessorMethodName(propertyName); op.addMethod(Modifier.PUBLIC, new MethodSignature(propertyType, methodName, null, null), "return " + fieldName + ";", location); }
String buildBindingAccessor(EnhancementOperation op, String fieldName, String parameterName, Location location) { BodyBuilder body = new BodyBuilder(); body.begin(); String bindingFieldName = fieldName + "$Binding"; String bindingCheckedName = bindingFieldName + "Checked"; op.addField(bindingFieldName, IBinding.class); op.addField(bindingCheckedName, Boolean.TYPE); body.addln("if (!{0})", bindingCheckedName); body.begin(); body.addln("{0} = getBinding(\"{1}\");", bindingFieldName, parameterName); body.addln("{0} = true;", bindingCheckedName); body.end(); body.addln("return {0};", bindingFieldName); body.end(); String methodName = EnhanceUtils.createAccessorMethodName(bindingFieldName); op.addMethod(Modifier.PUBLIC, new MethodSignature(IBinding.class, methodName, new Class[0], null), body.toString(), location); return methodName + "()"; }
String buildBindingAccessor(EnhancementOperation op, String fieldName, String parameterName, Location location) { BodyBuilder body = new BodyBuilder(); body.begin(); String bindingFieldName = fieldName + "$Binding"; String bindingCheckedName = bindingFieldName + "Checked"; op.addField(bindingFieldName, IBinding.class); op.addField(bindingCheckedName, Boolean.TYPE); body.addln("if (!{0})", bindingCheckedName); body.begin(); body.addln("{0} = getBinding(\"{1}\");", bindingFieldName, parameterName); body.addln("{0} = true;", bindingCheckedName); body.end(); body.addln("return {0};", bindingFieldName); body.end(); String methodName = EnhanceUtils.createAccessorMethodName(bindingFieldName); op.addMethod(Modifier.PUBLIC, new MethodSignature(IBinding.class, methodName, new Class[0], null), body.toString(), location); return methodName + "()"; }