aboutsummaryrefslogtreecommitdiff
path: root/java/dagger/spi/model/DaggerTypeElement.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/dagger/spi/model/DaggerTypeElement.java')
-rw-r--r--java/dagger/spi/model/DaggerTypeElement.java83
1 files changed, 16 insertions, 67 deletions
diff --git a/java/dagger/spi/model/DaggerTypeElement.java b/java/dagger/spi/model/DaggerTypeElement.java
index 2f70a54b8..935770d11 100644
--- a/java/dagger/spi/model/DaggerTypeElement.java
+++ b/java/dagger/spi/model/DaggerTypeElement.java
@@ -16,78 +16,27 @@
package dagger.spi.model;
-import com.google.auto.common.MoreElements;
-import com.google.auto.value.AutoValue;
import com.google.devtools.ksp.symbol.KSClassDeclaration;
-import javax.annotation.Nullable;
+import com.google.errorprone.annotations.DoNotMock;
import javax.lang.model.element.TypeElement;
/** Wrapper type for a type element. */
-@AutoValue
+@DoNotMock("Only use real implementations created by Dagger")
public abstract class DaggerTypeElement {
- public static DaggerTypeElement fromJavac(@Nullable TypeElement element) {
- return new AutoValue_DaggerTypeElement(element, null);
- }
-
- public static DaggerTypeElement fromKsp(@Nullable KSClassDeclaration declaration) {
- return new AutoValue_DaggerTypeElement(null, declaration);
- }
-
- /** Java representation for the type, returns {@code null} not using java annotation processor. */
- @Nullable
- public abstract TypeElement java();
-
- /** KSP declaration for the element, returns {@code null} not using KSP. */
- @Nullable
+ /**
+ * Returns the Javac representation for the type element.
+ *
+ * @throws IllegalStateException if the current backend isn't Javac.
+ */
+ public abstract TypeElement javac();
+
+ /**
+ * Returns the KSP representation for the type element.
+ *
+ * @throws IllegalStateException if the current backend isn't KSP.
+ */
public abstract KSClassDeclaration ksp();
- public final boolean hasAnnotation(String annotationName) {
- switch (backend()) {
- case JAVAC:
- return MoreElements.isAnnotationPresent(java(), annotationName);
- case KSP:
- return KspUtilsKt.hasAnnotation(ksp(), annotationName);
- }
- throw new IllegalStateException(String.format("Backend %s not supported yet.", backend()));
- }
-
- public String packageName() {
- switch (backend()) {
- case JAVAC:
- return MoreElements.getPackage(java()).getQualifiedName().toString();
- case KSP:
- return KspUtilsKt.getNormalizedPackageName(ksp());
- }
- throw new IllegalStateException(String.format("Backend %s not supported yet.", backend()));
- }
-
- public String qualifiedName() {
- switch (backend()) {
- case JAVAC:
- return java().getQualifiedName().toString();
- case KSP:
- return ksp().getQualifiedName().asString();
- }
- throw new IllegalStateException(String.format("Backend %s not supported yet.", backend()));
- }
-
- public DaggerProcessingEnv.Backend backend() {
- if (java() != null) {
- return DaggerProcessingEnv.Backend.JAVAC;
- } else if (ksp() != null) {
- return DaggerProcessingEnv.Backend.KSP;
- }
- throw new AssertionError("Unexpected backend");
- }
-
- @Override
- public final String toString() {
- switch (backend()) {
- case JAVAC:
- return java().toString();
- case KSP:
- return ksp().toString();
- }
- throw new IllegalStateException(String.format("Backend %s not supported yet.", backend()));
- }
+ /** Returns the backend used in this compilation. */
+ public abstract DaggerProcessingEnv.Backend backend();
}