public void testConstructor_getOwnerType() throws NoSuchMethodException { @SuppressWarnings("rawtypes") // raw class ArrayList.class Constructor<ArrayList> constructor = ArrayList.class.getConstructor(); assertEquals( TypeToken.of(ArrayList.class), TypeToken.of(ArrayList.class).constructor(constructor).getOwnerType()); assertEquals( new TypeToken<ArrayList<String>>() {}, new TypeToken<ArrayList<String>>() {}.constructor(constructor).getOwnerType()); }
public void testGetOwnerType_constructor() throws Exception { Invokable<String, String> invokable = Invokable.from(String.class.getConstructor()); assertEquals(TypeToken.of(String.class), invokable.getOwnerType()); }
public void testMethod_getOwnerType() throws NoSuchMethodException { Method sizeMethod = List.class.getMethod("size"); assertEquals( TypeToken.of(List.class), TypeToken.of(List.class).method(sizeMethod).getOwnerType()); assertEquals( new TypeToken<List<String>>() {}, new TypeToken<List<String>>() {}.method(sizeMethod).getOwnerType()); }
public void testGetOwnerType_method() throws Exception { Invokable<?, ?> invokable = Invokable.from(String.class.getMethod("length")); assertEquals(TypeToken.of(String.class), invokable.getOwnerType()); }
@Override public Set<String> apply(Invocation invocation) { Optional<Consumes> accept = Optional.fromNullable(invocation.getInvokable().getAnnotation(Consumes.class)).or( Optional.fromNullable(invocation.getInvokable().getOwnerType().getRawType().getAnnotation(Consumes.class))); return (accept.isPresent()) ? ImmutableSet.copyOf(accept.get().value()) : ImmutableSet.<String> of(); } }
@Override public Set<String> apply(Invocation invocation) { Optional<Consumes> accept = Optional.fromNullable(invocation.getInvokable().getAnnotation(Consumes.class)).or( Optional.fromNullable(invocation.getInvokable().getOwnerType().getRawType().getAnnotation(Consumes.class))); return (accept.isPresent()) ? ImmutableSet.copyOf(accept.get().value()) : ImmutableSet.<String> of(); } }
@Override public String getCommandName(Invocation invocation) { Invokable<?, ?> invoked = invocation.getInvokable(); if (invoked.isAnnotationPresent(Named.class)) { return invoked.getAnnotation(Named.class).value(); } else { // TODO: remove old logic once Named annotations are on all methods String className = invoked.getOwnerType().getRawType().getSimpleName().replace("AsyncClient", "Client") .replace("AsyncApi", "Api"); return className + "." + invoked.getName(); } }
@Override public String toString() { String callerString = caller != null ? String.format("%s.%s%s", caller.getInvokable().getOwnerType().getRawType().getSimpleName(), caller.getInvokable().getName(), caller.getArgs()) : null; return Objects.toStringHelper("").omitNullValues().add("caller", callerString).toString(); } }
@Override public String getCommandName(Invocation invocation) { Invokable<?, ?> invoked = invocation.getInvokable(); if (invoked.isAnnotationPresent(Named.class)) { return invoked.getAnnotation(Named.class).value(); } else { // TODO: remove old logic once Named annotations are on all methods String className = invoked.getOwnerType().getRawType().getSimpleName(); return className + "." + invoked.getName(); } }
private void addHeaderIfAnnotationPresentOnMethod(Multimap<String, String> headers, Invocation invocation, Multimap<String, ?> tokenValues) { if (invocation.getInvokable().getOwnerType().getRawType().isAnnotationPresent(Headers.class)) { Headers header = invocation.getInvokable().getOwnerType().getRawType().getAnnotation(Headers.class); addHeader(headers, header, tokenValues); } if (invocation.getInvokable().isAnnotationPresent(Headers.class)) { Headers header = invocation.getInvokable().getAnnotation(Headers.class); addHeader(headers, header, tokenValues); } }
private Multimap<String, Object> addPathAndGetTokens(Invocation invocation, UriBuilder uriBuilder) { if (invocation.getInvokable().getOwnerType().getRawType().isAnnotationPresent(Path.class)) uriBuilder.appendPath(invocation.getInvokable().getOwnerType().getRawType().getAnnotation(Path.class).value()); if (invocation.getInvokable().isAnnotationPresent(Path.class)) uriBuilder.appendPath(invocation.getInvokable().getAnnotation(Path.class).value()); return getPathParamKeyValues(invocation); }
private boolean checkPresentOrNullable(Invocation invocation, String paramKey, int argIndex, Object arg) { if (arg == null && !invocation.getInvokable().getParameters().get(argIndex).isAnnotationPresent(Nullable.class)) throw new NullPointerException(format("param{%s} for invocation %s.%s", paramKey, invocation.getInvokable() .getOwnerType().getRawType().getSimpleName(), invocation.getInvokable().getName())); return true; }
private void addProducesIfPresentOnTypeOrMethod(Multimap<String, String> headers, Invocation invocation) { if (invocation.getInvokable().getOwnerType().getRawType().isAnnotationPresent(Produces.class)) { Produces header = invocation.getInvokable().getOwnerType().getRawType().getAnnotation(Produces.class); headers.replaceValues(CONTENT_TYPE, asList(header.value())); } if (invocation.getInvokable().isAnnotationPresent(Produces.class)) { Produces header = invocation.getInvokable().getAnnotation(Produces.class); headers.replaceValues(CONTENT_TYPE, asList(header.value())); } }
private void addProducesIfPresentOnTypeOrMethod(Multimap<String, String> headers, Invocation invocation) { if (invocation.getInvokable().getOwnerType().getRawType().isAnnotationPresent(Produces.class)) { Produces header = invocation.getInvokable().getOwnerType().getRawType().getAnnotation(Produces.class); headers.replaceValues(CONTENT_TYPE, asList(header.value())); } if (invocation.getInvokable().isAnnotationPresent(Produces.class)) { Produces header = invocation.getInvokable().getAnnotation(Produces.class); headers.replaceValues(CONTENT_TYPE, asList(header.value())); } }
private void addProducesIfPresentOnTypeOrMethod(Multimap<String, String> headers, Invocation invocation) { if (invocation.getInvokable().getOwnerType().getRawType().isAnnotationPresent(Produces.class)) { Produces header = invocation.getInvokable().getOwnerType().getRawType().getAnnotation(Produces.class); headers.replaceValues(CONTENT_TYPE, asList(header.value())); } if (invocation.getInvokable().isAnnotationPresent(Produces.class)) { Produces header = invocation.getInvokable().getAnnotation(Produces.class); headers.replaceValues(CONTENT_TYPE, asList(header.value())); } }
private void overridePathEncoding(UriBuilder uriBuilder, Invocation invocation) { if (invocation.getInvokable().getOwnerType().getRawType().isAnnotationPresent(SkipEncoding.class)) { uriBuilder.skipPathEncoding(Chars.asList(invocation.getInvokable().getOwnerType().getRawType() .getAnnotation(SkipEncoding.class).value())); } if (invocation.getInvokable().isAnnotationPresent(SkipEncoding.class)) { uriBuilder.skipPathEncoding(Chars.asList(invocation.getInvokable().getAnnotation(SkipEncoding.class).value())); } }
public void testConstructor_getOwnerType() throws NoSuchMethodException { @SuppressWarnings("rawtypes") // raw class ArrayList.class Constructor<ArrayList> constructor = ArrayList.class.getConstructor(); assertEquals(TypeToken.of(ArrayList.class), TypeToken.of(ArrayList.class).constructor(constructor).getOwnerType()); assertEquals(new TypeToken<ArrayList<String>>() {}, new TypeToken<ArrayList<String>>() {}.constructor(constructor).getOwnerType()); }
public void testMethodFromClassAndNoParams() { @SuppressWarnings("rawtypes") Invokable<Set, Object> methodInSuper = method(Set.class, "iterator"); assertEquals(methodInSuper.getOwnerType(), typeToken(Set.class)); }
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 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); }