/*
 * Copyright (C) 2015 The Dagger Authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package dagger.internal.codegen.base;

import static androidx.room.compiler.processing.compat.XConverters.toJavac;
import static com.google.auto.common.MoreElements.isAnnotationPresent;

import androidx.room.compiler.processing.XElement;
import dagger.multibindings.ElementsIntoSet;
import dagger.multibindings.IntoMap;
import dagger.multibindings.IntoSet;
import javax.lang.model.element.Element;

/** Whether a binding or declaration is for a unique contribution or a map or set multibinding. */
public enum ContributionType {
  /** Represents map bindings. */
  MAP,
  /** Represents set bindings. */
  SET,
  /** Represents set values bindings. */
  SET_VALUES,
  /** Represents a valid non-collection binding. */
  UNIQUE,
  ;

  /** An object that is associated with a {@link ContributionType}. */
  public interface HasContributionType {

    /** The contribution type of this object. */
    ContributionType contributionType();
  }

  /** {@code true} if this is for a multibinding. */
  public boolean isMultibinding() {
    return !this.equals(UNIQUE);
  }

  /**
   * The contribution type from a binding element's annotations. Presumes a well-formed binding
   * element (at most one of @IntoSet, @IntoMap, @ElementsIntoSet and @Provides.type). {@link
   * dagger.internal.codegen.validation.BindingMethodValidator} and {@link
   * dagger.internal.codegen.validation.BindsInstanceProcessingStep} validate correctness on their
   * own.
   */
  public static ContributionType fromBindingElement(XElement element) {
    return fromBindingElement(toJavac(element));
  }

  /**
   * The contribution type from a binding element's annotations. Presumes a well-formed binding
   * element (at most one of @IntoSet, @IntoMap, @ElementsIntoSet and @Provides.type). {@link
   * dagger.internal.codegen.validation.BindingMethodValidator} and {@link
   * dagger.internal.codegen.validation.BindsInstanceProcessingStep} validate correctness on their
   * own.
   */
  public static ContributionType fromBindingElement(Element element) {
    // TODO(bcorso): Replace these class references with ClassName.
    if (isAnnotationPresent(element, IntoMap.class)) {
      return ContributionType.MAP;
    } else if (isAnnotationPresent(element, IntoSet.class)) {
      return ContributionType.SET;
    } else if (isAnnotationPresent(element, ElementsIntoSet.class)) {
      return ContributionType.SET_VALUES;
    }
    return ContributionType.UNIQUE;
  }
}

@@ -647,358 +647,101 @@
 ort 
-static androidx.room.compiler.processing.compat.XConverters.toJavac;%0Aimport static com.google.auto.common.MoreElements.isAnnotationPresent;%0A%0Aimport androidx.room.compiler.processing.XElement;%0Aimport dagger.multibindings.ElementsIntoSet;%0Aimport dagger.multibindings.IntoMap;%0Aimport dagger.multibindings.IntoSet;%0Aimport javax.lang.model.element.Element
+androidx.room.compiler.processing.XElement;%0Aimport dagger.internal.codegen.javapoet.TypeNames
 ;%0A%0A/
@@ -1550,32 +1550,36 @@
 toSet, @IntoMap,
+ and
  @ElementsIntoSe
@@ -1579,35 +1579,16 @@
 sIntoSet
- and @Provides.type
 ). %7B@lin
@@ -1859,633 +1859,52 @@
     
-return fromBindingElement(toJavac(element));%0A  %7D%0A%0A  /**%0A   * The contribution type from a binding element's annotations. Presumes a well-formed binding%0A   * element (at most one of @IntoSet, @IntoMap, @ElementsIntoSet and @Provides.type). %7B@link%0A   * dagger.internal.codegen.validation.BindingMethodValidator%7D and %7B@link%0A   * dagger.internal.codegen.validation.BindsInstanceProcessingStep%7D validate correctness on their%0A   * own.%0A   */%0A  public static ContributionType fromBindingElement(Element element) %7B%0A    // TODO(bcorso): Replace these class references with ClassName.%0A    if (isAnnotationPresent(element, IntoMap.class
+if (element.hasAnnotation(TypeNames.INTO_MAP
 )) %7B
@@ -1946,33 +1946,42 @@
 %0A    %7D else if (
-i
+element.ha
 sAnnotationPrese
@@ -1979,38 +1979,27 @@
 tion
-Present(element, IntoSet.class
+(TypeNames.INTO_SET
 )) %7B
@@ -2049,17 +2049,26 @@
 lse if (
-i
+element.ha
 sAnnotat
@@ -2074,46 +2074,36 @@
 tion
-Present(element, ElementsIntoSet.class
+(TypeNames.ELEMENTS_INTO_SET
 )) %7B

Migrate ContributionType to XProcessing.