Search in sources :

Example 1 with Either

use of com.palantir.conjure.either.Either in project conjure by palantir.

the class DealiasingTypeVisitor method visitReference.

@Override
public Either<TypeDefinition, Type> visitReference(TypeName value) {
    TypeDefinition typeDefinition = objects.get(value);
    Preconditions.checkState(typeDefinition != null, "Referenced TypeDefinition not found in map of types for TypeName: %s", value);
    return typeDefinition.accept(new TypeDefinition.Visitor<Either<TypeDefinition, Type>>() {

        @Override
        public Either<TypeDefinition, Type> visitAlias(AliasDefinition value) {
            // Recursively visit target of alias
            return value.getAlias().accept(DealiasingTypeVisitor.this);
        }

        @Override
        public Either<TypeDefinition, Type> visitEnum(EnumDefinition value) {
            return Either.left(TypeDefinition.enum_(value));
        }

        @Override
        public Either<TypeDefinition, Type> visitObject(ObjectDefinition value) {
            return Either.left(TypeDefinition.object(value));
        }

        @Override
        public Either<TypeDefinition, Type> visitUnion(UnionDefinition value) {
            return Either.left(TypeDefinition.union(value));
        }

        @Override
        public Either<TypeDefinition, Type> visitUnknown(String unknownType) {
            throw new IllegalStateException("Unsupported type: " + unknownType);
        }
    });
}
Also used : AliasDefinition(com.palantir.conjure.spec.AliasDefinition) Either(com.palantir.conjure.either.Either) UnionDefinition(com.palantir.conjure.spec.UnionDefinition) ObjectDefinition(com.palantir.conjure.spec.ObjectDefinition) EnumDefinition(com.palantir.conjure.spec.EnumDefinition) TypeDefinition(com.palantir.conjure.spec.TypeDefinition)

Aggregations

Either (com.palantir.conjure.either.Either)1 AliasDefinition (com.palantir.conjure.spec.AliasDefinition)1 EnumDefinition (com.palantir.conjure.spec.EnumDefinition)1 ObjectDefinition (com.palantir.conjure.spec.ObjectDefinition)1 TypeDefinition (com.palantir.conjure.spec.TypeDefinition)1 UnionDefinition (com.palantir.conjure.spec.UnionDefinition)1