Java Code Examples for java.lang.invoke.MethodHandles#filterReturnValue()

The following examples show how to use java.lang.invoke.MethodHandles#filterReturnValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CatchExceptionTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private TestCase(Class<T> rtype, Function<Object, T> cast,
        ThrowMode throwMode, Throwable thrown)
        throws NoSuchMethodException, IllegalAccessException {
    this.cast = cast;
    filter = MethodHandles.lookup().findVirtual(
            Function.class,
            "apply",
            MethodType.methodType(Object.class, Object.class))
                          .bindTo(cast);
    this.rtype = rtype;
    this.throwMode = throwMode;
    this.throwableClass = thrown.getClass();
    switch (throwMode) {
        case NOTHING:
            this.thrown = null;
            break;
        case ADAPTER:
        case UNCAUGHT:
            this.thrown = new Error("do not catch this");
            break;
        default:
            this.thrown = thrown;
    }

    MethodHandle throwOrReturn = THROW_OR_RETURN;
    if (throwMode == ThrowMode.ADAPTER) {
        MethodHandle fakeIdentity = FAKE_IDENTITY.bindTo(this);
        for (int i = 0; i < 10; ++i) {
            throwOrReturn = MethodHandles.filterReturnValue(
                    throwOrReturn, fakeIdentity);
        }
    }
    thrower = throwOrReturn.asType(MethodType.genericMethodType(2));
}
 
Example 2
Source File: CatchExceptionTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private TestCase(Class<T> rtype, Function<Object, T> cast,
        ThrowMode throwMode, Throwable thrown)
        throws NoSuchMethodException, IllegalAccessException {
    this.cast = cast;
    filter = MethodHandles.lookup().findVirtual(
            Function.class,
            "apply",
            MethodType.methodType(Object.class, Object.class))
                          .bindTo(cast);
    this.rtype = rtype;
    this.throwMode = throwMode;
    this.throwableClass = thrown.getClass();
    switch (throwMode) {
        case NOTHING:
            this.thrown = null;
            break;
        case ADAPTER:
        case UNCAUGHT:
            this.thrown = new Error("do not catch this");
            break;
        default:
            this.thrown = thrown;
    }

    MethodHandle throwOrReturn = THROW_OR_RETURN;
    if (throwMode == ThrowMode.ADAPTER) {
        MethodHandle fakeIdentity = FAKE_IDENTITY.bindTo(this);
        for (int i = 0; i < 10; ++i) {
            throwOrReturn = MethodHandles.filterReturnValue(
                    throwOrReturn, fakeIdentity);
        }
    }
    thrower = throwOrReturn.asType(MethodType.genericMethodType(2));
}
 
Example 3
Source File: CatchExceptionTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private TestCase(Class<T> rtype, Function<Object, T> cast,
        ThrowMode throwMode, Throwable thrown)
        throws NoSuchMethodException, IllegalAccessException {
    this.cast = cast;
    filter = MethodHandles.lookup().findVirtual(
            Function.class,
            "apply",
            MethodType.methodType(Object.class, Object.class))
                          .bindTo(cast);
    this.rtype = rtype;
    this.throwMode = throwMode;
    this.throwableClass = thrown.getClass();
    switch (throwMode) {
        case NOTHING:
            this.thrown = null;
            break;
        case ADAPTER:
        case UNCAUGHT:
            this.thrown = new Error("do not catch this");
            break;
        default:
            this.thrown = thrown;
    }

    MethodHandle throwOrReturn = THROW_OR_RETURN;
    if (throwMode == ThrowMode.ADAPTER) {
        MethodHandle fakeIdentity = FAKE_IDENTITY.bindTo(this);
        for (int i = 0; i < 10; ++i) {
            throwOrReturn = MethodHandles.filterReturnValue(
                    throwOrReturn, fakeIdentity);
        }
    }
    thrower = throwOrReturn.asType(MethodType.genericMethodType(2));
}
 
Example 4
Source File: CatchExceptionTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private TestCase(Class<T> rtype, Function<Object, T> cast,
        ThrowMode throwMode, Throwable thrown)
        throws NoSuchMethodException, IllegalAccessException {
    this.cast = cast;
    filter = MethodHandles.lookup().findVirtual(
            Function.class,
            "apply",
            MethodType.methodType(Object.class, Object.class))
                          .bindTo(cast);
    this.rtype = rtype;
    this.throwMode = throwMode;
    this.throwableClass = thrown.getClass();
    switch (throwMode) {
        case NOTHING:
            this.thrown = null;
            break;
        case ADAPTER:
        case UNCAUGHT:
            this.thrown = new Error("do not catch this");
            break;
        default:
            this.thrown = thrown;
    }

    MethodHandle throwOrReturn = THROW_OR_RETURN;
    if (throwMode == ThrowMode.ADAPTER) {
        MethodHandle fakeIdentity = FAKE_IDENTITY.bindTo(this);
        for (int i = 0; i < 10; ++i) {
            throwOrReturn = MethodHandles.filterReturnValue(
                    throwOrReturn, fakeIdentity);
        }
    }
    thrower = throwOrReturn.asType(MethodType.genericMethodType(2));
}
 
