use of org.immutables.value.processor.meta.Proto.AbstractDeclaring 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();
}
use of org.immutables.value.processor.meta.Proto.AbstractDeclaring 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();
}
Aggregations