Search in sources :

Example 1 with Computed

use of com.axellience.vuegwt.core.annotations.component.Computed in project vue-gwt by Axellience.

the class ComponentJsTypeGenerator method addFieldsForComputedMethod.

/**
 * Add fields for computed methods so they are visible in the template
 * @param component {@link VueComponent} to process
 * @param componentJsTypeBuilder Builder for the JsType class
 * @param alreadyDone Already processed computed properties (in case there is a getter and a
 * setter, avoid creating the field twice).
 */
private void addFieldsForComputedMethod(TypeElement component, Builder componentJsTypeBuilder, Set<String> alreadyDone) {
    getMethodsWithAnnotation(component, Computed.class).forEach(method -> {
        String propertyName = GeneratorsUtil.getComputedPropertyName(method);
        if (alreadyDone.contains(propertyName))
            return;
        TypeMirror propertyType;
        if ("void".equals(method.getReturnType().toString()))
            propertyType = method.getParameters().get(0).asType();
        else
            propertyType = method.getReturnType();
        componentJsTypeBuilder.addField(TypeName.get(propertyType), propertyName, Modifier.PUBLIC);
        alreadyDone.add(propertyName);
    });
    getSuperComponentType(component).ifPresent(superComponent -> addFieldsForComputedMethod(superComponent, componentJsTypeBuilder, alreadyDone));
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) Computed(com.axellience.vuegwt.core.annotations.component.Computed)

Example 2 with Computed

use of com.axellience.vuegwt.core.annotations.component.Computed in project vue-gwt by Axellience.

the class GeneratorsUtil method getComputedPropertyName.

public static String getComputedPropertyName(ExecutableElement method) {
    Computed computed = method.getAnnotation(Computed.class);
    String methodName = method.getSimpleName().toString();
    if (!"".equals(computed.value()))
        return computed.value();
    if (methodName.startsWith("get") || methodName.startsWith("set"))
        return Introspector.decapitalize(methodName.substring(3));
    if (methodName.startsWith("is"))
        return Introspector.decapitalize(methodName.substring(2));
    return methodName;
}
Also used : Computed(com.axellience.vuegwt.core.annotations.component.Computed)

Example 3 with Computed

use of com.axellience.vuegwt.core.annotations.component.Computed in project vue-gwt by Axellience.

the class ComponentJsTypeGenerator method processComputed.

/**
 * Process computed properties from the Component Class.
 * @param component {@link VueComponent} to process
 * @param optionsBuilder A {@link MethodSpec.Builder} for the method that creates the
 * {@link VueComponentOptions}
 * @param componentJsTypeBuilder Builder for the JsType class
 */
private void processComputed(TypeElement component, MethodSpec.Builder optionsBuilder, Builder componentJsTypeBuilder) {
    getMethodsWithAnnotation(component, Computed.class).forEach(method -> {
        String methodName = method.getSimpleName().toString();
        ComputedKind kind = ComputedKind.GETTER;
        if ("void".equals(method.getReturnType().toString()))
            kind = ComputedKind.SETTER;
        String propertyName = GeneratorsUtil.getComputedPropertyName(method);
        optionsBuilder.addStatement("options.addJavaComputed($S, $S, $T.$L)", methodName, propertyName, ComputedKind.class, kind);
        addProxyJsTypeMethodIfNecessary(componentJsTypeBuilder, method);
    });
    addFieldsForComputedMethod(component, componentJsTypeBuilder, new HashSet<>());
}
Also used : ComputedKind(com.axellience.vuegwt.core.client.component.options.computed.ComputedKind) Computed(com.axellience.vuegwt.core.annotations.component.Computed)

Aggregations

Computed (com.axellience.vuegwt.core.annotations.component.Computed)3 ComputedKind (com.axellience.vuegwt.core.client.component.options.computed.ComputedKind)1 TypeMirror (javax.lang.model.type.TypeMirror)1