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

com.apollographql.apollo.compiler.ClassNames.kt Maven / Gradle / Ivy

There is a newer version: 3.4.2
Show newest version
/**
 * Copyright 2018-2019 Amazon.com,
 * Inc. or its affiliates. All Rights Reserved.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

package com.apollographql.apollo.compiler

import com.apollographql.apollo.api.*
import com.apollographql.apollo.api.internal.Mutator
import com.apollographql.apollo.api.internal.Optional
import com.apollographql.apollo.api.internal.UnmodifiableMapBuilder
import com.apollographql.apollo.api.internal.Utils
import com.squareup.javapoet.ClassName
import com.squareup.javapoet.ParameterizedTypeName
import com.squareup.javapoet.TypeName
import java.util.*

object ClassNames {
  val OBJECT: ClassName = ClassName.get(Object::class.java)
  val STRING: ClassName = ClassName.get(String::class.java)
  val LIST: ClassName = ClassName.get(List::class.java)
  val ARRAY_LIST: ClassName = ClassName.get(ArrayList::class.java)
  val GRAPHQL_OPERATION: ClassName = ClassName.get(Operation::class.java)
  val GRAPHQL_QUERY: ClassName = ClassName.get(Query::class.java)
  val GRAPHQL_MUTATION: ClassName = ClassName.get(Mutation::class.java)
  val GRAPHQL_SUBSCRIPTION: ClassName = ClassName.get(Subscription::class.java)
  val GRAPHQL_OPERATION_VARIABLES: ClassName = ClassName.get("", "${GRAPHQL_OPERATION.simpleName()}.Variables")
  val ILLEGAL_STATE_EXCEPTION: TypeName = ClassName.get(IllegalStateException::class.java)
  val MAP: ClassName = ClassName.get(Map::class.java)
  val HASH_MAP: ClassName = ClassName.get(HashMap::class.java)
  val UNMODIFIABLE_MAP_BUILDER: ClassName = ClassName.get(UnmodifiableMapBuilder::class.java)
  val OPTIONAL: ClassName = ClassName.get(Optional::class.java)
  val GUAVA_OPTIONAL: ClassName = ClassName.get("com.google.common.base", "Optional")
  val JAVA_OPTIONAL: ClassName = ClassName.get("java.util", "Optional")
  val API_UTILS: ClassName = ClassName.get(Utils::class.java)
  val FRAGMENT: ClassName = ClassName.get(GraphqlFragment::class.java)
  val INPUT: ClassName = ClassName.get(Input::class.java)
  val BUILDER: ClassName = ClassName.get("", "Builder")
  val MUTATOR: ClassName = ClassName.get(Mutator::class.java)
  var S3ObjectInput: ClassName = ClassName.get(S3InputObjectInterface::class.java)
  var S3Object: ClassName = ClassName.get(S3ObjectInterface::class.java)
  val INPUT_TYPE: ClassName = ClassName.get(InputType::class.java)

  fun  parameterizedListOf(type: Class): TypeName =
      ParameterizedTypeName.get(LIST, ClassName.get(type))

  fun parameterizedListOf(typeArgument: TypeName): TypeName =
      ParameterizedTypeName.get(LIST, typeArgument.let { if (it.isPrimitive) it.box() else it.withoutAnnotations() })

  fun  parameterizedMapOf(keyTypeArgument: Class, valueTypeArgument: Class): TypeName =
      ParameterizedTypeName.get(MAP, ClassName.get(keyTypeArgument).withoutAnnotations(),
          ClassName.get(valueTypeArgument).withoutAnnotations())

  fun  parameterizedHashMapOf(keyTypeArgument: Class, valueTypeArgument: Class): TypeName =
      ParameterizedTypeName.get(HASH_MAP, ClassName.get(keyTypeArgument).withoutAnnotations(),
          ClassName.get(valueTypeArgument).withoutAnnotations())

  fun  parameterizedUnmodifiableMapBuilderOf(keyTypeArgument: Class,
      valueTypeArgument: Class): TypeName =
      ParameterizedTypeName.get(UNMODIFIABLE_MAP_BUILDER, ClassName.get(keyTypeArgument).withoutAnnotations(),
          ClassName.get(valueTypeArgument).withoutAnnotations())

  fun  parameterizedOptional(type: Class): TypeName =
      ParameterizedTypeName.get(OPTIONAL, ClassName.get(type))

  fun parameterizedOptional(type: TypeName): TypeName =
      ParameterizedTypeName.get(OPTIONAL, type)

  fun parameterizedGuavaOptional(type: TypeName): TypeName =
      ParameterizedTypeName.get(GUAVA_OPTIONAL, type)

  fun parameterizedJavaOptional(type: TypeName): TypeName =
      ParameterizedTypeName.get(JAVA_OPTIONAL, type)

  fun parameterizedInputType(type: TypeName): TypeName =
      ParameterizedTypeName.get(INPUT, type)

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy