/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.litho.specmodels.model;
import java.util.List;
import com.facebook.litho.specmodels.internal.ImmutableList;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.TypeName;
import com.squareup.javapoet.TypeSpec;
import com.squareup.javapoet.TypeVariableName;
/**
* Model that is an abstract representation of a
* {@link com.facebook.litho.annotations.LayoutSpec}.
*/
public class LayoutSpecModel implements SpecModel, HasPureRender {
private final SpecModelImpl mSpecModel;
private final boolean mIsPureRender;
private final LayoutSpecGenerator mLayoutSpecGenerator;
public LayoutSpecModel(
String qualifiedSpecClassName,
String componentClassName,
ImmutableList<DelegateMethodModel> delegateMethods,
ImmutableList<EventMethodModel> eventMethods,
ImmutableList<UpdateStateMethodModel> updateStateMethods,
ImmutableList<TypeVariableName> typeVariables,
ImmutableList<PropDefaultModel> propDefaults,
ImmutableList<EventDeclarationModel> eventDeclarations,
String classJavadoc,
ImmutableList<PropJavadocModel> propJavadocs,
boolean isPublic,
DependencyInjectionHelper dependencyInjectionHelper,
boolean isPureRender,
Object representedObject,
LayoutSpecGenerator layoutSpecGenerator) {
mSpecModel =
SpecModelImpl.newBuilder()
.qualifiedSpecClassName(qualifiedSpecClassName)
.componentClassName(componentClassName)
.delegateMethods(delegateMethods)
.eventMethods(eventMethods)
.updateStateMethods(updateStateMethods)
.typeVariables(typeVariables)
.propDefaults(propDefaults)
.eventDeclarations(eventDeclarations)
.classJavadoc(classJavadoc)
.propJavadocs(propJavadocs)
.isPublic(isPublic)
.dependencyInjectionGenerator(dependencyInjectionHelper)
.representedObject(representedObject)
.build();
mIsPureRender = isPureRender;
mLayoutSpecGenerator = layoutSpecGenerator;
}
@Override
public String getSpecName() {
return mSpecModel.getSpecName();
}
@Override
public TypeName getSpecTypeName() {
return mSpecModel.getSpecTypeName();
}
@Override
public String getComponentName() {
return mSpecModel.getComponentName();
}
@Override
public TypeName getComponentTypeName() {
return mSpecModel.getComponentTypeName();
}
@Override
public ImmutableList<DelegateMethodModel> getDelegateMethods() {
return mSpecModel.getDelegateMethods();
}
@Override
public ImmutableList<EventMethodModel> getEventMethods() {
return mSpecModel.getEventMethods();
}
@Override
public ImmutableList<UpdateStateMethodModel> getUpdateStateMethods() {
return mSpecModel.getUpdateStateMethods();
}
@Override
public ImmutableList<PropModel> getProps() {
return mSpecModel.getProps();
}
@Override
public ImmutableList<PropDefaultModel> getPropDefaults() {
return mSpecModel.getPropDefaults();
}
@Override
public ImmutableList<TypeVariableName> getTypeVariables() {
return mSpecModel.getTypeVariables();
}
@Override
public ImmutableList<StateParamModel> getStateValues() {
return mSpecModel.getStateValues();
}
@Override
public ImmutableList<InterStageInputParamModel> getInterStageInputs() {
return mSpecModel.getInterStageInputs();
}
@Override
public ImmutableList<TreePropModel> getTreeProps() {
return mSpecModel.getTreeProps();
}
@Override
public ImmutableList<EventDeclarationModel> getEventDeclarations() {
return mSpecModel.getEventDeclarations();
}
@Override
public String getClassJavadoc() {
return mSpecModel.getClassJavadoc();
}
@Override
public ImmutableList<PropJavadocModel> getPropJavadocs() {
return mSpecModel.getPropJavadocs();
}
@Override
public boolean isPublic() {
return mSpecModel.isPublic();
}
@Override
public ClassName getContextClass() {
return ClassNames.COMPONENT_CONTEXT;
}
@Override
public ClassName getComponentClass() {
return ClassNames.COMPONENT;
}
@Override
public ClassName getStateContainerClass() {
return ClassNames.STATE_CONTAINER_COMPONENT;
}
@Override
public TypeName getUpdateStateInterface() {
return ClassNames.COMPONENT_STATE_UPDATE;
}
@Override
public boolean isStylingSupported() {
return true;
}
@Override
public boolean hasInjectedDependencies() {
return mSpecModel.hasInjectedDependencies();
}
@Override
public DependencyInjectionHelper getDependencyInjectionHelper() {
return mSpecModel.getDependencyInjectionHelper();
}
@Override
public Object getRepresentedObject() {
return mSpecModel.getRepresentedObject();
}
@Override
public List<SpecModelValidationError> validate() {
return SpecModelValidation.validateLayoutSpecModel(this);
}
@Override
public TypeSpec generate() {
return mLayoutSpecGenerator.generate(this);
}
@Override
public boolean isPureRender() {
return mIsPureRender;
}
}