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)
| 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 |
no test coverage detected