private void implementListGetter(final Tree listNode) { plasticClass.introduceMethod(ConduitMethods.GET, new InstructionBuilderCallback() { public void doBuild(InstructionBuilder builder) { implementListConstructor(builder, listNode); builder.returnResult(); } }); }
private void implementMapGetter(final Tree mapNode) { plasticClass.introduceMethod(ConduitMethods.GET, new InstructionBuilderCallback() { public void doBuild(InstructionBuilder builder) { implementMapConstructor(builder, mapNode); builder.returnResult(); } }); }
private void implementRangeOpGetter(final Tree rangeNode) { plasticClass.introduceMethod(ConduitMethods.GET, new InstructionBuilderCallback() { public void doBuild(InstructionBuilder builder) { // Put the delegate on top of the stack builder.loadThis().getField(getDelegateField()); invokeMethod(builder, DelegateMethods.RANGE, rangeNode, 0); builder.returnResult(); } }); }
private void implementGetter(final Method readMethod) { plasticClass.introduceMethod(ConduitMethods.GET, new InstructionBuilderCallback() { public void doBuild(InstructionBuilder builder) { invokeNavigateMethod(builder); invokeMethod(builder, readMethod, null, 0); boxIfPrimitive(builder, conduitPropertyType); builder.returnResult(); } }); }
private void implementSetter(final Method writeMethod) { plasticClass.introduceMethod(ConduitMethods.SET, new InstructionBuilderCallback() { public void doBuild(InstructionBuilder builder) { invokeNavigateMethod(builder); Class propertyType = writeMethod.getParameterTypes()[0]; String propertyTypeName = PlasticUtils.toTypeName(propertyType); builder.loadArgument(1).castOrUnbox(propertyTypeName); builder.invoke(writeMethod); builder.returnResult(); } }); }
/** * @param node * subexpression to invert */ private void implementNotOpGetter(final Tree node) { // Implement get() as navigate, then do a method invocation based on node // then, then pass (wrapped) result to delegate.invert() plasticClass.introduceMethod(ConduitMethods.GET, new InstructionBuilderCallback() { public void doBuild(InstructionBuilder builder) { Type expressionType = implementNotExpression(builder, node); // Yes, we know this will always be the case, for now. boxIfPrimitive(builder, expressionType); builder.returnResult(); } }); }
@Override public void adviseMethod(Method method, org.apache.tapestry5.plastic.MethodAdvice advice) { assert method != null; assert advice != null; if (!allMethods.contains(method)) throw new IllegalArgumentException(String.format("Method %s is not defined for interface %s.", method, serviceInterface)); plasticClass.introduceMethod(method).addAdvice(advice); }
public void implementNoOpMethod(MethodDescription method, String format, Object... arguments) { final String message = String.format(format, arguments); plasticClass.introduceMethod(method).changeImplementation(new InstructionBuilderCallback() { public void doBuild(InstructionBuilder builder) { builder.throwException(RuntimeException.class, message); } }); }
@Override public void adviseMethod(Method method, org.apache.tapestry5.plastic.MethodAdvice advice) { assert method != null; assert advice != null; if (!allMethods.contains(method)) throw new IllegalArgumentException(String.format("Method %s is not defined for interface %s.", method, serviceInterface)); plasticClass.introduceMethod(method).addAdvice(advice); }
/** * Commits any stored changes to the PlasticClass; this is used to defer adding advice to the dispatch method. */ public void commit() { if (!eventHandlerAdvice.isEmpty()) { PlasticMethod dispatchMethod = plasticClass.introduceMethod(TransformConstants.DISPATCH_COMPONENT_EVENT_DESCRIPTION); for (MethodAdvice advice : eventHandlerAdvice) { dispatchMethod.addAdvice(advice); } } }
public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) { if (model.getComponentClassName().equals(Form.class.getName())) { PlasticMethod setupRender = plasticClass.introduceMethod(TransformConstants.SETUP_RENDER_DESCRIPTION); setupRender.addAdvice(new MethodAdvice() { public void advise(MethodInvocation invocation) { javaScriptSupport.importStack(FormSupportStack.STACK_ID); invocation.proceed(); } }); model.addRenderPhase(SetupRender.class); } } }
public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) { if (model.getComponentClassName().equals(DateField.class.getName()) && js.getStack("core-datefield").toString().contains("JQueryDateFieldStack")) { PlasticMethod setupRender = plasticClass.introduceMethod(TransformConstants.AFTER_RENDER_DESCRIPTION); setupRender.addAdvice(new MethodAdvice() { public void advise(MethodInvocation invocation) { MarkupWriter writer = (MarkupWriter) invocation.getParameter(0); invocation.proceed(); Element el = writer.getElement().getElementByAttributeValue("class", "t-calendar-trigger"); if(el != null){ el.remove(); } } }); model.addRenderPhase(AfterRender.class); } }
private void processClassAnnotationAtSetupRenderPhase(PlasticClass componentClass, MutableComponentModel model) { Import annotation = componentClass.getAnnotation(Import.class); if (annotation != null) { PlasticMethod setupRender = componentClass.introduceMethod(TransformConstants.SETUP_RENDER_DESCRIPTION); decorateMethod(componentClass, model, setupRender, annotation); model.addRenderPhase(SetupRender.class); } }
private void invokeMethodWithinLifecycle(PlasticClass plasticClass, PlasticMethod method) { MethodHandle handle = method.getHandle(); plasticClass.introduceMethod(lifecycleMethodDescription).addAdvice(createAdvice(handle)); }
public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) { // Subclasses don't need to bother, they'll inherit from super-classes. if (!support.isRootTransformation()) { return; } plasticClass.introduceInterface(RenderCommand.class); PlasticField resourcesField = plasticClass.introduceField(InternalComponentResources.class, "resources").injectFromInstanceContext(); plasticClass.introduceMethod(RENDER_DESCRIPTION).delegateTo(resourcesField); plasticClass.introduceMethod(TransformConstants.POST_RENDER_CLEANUP_DESCRIPTION).delegateTo(resourcesField); } }
private void implementComponentInterface(PlasticClass plasticClass) { plasticClass.introduceInterface(Component.class); final PlasticField resourcesField = plasticClass.introduceField(InternalComponentResources.class, "internalComponentResources").injectFromInstanceContext(); plasticClass.introduceMethod(GET_COMPONENT_RESOURCES, new InstructionBuilderCallback() { public void doBuild(InstructionBuilder builder) { builder.loadThis().getField(resourcesField).returnResult(); } }); }
public void transform(PlasticClass plasticClass) { PlasticMethod delegateMethod = plasticClass.introducePrivateMethod( PlasticUtils.toTypeName(serviceType), "delegate", null, null); delegateMethod.addAdvice(new MethodAdvice() { public void advise(MethodInvocation invocation) { invocation.setReturnValue(environment.peekRequired(serviceType)); } }); for (Method method : serviceType.getMethods()) { plasticClass.introduceMethod(method).delegateTo(delegateMethod); } plasticClass.addToString(String.format("<EnvironmentalProxy for %s>", serviceType.getName())); } });
private void invokeMethodsOnPageReset(PlasticClass plasticClass, Flow<PlasticMethod> methods) { final MethodHandle[] handles = methods.map(TO_HANDLE).toArray(MethodHandle.class); plasticClass.introduceMethod(TransformConstants.CONTAINING_PAGE_DID_RESET_DESCRIPTION).addAdvice(new MethodAdvice() { public void advise(MethodInvocation invocation) { invocation.proceed(); Object instance = invocation.getInstance(); for (MethodHandle handle : handles) { handle.invoke(instance); } } }); }
private void addComponentIdValidationLogicOnPageLoad(PlasticClass plasticClass, Flow<EventHandlerMethod> eventHandlerMethods) { ComponentIdValidator[] validators = extractComponentIdValidators(eventHandlerMethods); if (validators.length > 0) { plasticClass.introduceInterface(PageLifecycleListener.class); plasticClass.introduceMethod(TransformConstants.CONTAINING_PAGE_DID_LOAD_DESCRIPTION).addAdvice(new ValidateComponentIds(validators)); } }
public void implementMethodAccessors(final Type activeType, final Tree invokeNode) { final Term term = buildInvokeTerm(activeType, invokeNode); implementNoOpSetter(); conduitPropertyName = term.description; conduitPropertyType = term.genericType; conduitPropertyGenericType = term.genericType; annotationProvider = term.annotationProvider; plasticClass.introduceMethod(ConduitMethods.GET, new InstructionBuilderCallback() { public void doBuild(InstructionBuilder builder) { invokeNavigateMethod(builder); term.callback.doBuild(builder); boxIfPrimitive(builder, conduitPropertyType); builder.returnResult(); } }); implementNoOpSetter(); }