Search in sources :

Example 1 with DeclaringPackage

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

the class Processor method process.

@Override
protected void process() {
    Round round = ImmutableRound.builder().addAllAnnotations(annotations()).processing(processing()).addAllCustomImmutableAnnotations(CustomImmutableAnnotations.annotations()).round(round()).build();
    Multimap<DeclaringPackage, ValueType> values = round.collectValues();
    invoke(new Generator_Immutables().usingValues(values).generate());
    invoke(new Generator_Modifiables().usingValues(values).generate());
    if (round.environment().hasGsonLib()) {
        invoke(new Generator_Gsons().usingValues(values).generate());
    }
    if (round.environment().hasMongoModule()) {
        invoke(new Generator_Repositories().usingValues(values).generate());
    }
    if (round.environment().hasFuncModule()) {
        invoke(new Generator_Funcs().usingValues(values).generate());
    }
    if (round.environment().hasTreesModule()) {
        invoke(new Generator_Transformers().usingValues(values).generate());
        invoke(new Generator_Visitors().usingValues(values).generate());
    }
    if (round.environment().hasAstModule()) {
        invoke(new Generator_Asts().usingValues(values).generate());
    }
    if (round.environment().hasEncodeModule()) {
        invoke(new Generator_Encodings().generate());
    }
}
Also used : ValueType(org.immutables.value.processor.meta.ValueType) ImmutableRound(org.immutables.value.processor.meta.ImmutableRound) Round(org.immutables.value.processor.meta.Round) Generator_Encodings(org.immutables.value.processor.encode.Generator_Encodings) DeclaringPackage(org.immutables.value.processor.meta.Proto.DeclaringPackage)

Example 2 with DeclaringPackage

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

DeclaringPackage (org.immutables.value.processor.meta.Proto.DeclaringPackage)2 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 Nullable (javax.annotation.Nullable)1 Generator_Encodings (org.immutables.value.processor.encode.Generator_Encodings)1 ImmutableRound (org.immutables.value.processor.meta.ImmutableRound)1 DeclaringType (org.immutables.value.processor.meta.Proto.DeclaringType)1 Protoclass (org.immutables.value.processor.meta.Proto.Protoclass)1 Round (org.immutables.value.processor.meta.Round)1 ValueType (org.immutables.value.processor.meta.ValueType)1