@Inject DelegatesToInvocationFunction(Injector injector, SetCaller setCaller, Class<S> ownerType, Function<InvocationSuccess, Optional<Object>> optionalConverter, F methodInvoker) { this.injector = checkNotNull(injector, "injector"); this.ownerType = typeToken(checkNotNull(ownerType, "ownerType")); this.setCaller = checkNotNull(setCaller, "setCaller"); this.optionalConverter = checkNotNull(optionalConverter, "optionalConverter"); this.methodInvoker = checkNotNull(methodInvoker, "methodInvoker"); }
@Override protected TypeToken<LoadBalancerServiceContext> viewType() { return typeToken(LoadBalancerServiceContext.class); } }
/** * @see #buildView(TypeToken) */ public <V extends View> V buildView(Class<V> viewType) { return buildView(typeToken(viewType)); }
public static Iterable<ProviderMetadata> collocatedWith(ProviderMetadata providerMetadata, Class<? extends View> viewableAs) { return collocatedWith(providerMetadata, typeToken(viewableAs)); } }
/** * return all methods present in the class as {@link Invokable}s. * * @param ownerType * corresponds to {@link Invokable#getOwnerType()} */ @SuppressWarnings("unchecked") public static <T> Collection<Invokable<T, Object>> methods(Class<T> ownerType) { return Collection.class.cast(get(methodsForTypeToken, typeToken(ownerType))); }
protected Builder(Class<?> api, Class<?> asyncApi) { checkNotNull(api, "api"); checkNotNull(asyncApi, "asyncApi"); javaApi(api, asyncApi) .name(String.format("%s->%s", api.getSimpleName(), asyncApi.getSimpleName())) .context(contextToken(typeToken(api), typeToken(asyncApi))) .defaultProperties(BaseRestApiMetadata.defaultProperties()); }
protected Builder(Class<?> api, Class<?> asyncApi) { checkNotNull(api, "api"); checkNotNull(asyncApi, "asyncApi"); javaApi(api, asyncApi) .name(String.format("%s->%s", api.getSimpleName(), asyncApi.getSimpleName())) .context(contextToken(typeToken(api), typeToken(asyncApi))) .defaultProperties(BaseRestApiMetadata.defaultProperties()); }
/** * useful when converting to and from type literals from other libraries such as guice and gson. */ public void testTypeTokenForType() { TypeLiteral<Set<String>> guice = new TypeLiteral<Set<String>>() { }; assertEquals(typeToken(guice.getType()), new TypeToken<Set<String>>() { private static final long serialVersionUID = 1L; }); }
@Test public void testContextAssignableFromRestContext() { Set<ApiMetadata> all = ImmutableSet.copyOf(Apis.contextAssignableFrom(typeToken(ApiContext.class))); assert all.contains(toTest) : String.format("%s not found in %s", toTest, all); }
public void testPeanutButterDidntTurnIntoWine() { Wine wine = new Wine(); assertNotEquals(wine.getBackendType(), typeToken(PeanutButter.class)); try { wine.unwrap(typeToken(PeanutButter.class)); fail(); } catch (IllegalArgumentException e) { assertEquals(e.getMessage(), "backend type: org.jclouds.internal.BaseViewTest$Water not assignable from org.jclouds.internal.BaseViewTest$PeanutButter"); } }
@Test(expectedExceptions = TestException.class) public void testPropagateWrappedExceptionThatsInList() throws Throwable { Exception e = new TestException(); propagateIfPossible(new RuntimeException(e), ImmutableSet.<TypeToken<? extends Throwable>> of(typeToken(TestException.class))); }
@Test(expectedExceptions = TestException.class) public void testPropagateExceptionThatsInList() throws Throwable { Exception e = new TestException(); propagateIfPossible(e, ImmutableSet.<TypeToken<? extends Throwable>> of(typeToken(TestException.class))); }
private void init() { api(api) .name(api.getSimpleName()) .context(contextToken(typeToken(api))) .defaultProperties(BaseHttpApiMetadata.defaultProperties()); }
public void testMethodFromClassAndNoParams() { @SuppressWarnings("rawtypes") Invokable<Set, Object> methodInSuper = method(Set.class, "iterator"); assertEquals(methodInSuper.getOwnerType(), typeToken(Set.class)); }
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { com.google.common.reflect.TypeToken<T> token = typeToken(type.getType()); Invokable<T, T> deserializationCtor = constructorFieldNamingPolicy.getDeserializer(token); if (deserializationCtor == null) { return null; // allow GSON to choose the correct Adapter (can't simply return delegateFactory.create()) } else { return new DeserializeIntoParameterizedConstructor<T>(delegateFactory.create(gson, type), deserializationCtor, getParameterReaders(gson, deserializationCtor)); } }
public void testMethodFromClassAndParams() { @SuppressWarnings("rawtypes") Invokable<Set, Object> methodInSuper = method(Set.class, "equals", Object.class); assertEquals(methodInSuper.getOwnerType(), typeToken(Set.class)); assertEquals(methodInSuper.getParameters().get(0).getType().getRawType(), Object.class); }
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { com.google.common.reflect.TypeToken<T> token = typeToken(type.getType()); Invokable<T, T> deserializationCtor = constructorFieldNamingPolicy.getDeserializer(token); if (deserializationCtor == null) { return null; // allow GSON to choose the correct Adapter (can't simply return delegateFactory.create()) } else { return new DeserializeIntoParameterizedConstructor<T>(delegateFactory.create(gson, type), deserializationCtor, getParameterReaders(gson, deserializationCtor)); } }