MCPcopy Create free account
hub / github.com/antlr/codebuff / TypeVariableInvocationHandler

Class TypeVariableInvocationHandler

output/java_guava/1.4.19/Types.java:362–403  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

360 */
361
362 private static final class TypeVariableInvocationHandler implements InvocationHandler {
363
364 private static final ImmutableMap<String, Method> typeVariableMethods;
365
366 static {
367 ImmutableMap.Builder<String, Method> builder = ImmutableMap.builder();
368 for (Method method : TypeVariableImpl.class.getMethods()) {
369 if (method.getDeclaringClass().equals(TypeVariableImpl.class)) {
370 try {
371 method.setAccessible(true);
372 } catch (AccessControlException e) {
373 // OK: the method is accessible to us anyway. The setAccessible call is only for
374 // unusual execution environments where that might not be true.
375 }
376 builder.put(method.getName(), method);
377 }
378 }
379 typeVariableMethods = builder.build();
380 }
381
382
383 private final TypeVariableImpl<?> typeVariableImpl;
384
385 TypeVariableInvocationHandler(TypeVariableImpl<?> typeVariableImpl) {
386 this.typeVariableImpl = typeVariableImpl;
387 }
388
389 @Override
390 public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
391 String methodName = method.getName();
392 Method typeVariableMethod = typeVariableMethods.get(methodName);
393 if (typeVariableMethod == null) {
394 throw new UnsupportedOperationException(methodName);
395 } else {
396 try {
397 return typeVariableMethod.invoke(typeVariableImpl, args);
398 } catch (InvocationTargetException e) {
399 throw e.getCause();
400 }
401 }
402 }
403 }
404
405 private static final class TypeVariableImpl<D extends GenericDeclaration> {
406

Callers

nothing calls this directly

Calls 7

builderMethod · 0.95
equalsMethod · 0.65
putMethod · 0.65
getDeclaringClassMethod · 0.45
setAccessibleMethod · 0.45
getNameMethod · 0.45
buildMethod · 0.45

Tested by

no test coverage detected