类java.lang.invoke.SerializedLambda源码实例Demo

下面列出了怎么用java.lang.invoke.SerializedLambda的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: dragonwell8_jdk   文件: SerialFilterTest.java
@Override
public ObjectInputFilter.Status checkInput(FilterInfo filter) {
    Class<?> serialClass = filter.serialClass();
    System.out.printf("     checkInput: class: %s, arrayLen: %d, refs: %d, depth: %d, bytes; %d%n",
            serialClass, filter.arrayLength(), filter.references(),
            filter.depth(), filter.streamBytes());
    count++;
    if (serialClass != null) {
        if (serialClass.getName().contains("$$Lambda$")) {
            // TBD: proper identification of serialized Lambdas?
            // Fold the serialized Lambda into the SerializedLambda type
            classes.add(SerializedLambda.class);
        } else if (Proxy.isProxyClass(serialClass)) {
            classes.add(Proxy.class);
        } else {
            classes.add(serialClass);
        }

    }
    this.maxArray = Math.max(this.maxArray, filter.arrayLength());
    this.maxRefs = Math.max(this.maxRefs, filter.references());
    this.maxDepth = Math.max(this.maxDepth, filter.depth());
    this.maxBytes = Math.max(this.maxBytes, filter.streamBytes());
    return ObjectInputFilter.Status.UNDECIDED;
}
 
源代码2 项目: TencentKona-8   文件: SerialFilterTest.java
@Override
public ObjectInputFilter.Status checkInput(FilterInfo filter) {
    Class<?> serialClass = filter.serialClass();
    System.out.printf("     checkInput: class: %s, arrayLen: %d, refs: %d, depth: %d, bytes; %d%n",
            serialClass, filter.arrayLength(), filter.references(),
            filter.depth(), filter.streamBytes());
    count++;
    if (serialClass != null) {
        if (serialClass.getName().contains("$$Lambda$")) {
            // TBD: proper identification of serialized Lambdas?
            // Fold the serialized Lambda into the SerializedLambda type
            classes.add(SerializedLambda.class);
        } else if (Proxy.isProxyClass(serialClass)) {
            classes.add(Proxy.class);
        } else {
            classes.add(serialClass);
        }

    }
    this.maxArray = Math.max(this.maxArray, filter.arrayLength());
    this.maxRefs = Math.max(this.maxRefs, filter.references());
    this.maxDepth = Math.max(this.maxDepth, filter.depth());
    this.maxBytes = Math.max(this.maxBytes, filter.streamBytes());
    return ObjectInputFilter.Status.UNDECIDED;
}
 
源代码3 项目: summerframework   文件: MyBatisUtil.java
public static <T> String getFieldName(EntityGetterMethod<T, Object> expression) {
    if (expression == null)
        throw new IllegalArgumentException("Expression should not be null");
    try {
        Method method = expression.getClass().getDeclaredMethod("writeReplace");
        method.setAccessible(Boolean.TRUE);
        SerializedLambda serializedLambda = (SerializedLambda)method.invoke(expression);
        String fieldName = StringUtils.resolveFieldName(serializedLambda.getImplMethodName());
        String className = serializedLambda.getImplClass().replace("/", ".");
        Field field = ReflectionUtils.findField(Class.forName(className), fieldName);
        String columnName = field.getName();
        TableField[] tableField = field.getAnnotationsByType(TableField.class);
        if (null != tableField && tableField.length == 1) {
            if (!StringUtils.isEmpty(tableField[0].value())) {
                columnName = tableField[0].value();
            }
        }
        String ret = StringUtils.camelToUnderline(columnName);
        return ret;
    } catch (ReflectiveOperationException e) {
        throw new RuntimeException("This will never happen!", e);
    }
}
 
