diff --git a/apis/s3/src/main/java/org/jclouds/s3/util/S3Utils.java b/apis/s3/src/main/java/org/jclouds/s3/util/S3Utils.java index 4080b224bb..ef836c3058 100644 --- a/apis/s3/src/main/java/org/jclouds/s3/util/S3Utils.java +++ b/apis/s3/src/main/java/org/jclouds/s3/util/S3Utils.java @@ -22,15 +22,16 @@ import static com.google.common.collect.Iterables.any; import java.lang.annotation.Annotation; import java.util.Arrays; +import java.util.List; import java.util.regex.Pattern; import org.jclouds.http.HttpRequest; +import org.jclouds.reflect.Reflection2; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.s3.Bucket; import org.jclouds.s3.S3Client; import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableList; import com.google.common.reflect.Parameter; /** @@ -77,7 +78,7 @@ public class S3Utils { String bucketName = null; - ImmutableList parameters = request.getInvocation().getInvokable().getParameters(); + List parameters = Reflection2.getInvokableParameters(request.getInvocation().getInvokable()); for (int i = 0; i < parameters.size(); i++) { if (any(Arrays.asList(parameters.get(i).getAnnotations()), ANNOTATIONTYPE_BUCKET)) { bucketName = (String) request.getInvocation().getArgs().get(i); diff --git a/core/src/main/java/org/jclouds/reflect/Reflection2.java b/core/src/main/java/org/jclouds/reflect/Reflection2.java index 674c41630a..7246f64443 100644 --- a/core/src/main/java/org/jclouds/reflect/Reflection2.java +++ b/core/src/main/java/org/jclouds/reflect/Reflection2.java @@ -195,6 +195,24 @@ public class Reflection2 { } }); + private static final LoadingCache, ImmutableList> invokableParamsCache = + CacheBuilder.newBuilder().maximumSize(100).build(new CacheLoader, ImmutableList>() { + @Override + public ImmutableList load(Invokable invokable) { + return invokable.getParameters(); + } + }); + + /** + * Returns the {@link Parameter}s associated with the given {@link Invokable}. This function is backed by a cache. + * + * @param invokable + * The {@link Invokable} we want to get Parameters from + */ + public static List getInvokableParameters(final Invokable invokable) { + return invokableParamsCache.getUnchecked(invokable); + } + private static class TypeTokenAndParameterTypes { protected TypeToken type; diff --git a/core/src/main/java/org/jclouds/rest/InputParamValidator.java b/core/src/main/java/org/jclouds/rest/InputParamValidator.java index c7c5bb9acc..3931e39305 100644 --- a/core/src/main/java/org/jclouds/rest/InputParamValidator.java +++ b/core/src/main/java/org/jclouds/rest/InputParamValidator.java @@ -26,7 +26,6 @@ import org.jclouds.predicates.Validator; import org.jclouds.reflect.Invocation; import org.jclouds.rest.annotations.ParamValidators; -import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.reflect.Parameter; @@ -67,7 +66,7 @@ public class InputParamValidator { * @throws IllegalStateException * if validation failed */ - public void validateMethodParametersOrThrow(Invocation invocation, ImmutableList parameters) { + public void validateMethodParametersOrThrow(Invocation invocation, List parameters) { try { performMethodValidation(checkNotNull(invocation, "invocation")); performParameterValidation(invocation, checkNotNull(parameters, "parameters")); @@ -105,7 +104,7 @@ public class InputParamValidator { * @param args * arguments that correspond to the array of annotations */ - private void performParameterValidation(Invocation invocation, ImmutableList parameters) { + private void performParameterValidation(Invocation invocation, List parameters) { for (Parameter param : parameters) { ParamValidators annotation = param.getAnnotation(ParamValidators.class); if (annotation == null) diff --git a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java index 89b430c3e7..d48d876f8a 100644 --- a/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java +++ b/core/src/main/java/org/jclouds/rest/internal/RestAnnotationProcessor.java @@ -38,6 +38,7 @@ import static org.jclouds.http.HttpUtils.filterOutContentHeaders; import static org.jclouds.http.HttpUtils.tryFindHttpMethod; import static org.jclouds.http.Uris.uriBuilder; import static org.jclouds.io.Payloads.newPayload; +import static org.jclouds.reflect.Reflection2.getInvokableParameters; import static org.jclouds.util.Strings2.replaceTokens; import java.lang.annotation.Annotation; @@ -150,13 +151,6 @@ public class RestAnnotationProcessor implements Function, ImmutableList> invokableParamsCache = - CacheBuilder.newBuilder().maximumSize(100).build(new CacheLoader, ImmutableList>() { - @Override - public ImmutableList load(Invokable invokable) { - return invokable.getParameters(); - } - }); @Inject private RestAnnotationProcessor(Injector injector, @ApiVersion String apiVersion, @BuildVersion String buildVersion, @@ -186,7 +180,7 @@ public class RestAnnotationProcessor implements Function endpoint = Optional.absent(); HttpRequest r = findOrNull(invocation.getArgs(), HttpRequest.class); @@ -506,7 +500,7 @@ public class RestAnnotationProcessor implements Function parametersWithAnnotation(Invokable invokable, final Class annotationType) { - return filter(invokableParamsCache.getUnchecked(invokable), new Predicate() { + return filter(getInvokableParameters(invokable), new Predicate() { public boolean apply(Parameter in) { return in.isAnnotationPresent(annotationType); } @@ -609,7 +603,7 @@ public class RestAnnotationProcessor implements Function load(Invokable invokable) { Builder toReturn = ImmutableSet.builder(); - for (Parameter param : invokable.getParameters()) { + for (Parameter param : getInvokableParameters(invokable)) { Class type = param.getType().getRawType(); if (HttpRequestOptions.class.isAssignableFrom(type) || HttpRequestOptions[].class.isAssignableFrom(type)) @@ -776,7 +770,7 @@ public class RestAnnotationProcessor implements Function