All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.raml.ramltopojo.extensions.ObjectPluginContextImpl Maven / Gradle / Ivy

There is a newer version: 1.0.8
Show newest version
package org.raml.ramltopojo.extensions;

import com.google.common.base.Function;
import com.google.common.collect.FluentIterable;
import com.squareup.javapoet.TypeName;
import org.raml.ramltopojo.CreationResult;
import org.raml.ramltopojo.EventType;
import org.raml.ramltopojo.GenerationContext;
import org.raml.ramltopojo.TypeDeclarationType;
import org.raml.v2.api.model.v10.datamodel.TypeDeclaration;

import javax.annotation.Nullable;
import java.util.Set;

/**
 * Created. There, you have it.
 */
public class ObjectPluginContextImpl implements ObjectPluginContext {
    private final GenerationContext generationContext;
    private final CreationResult result;

    public ObjectPluginContextImpl(GenerationContext generationContext, CreationResult result) {
        this.generationContext = generationContext;
        this.result = result;
    }

    @Override
    public Set childClasses(String ramlTypeName) {

        return FluentIterable.from(generationContext.childClasses(ramlTypeName)).transform(new Function() {
            @Nullable
            @Override
            public CreationResult apply(@Nullable String input) {
                return generationContext.findCreatedType(input, null);
            }
        }).toSet();
    }

    @Override
    public CreationResult creationResult() {

        return result;
    }

    @Override
    public CreationResult dependentType(TypeDeclaration items) {
        return generationContext.findCreatedType(items.name(), items);
    }

    @Override
    public TypeName forProperty(TypeDeclaration typeDeclaration) {
        return TypeDeclarationType.calculateTypeName("", typeDeclaration, generationContext, EventType.INTERFACE);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy