@SuppressWarnings({"unchecked", "rawtypes"}) static TypeAndValue<?> typeAndValueOfMapKey(Annotation mapKeyAnnotation) { if (!mapKeyAnnotation.annotationType().getAnnotation(MapKey.class).unwrapValue()) { return new TypeAndValue(TypeLiteral.get(mapKeyAnnotation.annotationType()), mapKeyAnnotation); } else { try { Method valueMethod = mapKeyAnnotation.annotationType().getDeclaredMethod("value"); valueMethod.setAccessible(true); TypeLiteral<?> returnType = TypeLiteral.get(mapKeyAnnotation.annotationType()).getReturnType(valueMethod); return new TypeAndValue(returnType, valueMethod.invoke(mapKeyAnnotation)); } catch (NoSuchMethodException e) { throw new IllegalStateException(e); } catch (SecurityException e) { throw new IllegalStateException(e); } catch (IllegalAccessException e) { throw new IllegalStateException(e); } catch (InvocationTargetException e) { throw new IllegalStateException(e); } } }
return AnnotationOrError.forError(); if (mapKey.unwrapValue()) { try {
@SuppressWarnings({"unchecked", "rawtypes"}) static TypeAndValue<?> typeAndValueOfMapKey(Annotation mapKeyAnnotation) { if (!mapKeyAnnotation.annotationType().getAnnotation(MapKey.class).unwrapValue()) { return new TypeAndValue(TypeLiteral.get(mapKeyAnnotation.annotationType()), mapKeyAnnotation); } else { try { Method valueMethod = mapKeyAnnotation.annotationType().getDeclaredMethod("value"); valueMethod.setAccessible(true); TypeLiteral<?> returnType = TypeLiteral.get(mapKeyAnnotation.annotationType()).getReturnType(valueMethod); return new TypeAndValue(returnType, valueMethod.invoke(mapKeyAnnotation)); } catch (NoSuchMethodException e) { throw new IllegalStateException(e); } catch (SecurityException e) { throw new IllegalStateException(e); } catch (IllegalAccessException e) { throw new IllegalStateException(e); } catch (InvocationTargetException e) { throw new IllegalStateException(e); } } }
@SuppressWarnings({"unchecked", "rawtypes"}) static TypeAndValue<?> typeAndValueOfMapKey(Annotation mapKeyAnnotation) { if (!mapKeyAnnotation.annotationType().getAnnotation(MapKey.class).unwrapValue()) { return new TypeAndValue(TypeLiteral.get(mapKeyAnnotation.annotationType()), mapKeyAnnotation); } else { try { Method valueMethod = mapKeyAnnotation.annotationType().getDeclaredMethod("value"); valueMethod.setAccessible(true); TypeLiteral<?> returnType = TypeLiteral.get(mapKeyAnnotation.annotationType()).getReturnType(valueMethod); return new TypeAndValue(returnType, valueMethod.invoke(mapKeyAnnotation)); } catch (NoSuchMethodException e) { throw new IllegalStateException(e); } catch (SecurityException e) { throw new IllegalStateException(e); } catch (IllegalAccessException e) { throw new IllegalStateException(e); } catch (InvocationTargetException e) { throw new IllegalStateException(e); } } }
@SuppressWarnings({"unchecked", "rawtypes"}) static TypeAndValue<?> typeAndValueOfMapKey(Annotation mapKeyAnnotation) { if (!mapKeyAnnotation.annotationType().getAnnotation(MapKey.class).unwrapValue()) { return new TypeAndValue(TypeLiteral.get(mapKeyAnnotation.annotationType()), mapKeyAnnotation); } else { try { Method valueMethod = mapKeyAnnotation.annotationType().getDeclaredMethod("value"); valueMethod.setAccessible(true); TypeLiteral<?> returnType = TypeLiteral.get(mapKeyAnnotation.annotationType()).getReturnType(valueMethod); return new TypeAndValue(returnType, valueMethod.invoke(mapKeyAnnotation)); } catch (NoSuchMethodException e) { throw new IllegalStateException(e); } catch (SecurityException e) { throw new IllegalStateException(e); } catch (IllegalAccessException e) { throw new IllegalStateException(e); } catch (InvocationTargetException e) { throw new IllegalStateException(e); } } }
return AnnotationOrError.forError(); if (mapKey.unwrapValue()) { try {
private static AnnotationOrError findMapKeyAnnotation(Binder binder, Method method) { Annotation foundAnnotation = null; for (Annotation annotation : method.getAnnotations()) { MapKey mapKey = annotation.annotationType().getAnnotation(MapKey.class); if (mapKey != null) { if (foundAnnotation != null) { binder.addError("Found more than one MapKey annotations on %s.", method); return AnnotationOrError.forError(); } if (mapKey.unwrapValue()) { try { // validate there's a declared method called "value" Method valueMethod = annotation.annotationType().getDeclaredMethod("value"); if (valueMethod.getReturnType().isArray()) { binder.addError("Array types are not allowed in a MapKey with unwrapValue=true: %s", annotation.annotationType()); return AnnotationOrError.forError(); } } catch (NoSuchMethodException invalid) { binder.addError("No 'value' method in MapKey with unwrapValue=true: %s", annotation.annotationType()); return AnnotationOrError.forError(); } } foundAnnotation = annotation; } } return AnnotationOrError.forPossiblyNullAnnotation(foundAnnotation); }
return AnnotationOrError.forError(); if (mapKey.unwrapValue()) { try {