MCPcopy Index your code
hub / github.com/google/dagger / getUnwrappedMapKeyType

Method getUnwrappedMapKeyType

java/dagger/internal/codegen/MapKeys.java:106–136  ·  view source on GitHub ↗

Returns the map key type for an unwrapped MapKey annotation type. If the single member type is primitive, returns the boxed type. @throws IllegalArgumentException if mapKeyAnnotationType is not an annotation type or has more than one member, or if its single member is an array @

(
      final DeclaredType mapKeyAnnotationType, final Types types)

Source from the content-addressed store, hash-verified

104 * @throws NoSuchElementException if the annotation has no members
105 */
106 static DeclaredType getUnwrappedMapKeyType(
107 final DeclaredType mapKeyAnnotationType, final Types types) {
108 checkArgument(
109 MoreTypes.asTypeElement(mapKeyAnnotationType).getKind() == ElementKind.ANNOTATION_TYPE,
110 "%s is not an annotation type",
111 mapKeyAnnotationType);
112
113 final ExecutableElement onlyElement =
114 getOnlyElement(methodsIn(mapKeyAnnotationType.asElement().getEnclosedElements()));
115
116 SimpleTypeVisitor6<DeclaredType, Void> keyTypeElementVisitor =
117 new SimpleTypeVisitor6<DeclaredType, Void>() {
118
119 @Override
120 public DeclaredType visitArray(ArrayType t, Void p) {
121 throw new IllegalArgumentException(
122 mapKeyAnnotationType + "." + onlyElement.getSimpleName() + " cannot be an array");
123 }
124
125 @Override
126 public DeclaredType visitPrimitive(PrimitiveType t, Void p) {
127 return MoreTypes.asDeclared(types.boxedClass(t).asType());
128 }
129
130 @Override
131 public DeclaredType visitDeclared(DeclaredType t, Void p) {
132 return t;
133 }
134 };
135 return keyTypeElementVisitor.visit(onlyElement.getReturnType());
136 }
137
138 /**
139 * Returns a code block for {@code binding}'s {@link ContributionBinding#mapKey() map key}. If for

Callers 2

mapKeyTypeMethod · 0.95
unwrappedValueKindMethod · 0.80

Calls 1

asElementMethod · 0.80

Tested by

no test coverage detected