源代码4 项目: openjdk-jdk8u   文件: SerialFilterTest.java
@Override
public ObjectInputFilter.Status checkInput(FilterInfo filter) {
    Class<?> serialClass = filter.serialClass();
    System.out.printf("     checkInput: class: %s, arrayLen: %d, refs: %d, depth: %d, bytes; %d%n",
            serialClass, filter.arrayLength(), filter.references(),
            filter.depth(), filter.streamBytes());
    count++;
    if (serialClass != null) {
        if (serialClass.getName().contains("$$Lambda$")) {
            // TBD: proper identification of serialized Lambdas?
            // Fold the serialized Lambda into the SerializedLambda type
            classes.add(SerializedLambda.class);
        } else if (Proxy.isProxyClass(serialClass)) {
            classes.add(Proxy.class);
        } else {
            classes.add(serialClass);
        }

    }
    this.maxArray = Math.max(this.maxArray, filter.arrayLength());
    this.maxRefs = Math.max(this.maxRefs, filter.references());
    this.maxDepth = Math.max(this.maxDepth, filter.depth());
    this.maxBytes = Math.max(this.maxBytes, filter.streamBytes());
    return ObjectInputFilter.Status.UNDECIDED;
}
 
源代码5 项目: openjdk-jdk8u-backup   文件: SerialFilterTest.java
@Override
public ObjectInputFilter.Status checkInput(FilterInfo filter) {
    Class<?> serialClass = filter.serialClass();
    System.out.printf("     checkInput: class: %s, arrayLen: %d, refs: %d, depth: %d, bytes; %d%n",
            serialClass, filter.arrayLength(), filter.references(),
            filter.depth(), filter.streamBytes());
    count++;
    if (serialClass != null) {
        if (serialClass.getName().contains("$$Lambda$")) {
            // TBD: proper identification of serialized Lambdas?
            // Fold the serialized Lambda into the SerializedLambda type
            classes.add(SerializedLambda.class);
        } else if (Proxy.isProxyClass(serialClass)) {
            classes.add(Proxy.class);
        } else {
            classes.add(serialClass);
        }

    }
    this.maxArray = Math.max(this.maxArray, filter.arrayLength());
    this.maxRefs = Math.max(this.maxRefs, filter.references());
    this.maxDepth = Math.max(this.maxDepth, filter.depth());
    this.maxBytes = Math.max(this.maxBytes, filter.streamBytes());
    return ObjectInputFilter.Status.UNDECIDED;
}
 
源代码6 项目: openjdk-jdk9   文件: SerialFilterTest.java
@Override
public ObjectInputFilter.Status checkInput(FilterInfo filter) {
    Class<?> serialClass = filter.serialClass();
    System.out.printf("     checkInput: class: %s, arrayLen: %d, refs: %d, depth: %d, bytes; %d%n",
            serialClass, filter.arrayLength(), filter.references(),
            filter.depth(), filter.streamBytes());
    count++;
    if (serialClass != null) {
        if (serialClass.getName().contains("$$Lambda$")) {
            // TBD: proper identification of serialized Lambdas?
            // Fold the serialized Lambda into the SerializedLambda type
            classes.add(SerializedLambda.class);
        } else if (Proxy.isProxyClass(serialClass)) {
            classes.add(Proxy.class);
        } else {
            classes.add(serialClass);
        }

    }
    this.maxArray = Math.max(this.maxArray, filter.arrayLength());
    this.maxRefs = Math.max(this.maxRefs, filter.references());
    this.maxDepth = Math.max(this.maxDepth, filter.depth());
    this.maxBytes = Math.max(this.maxBytes, filter.streamBytes());
    return ObjectInputFilter.Status.UNDECIDED;
}
 
源代码7 项目: jdk8u-jdk   文件: SerialFilterTest.java
@Override
public ObjectInputFilter.Status checkInput(FilterInfo filter) {
    count++;
    if (filter.serialClass() != null) {
        if (filter.serialClass().getName().contains("$$Lambda$")) {
            // TBD: proper identification of serialized Lambdas?
            // Fold the serialized Lambda into the SerializedLambda type
            classes.add(SerializedLambda.class);
        } else if (Proxy.isProxyClass(filter.serialClass())) {
            classes.add(Proxy.class);
        } else {
            classes.add(filter.serialClass());
        }

    }
    this.maxArray = Math.max(this.maxArray, filter.arrayLength());
    this.maxRefs = Math.max(this.maxRefs, filter.references());
    this.maxDepth = Math.max(this.maxDepth, filter.depth());
    this.maxBytes = Math.max(this.maxBytes, filter.streamBytes());
    return ObjectInputFilter.Status.UNDECIDED;
}
 
