Search in sources :

Example 21 with Type

use of org.apache.tapestry5.internal.plastic.asm.Type in project tapestry-5 by apache.

the class Remapper method mapValue.

/**
 * Returns the given value, remapped with this remapper. Possible values are {@link Boolean},
 * {@link Byte}, {@link Short}, {@link Character}, {@link Integer}, {@link Long}, {@link Double},
 * {@link Float}, {@link String}, {@link Type}, {@link Handle}, {@link ConstantDynamic} or arrays
 * of primitive types .
 *
 * @param value an object. Only {@link Type}, {@link Handle} and {@link ConstantDynamic} values
 *     are remapped.
 * @return the given value, remapped with this remapper.
 */
public Object mapValue(final Object value) {
    if (value instanceof Type) {
        return mapType((Type) value);
    }
    if (value instanceof Handle) {
        Handle handle = (Handle) value;
        return new Handle(handle.getTag(), mapType(handle.getOwner()), mapMethodName(handle.getOwner(), handle.getName(), handle.getDesc()), handle.getTag() <= Opcodes.H_PUTSTATIC ? mapDesc(handle.getDesc()) : mapMethodDesc(handle.getDesc()), handle.isInterface());
    }
    if (value instanceof ConstantDynamic) {
        ConstantDynamic constantDynamic = (ConstantDynamic) value;
        int bootstrapMethodArgumentCount = constantDynamic.getBootstrapMethodArgumentCount();
        Object[] remappedBootstrapMethodArguments = new Object[bootstrapMethodArgumentCount];
        for (int i = 0; i < bootstrapMethodArgumentCount; ++i) {
            remappedBootstrapMethodArguments[i] = mapValue(constantDynamic.getBootstrapMethodArgument(i));
        }
        String descriptor = constantDynamic.getDescriptor();
        return new ConstantDynamic(mapInvokeDynamicMethodName(constantDynamic.getName(), descriptor), mapDesc(descriptor), (Handle) mapValue(constantDynamic.getBootstrapMethod()), remappedBootstrapMethodArguments);
    }
    return value;
}
Also used : Type(org.apache.tapestry5.internal.plastic.asm.Type) Handle(org.apache.tapestry5.internal.plastic.asm.Handle) ConstantDynamic(org.apache.tapestry5.internal.plastic.asm.ConstantDynamic)

Example 22 with Type

use of org.apache.tapestry5.internal.plastic.asm.Type in project tapestry-5 by apache.

the class AnalyzerAdapter method pop.

private void pop(final String descriptor) {
    char firstDescriptorChar = descriptor.charAt(0);
    if (firstDescriptorChar == '(') {
        int numSlots = 0;
        Type[] types = Type.getArgumentTypes(descriptor);
        for (Type type : types) {
            numSlots += type.getSize();
        }
        pop(numSlots);
    } else if (firstDescriptorChar == 'J' || firstDescriptorChar == 'D') {
        pop(2);
    } else {
        pop(1);
    }
}
Also used : Type(org.apache.tapestry5.internal.plastic.asm.Type)

Example 23 with Type

use of org.apache.tapestry5.internal.plastic.asm.Type in project tapestry-5 by apache.

the class FieldValidatorSourceImpl method createValidator.

private FieldValidator createValidator(Field field, ValidatorSpecification spec, String overrideId, Messages overrideMessages) {
    String validatorType = spec.getValidatorType();
    assert InternalUtils.isNonBlank(validatorType);
    Validator validator = validators.get(validatorType);
    if (validator == null)
        throw new IllegalArgumentException(String.format("Unknown validator type '%s'. Configured validators are %s.", validatorType, InternalUtils.join(InternalUtils.sortedKeys(validators))));
    // I just have this thing about always treating parameters as finals, so
    // we introduce a second variable to treat a mutable.
    String formValidationid = formSupport.getFormValidationId();
    Object coercedConstraintValue = computeConstraintValue(validatorType, validator, spec.getConstraintValue(), formValidationid, overrideId, overrideMessages);
    MessageFormatter formatter = findMessageFormatter(formValidationid, overrideId, overrideMessages, validatorType, validator);
    return new FieldValidatorImpl(field, coercedConstraintValue, formatter, validator, formSupport);
}
Also used : MessageFormatter(org.apache.tapestry5.commons.MessageFormatter) FieldValidator(org.apache.tapestry5.FieldValidator) Validator(org.apache.tapestry5.Validator)

Example 24 with Type

use of org.apache.tapestry5.internal.plastic.asm.Type in project tapestry-5 by apache.

the class SubmitTest method submit_form.

@Test
public void submit_form() {
    Element submitButton = doc.getElementById("capitalize1");
    assertEquals("submit", submitButton.getAttribute("type"));
    fieldValues.put("t1", "hello");
    doc = tester.clickSubmit(submitButton, fieldValues);
    assertTrue(doc.toString().contains("Value is: HELLO"));
}
Also used : Element(org.apache.tapestry5.dom.Element) Test(org.testng.annotations.Test)

Example 25 with Type

use of org.apache.tapestry5.internal.plastic.asm.Type in project tapestry-5 by apache.

the class SubmitTest method not_in_form.

@Test
public void not_in_form() {
    try {
        Element submitButton = doc.getElementById("orphanedSubmit");
        tester.clickSubmit(submitButton, fieldValues);
        throw new RuntimeException("Should not be reachable.");
    } catch (RuntimeException ex) {
        assertEquals(ex.getMessage(), "Could not locate an ancestor element of type 'form'.");
    }
}
Also used : Element(org.apache.tapestry5.dom.Element) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)26 Type (org.apache.tapestry5.internal.plastic.asm.Type)23 Element (org.apache.tapestry5.dom.Element)13 TapestryException (org.apache.tapestry5.commons.internal.util.TapestryException)9 ComponentResources (org.apache.tapestry5.ComponentResources)8 Messages (org.apache.tapestry5.commons.Messages)7 UnknownValueException (org.apache.tapestry5.commons.util.UnknownValueException)7 Translator (org.apache.tapestry5.Translator)6 Location (org.apache.tapestry5.commons.Location)6 Link (org.apache.tapestry5.http.Link)6 JSONObject (org.apache.tapestry5.json.JSONObject)6 Type (java.lang.reflect.Type)4 FieldValidator (org.apache.tapestry5.FieldValidator)4 BeanModel (org.apache.tapestry5.beanmodel.BeanModel)4 PlasticClass (org.apache.tapestry5.plastic.PlasticClass)4 Annotation (java.lang.annotation.Annotation)3 BigInteger (java.math.BigInteger)3 List (java.util.List)3 ValueEncoder (org.apache.tapestry5.ValueEncoder)3 TypeCoercer (org.apache.tapestry5.commons.services.TypeCoercer)3