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

Class TypeVariableInvocationHandler

output/java_guava/1.4.17/Types.java:363–404  ·  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

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

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