源代码8 项目: jdk8u_jdk   文件: SerialFilterTest.java
@Override
public ObjectInputFilter.Status checkInput(FilterInfo filter) {
    Class<?> serialClass = filter.serialClass();
    System.out.printf("     checkInput: class: %s, arrayLen: %d, refs: %d, depth: %d, bytes; %d%n",
            serialClass, filter.arrayLength(), filter.references(),
            filter.depth(), filter.streamBytes());
    count++;
    if (serialClass != null) {
        if (serialClass.getName().contains("$$Lambda$")) {
            // TBD: proper identification of serialized Lambdas?
            // Fold the serialized Lambda into the SerializedLambda type
            classes.add(SerializedLambda.class);
        } else if (Proxy.isProxyClass(serialClass)) {
            classes.add(Proxy.class);
        } else {
            classes.add(serialClass);
        }

    }
    this.maxArray = Math.max(this.maxArray, filter.arrayLength());
    this.maxRefs = Math.max(this.maxRefs, filter.references());
    this.maxDepth = Math.max(this.maxDepth, filter.depth());
    this.maxBytes = Math.max(this.maxBytes, filter.streamBytes());
    return ObjectInputFilter.Status.UNDECIDED;
}
 
private static String[] getSerializedLambdaParameterizedTypeNames(Object source) {
	Method method = ReflectionUtils.findMethod(source.getClass(), "writeReplace");
	if (method == null) {
		return null;
	}
	ReflectionUtils.makeAccessible(method);
	SerializedLambda serializedLambda = (SerializedLambda) ReflectionUtils
			.invokeMethod(method, source);
	String signature = serializedLambda.getImplMethodSignature().replaceAll("[()]",
			"");

	List<String> typeNames = Stream.of(signature.split(";"))
			.map(t -> t.substring(1).replace('/', '.')).collect(Collectors.toList());

	return typeNames.toArray(new String[typeNames.size()]);
}
 
源代码10 项目: 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);
    }
}
 
源代码11 项目: 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);
    }
}
 
源代码12 项目: 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);
    }
}
 
源代码13 项目: 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);
    }
}
 
源代码14 项目: dragonwell8_jdk   文件: DeserializeMethodTest.java
private void assertDeserializeMethod(Class<?> clazz, boolean expectedPresent) {
    try {
        Method m = clazz.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
        if (!expectedPresent)
            fail("Unexpected $deserializeLambda$ in " + clazz);
    }
    catch (NoSuchMethodException e) {
        if (expectedPresent)
            fail("Expected to find $deserializeLambda$ in " + clazz);
    }
}
 
源代码15 项目: TencentKona-8   文件: DeserializeMethodTest.java
private void assertDeserializeMethod(Class<?> clazz, boolean expectedPresent) {
    try {
        Method m = clazz.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
        if (!expectedPresent)
            fail("Unexpected $deserializeLambda$ in " + clazz);
    }
    catch (NoSuchMethodException e) {
        if (expectedPresent)
            fail("Expected to find $deserializeLambda$ in " + clazz);
    }
}
 
源代码16 项目: 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 "";
    }
}
 
源代码17 项目: jdk8u60   文件: DeserializeMethodTest.java
private void assertDeserializeMethod(Class<?> clazz, boolean expectedPresent) {
    try {
        Method m = clazz.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
        if (!expectedPresent)
            fail("Unexpected $deserializeLambda$ in " + clazz);
    }
    catch (NoSuchMethodException e) {
        if (expectedPresent)
            fail("Expected to find $deserializeLambda$ in " + clazz);
    }
}
 
源代码18 项目: 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);
    }
}
 
源代码19 项目: openjdk-jdk8u   文件: DeserializeMethodTest.java
private void assertDeserializeMethod(Class<?> clazz, boolean expectedPresent) {
    try {
        Method m = clazz.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
        if (!expectedPresent)
            fail("Unexpected $deserializeLambda$ in " + clazz);
    }
    catch (NoSuchMethodException e) {
        if (expectedPresent)
            fail("Expected to find $deserializeLambda$ in " + clazz);
    }
}
 
