Search in sources :

Example 1 with LocalComponent

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());
        }
    });
}
Also used : Prop(com.axellience.vuegwt.core.annotations.component.Prop) VueComponent(com.axellience.vuegwt.core.client.component.VueComponent) Component(com.axellience.vuegwt.core.annotations.component.Component) LocalComponent(com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponent) LocalComponent(com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponent)

Example 2 with LocalComponent

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));
}
Also used : LocalComponentProp(com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponentProp) Attribute(net.htmlparser.jericho.Attribute) LocalComponent(com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponent) HashSet(java.util.HashSet)

Aggregations

LocalComponent (com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponent)2 Component (com.axellience.vuegwt.core.annotations.component.Component)1 Prop (com.axellience.vuegwt.core.annotations.component.Prop)1 VueComponent (com.axellience.vuegwt.core.client.component.VueComponent)1 LocalComponentProp (com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponentProp)1 HashSet (java.util.HashSet)1 Attribute (net.htmlparser.jericho.Attribute)1