use of org.immutables.value.processor.meta.Proto.DeclaringType in project immutables by immutables.
the class ImportsTypeStringResolver method getFromSourceImports.
@Nullable
private String getFromSourceImports(String resolvable, boolean notTypeArgument) {
SourceExtraction.Imports[] importsSet = usingType == null && originType == null ? new SourceExtraction.Imports[] {} : usingType == null ? new SourceExtraction.Imports[] { originType.sourceImports() } : originType == null || usingType == originType ? new SourceExtraction.Imports[] { usingType.sourceImports() } : new SourceExtraction.Imports[] { originType.sourceImports(), usingType.sourceImports() };
for (SourceExtraction.Imports imports : importsSet) {
@Nullable String resolved = imports.classes.get(resolvable);
if (resolved != null) {
return resolved;
}
}
if (extendedClasses != null)
for (TypeElement type : extendedClasses) {
DeclaringType top = round.declaringTypeFrom(type).associatedTopLevel();
@Nullable String resolved = top.sourceImports().classes.get(resolvable);
if (resolved != null) {
return resolved;
}
}
if (implementedInterfaces != null) {
for (TypeElement type : implementedInterfaces) {
DeclaringType top = round.declaringTypeFrom(type).associatedTopLevel();
@Nullable String resolved = top.sourceImports().classes.get(resolvable);
if (resolved != null) {
return resolved;
}
}
}
// where types are present and are different
if (notTypeArgument && originType != null) {
if (!hasStarImports(importsSet)) {
// Strongly assuming it comes from originating type's package
return originType.packageOf().name() + "." + resolvable;
}
}
return null;
}
use of org.immutables.value.processor.meta.Proto.DeclaringType 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.DeclaringType in project immutables by immutables.
the class ValueType method getRequiredSourceStarImports.
public Set<String> getRequiredSourceStarImports() {
if (!hasSomeUnresolvedTypes()) {
return additionalImports != null ? additionalImports : ImmutableSet.<String>of();
}
Set<String> starImports = Sets.newLinkedHashSet();
if (additionalImports != null) {
starImports.addAll(additionalImports);
}
for (ValueType n : FluentIterable.from(nested).append(this)) {
for (ValueAttribute a : n.attributes) {
if (a.hasSomeUnresolvedTypes) {
DeclaringType topLevel = a.getDeclaringType().associatedTopLevel();
SourceExtraction.Imports sourceImports = topLevel.sourceImports();
for (String importStatement : sourceImports.all) {
if (importStatement.indexOf('*') > 0) {
starImports.add(importStatement);
}
}
if (!topLevel.packageOf().equals(constitution.protoclass().packageOf())) {
String prefix = topLevel.packageOf().asPrefix();
// guard against unnamed packages
if (!prefix.isEmpty()) {
starImports.add(prefix + '*');
}
}
}
}
}
return starImports;
}
use of org.immutables.value.processor.meta.Proto.DeclaringType in project immutables by immutables.
the class ValueType method toSignature.
private String toSignature(ExecutableElement m, TypeMirror returnType) {
DeclaringType declaringType = inferDeclaringType(m);
StringBuilder signature = new StringBuilder();
appendAccessModifier(m, signature);
appendReturnType(m, signature, declaringType, returnType);
signature.append(" ").append(m.getSimpleName());
appendParameters(m, signature, declaringType, true, false);
return signature.toString();
}
use of org.immutables.value.processor.meta.Proto.DeclaringType 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