Add asDeclared():DeclaredType to MoreTypes util class
package org.immutables.value.processor.meta;
import javax.lang.model.type.ArrayType;
+import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.ExecutableType;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.SimpleTypeVisitor6;
@@ -82,4 +83,26 @@ public class MoreTypes {
}
}
+ /**
+ * Returns a {@link DeclaredType} if the {@link TypeMirror} represents a declared type such as a
+ * class, interface, union/compound, or enum or throws an {@link IllegalArgumentException}.
+ */
+ public static DeclaredType asDeclared(TypeMirror maybeDeclaredType) {
+ return maybeDeclaredType.accept(DeclaredTypeVisitor.INSTANCE, null);
+ }
+
+ private static final class DeclaredTypeVisitor extends AbstractVisitor<DeclaredType> {
+ private static final DeclaredTypeVisitor INSTANCE = new DeclaredTypeVisitor();
+
+ DeclaredTypeVisitor() {
+ super("declared type");
+ }
+
+ @Override
+ public DeclaredType visitDeclared(DeclaredType type, Void ignore) {
+ return type;
+ }
+ }
+
+
}
