override fun produce()

in sample/plugins-compiler/plugins-compiler/kotlin/src/main/kotlin/com/uber/crumb/sample/pluginscompiler/PluginsCompiler.kt [181:222]


  override fun produce(context: CrumbContext,
      type: TypeElement,
      annotations: Collection<AnnotationMirror>): ProducerMetadata {
    // Must be a class
    if (type.kind != CLASS) {
      context
          .processingEnv
          .messager
          .printMessage(
              ERROR,
              "@${Plugin::class.java.simpleName} is only applicable on classes!",
              type)
      return emptyMap<String, String>() to emptySet()
    }

    // Must be instantiable (not abstract)
    if (ABSTRACT in type.modifiers) {
      context
          .processingEnv
          .messager
          .printMessage(
              ERROR,
              "@${Plugin::class.java.simpleName} is not applicable on abstract classes!",
              type)
      return emptyMap<String, String>() to emptySet()
    }

    // If they define a default constructor, it must be public
    val defaultConstructor = ElementFilter.constructorsIn(type.enclosedElements)
        .firstOrNull { it.isDefault }
    if (defaultConstructor?.modifiers?.contains(Modifier.PUBLIC) == true) {
      context
          .processingEnv
          .messager
          .printMessage(
              ERROR,
              "Must have a public default constructor to be usable in plugin points.",
              type)
      return emptyMap<String, String>() to emptySet()
    }
    return mapOf(METADATA_KEY to type.qualifiedName.toString()) to setOf(type)
  }