源代码20 项目: redpipe   文件: MethodFinder.java
default SerializedLambda serialized() {
    try {
        Method replaceMethod = getClass().getDeclaredMethod("writeReplace");
        replaceMethod.setAccessible(true);
        return (SerializedLambda) replaceMethod.invoke(this);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
源代码21 项目: redpipe   文件: MethodFinder.java
default Method method() {
    SerializedLambda lambda = serialized();
    Class<?> containingClass = getContainingClass();
    return Arrays.asList(containingClass.getDeclaredMethods())
            .stream()
            .filter(method -> Objects.equals(method.getName(), lambda.getImplMethodName()))
            .findFirst()
            .orElseThrow(UnableToGuessMethodException::new);
}
 
源代码22 项目: vertx-sql-client   文件: ColumnChecker.java
default SerializedLambda serialized() {
  try {
    Method replaceMethod = getClass().getDeclaredMethod("writeReplace");
    replaceMethod.setAccessible(true);
    return (SerializedLambda) replaceMethod.invoke(this);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
源代码23 项目: vertx-sql-client   文件: ColumnChecker.java
default Method method() {
  SerializedLambda lambda = serialized();
  Class containingClass = getContainingClass();
  return Arrays.stream(containingClass.getDeclaredMethods())
    .filter(method -> Objects.equals(method.getName(), lambda.getImplMethodName()))
    .findFirst()
    .orElseThrow(MethodReferenceReflection.UnableToGuessMethodException::new);
}
 
private void assertDeserializeMethod(Class<?> clazz, boolean expectedPresent) {
    try {
        Method m = clazz.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
        if (!expectedPresent)
            fail("Unexpected $deserializeLambda$ in " + clazz);
    }
    catch (NoSuchMethodException e) {
        if (expectedPresent)
            fail("Expected to find $deserializeLambda$ in " + clazz);
    }
}
 
源代码25 项目: openjdk-jdk9   文件: DeserializeMethodTest.java
private void assertDeserializeMethod(Class<?> clazz, boolean expectedPresent) {
    try {
        Method m = clazz.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
        if (!expectedPresent)
            fail("Unexpected $deserializeLambda$ in " + clazz);
    }
    catch (NoSuchMethodException e) {
        if (expectedPresent)
            fail("Expected to find $deserializeLambda$ in " + clazz);
    }
}
 
源代码26 项目: jdk8u-jdk   文件: DeserializeMethodTest.java
private void assertDeserializeMethod(Class<?> clazz, boolean expectedPresent) {
    try {
        Method m = clazz.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
        if (!expectedPresent)
            fail("Unexpected $deserializeLambda$ in " + clazz);
    }
    catch (NoSuchMethodException e) {
        if (expectedPresent)
            fail("Expected to find $deserializeLambda$ in " + clazz);
    }
}
 
源代码27 项目: 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);
    }
}
 
源代码28 项目: hottub   文件: DeserializeMethodTest.java
private void assertDeserializeMethod(Class<?> clazz, boolean expectedPresent) {
    try {
        Method m = clazz.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
        if (!expectedPresent)
            fail("Unexpected $deserializeLambda$ in " + clazz);
    }
    catch (NoSuchMethodException e) {
        if (expectedPresent)
            fail("Expected to find $deserializeLambda$ in " + clazz);
    }
}
 
源代码29 项目: openjdk-8-source   文件: DeserializeMethodTest.java
private void assertDeserializeMethod(Class<?> clazz, boolean expectedPresent) {
    try {
        Method m = clazz.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
        if (!expectedPresent)
            fail("Unexpected $deserializeLambda$ in " + clazz);
    }
    catch (NoSuchMethodException e) {
        if (expectedPresent)
            fail("Expected to find $deserializeLambda$ in " + clazz);
    }
}
 
源代码30 项目: openjdk-8   文件: DeserializeMethodTest.java
private void assertDeserializeMethod(Class<?> clazz, boolean expectedPresent) {
    try {
        Method m = clazz.getDeclaredMethod("$deserializeLambda$", SerializedLambda.class);
        if (!expectedPresent)
            fail("Unexpected $deserializeLambda$ in " + clazz);
    }
    catch (NoSuchMethodException e) {
        if (expectedPresent)
            fail("Expected to find $deserializeLambda$ in " + clazz);
    }
}
 
 类所在包
 同包方法