use of org.apache.tapestry5.plastic.PlasticMethod in project tapestry-5 by apache.
the class ImportWorker method processClassAnnotationAtSetupRenderPhase.
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);
}
}
use of org.apache.tapestry5.plastic.PlasticMethod in project tapestry-5 by apache.
the class HeartbeatDeferredWorkerTest method testFailure.
private void testFailure(MethodDescription description, String messageFragment) {
PlasticMethod method = newMock(PlasticMethod.class);
boolean isVoid = description.returnType.equals("void");
expect(method.isVoid()).andReturn(isVoid);
if (isVoid) {
expect(method.getDescription()).andReturn(description).atLeastOnce();
}
expect(method.getMethodIdentifier()).andReturn("<MethodId>");
replay();
try {
worker.deferMethodInvocations(method);
unreachable();
} catch (RuntimeException ex) {
assertMessageContains(ex, messageFragment);
}
verify();
}
use of org.apache.tapestry5.plastic.PlasticMethod in project tapestry-5 by apache.
the class CommitAfterWorker method transform.
@Override
public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) {
for (final PlasticMethod method : plasticClass.getMethodsWithAnnotation(CommitAfter.class)) {
PersistenceContext annotation = method.getAnnotation(PersistenceContext.class);
method.addAdvice(methodAdvices.get(annotation == null ? null : annotation.unitName()));
}
}
use of org.apache.tapestry5.plastic.PlasticMethod in project tapestry-5 by apache.
the class ThunkCreatorImpl method createInstantiator.
private <T> ClassInstantiator<T> createInstantiator(final Class<T> interfaceType) {
return proxyFactory.createProxy(interfaceType, new PlasticClassTransformer() {
@Override
public void transform(PlasticClass plasticClass) {
final PlasticField objectCreatorField = plasticClass.introduceField(ObjectCreator.class, "creator").injectFromInstanceContext();
PlasticMethod delegateMethod = plasticClass.introducePrivateMethod(interfaceType.getName(), "delegate", null, null);
delegateMethod.changeImplementation(new InstructionBuilderCallback() {
@Override
public void doBuild(InstructionBuilder builder) {
builder.loadThis().getField(objectCreatorField);
builder.invoke(CREATE_OBJECT);
builder.checkcast(interfaceType).returnResult();
}
});
for (Method method : interfaceType.getMethods()) {
plasticClass.introduceMethod(method).delegateTo(delegateMethod);
}
if (!plasticClass.isMethodImplemented(PlasticUtils.TO_STRING_DESCRIPTION)) {
final PlasticField descriptionField = plasticClass.introduceField(String.class, "description").injectFromInstanceContext();
plasticClass.introduceMethod(PlasticUtils.TO_STRING_DESCRIPTION, new InstructionBuilderCallback() {
@Override
public void doBuild(InstructionBuilder builder) {
builder.loadThis().getField(descriptionField).returnResult();
}
});
}
}
});
}
use of org.apache.tapestry5.plastic.PlasticMethod in project tapestry-5 by apache.
the class OnEventWorker method createRequestBodyProvider.
@SuppressWarnings({ "unchecked", "rawtypes" })
private EventHandlerMethodParameterProvider createRequestBodyProvider(PlasticMethod method, final int parameterIndex, final String parameterTypeName, final boolean allowEmpty) {
final String methodIdentifier = method.getMethodIdentifier();
return (event) -> {
Invokable<Object> operation = () -> {
Class parameterType = classCache.forName(parameterTypeName);
Optional result = restSupport.getRequestBodyAs(parameterType);
if (!allowEmpty && !result.isPresent()) {
throw new RuntimeException(String.format("The request has an empty body and %s has one parameter with @RequestBody(allowEmpty=false)", methodIdentifier));
}
return result.orElse(null);
};
return operationTracker.invoke("Converting HTTP request body for @RequestBody parameter", operation);
};
}
Aggregations