Search in sources :

Example 1 with ValueType

use of org.immutables.value.processor.meta.ValueType in project immutables by immutables.

the class Gsons method typeAdapters.

public Iterable<TypeAdapterTypes> typeAdapters() {
    Map<AbstractDeclaring, GsonMirrors.TypeAdapters> mirrors = Maps.newHashMap();
    Multimap<AbstractDeclaring, ValueType> byDeclaring = HashMultimap.create();
    for (ValueType value : values().values()) {
        Protoclass protoclass = value.constitution.protoclass();
        if (protoclass.kind().isValue()) {
            Optional<AbstractDeclaring> typeAdaptersProvider = protoclass.typeAdaptersProvider();
            if (typeAdaptersProvider.isPresent()) {
                AbstractDeclaring key = typeAdaptersProvider.get();
                mirrors.put(key, key.typeAdapters().get());
                byDeclaring.put(key, value);
            } else if (protoclass.gsonTypeAdapters().isPresent() && protoclass.declaringType().isPresent()) {
                DeclaringType topLevel = protoclass.declaringType().get().associatedTopLevel();
                mirrors.put(topLevel, protoclass.gsonTypeAdapters().get());
                byDeclaring.put(topLevel, value);
            }
        }
    }
    ImmutableList.Builder<TypeAdapterTypes> builder = ImmutableList.builder();
    for (Entry<AbstractDeclaring, Collection<ValueType>> entry : byDeclaring.asMap().entrySet()) {
        String pack = Iterables.get(entry.getValue(), 0).$$package();
        builder.add(ImmutableTypeAdapterTypes.builder().definedBy(entry.getKey()).mirror(mirrors.get(entry.getKey())).packageGenerated(pack).addAllTypes(entry.getValue()).build());
    }
    return builder.build();
}
Also used : Protoclass(org.immutables.value.processor.meta.Proto.Protoclass) ValueType(org.immutables.value.processor.meta.ValueType) ImmutableList(com.google.common.collect.ImmutableList) AbstractDeclaring(org.immutables.value.processor.meta.Proto.AbstractDeclaring) Collection(java.util.Collection) DeclaringType(org.immutables.value.processor.meta.Proto.DeclaringType)

Example 2 with ValueType

use of org.immutables.value.processor.meta.ValueType in project immutables by immutables.

the class OkJsons method typeAdapters.

Iterable<OkTypeAdapterTypes> typeAdapters() {
    Multimap<AbstractDeclaring, ValueType> byDeclaring = HashMultimap.create();
    for (ValueType value : values().values()) {
        Protoclass protoclass = value.constitution.protoclass();
        if (protoclass.kind().isValue()) {
            Optional<AbstractDeclaring> typeAdaptersProvider = protoclass.okTypeAdaptersProvider();
            if (typeAdaptersProvider.isPresent()) {
                byDeclaring.put(typeAdaptersProvider.get(), value);
            } else if (protoclass.okJsonTypeAdapters().isPresent() && protoclass.declaringType().isPresent()) {
                DeclaringType topLevel = protoclass.declaringType().get().associatedTopLevel();
                byDeclaring.put(topLevel, value);
            }
        }
    }
    ImmutableList.Builder<OkTypeAdapterTypes> builder = ImmutableList.builder();
    for (Entry<AbstractDeclaring, Collection<ValueType>> entry : byDeclaring.asMap().entrySet()) {
        String pack = Iterables.get(entry.getValue(), 0).$$package();
        builder.add(ImmutableOkTypeAdapterTypes.builder().definedBy(entry.getKey()).packageGenerated(pack).addAllTypes(entry.getValue()).build());
    }
    return builder.build();
}
Also used : Protoclass(org.immutables.value.processor.meta.Proto.Protoclass) ValueType(org.immutables.value.processor.meta.ValueType) DeclaringType(org.immutables.value.processor.meta.Proto.DeclaringType) AbstractDeclaring(org.immutables.value.processor.meta.Proto.AbstractDeclaring)

Example 3 with ValueType

use of org.immutables.value.processor.meta.ValueType in project immutables by immutables.

the class Processor method process.

@Override
protected void process() {
    Round round = ImmutableRound.builder().addAllAnnotations(annotations()).processing(processing()).addAllCustomImmutableAnnotations(CustomImmutableAnnotations.annotations()).round(round()).build();
    Multimap<DeclaringPackage, ValueType> values = round.collectValues();
    invoke(new Generator_Immutables().usingValues(values).generate());
    invoke(new Generator_Modifiables().usingValues(values).generate());
    if (round.environment().hasGsonLib()) {
        invoke(new Generator_Gsons().usingValues(values).generate());
    }
    if (round.environment().hasMongoModule()) {
        invoke(new Generator_Repositories().usingValues(values).generate());
    }
    if (round.environment().hasFuncModule()) {
        invoke(new Generator_Funcs().usingValues(values).generate());
    }
    if (round.environment().hasTreesModule()) {
        invoke(new Generator_Transformers().usingValues(values).generate());
        invoke(new Generator_Visitors().usingValues(values).generate());
    }
    if (round.environment().hasAstModule()) {
        invoke(new Generator_Asts().usingValues(values).generate());
    }
    if (round.environment().hasEncodeModule()) {
        invoke(new Generator_Encodings().generate());
    }
}
Also used : ValueType(org.immutables.value.processor.meta.ValueType) ImmutableRound(org.immutables.value.processor.meta.ImmutableRound) Round(org.immutables.value.processor.meta.Round) Generator_Encodings(org.immutables.value.processor.encode.Generator_Encodings) DeclaringPackage(org.immutables.value.processor.meta.Proto.DeclaringPackage)

Aggregations

ValueType (org.immutables.value.processor.meta.ValueType)3 AbstractDeclaring (org.immutables.value.processor.meta.Proto.AbstractDeclaring)2 DeclaringType (org.immutables.value.processor.meta.Proto.DeclaringType)2 Protoclass (org.immutables.value.processor.meta.Proto.Protoclass)2 ImmutableList (com.google.common.collect.ImmutableList)1 Collection (java.util.Collection)1 Generator_Encodings (org.immutables.value.processor.encode.Generator_Encodings)1 ImmutableRound (org.immutables.value.processor.meta.ImmutableRound)1 DeclaringPackage (org.immutables.value.processor.meta.Proto.DeclaringPackage)1 Round (org.immutables.value.processor.meta.Round)1