Search in sources :

Example 1 with Protoclass

use of org.immutables.value.processor.meta.Proto.Protoclass 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 Protoclass

use of org.immutables.value.processor.meta.Proto.Protoclass 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 Protoclass

use of org.immutables.value.processor.meta.Proto.Protoclass in project immutables by immutables.

the class ValueType method allKnownValuesInContext.

private Iterable<ValueType> allKnownValuesInContext() {
    List<ValueType> values = Lists.newArrayList(nested);
    Environment environment = constitution.protoclass().environment();
    Optional<TreesIncludeMirror> include = constitution.protoclass().getTreesInclude();
    if (include.isPresent()) {
        for (Protoclass p : environment.protoclassesFrom(includedElements(include.get()))) {
            values.add(environment.composeValue(p));
        }
    }
    return values;
}
Also used : Protoclass(org.immutables.value.processor.meta.Proto.Protoclass) Environment(org.immutables.value.processor.meta.Proto.Environment)

Example 4 with Protoclass

use of org.immutables.value.processor.meta.Proto.Protoclass in project immutables by immutables.

the class ValueType method detectSerialization.

void detectSerialization() {
    Protoclass p = constitution.protoclass();
    boolean isSerializable = isSerializable();
    if (p.isSerialStructural()) {
        serial = isSerializable ? Serialization.STRUCTURAL_IMPLEMENTS : Serialization.STRUCTURAL;
    } else if (isSerializable) {
        serial = Serialization.IMPLEMENTS;
    } else if (p.serialVersion().isPresent()) {
        serial = Serialization.SERIAL_VERSION;
    }
}
Also used : Protoclass(org.immutables.value.processor.meta.Proto.Protoclass)

Example 5 with Protoclass

use of org.immutables.value.processor.meta.Proto.Protoclass in project immutables by immutables.

the class Round method collectValues.

public Multimap<DeclaringPackage, ValueType> collectValues() {
    ImmutableList<Protoclass> protoclasses = collectProtoclasses();
    Map<DeclaringType, ValueType> enclosingTypes = Maps.newHashMap();
    ImmutableMultimap.Builder<DeclaringPackage, ValueType> builder = ImmutableMultimap.builder();
    // Collect enclosing
    for (Protoclass protoclass : protoclasses) {
        if (protoclass.kind().isEnclosing()) {
            ValueType type = composeValue(protoclass);
            enclosingTypes.put(protoclass.declaringType().get(), type);
        }
    }
    // Collect remaining and attach if nested
    for (Protoclass protoclass : protoclasses) {
        @Nullable ValueType current = null;
        if (protoclass.kind().isNested()) {
            @Nullable ValueType enclosing = enclosingTypes.get(protoclass.enclosingOf().get());
            if (enclosing != null) {
                current = composeValue(protoclass);
                // Attach nested to enclosing
                enclosing.addNested(current);
            }
        }
        // getting the ValueType if it was alredy created and put into enclosingTypes
        if (current == null && protoclass.kind().isEnclosing()) {
            current = enclosingTypes.get(protoclass.declaringType().get());
        }
        // If none then we just create it
        if (current == null) {
            current = composeValue(protoclass);
        }
        // We put all enclosing and nested values by the package
        builder.put(protoclass.packageOf(), current);
    }
    return builder.build();
}
Also used : Protoclass(org.immutables.value.processor.meta.Proto.Protoclass) DeclaringType(org.immutables.value.processor.meta.Proto.DeclaringType) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Nullable(javax.annotation.Nullable) DeclaringPackage(org.immutables.value.processor.meta.Proto.DeclaringPackage)

Aggregations

Protoclass (org.immutables.value.processor.meta.Proto.Protoclass)5 DeclaringType (org.immutables.value.processor.meta.Proto.DeclaringType)3 AbstractDeclaring (org.immutables.value.processor.meta.Proto.AbstractDeclaring)2 ValueType (org.immutables.value.processor.meta.ValueType)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 Collection (java.util.Collection)1 Nullable (javax.annotation.Nullable)1 DeclaringPackage (org.immutables.value.processor.meta.Proto.DeclaringPackage)1 Environment (org.immutables.value.processor.meta.Proto.Environment)1