Example usage for com.google.common.reflect Invokable getReturnType

List of usage examples for com.google.common.reflect Invokable getReturnType

Introduction

In this page you can find the example usage for com.google.common.reflect Invokable getReturnType.

Prototype


@SuppressWarnings("unchecked")
public final TypeToken<? extends R> getReturnType() 

Source Link

Document

Returns the return type of this Invokable .

Usage

From source file:org.jclouds.util.Optionals2.java

public static boolean isReturnTypeOptional(Invokable<?, ?> method) {
    return method.getReturnType().getRawType().isAssignableFrom(Optional.class);
}

From source file:org.jclouds.rest.internal.TransformerForRequest.java

@SuppressWarnings({ "unchecked" })
private static Key<? extends Function<HttpResponse, ?>> getJsonParserKeyForMethod(Invokable<?, ?> invoked) {
    ParameterizedType parserType;
    if (invoked.isAnnotationPresent(Unwrap.class)) {
        parserType = newParameterizedType(UnwrapOnlyJsonValue.class, getReturnTypeFor(invoked.getReturnType()));
    } else {// www .j a v  a2  s.  co  m
        parserType = newParameterizedType(ParseJson.class, getReturnTypeFor(invoked.getReturnType()));
    }
    return (Key<? extends Function<HttpResponse, ?>>) Key.get(parserType);
}

From source file:org.immutables.eventual.Providers.java

/** Checks if we need special logic for void side-effect only methods. */
private static boolean isVoid(Invokable<?, ?> method) {
    Class<?> raw = method.getReturnType().getRawType();
    return raw == void.class || raw == Void.class;
}

From source file:org.jclouds.rest.internal.TransformerForRequest.java

@SuppressWarnings("unchecked")
private static Key<? extends Function<HttpResponse, ?>> getJAXBParserKeyForMethod(Invokable<?, ?> invoked) {
    Optional<Type> configuredReturnVal = Optional.absent();
    if (invoked.isAnnotationPresent(JAXBResponseParser.class)) {
        Type configuredClass = invoked.getAnnotation(JAXBResponseParser.class).value();
        configuredReturnVal = configuredClass.equals(NullType.class) ? Optional.<Type>absent()
                : Optional.<Type>of(configuredClass);
    }/*from   www  . j  av a 2s.  c  o m*/
    Type returnVal = configuredReturnVal.or(getReturnTypeFor(invoked.getReturnType()));
    Type parserType = newParameterizedType(ParseXMLWithJAXB.class, returnVal);
    return (Key<? extends Function<HttpResponse, ?>>) Key.get(parserType);
}

From source file:org.jclouds.rest.internal.InvokeAndCallGetOnFutures.java

private boolean isFuture(Invokable<?, ?> target) {
    return target.getReturnType().getRawType().isAssignableFrom(ListenableFuture.class);
}

From source file:net.navatwo.jfxproperties.SetPropertyInfo.java

public ReadOnlySetProperty<V> getReadOnlyProperty(Object instance) {
    checkGetValue(instance);/*w  w  w.j a  va 2 s . c o m*/

    checkState(getAccessorRef().isPresent(),
            "Can not get read-only property if no accessor method is present.");

    Invokable<Object, ? extends ReadOnlyProperty<? extends Set<V>>> accessor = getAccessorRef().get();

    TypeToken<? extends ReadOnlyProperty<? extends Set<V>>> retType = accessor.getReturnType();
    checkState(retType.isSubtypeOf(new TypeToken<ReadOnlySetProperty<V>>(getPropertyClass()) {
    }), "Property %s is not readable property, it is %s", getName(), retType);

    try {
        return (ReadOnlySetProperty<V>) accessor.invoke(instance);
    } catch (IllegalAccessException | InvocationTargetException e) {
        throw new IllegalStateException("Invalid method state", e);
    }
}

From source file:net.navatwo.jfxproperties.ListPropertyInfo.java

public ReadOnlyListProperty<E> getReadOnlyProperty(Object instance) {
    checkGetValue(instance);/*w w  w.j av  a2 s.c om*/

    checkState(getAccessorRef().isPresent(),
            "Can not get read-only property if no accessor method is present.");

    Invokable<Object, ? extends ReadOnlyProperty<? extends List<E>>> accessor = getAccessorRef().get();

    TypeToken<? extends ReadOnlyProperty<? extends List<E>>> retType = accessor.getReturnType();
    checkState(retType.isSubtypeOf(ReadOnlyListProperty.class),
            "Property %s is not readable property, it is %s", getName(), retType);
    try {
        return (ReadOnlyListProperty<E>) accessor.invoke(instance);
    } catch (IllegalAccessException | InvocationTargetException e) {
        throw new IllegalStateException("Invalid method state", e);
    }
}

From source file:org.jclouds.rest.internal.InvokeSyncToAsyncHttpMethod.java

private boolean isFuture(Invokable<?, ?> in) {
    return in.getReturnType().getRawType().equals(ListenableFuture.class);
}

From source file:net.navatwo.jfxproperties.SetPropertyInfo.java

public SetProperty<V> getProperty(Object instance) {
    checkGetValue(instance);//from w  w  w. ja v  a2  s. c om

    checkState(getAccessorRef().isPresent(), "Can not get property if no accessor method is present.");
    Invokable<Object, ? extends Property<? extends Set<V>>> accessor = (Invokable<Object, ? extends Property<? extends Set<V>>>) getAccessorRef()
            .get();

    TypeToken<? extends Property<? extends Set<V>>> retType = accessor.getReturnType();
    checkState(retType.isSubtypeOf(new TypeToken<SetProperty<V>>(getPropertyClass()) {
    }), "Property %s is not writeable property, it is %s", getName(), retType);

    // write available
    try {
        return (SetProperty<V>) accessor.invoke(instance);
    } catch (IllegalAccessException | InvocationTargetException e) {
        throw new IllegalStateException("Invalid method state", e);
    }
}

From source file:net.navatwo.jfxproperties.ObjectPropertyInfo.java

private Function<Object, Optional<V>> getterFromMethod(Invokable<Object, ? extends V> getter) {
    checkState(getter != null, "Can not get getter without Getter Function");

    TypeToken<?> returnType = getter.getReturnType();

    if (MoreReflection.isOptional(returnType)) {
        return o -> {
            try {
                @SuppressWarnings("unchecked")
                Optional<V> out = (Optional<V>) getter.invoke(o);
                return out;
            } catch (InvocationTargetException | IllegalAccessException t) {
                throw new IllegalStateException(t);
            }//w  w w.  j av  a  2 s  .c om
        };
    } else {
        // got a non-optional, do it a bit differently
        // We get the value and place it into the Optional instead
        return o -> {
            try {
                return Optional.ofNullable(getter.invoke(o));
            } catch (InvocationTargetException | IllegalAccessException t) {
                throw new IllegalStateException(t);
            }
        };
    }
}