You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by an...@apache.org on 2014/01/23 06:07:56 UTC
git commit: Getting even hairier now...down into Guava
Updated Branches:
refs/heads/JCLOUDS-427 3b7570f7d -> 2c63e222e
Getting even hairier now...down into Guava
Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/2c63e222
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/2c63e222
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/2c63e222
Branch: refs/heads/JCLOUDS-427
Commit: 2c63e222eec1b8ede14d84aa8d693921d26e6264
Parents: 3b7570f
Author: Andrew Phillips <an...@apache.org>
Authored: Thu Jan 23 00:07:01 2014 -0500
Committer: Andrew Phillips <an...@apache.org>
Committed: Thu Jan 23 00:07:15 2014 -0500
----------------------------------------------------------------------
.../com/google/common/reflect/TypeToken2.java | 33 ++++++++++++++++++++
.../org/jclouds/rest/config/BinderUtils.java | 19 +++++------
2 files changed, 41 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds/blob/2c63e222/core/src/main/java/com/google/common/reflect/TypeToken2.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/com/google/common/reflect/TypeToken2.java b/core/src/main/java/com/google/common/reflect/TypeToken2.java
new file mode 100644
index 0000000..b12bf69
--- /dev/null
+++ b/core/src/main/java/com/google/common/reflect/TypeToken2.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.google.common.reflect;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.reflect.TypeParameter;
+import com.google.common.reflect.TypeToken;
+
+/*
+ * Evil stuff. See https://issues.apache.org/jira/browse/JCLOUDS-427
+ */
+public class TypeToken2<T> extends TypeToken<T> {
+ public <X, Y> TypeToken<T> where(TypeParameter<X> typeParam, Class<X> typeArg, TypeParameter<Y> typeParam2, Class<Y> typeArg2) {
+ TypeResolver resolver = new TypeResolver()
+ .where(ImmutableMap.of(typeParam.typeVariable, of(typeArg).getType(), typeParam2.typeVariable, of(typeArg2).getType()));
+ // If there's any type error, we'd report now rather than later.
+ return (TypeToken<T>) TypeToken.of(resolver.resolveType(getType()));
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jclouds/blob/2c63e222/core/src/main/java/org/jclouds/rest/config/BinderUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/jclouds/rest/config/BinderUtils.java b/core/src/main/java/org/jclouds/rest/config/BinderUtils.java
index 11c5f25..22d837f 100644
--- a/core/src/main/java/org/jclouds/rest/config/BinderUtils.java
+++ b/core/src/main/java/org/jclouds/rest/config/BinderUtils.java
@@ -18,6 +18,7 @@ package org.jclouds.rest.config;
import com.google.common.reflect.TypeParameter;
import com.google.common.reflect.TypeToken;
+import com.google.common.reflect.TypeToken2;
import com.google.inject.Binder;
import com.google.inject.TypeLiteral;
import java.util.Map;
@@ -102,27 +103,23 @@ public class BinderUtils {
private static <S, A> void bindHttpApiProvider(Binder binder, Class<S> sync, Class<A> async) {
TypeToken<SyncToAsyncHttpApiProvider<S, A>> token = new TypeToken<SyncToAsyncHttpApiProvider<S, A>>() {
};
- System.out.println("Printing Guava sample for 'where': " + mapOf(TypeToken.of(String.class), TypeToken.of(Integer.class)));
System.out.println("**** token now (step 1): " + token);
token = token.where(new TypeParameter<A>() {}, async);
System.out.println("**** token now (after A): " + token);
token = token.where(new TypeParameter<S>() {}, TypeToken.of(sync));
System.out.println("**** token now (after S, using TypeToken): " + token);
+ TypeToken2<SyncToAsyncHttpApiProvider<S, A>> token2 = new TypeToken2<SyncToAsyncHttpApiProvider<S, A>>() {
+ };
+ TypeToken<SyncToAsyncHttpApiProvider<S, A>> done = token2.where(new TypeParameter<A>() {}, async, new TypeParameter<S>() {}, sync);
+ System.out.println("**** token2 now: " + done);
try {
- binder.bind(sync).toProvider(TypeLiteral.class.cast(TypeLiteral.get(token.getType())));
- } catch(RuntimeException e) {
+ binder.bind(sync).toProvider(TypeLiteral.class.cast(TypeLiteral.get(done.getType())));
+ } catch (RuntimeException e) {
System.err.format("************ Caught '%s' trying to bind '%s' to '%s'. Input async class: '%s'%n%n", e.getMessage(), TypeLiteral.get(token.getType()), sync, async);
throw e;
}
}
-
- public static <K, V> TypeToken<Map<K, V>> mapOf(
- TypeToken<K> keyType, TypeToken<V> valueType) {
- return new TypeToken<Map<K, V>>() {}
- .where(new TypeParameter<K>() {}, keyType)
- .where(new TypeParameter<V>() {}, valueType);
- }
-
+
/**
* adds an explicit binding for an interface which synchronously blocks on
* similar calls to an {@code async} type.