All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.easy.query.api4j.util.EasyLambdaUtil Maven / Gradle / Ivy

There is a newer version: 2.3.3
Show newest version
package com.easy.query.api4j.util;

import com.easy.query.core.expression.lambda.Property;
import com.easy.query.core.util.EasyStringUtil;

import java.lang.invoke.SerializedLambda;
import java.lang.reflect.Method;

/**
 *
 * @FileName: LambdaUtil.java
 * @Description: 文件说明
 * @Date: 2023/2/7 08:36
 * @author xuejiaming
 */
public class EasyLambdaUtil {

    private EasyLambdaUtil(){}
    public static  String getPropertyName(Property property) {
        if (property == null) {
            return null;
        }
        try {
            Method declaredMethod = property.getClass().getDeclaredMethod("writeReplace");
            declaredMethod.setAccessible(Boolean.TRUE);
            SerializedLambda serializedLambda = (SerializedLambda) declaredMethod.invoke(property);
            String method = serializedLambda.getImplMethodName();


            String attr = null;
            if (method.startsWith("get")) {
                attr = method.substring(3);
            } else {
                attr = method.substring(2);
            }
            return EasyStringUtil.toLowerCaseFirstOne(attr);
        } catch (ReflectiveOperationException e) {
            throw new RuntimeException(e);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy