Java Code Examples for java.lang.invoke.SerializedLambda#getImplClass()

The following examples show how to use java.lang.invoke.SerializedLambda#getImplClass() . 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: PropertyWrap.java    From weed3 with Apache License 2.0 6 votes vote down vote up
/** 将 Property 转为 PropertyWrap  */
private static <C> PropertyWrap wrap(Property<C, ?> p) {
    try {
        Method fun = p.getClass().getDeclaredMethod("writeReplace");
        fun.setAccessible(Boolean.TRUE);
        SerializedLambda slambda = (SerializedLambda) fun.invoke(p);
        String method = slambda.getImplMethodName();
        String attr = null;
        if (method.startsWith("get")) {
            attr = method.substring(3);
        } else {
            attr = method.substring(2);//is
        }
        return new PropertyWrap(p, slambda.getImplClass(), attr);
    } catch (ReflectiveOperationException e) {
        throw new RuntimeException(e);
    }
}
 
Example 2
Source File: CommonsHelper.java    From mybatis-dynamic-query with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("squid:S00112")
public static <T, R extends Comparable> PropertyInfo getPropertyInfo(GetPropertyFunction<T, R> fn) {
    try {
        Method method = fn.getClass().getDeclaredMethod("writeReplace");
        method.setAccessible(true);
        SerializedLambda serializedLambda = (SerializedLambda) method.invoke(fn);
        String methodName = serializedLambda.getImplMethodName();
        String className = serializedLambda.getImplClass();
        String propertyName;
        String getString = "get";
        String isString = "is";
        if (methodName.startsWith(getString)) {
            propertyName = java.beans.Introspector.decapitalize(methodName.substring(3));
        } else if (methodName.startsWith(isString)) {
            propertyName = java.beans.Introspector.decapitalize(methodName.substring(2));
        } else {
            propertyName = methodName;
        }

        Class ownerClass;
        if (classMap.containsKey(className)) {
            ownerClass = classMap.get(className);
        } else {
            ownerClass = Class.forName(className.replace('/', '.'));
            classMap.put(className, ownerClass);
        }

        PropertyInfo propertyInfo = new PropertyInfo();
        propertyInfo.setPropertyName(propertyName);
        propertyInfo.setOwnerClass(ownerClass);
        return propertyInfo;
    } catch (ReflectiveOperationException e) {
        throw new InternalRuntimeException(e);
    }
}