Search in sources :

Example 1 with InstantiationCreator

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);
}
Also used : InstantiationCreator(org.immutables.value.processor.encode.Instantiator.InstantiationCreator) TypeMirror(javax.lang.model.type.TypeMirror) ExecutableElement(javax.lang.model.element.ExecutableElement) Parameterizable(javax.lang.model.element.Parameterizable) Instantiator(org.immutables.value.processor.encode.Instantiator) VariableElement(javax.lang.model.element.VariableElement) Nullable(javax.annotation.Nullable)

Example 2 with InstantiationCreator

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;
}
Also used : InstantiationCreator(org.immutables.value.processor.encode.Instantiator.InstantiationCreator) Instantiator(org.immutables.value.processor.encode.Instantiator) Nullable(javax.annotation.Nullable)

Aggregations

Nullable (javax.annotation.Nullable)2 Instantiator (org.immutables.value.processor.encode.Instantiator)2 InstantiationCreator (org.immutables.value.processor.encode.Instantiator.InstantiationCreator)2 ExecutableElement (javax.lang.model.element.ExecutableElement)1 Parameterizable (javax.lang.model.element.Parameterizable)1 VariableElement (javax.lang.model.element.VariableElement)1 TypeMirror (javax.lang.model.type.TypeMirror)1