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();
}
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();
}
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;
}
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;
}
}
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();
}
Aggregations