Search in sources :

Example 1 with DeclaringType

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;
}
Also used : TypeElement(javax.lang.model.element.TypeElement) DeclaringType(org.immutables.value.processor.meta.Proto.DeclaringType) SourceExtraction(org.immutables.generator.SourceExtraction) Nullable(javax.annotation.Nullable) Nullable(javax.annotation.Nullable)

Example 2 with DeclaringType

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();
}
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 3 with DeclaringType

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;
}
Also used : DeclaringType(org.immutables.value.processor.meta.Proto.DeclaringType) SourceExtraction(org.immutables.generator.SourceExtraction)

Example 4 with DeclaringType

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();
}
Also used : DeclaringType(org.immutables.value.processor.meta.Proto.DeclaringType)

Example 5 with DeclaringType

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

Aggregations

DeclaringType (org.immutables.value.processor.meta.Proto.DeclaringType)8 Protoclass (org.immutables.value.processor.meta.Proto.Protoclass)3 Nullable (javax.annotation.Nullable)2 SourceExtraction (org.immutables.generator.SourceExtraction)2 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 Parameterizable (javax.lang.model.element.Parameterizable)1 TypeElement (javax.lang.model.element.TypeElement)1 TypeParameterElement (javax.lang.model.element.TypeParameterElement)1 TypeMirror (javax.lang.model.type.TypeMirror)1 Naming (org.immutables.generator.Naming)1 DeclaringPackage (org.immutables.value.processor.meta.Proto.DeclaringPackage)1 PackageNaming (org.immutables.value.processor.meta.Styles.PackageNaming)1