use of com.axellience.vuegwt.core.client.component.options.VueComponentOptions in project vue-gwt by Axellience.
the class ComponentJsTypeGenerator method getOptionsMethodBuilder.
/**
* Create and return the builder for the method that creating the {@link VueComponentOptions}
* for this {@link VueComponent}.
* @param component The {@link VueComponent} we are generating for
* @return A {@link MethodSpec.Builder} for the method that creates the {@link VueComponentOptions}
*/
private MethodSpec.Builder getOptionsMethodBuilder(TypeElement component) {
TypeName optionsTypeName = ParameterizedTypeName.get(ClassName.get(VueComponentOptions.class), ClassName.get(component));
MethodSpec.Builder optionsMethodBuilder = MethodSpec.methodBuilder("getOptions").addModifiers(Modifier.PUBLIC, Modifier.STATIC).returns(optionsTypeName).addStatement("$T options = new $T()", optionsTypeName, optionsTypeName);
Component annotation = component.getAnnotation(Component.class);
if (!"".equals(annotation.name()))
optionsMethodBuilder.addStatement("options.setName($S)", annotation.name());
optionsMethodBuilder.addStatement("options.setComponentJavaPrototype($T.getJavaConstructor($T.class).prototype)", VueGWT.class, componentJsTypeName(component));
return optionsMethodBuilder;
}
use of com.axellience.vuegwt.core.client.component.options.VueComponentOptions in project vue-gwt by Axellience.
the class ComponentJsTypeGenerator method processData.
/**
* Process data fields from the {@link VueComponent} Class.
* @param component {@link VueComponent} to process
* @param optionsBuilder A {@link MethodSpec.Builder} for the method that creates the
* {@link VueComponentOptions}
*/
private void processData(TypeElement component, MethodSpec.Builder optionsBuilder) {
Component annotation = component.getAnnotation(Component.class);
List<String> fieldsName = ElementFilter.fieldsIn(component.getEnclosedElements()).stream().filter(ComponentGeneratorsUtil::isFieldVisibleInJS).filter(field -> field.getAnnotation(Prop.class) == null).map(field -> field.getSimpleName().toString()).collect(Collectors.toList());
if (fieldsName.isEmpty())
return;
// Declare data fields
String fieldNamesParameters = fieldsName.stream().map(fieldName -> "\"" + fieldName + "\"").collect(Collectors.joining(", "));
optionsBuilder.addStatement("options.initData($L, $L)", annotation.useFactory(), fieldNamesParameters);
}
use of com.axellience.vuegwt.core.client.component.options.VueComponentOptions in project vue-gwt by Axellience.
the class ComponentJsTypeGenerator method processProps.
/**
* Process Vue Props from the {@link VueComponent} Class.
* @param component {@link VueComponent} to process
* @param optionsBuilder A {@link MethodSpec.Builder} for the method that creates the
* {@link VueComponentOptions}
*/
private void processProps(TypeElement component, MethodSpec.Builder optionsBuilder) {
ElementFilter.fieldsIn(component.getEnclosedElements()).stream().filter(field -> hasAnnotation(field, Prop.class)).forEach(field -> {
String fieldName = field.getSimpleName().toString();
Prop prop = field.getAnnotation(Prop.class);
if (!isFieldVisibleInJS(field)) {
printError("The field \"" + fieldName + "\" annotated with @Prop must also be annotated with @JsProperty.", component);
}
optionsBuilder.addStatement("options.addJavaProp($S, $L, $S)", fieldName, prop.required(), prop.checkType() ? getNativeNameForJavaType(field.asType()) : null);
});
}
Aggregations