Invocation handler to work around a compatibility problem between Java 7 and Java 8. Java 8 introduced a new method getAnnotatedBounds() in the TypeVariable interface, whose return type AnnotatedType[] is also new in Java 8. That means that we cannot implement that interf
| 361 | */ |
| 362 | |
| 363 | private static final class TypeVariableInvocationHandler implements InvocationHandler { |
| 364 | |
| 365 | private static final ImmutableMap<String, Method> typeVariableMethods; |
| 366 | |
| 367 | static { |
| 368 | ImmutableMap.Builder<String, Method> builder = ImmutableMap.builder(); |
| 369 | for (Method method : TypeVariableImpl.class.getMethods()) { |
| 370 | if (method.getDeclaringClass().equals(TypeVariableImpl.class)) { |
| 371 | try { |
| 372 | method.setAccessible(true); |
| 373 | } catch (AccessControlException e) { |
| 374 | // OK: the method is accessible to us anyway. The setAccessible call is only for |
| 375 | // unusual execution environments where that might not be true. |
| 376 | } |
| 377 | builder.put(method.getName(), method); |
| 378 | } |
| 379 | } |
| 380 | typeVariableMethods = builder.build(); |
| 381 | } |
| 382 | |
| 383 | |
| 384 | private final TypeVariableImpl<?> typeVariableImpl; |
| 385 | |
| 386 | TypeVariableInvocationHandler(TypeVariableImpl<?> typeVariableImpl) { |
| 387 | this.typeVariableImpl = typeVariableImpl; |
| 388 | } |
| 389 | |
| 390 | @Override |
| 391 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { |
| 392 | String methodName = method.getName(); |
| 393 | Method typeVariableMethod = typeVariableMethods.get(methodName); |
| 394 | if (typeVariableMethod == null) { |
| 395 | throw new UnsupportedOperationException(methodName); |
| 396 | } else { |
| 397 | try { |
| 398 | return typeVariableMethod.invoke(typeVariableImpl, args); |
| 399 | } catch (InvocationTargetException e) { |
| 400 | throw e.getCause(); |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | private static final class TypeVariableImpl<D extends GenericDeclaration> { |
| 407 |
nothing calls this directly
no test coverage detected