Example 5
Source File: CatchExceptionTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private TestCase(Class<T> rtype, Function<Object, T> cast,
        ThrowMode throwMode, Throwable thrown)
        throws NoSuchMethodException, IllegalAccessException {
    this.cast = cast;
    filter = MethodHandles.lookup().findVirtual(
            Function.class,
            "apply",
            MethodType.methodType(Object.class, Object.class))
                          .bindTo(cast);
    this.rtype = rtype;
    this.throwMode = throwMode;
    this.throwableClass = thrown.getClass();
    switch (throwMode) {
        case NOTHING:
            this.thrown = null;
            break;
        case ADAPTER:
        case UNCAUGHT:
            this.thrown = new Error("do not catch this");
            break;
        default:
            this.thrown = thrown;
    }

    MethodHandle throwOrReturn = THROW_OR_RETURN;
    if (throwMode == ThrowMode.ADAPTER) {
        MethodHandle fakeIdentity = FAKE_IDENTITY.bindTo(this);
        for (int i = 0; i < 10; ++i) {
            throwOrReturn = MethodHandles.filterReturnValue(
                    throwOrReturn, fakeIdentity);
        }
    }
    thrower = throwOrReturn.asType(MethodType.genericMethodType(2));
}
 
Example 6
Source File: CatchExceptionTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private TestCase(Class<T> rtype, Function<Object, T> cast,
        ThrowMode throwMode, Throwable thrown)
        throws NoSuchMethodException, IllegalAccessException {
    this.cast = cast;
    filter = MethodHandles.lookup().findVirtual(
            Function.class,
            "apply",
            MethodType.methodType(Object.class, Object.class))
                          .bindTo(cast);
    this.rtype = rtype;
    this.throwMode = throwMode;
    this.throwableClass = thrown.getClass();
    switch (throwMode) {
        case NOTHING:
            this.thrown = null;
            break;
        case ADAPTER:
        case UNCAUGHT:
            this.thrown = new Error("do not catch this");
            break;
        default:
            this.thrown = thrown;
    }

    MethodHandle throwOrReturn = THROW_OR_RETURN;
    if (throwMode == ThrowMode.ADAPTER) {
        MethodHandle fakeIdentity = FAKE_IDENTITY.bindTo(this);
        for (int i = 0; i < 10; ++i) {
            throwOrReturn = MethodHandles.filterReturnValue(
                    throwOrReturn, fakeIdentity);
        }
    }
    thrower = throwOrReturn.asType(MethodType.genericMethodType(2));
}
 
Example 7
Source File: CatchExceptionTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public MethodHandle getCatcher(List<Class<?>> classes) {
    return MethodHandles.filterReturnValue(Helper.AS_LIST.asType(
            MethodType.methodType(Object.class, classes)),
            CATCHER
    );
}
 
Example 8
Source File: MethodHandleFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MethodHandle filterReturnValue(final MethodHandle target, final MethodHandle filter) {
    final MethodHandle mh = MethodHandles.filterReturnValue(target, filter);
    return debug(mh, "filterReturnValue", target, filter);
}
 
Example 9
Source File: MethodHandleFactory.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MethodHandle filterReturnValue(final MethodHandle target, final MethodHandle filter) {
    final MethodHandle mh = MethodHandles.filterReturnValue(target, filter);
    return debug(mh, "filterReturnValue", target, filter);
}
 
Example 10
Source File: CatchExceptionTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public MethodHandle getCatcher(List<Class<?>> classes) {
    return MethodHandles.filterReturnValue(Helper.AS_LIST.asType(
            MethodType.methodType(Object.class, classes)),
            CATCHER
    );
}
 
Example 11
Source File: CatchExceptionTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public MethodHandle filter(MethodHandle target) {
    return MethodHandles.filterReturnValue(target, filter);
}
 
Example 12
Source File: MethodHandleFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MethodHandle filterReturnValue(final MethodHandle target, final MethodHandle filter) {
    final MethodHandle mh = MethodHandles.filterReturnValue(target, filter);
    return debug(mh, "filterReturnValue", target, filter);
}
 
Example 13
Source File: CatchExceptionTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public MethodHandle getCatcher(List<Class<?>> classes) {
    return MethodHandles.filterReturnValue(Helper.AS_LIST.asType(
            MethodType.methodType(Object.class, classes)),
            CATCHER
    );
}
 
Example 14
Source File: CatchExceptionTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public MethodHandle filter(MethodHandle target) {
    return MethodHandles.filterReturnValue(target, filter);
}
 
Example 15
Source File: CatchExceptionTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public MethodHandle getCatcher(List<Class<?>> classes) {
    return MethodHandles.filterReturnValue(Helper.AS_LIST.asType(
            MethodType.methodType(Object.class, classes)),
            CATCHER
    );
}
 
Example 16
Source File: ValueConversions.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private static MethodHandle buildVarargsList(int nargs) {
    return MethodHandles.filterReturnValue(varargsArray(nargs), LazyStatics.MAKE_LIST);
}
 
Example 17
Source File: CatchExceptionTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public MethodHandle filter(MethodHandle target) {
    return MethodHandles.filterReturnValue(target, filter);
}
 
Example 18
Source File: MethodHandleFactory.java    From nashorn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public MethodHandle filterReturnValue(final MethodHandle target, final MethodHandle filter) {
    return MethodHandles.filterReturnValue(target, filter);
}
 
Example 19
Source File: CatchExceptionTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public MethodHandle getCatcher(List<Class<?>> classes) {
    return MethodHandles.filterReturnValue(Helper.AS_LIST.asType(
            MethodType.methodType(Object.class, classes)),
            CATCHER
    );
}
 
Example 20
Source File: CatchExceptionTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public MethodHandle filter(MethodHandle target) {
    return MethodHandles.filterReturnValue(target, filter);
}