private void addMethodAssetOperationAdvice(PlasticMethod method, final FieldHandle access, final Worker<Asset> operation) { method.addAdvice(new MethodAdvice() { public void advise(MethodInvocation invocation) { invocation.proceed(); Asset[] assets = (Asset[]) access.get(invocation.getInstance()); F.flow(assets).each(operation); } }); } }
private void bridgeServiceMethodToFilterMethod(PlasticMethod method, final PlasticField filterField, final PlasticField nextField, final int position, MethodSignature ms, final MethodSignature fms) { method.changeImplementation(new InstructionBuilderCallback() { @Override public void doBuild(InstructionBuilder builder) { builder.loadThis().getField(filterField); int argumentIndex = 0; for (int i = 0; i < fms.getParameterTypes().length; i++) { if (i == position) { builder.loadThis().getField(nextField); } else { builder.loadArgument(argumentIndex++); } } builder.invoke(fms.getMethod()).returnResult(); } }); }
@Override public InstructionBuilder invokeVirtual(PlasticMethod method) { check(); assert method != null; MethodDescription description = method.getDescription(); return invokeVirtual(method.getPlasticClass().getClassName(), description.returnType, description.methodName, description.argumentTypes); }
public boolean accept(PlasticMethod method) { return method.getDescription().methodName.equalsIgnoreCase(methodAlias) || method.hasAnnotation(methodAnnotationClass); } };
public boolean accept(PlasticMethod method) { return !method.isOverride() && !lifecycleMethods.contains(method.getDescription()); } });
EventHandlerMethod(PlasticMethod method) { this.method = method; description = method.getDescription(); parameterSource = buildSource(); String methodName = method.getDescription().methodName; OnEvent onEvent = method.getAnnotation(OnEvent.class); eventType = extractEventType(methodName, onEvent); componentId = extractComponentId(methodName, onEvent); publishEvent = method.getAnnotation(PublishEvent.class); }
delegateMethod.changeImplementation(new InstructionBuilderCallback() plasticClass.introduceMethod(m).delegateTo(delegateMethod);
@Override public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model) { for (final PlasticMethod method : plasticClass .getMethodsWithAnnotation(CommitAfter.class)) { PersistenceContext annotation = method.getAnnotation(PersistenceContext.class); MethodAdvice advice = annotation == null ? shared : new CommitAfterMethodAdvice(manager); method.addAdvice(advice); } } }
private void adviseMethod(PlasticClass plasticClass, PlasticMethod method) { // Every instance of the clas srequires its own per-thread value. This handles the case of multiple // pages containing the component, or the same page containing the component multiple times. PlasticField cacheField = plasticClass.introduceField(PerThreadValue.class, "cache$" + method.getDescription().methodName); cacheField.injectComputed(new ComputedValue<PerThreadValue>() { public PerThreadValue get(InstanceContext context) { // Each instance will get a new PerThreadValue return perThreadManager.createValue(); } }); Cached annotation = method.getAnnotation(Cached.class); MethodResultCacheFactory factory = createFactory(plasticClass, annotation.watch(), method); MethodAdvice advice = createAdvice(cacheField, factory); method.addAdvice(advice); }
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())); } });
@Override public PlasticClass proxyInterface(Class interfaceType, PlasticMethod method) { check(); assert method != null; introduceInterface(interfaceType); // TAP5-2582: avoiding adding/delegating the same method more than once Map<MethodSignature, MethodDescription> map = createMethodSignatureMap(interfaceType); for (MethodSignature methodSignature : map.keySet()) { introduceMethod(map.get(methodSignature)).delegateTo(method); } return this; }
final FieldHandle bindingFieldHandle = plasticClass.introduceField(Binding.class, "cache$watchBinding$" + method.getDescription().methodName).getHandle(); plasticClass.introduceMethod(TransformConstants.CONTAINING_PAGE_DID_LOAD_DESCRIPTION).addAdvice(new MethodAdvice()
public boolean accept(PlasticMethod method) { return method.getDescription().argumentTypes.length == 0 && method.getDescription().methodName.equalsIgnoreCase(methodName); } };
private void invokeMethod(InstructionBuilder builder, PlasticMethod method) { // First, tell the Event object what method is being invoked. builder.loadArgument(1); builder.loadConstant( method.getMethodIdentifier()); builder.invoke(Event.class, void.class, "setMethodDescription", String.class); builder.loadThis(); // Methods either take no parameters, or take a MarkupWriter parameter. if (method.getParameters().size() > 0) { builder.loadArgument(0); } builder.invokeVirtual(method); // Non-void methods will pass a value to the event. if (!method.isVoid()) { builder.boxPrimitive(method.getDescription().returnType); builder.loadArgument(1).swap(); builder.invoke(Event.class, boolean.class, "storeResult", Object.class); builder.when(Condition.NON_ZERO, JUST_RETURN); } }
private void validateNoCheckedExceptions(PlasticMethod method) { if (method.getDescription().checkedExceptionTypes.length > 0) throw new RuntimeException( String.format( "Method %s is not compatible with the @HeartbeatDeferred annotation, as it throws checked exceptions.", method.getMethodIdentifier())); }
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(); } }
private EventHandlerMethodParameterSource buildSource() final String[] parameterTypes = method.getDescription().argumentTypes; RequestParameter parameterAnnotation = method.getParameters().get(i).getAnnotation(RequestParameter.class); return new EventHandlerMethodParameterSource(method.getMethodIdentifier(), operationTracker, providerArray);
private boolean hasAnnotation(PlasticMethod method) { return method.hasAnnotation(OnEvent.class); } };
private void decorateMethod(PlasticClass componentClass, MutableComponentModel model, PlasticMethod method) { Import annotation = method.getAnnotation(Import.class); decorateMethod(componentClass, model, method, annotation); }