use of com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponent in project vue-gwt by Axellience.
the class ComponentTemplateProcessor method processLocalComponentClass.
/**
* Register the local component and all of its {@link Prop}.
* This will be used for type validation.
* @param localComponents The {@link LocalComponents} object where we should register our {@link LocalComponent}
* @param localComponentType The class to process
*/
private void processLocalComponentClass(LocalComponents localComponents, TypeElement localComponentType) {
Component componentAnnotation = localComponentType.getAnnotation(Component.class);
String localComponentTagName = componentToTagName(localComponentType.getSimpleName().toString(), componentAnnotation);
if (localComponents.hasLocalComponent(localComponentTagName))
return;
LocalComponent localComponent = localComponents.addLocalComponent(localComponentTagName);
ElementFilter.fieldsIn(localComponentType.getEnclosedElements()).forEach(field -> {
Prop propAnnotation = field.getAnnotation(Prop.class);
if (propAnnotation != null) {
localComponent.addProp(field.getSimpleName().toString(), TypeName.get(field.asType()), propAnnotation.required());
}
});
}
use of com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponent in project vue-gwt by Axellience.
the class TemplateParser method processElementAttributes.
/**
* Process an {@link Element} and check for vue attributes.
* @param element Current element being processed
*/
private void processElementAttributes(Element element) {
Optional<LocalComponent> localComponent = getLocalComponentForElement(element);
// Iterate on element attributes
Set<LocalComponentProp> foundProps = new HashSet<>();
for (Attribute attribute : element.getAttributes()) {
if ("v-for".equals(attribute.getKey()) || "v-model".equals(attribute.getKey()))
continue;
Optional<LocalComponentProp> optionalProp = localComponent.flatMap(lc -> lc.getPropForAttribute(attribute.getName()));
optionalProp.ifPresent(foundProps::add);
if (!VUE_ATTR_PATTERN.matcher(attribute.getKey()).matches()) {
optionalProp.ifPresent(this::validateStringPropBinding);
continue;
}
context.setCurrentSegment(attribute);
currentAttribute = attribute;
currentProp = optionalProp.orElse(null);
currentExpressionReturnType = getExpressionReturnTypeForAttribute(attribute);
String processedExpression = processExpression(attribute.getValue());
if (attribute.getValueSegment() != null)
outputDocument.replace(attribute.getValueSegment(), processedExpression);
}
localComponent.ifPresent(lc -> validateRequiredProps(lc, foundProps));
}
Aggregations