formatting

This commit is contained in:
Adrian Cole 2011-09-30 09:47:52 -07:00
parent d53c89b4e3
commit 1fdd46c164
2 changed files with 30 additions and 22 deletions

View File

@ -46,9 +46,9 @@ import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.Map.Entry;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -77,7 +77,6 @@ import org.jclouds.http.HttpUtils;
import org.jclouds.http.functions.ParseFirstJsonValueNamed; import org.jclouds.http.functions.ParseFirstJsonValueNamed;
import org.jclouds.http.functions.ParseJson; import org.jclouds.http.functions.ParseJson;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.HandlerWithResult;
import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x; import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x;
import org.jclouds.http.functions.ReleasePayloadAndReturn; import org.jclouds.http.functions.ReleasePayloadAndReturn;
import org.jclouds.http.functions.ReturnInputStream; import org.jclouds.http.functions.ReturnInputStream;
@ -87,6 +86,7 @@ import org.jclouds.http.functions.UnwrapOnlyJsonValue;
import org.jclouds.http.functions.UnwrapOnlyJsonValueInSet; import org.jclouds.http.functions.UnwrapOnlyJsonValueInSet;
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue; import org.jclouds.http.functions.UnwrapOnlyNestedJsonValue;
import org.jclouds.http.functions.UnwrapOnlyNestedJsonValueInSet; import org.jclouds.http.functions.UnwrapOnlyNestedJsonValueInSet;
import org.jclouds.http.functions.ParseSax.HandlerWithResult;
import org.jclouds.http.options.HttpRequestOptions; import org.jclouds.http.options.HttpRequestOptions;
import org.jclouds.http.utils.ModifyRequest; import org.jclouds.http.utils.ModifyRequest;
import org.jclouds.internal.ClassMethodArgs; import org.jclouds.internal.ClassMethodArgs;
@ -145,12 +145,12 @@ import com.google.common.cache.CacheLoader;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.LinkedHashMultimap;
import com.google.common.collect.LinkedListMultimap; import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.collect.ImmutableSet.Builder;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -921,12 +921,12 @@ public class RestAnnotationProcessor<T> {
}; };
public GeneratedHttpRequest<T> decorateRequest(GeneratedHttpRequest<T> request) throws NegativeArraySizeException, public GeneratedHttpRequest<T> decorateRequest(GeneratedHttpRequest<T> request) throws NegativeArraySizeException,
ExecutionException { ExecutionException {
OUTER: for (Entry<Integer, Set<Annotation>> entry : concat(// OUTER: for (Entry<Integer, Set<Annotation>> entry : concat(//
filterValues(methodToIndexOfParamToBinderParamAnnotation.get(request.getJavaMethod()).asMap(), notEmpty) filterValues(methodToIndexOfParamToBinderParamAnnotation.get(request.getJavaMethod()).asMap(), notEmpty)
.entrySet(), // .entrySet(), //
filterValues(methodToIndexOfParamToWrapWithAnnotation.get(request.getJavaMethod()).asMap(), notEmpty) filterValues(methodToIndexOfParamToWrapWithAnnotation.get(request.getJavaMethod()).asMap(), notEmpty)
.entrySet())) { .entrySet())) {
boolean shouldBreak = false; boolean shouldBreak = false;
Annotation annotation = Iterables.get(entry.getValue(), 0); Annotation annotation = Iterables.get(entry.getValue(), 0);
Binder binder; Binder binder;
@ -934,7 +934,7 @@ public class RestAnnotationProcessor<T> {
binder = injector.getInstance(BinderParam.class.cast(annotation).value()); binder = injector.getInstance(BinderParam.class.cast(annotation).value());
else else
binder = injector.getInstance(BindToJsonPayloadWrappedWith.Factory.class).create( binder = injector.getInstance(BindToJsonPayloadWrappedWith.Factory.class).create(
WrapWith.class.cast(annotation).value()); WrapWith.class.cast(annotation).value());
if (request.getArgs().size() >= entry.getKey() + 1 && request.getArgs().get(entry.getKey()) != null) { if (request.getArgs().size() >= entry.getKey() + 1 && request.getArgs().get(entry.getKey()) != null) {
Object input; Object input;
Class<?> parameterType = request.getJavaMethod().getParameterTypes()[entry.getKey()]; Class<?> parameterType = request.getJavaMethod().getParameterTypes()[entry.getKey()];
@ -966,19 +966,21 @@ public class RestAnnotationProcessor<T> {
// (first, however, let's make sure we have enough args on the actual method) // (first, however, let's make sure we have enough args on the actual method)
if (entry.getKey() >= request.getJavaMethod().getParameterAnnotations().length) { if (entry.getKey() >= request.getJavaMethod().getParameterAnnotations().length) {
// not known whether this happens // not known whether this happens
throw new IllegalArgumentException("Argument index "+(entry.getKey()+1)+" is out of bounds for method "+request.getJavaMethod()); throw new IllegalArgumentException("Argument index " + (entry.getKey() + 1)
+ " is out of bounds for method " + request.getJavaMethod());
} }
if (request.getJavaMethod().isVarArgs() && entry.getKey() + 1 == request.getJavaMethod().getParameterTypes().length) if (request.getJavaMethod().isVarArgs()
//allow null/missing for var args && entry.getKey() + 1 == request.getJavaMethod().getParameterTypes().length)
// allow null/missing for var args
continue OUTER; continue OUTER;
Annotation[] annotations = request.getJavaMethod().getParameterAnnotations()[entry.getKey()]; Annotation[] annotations = request.getJavaMethod().getParameterAnnotations()[entry.getKey()];
for (Annotation a: annotations) { for (Annotation a : annotations) {
if (Nullable.class.isAssignableFrom(a.annotationType())) if (Nullable.class.isAssignableFrom(a.annotationType()))
continue OUTER; continue OUTER;
} }
Preconditions.checkNotNull(null, request.getJavaMethod().getName()+" parameter "+(entry.getKey()+1)); Preconditions.checkNotNull(null, request.getJavaMethod().getName() + " parameter " + (entry.getKey() + 1));
} }
} }

View File

@ -602,7 +602,7 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
public void testCreatePostRequestNullOk2() throws SecurityException, NoSuchMethodException, IOException { public void testCreatePostRequestNullOk2() throws SecurityException, NoSuchMethodException, IOException {
Method method = TestPost.class.getMethod("post", String.class); Method method = TestPost.class.getMethod("post", String.class);
HttpRequest request = factory(TestPost.class).createRequest(method, (String)null); HttpRequest request = factory(TestPost.class).createRequest(method, (String) null);
assertRequestLineEquals(request, "POST http://localhost:9999 HTTP/1.1"); assertRequestLineEquals(request, "POST http://localhost:9999 HTTP/1.1");
assertNonPayloadHeadersEqual(request, ""); assertNonPayloadHeadersEqual(request, "");
@ -613,19 +613,25 @@ public class RestAnnotationProcessorTest extends BaseRestClientTest {
Method method = TestPost.class.getMethod("postNonnull", String.class); Method method = TestPost.class.getMethod("postNonnull", String.class);
try { try {
HttpRequest request = factory(TestPost.class).createRequest(method); HttpRequest request = factory(TestPost.class).createRequest(method);
Assert.fail("call should have failed with illegal null parameter, not permitted "+request+" to be created"); Assert
.fail("call should have failed with illegal null parameter, not permitted " + request
+ " to be created");
} catch (NullPointerException e) { } catch (NullPointerException e) {
Assert.assertTrue(e.toString().indexOf("postNonnull parameter 1")>=0, "Error message should have referred to 'parameter 1': "+e); Assert.assertTrue(e.toString().indexOf("postNonnull parameter 1") >= 0,
"Error message should have referred to 'parameter 1': " + e);
} }
} }
public void testCreatePostRequestNullNotOk2() throws SecurityException, NoSuchMethodException, IOException { public void testCreatePostRequestNullNotOk2() throws SecurityException, NoSuchMethodException, IOException {
Method method = TestPost.class.getMethod("postNonnull", String.class); Method method = TestPost.class.getMethod("postNonnull", String.class);
try { try {
HttpRequest request = factory(TestPost.class).createRequest(method, (String)null); HttpRequest request = factory(TestPost.class).createRequest(method, (String) null);
Assert.fail("call should have failed with illegal null parameter, not permitted "+request+" to be created"); Assert
.fail("call should have failed with illegal null parameter, not permitted " + request
+ " to be created");
} catch (NullPointerException e) { } catch (NullPointerException e) {
Assert.assertTrue(e.toString().indexOf("postNonnull parameter 1")>=0, "Error message should have referred to parameter 'parameter 1': "+e); Assert.assertTrue(e.toString().indexOf("postNonnull parameter 1") >= 0,
"Error message should have referred to parameter 'parameter 1': " + e);
} }
} }