use of com.axellience.vuegwt.core.annotations.component.Component in project vue-gwt by Axellience.
the class VueComponentFactoryGenerator method registerLocalComponents.
/**
* Register components passed to the annotation.
* The parameters of the generated method are the factories for the local components we depend
* on.
* Their values are either injected, or pass directly when using the "get()" static accessor.
* @param component The Component we generate for
* @param initBuilder The builder for the init method
* @param staticInitParameters The parameters of the static init function
*/
private void registerLocalComponents(TypeElement component, MethodSpec.Builder initBuilder, List<CodeBlock> staticInitParameters) {
List<TypeMirror> localComponents = getComponentLocalComponents(elements, component);
if (localComponents.isEmpty())
return;
initBuilder.addStatement("$T<$T> components = jsConstructor.getOptionsComponents()", JsPropertyMap.class, ParameterizedTypeName.get(VueJsAsyncProvider.class, VueJsConstructor.class));
localComponents.forEach(localComponent -> {
ClassName factory = componentFactoryName(localComponent);
String parameterName = factory.reflectionName().replaceAll("\\.", "_");
initBuilder.addParameter(providerOf(factory), parameterName);
staticInitParameters.add(CodeBlock.of("() -> $T.get()", factory));
Element localComponentElement = ((DeclaredType) localComponent).asElement();
String tagName = componentToTagName(localComponentElement.getSimpleName().toString(), localComponentElement.getAnnotation(Component.class));
initBuilder.addStatement("components.set($S, render -> render.accept($L.get().getJsConstructor()))", tagName, parameterName);
});
}
use of com.axellience.vuegwt.core.annotations.component.Component in project vue-gwt by Axellience.
the class VueComponentFactoryGenerator method createInitMethod.
@Override
protected List<CodeBlock> createInitMethod(TypeElement component, Builder vueFactoryClassBuilder) {
MethodSpec.Builder initBuilder = MethodSpec.methodBuilder("init").addModifiers(Modifier.PROTECTED).addAnnotation(Inject.class);
List<CodeBlock> initParametersCall = new LinkedList<>();
// Get options
initBuilder.addStatement("$T<$T> componentOptions = $T.getOptions()", VueComponentOptions.class, component.asType(), componentJsTypeName(component));
processCustomizeOptions(component, initBuilder, initParametersCall);
// Extend the parent Component
Optional<ClassName> superFactoryType = getSuperComponentType(component).map(GeneratorsNameUtil::componentFactoryName);
if (superFactoryType.isPresent()) {
initBuilder.addParameter(superFactoryType.get(), "superFactory");
initBuilder.addStatement("jsConstructor = superFactory.getJsConstructor().extendJavaComponent($L)", "componentOptions");
initParametersCall.add(CodeBlock.of("$T.get()", superFactoryType.get()));
} else {
initBuilder.addStatement("jsConstructor = $T.extendJavaComponent($L)", Vue.class, "componentOptions");
}
Component componentAnnotation = component.getAnnotation(Component.class);
if (hasInjectedDependencies)
registerDependenciesProvider(component, initBuilder, initParametersCall);
registerLocalComponents(component, initBuilder, initParametersCall);
registerLocalDirectives(componentAnnotation, initBuilder);
MethodSpec initMethod = initBuilder.build();
vueFactoryClassBuilder.addMethod(initMethod);
return initParametersCall;
}
use of com.axellience.vuegwt.core.annotations.component.Component in project vue-gwt by Axellience.
the class ComponentTemplateProcessor method findLocalComponentsForComponent.
/**
* Register all locally declared components.
* @param localComponents The {@link LocalComponents} where we register our local components
* @param componentTypeElement The class to process
*/
private void findLocalComponentsForComponent(LocalComponents localComponents, TypeElement componentTypeElement) {
Component componentAnnotation = componentTypeElement.getAnnotation(Component.class);
if (componentAnnotation == null)
return;
getComponentLocalComponents(elementUtils, componentTypeElement).stream().map(DeclaredType.class::cast).map(DeclaredType::asElement).map(TypeElement.class::cast).forEach(childTypeElement -> processLocalComponentClass(localComponents, childTypeElement));
getSuperComponentType(componentTypeElement).ifPresent(superComponentType -> findLocalComponentsForComponent(localComponents, superComponentType));
}
use of com.axellience.vuegwt.core.annotations.component.Component 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.core.annotations.component.Component 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;
}
Aggregations