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));
}
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;
}
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<>());
}
Aggregations