use of com.axellience.vuegwt.processors.component.template.parser.context.TemplateParserContext 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.component.template.parser.context.TemplateParserContext in project vue-gwt by Axellience.
the class ComponentTemplateProcessor method processComponentTemplate.
public void processComponentTemplate(TypeElement componentTypeElement, Builder componentJsTypeBuilder) {
ClassName componentTypeName = ClassName.get(componentTypeElement);
Optional<String> optionalTemplateContent = getTemplateContent(componentTypeName, componentTypeElement);
if (!optionalTemplateContent.isPresent())
return;
LocalComponents localComponents = new LocalComponents();
findLocalComponentsForComponent(localComponents, componentTypeElement);
// Initialize the template parser context based on the VueComponent type element
TemplateParserContext templateParserContext = new TemplateParserContext(componentTypeElement, localComponents);
registerFieldsAndMethodsInContext(templateParserContext, componentTypeElement, new HashSet<>(), new HashSet<>());
// Parse the template
TemplateParserResult templateParserResult = new TemplateParser().parseHtmlTemplate(optionalTemplateContent.get(), templateParserContext, messager);
// Add expressions from the template to JsType and compile template
TemplateMethodsBuilder templateMethodsBuilder = new TemplateMethodsBuilder();
templateMethodsBuilder.addTemplateMethodsToComponentJsType(componentJsTypeBuilder, templateParserResult);
}
Aggregations