java.lang.invoke.SerializedLambda#getImplMethodName ( )源码实例Demo

下面列出了java.lang.invoke.SerializedLambda#getImplMethodName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: weed3   文件: PropertyWrap.java
/** 将 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);
    }
}
 
源代码2 项目: weed3   文件: PropertyTest.java
private static  <C> String getName(Property<C, ?> property) {
    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 attr;
    } catch (ReflectiveOperationException e) {
        throw new RuntimeException(e);
    }
}
 
源代码3 项目: blade   文件: BladeCache.java
public static String getLambdaFieldName(SerializedLambda serializedLambda) {
    String name = CACHE_LAMBDA_NAME.get(serializedLambda);
    if (null != name) {
        return name;
    }
    String className  = serializedLambda.getImplClass().replace("/", ".");
    String methodName = serializedLambda.getImplMethodName();
    String fieldName  = methodToFieldName(methodName);
    try {
        Field field = Class.forName(className).getDeclaredField(fieldName);
        name = field.getName();
        CACHE_LAMBDA_NAME.put(serializedLambda, name);
        return name;
    } catch (NoSuchFieldException | ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}
 
源代码4 项目: Mapper   文件: Reflections.java
public static String fnToFieldName(Fn fn) {
    try {
        Method method = fn.getClass().getDeclaredMethod("writeReplace");
        method.setAccessible(Boolean.TRUE);
        SerializedLambda serializedLambda = (SerializedLambda) method.invoke(fn);
        String getter = serializedLambda.getImplMethodName();
        if (GET_PATTERN.matcher(getter).matches()) {
            getter = getter.substring(3);
        } else if (IS_PATTERN.matcher(getter).matches()) {
            getter = getter.substring(2);
        }
        return Introspector.decapitalize(getter);
    } catch (ReflectiveOperationException e) {
        throw new ReflectionOperationException(e);
    }
}
 
源代码5 项目: summerframework   文件: ExpressionUtil.java
public static String expressionToMethodName(Expression expression) {
    if (expression == null)
        return "";
    try {
        Method method = expression.getClass().getDeclaredMethod("writeReplace");
        method.setAccessible(Boolean.TRUE);
        SerializedLambda serializedLambda = (SerializedLambda)method.invoke(expression);
        return serializedLambda.getImplMethodName();
    } catch (ReflectiveOperationException e) {
        return "";
    }
}
 
源代码6 项目: GyJdbc   文件: TypeFunction.java
/**
 * 获取列名称
 * @param lambda lamda表达式
 * @return String 列名称
 */
static String getLambdaColumnName(Serializable lambda) {
    try {
        Method method = lambda.getClass().getDeclaredMethod("writeReplace");
        method.setAccessible(Boolean.TRUE);
        SerializedLambda serializedLambda = (SerializedLambda) method.invoke(lambda);
        String getter = serializedLambda.getImplMethodName();
        String fieldName = Introspector.decapitalize(getter.replace("get", ""));
        return EntityTools.transferColumnName(fieldName);
    } catch (ReflectiveOperationException e) {
        throw new IllegalArgumentException(e);
    }
}
 
源代码7 项目: mybatis-dynamic-query   文件: CommonsHelper.java
@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);
    }
}
 
源代码8 项目: core-ng-project   文件: ControllerInspector.java
public ControllerInspector(Controller controller) {
    Class<?> controllerClass = controller.getClass();

    try {
        if (controller instanceof LambdaController) {
            Method writeReplace = controllerClass.getDeclaredMethod("writeReplace");
            if (!writeReplace.trySetAccessible()) {
                throw new Error("failed to inspect controller, cannot access writeReplace");
            }
            SerializedLambda lambda = (SerializedLambda) writeReplace.invoke(controller);
            Class<?> targetClass = Class.forName(lambda.getImplClass().replace('/', '.'));
            String targetMethodName = lambda.getImplMethodName();
            controllerInfo = targetClass.getCanonicalName() + "." + targetMethodName;
            if (targetMethodName.contains("$")) {   // for lambda
                this.targetClass = controllerClass;
                targetMethod = controllerClass.getMethod("execute", Request.class);
            } else {    // for method reference
                this.targetClass = targetClass;
                targetMethod = targetClass.getDeclaredMethod(targetMethodName, Request.class);
            }
        } else {
            targetClass = controllerClass;
            targetMethod = controllerClass.getMethod("execute", Request.class);
            controllerInfo = controllerClass.getCanonicalName() + ".execute";
        }
    } catch (ReflectiveOperationException e) {
        throw new Error("failed to inspect controller", e);
    }
}
 
源代码9 项目: java-8-matchers   文件: DescribablePredicate.java
default String getResultDescription() {
    SerializedLambda lambda = asSerializedLambda();
    if (! lambda.getImplMethodName().startsWith("lambda$")) {
        return lambda.getImplMethodName();
    }
    return "boolean";
}
 
源代码10 项目: java-8-matchers   文件: DescribableFunction.java
default String getResultDescription() {
    SerializedLambda lambda = asSerializedLambda();
    MethodType lambdaMethodType = MethodType.fromMethodDescriptorString(lambda.getImplMethodSignature(), getClass().getClassLoader());
    String resultType = lambdaMethodType.returnType().getSimpleName();
    if (! lambda.getImplMethodName().startsWith("lambda$")) {
        return lambda.getImplMethodName() + " (" + withPrefixedArticle(resultType) + ")";
    }
    return resultType;
}