use of org.immutables.value.processor.encode.Instantiator.InstantiationCreator in project immutables by immutables.
the class FactoryMethodAttributesCollector method collect.
void collect() {
ExecutableElement factoryMethodElement = (ExecutableElement) protoclass.sourceElement();
Parameterizable element = (Parameterizable) (factoryMethodElement.getKind() == ElementKind.CONSTRUCTOR ? factoryMethodElement.getEnclosingElement() : type.element);
for (VariableElement parameter : factoryMethodElement.getParameters()) {
TypeMirror returnType = parameter.asType();
ValueAttribute attribute = new ValueAttribute();
attribute.isGenerateAbstract = true;
attribute.reporter = reporter;
attribute.returnType = returnType;
attribute.element = parameter;
String parameterName = parameter.getSimpleName().toString();
attribute.names = styles.forAccessorWithRaw(parameterName, parameterName);
attribute.containingType = type;
attributes.add(attribute);
}
Instantiator encodingInstantiator = protoclass.encodingInstantiator();
@Nullable InstantiationCreator instantiationCreator = encodingInstantiator.creatorFor(element);
for (ValueAttribute attribute : attributes) {
attribute.initAndValidate(instantiationCreator);
}
if (instantiationCreator != null) {
type.additionalImports(instantiationCreator.imports);
}
type.attributes.addAll(attributes);
type.throwing = extractThrowsClause(factoryMethodElement);
}
use of org.immutables.value.processor.encode.Instantiator.InstantiationCreator in project immutables by immutables.
the class AccessorAttributesCollector method collect.
void collect() {
collectGeneratedCandidateMethods(getTypeElement());
if (attributes.size() > USEFUL_PARAMETER_COUNT_LIMIT) {
ArrayList<ValueAttribute> list = Lists.newArrayListWithCapacity(USEFUL_PARAMETER_COUNT_LIMIT);
list.addAll(attributes.subList(0, USEFUL_PARAMETER_COUNT_LIMIT));
attributes.clear();
attributes.addAll(list);
protoclass.report().error("Value objects with more than %d attributes (including inherited) are not supported." + " You can decompose '%s' class into a smaller ones", USEFUL_PARAMETER_COUNT_LIMIT, protoclass.name());
}
Instantiator encodingInstantiator = protoclass.encodingInstantiator();
@Nullable InstantiationCreator instantiationCreator = encodingInstantiator.creatorFor((Parameterizable) type.element);
for (ValueAttribute attribute : attributes) {
attribute.initAndValidate(instantiationCreator);
}
if (instantiationCreator != null) {
type.additionalImports(instantiationCreator.imports);
}
type.attributes.addAll(attributes);
type.accessorMapping = accessorMapping;
}
Aggregations