use of com.axellience.vuegwt.processors.utils.ComponentGeneratorsUtil in project vue-gwt by Axellience.
the class ComponentTemplateProcessor method registerFieldsAndMethodsInContext.
/**
* Process the ComponentJsType class to register all the fields and methods visible in
* the context.
* TODO: Improve this method by putting things together with {@link ComponentJsTypeGenerator}
* @param componentTypeElement The class to process
*/
private void registerFieldsAndMethodsInContext(TemplateParserContext templateParserContext, TypeElement componentTypeElement, Set<String> alreadyDoneVariable, Set<String> alreadyDoneMethods) {
ElementFilter.fieldsIn(componentTypeElement.getEnclosedElements()).stream().filter(ComponentGeneratorsUtil::isFieldVisibleInJS).forEach(field -> {
String name = field.getSimpleName().toString();
if (alreadyDoneVariable.contains(name))
return;
alreadyDoneVariable.add(name);
templateParserContext.addRootVariable(ClassName.get(field.asType()), name);
});
ElementFilter.methodsIn(componentTypeElement.getEnclosedElements()).stream().filter(method -> hasAnnotation(method, Computed.class)).filter(method -> !"void".equals(method.getReturnType().toString())).forEach(method -> {
String name = getComputedPropertyName(method);
if (alreadyDoneVariable.contains(name))
return;
alreadyDoneVariable.add(name);
TypeMirror propertyType;
if ("void".equals(method.getReturnType().toString()))
propertyType = method.getParameters().get(0).asType();
else
propertyType = method.getReturnType();
templateParserContext.addRootVariable(ClassName.get(propertyType), name);
});
ElementFilter.methodsIn(componentTypeElement.getEnclosedElements()).stream().filter(ComponentGeneratorsUtil::isMethodVisibleInTemplate).map(ExecutableElement::getSimpleName).map(Object::toString).forEach(methodName -> {
if (alreadyDoneMethods.contains(methodName))
return;
alreadyDoneMethods.add(methodName);
templateParserContext.addRootMethod(methodName);
});
getSuperComponentType(componentTypeElement).ifPresent(superComponent -> registerFieldsAndMethodsInContext(templateParserContext, superComponent, alreadyDoneVariable, alreadyDoneMethods));
}
use of com.axellience.vuegwt.processors.utils.ComponentGeneratorsUtil 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);
}
Aggregations