本文整理汇总了Java中java.lang.invoke.MethodHandleInfo类的典型用法代码示例。如果您正苦于以下问题:Java MethodHandleInfo类的具体用法?Java MethodHandleInfo怎么用?Java MethodHandleInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MethodHandleInfo类属于java.lang.invoke包,在下文中一共展示了MethodHandleInfo类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: invocationOpcode
import java.lang.invoke.MethodHandleInfo; //导入依赖的package包/类
public static int invocationOpcode(int kind) throws InternalError
{
switch (kind)
{
case MethodHandleInfo.REF_invokeStatic:
return INVOKESTATIC;
case MethodHandleInfo.REF_newInvokeSpecial:
return INVOKESPECIAL;
case MethodHandleInfo.REF_invokeVirtual:
return INVOKEVIRTUAL;
case MethodHandleInfo.REF_invokeInterface:
return INVOKEINTERFACE;
case MethodHandleInfo.REF_invokeSpecial:
return INVOKESPECIAL;
default:
throw new InternalError("Unexpected invocation kind: " + kind);
}
}
开发者ID:Dyvil,项目名称:Dyvil,代码行数:19,代码来源:TypeConverter.java
示例2: bind
import java.lang.invoke.MethodHandleInfo; //导入依赖的package包/类
private static MethodHandle bind(VarHandle vh, MethodHandle mh, MethodType emt) {
assertEquals(mh.type(), emt.insertParameterTypes(0, VarHandle.class),
"MethodHandle type differs from access mode type");
MethodHandleInfo info = MethodHandles.lookup().revealDirect(mh);
assertEquals(info.getMethodType(), emt,
"MethodHandleInfo method type differs from access mode type");
return mh.bindTo(vh);
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:VarHandleBaseTest.java
示例3: methodInvocationFromMethodInfo
import java.lang.invoke.MethodHandleInfo; //导入依赖的package包/类
@Test(dataProvider = "accessModesProvider", expectedExceptions = IllegalArgumentException.class)
public void methodInvocationFromMethodInfo(VarHandle.AccessMode accessMode) throws Exception {
VarHandle v = handle();
// Try a reflective invoke using a Method obtained from cracking
// a MethodHandle
MethodHandle mh = MethodHandles.lookup().unreflect(
VarHandle.class.getMethod(accessMode.methodName(), Object[].class));
MethodHandleInfo info = MethodHandles.lookup().revealDirect(mh);
Method im = info.reflectAs(Method.class, MethodHandles.lookup());
im.invoke(v, new Object[]{});
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:VarHandleTestReflection.java
示例4: reflectAsFromVarHandleInvoker
import java.lang.invoke.MethodHandleInfo; //导入依赖的package包/类
@Test(dataProvider = "accessModesProvider", expectedExceptions = IllegalArgumentException.class)
public void reflectAsFromVarHandleInvoker(VarHandle.AccessMode accessMode) throws Exception {
VarHandle v = handle();
MethodHandle mh = MethodHandles.varHandleInvoker(
accessMode, v.accessModeType(accessMode));
MethodHandleInfo info = MethodHandles.lookup().revealDirect(mh);
info.reflectAs(Method.class, MethodHandles.lookup());
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:VarHandleTestReflection.java
示例5: reflectAsFromFindVirtual
import java.lang.invoke.MethodHandleInfo; //导入依赖的package包/类
@Test(dataProvider = "accessModesProvider", expectedExceptions = IllegalArgumentException.class)
public void reflectAsFromFindVirtual(VarHandle.AccessMode accessMode) throws Exception {
VarHandle v = handle();
MethodHandle mh = MethodHandles.publicLookup().findVirtual(
VarHandle.class, accessMode.methodName(), v.accessModeType(accessMode));
MethodHandleInfo info = MethodHandles.lookup().revealDirect(mh);
info.reflectAs(Method.class, MethodHandles.lookup());
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:VarHandleTestReflection.java
示例6: findMethodWithType
import java.lang.invoke.MethodHandleInfo; //导入依赖的package包/类
/**
* Get the only method in the class with the given return and parameter types
* <p>Throws an exception if no fields are found, or if multiple fields are found.</p>
* <p>Fields may have a subclass of the required type, and primitives are interchangeable with wrappers. Therefore passing Object accepts all fields.</p>
*
* @param clazz the type to find the method in
* @param returnType the return type of the method to find
* @param parameters the parameters of the method to find
* @return the only method with the given return type and parameters
* @throws IllegalArgumentException if there is more than one field with the given type
* @throws IllegalArgumentException if not found
* @throws NullPointerException if any args are null
*/
public static MethodHandle findMethodWithType(Class<?> clazz, Class returnType, Class<?>... parameters) {
ImmutableList<MethodHandle> methods = findMethodsWithType(clazz, returnType, parameters);
StringBuilder builder;
switch (methods.size()) {
case 1:
return methods.get(0);
case 0:
throw new IllegalArgumentException(format(
"Method in {} not found with type '({}){}'",
clazz.getTypeName(),
returnType,
Arrays.stream(parameters)
.map(Class::getTypeName)
.collect(Collectors.joining(","))
));
default:
throw new IllegalArgumentException(format(
"Multiple methods with type '({}){}' found in {}: {}",
returnType,
Arrays.stream(parameters)
.map(Class::getTypeName)
.collect(Collectors.joining(",")),
clazz.getTypeName(),
methods.stream()
.map(MethodHandles.lookup()::revealDirect)
.map(MethodHandleInfo::getName)
.collect(Collectors.joining(",", "[", "]"))
));
}
}
开发者ID:Techcable,项目名称:PineappleCommons,代码行数:44,代码来源:Reflection.java
示例7: implMethod
import java.lang.invoke.MethodHandleInfo; //导入依赖的package包/类
private MethodHandle implMethod(Lookup lookup, Class<?> implClass, MethodType implType) throws NoSuchMethodException, IllegalAccessException {
switch (implMethodKind) {
case MethodHandleInfo.REF_invokeInterface:
case MethodHandleInfo.REF_invokeVirtual:
return lookup.findVirtual(implClass, implMethodName, implType);
case MethodHandleInfo.REF_invokeSpecial:
return lookup.findSpecial(implClass, implMethodName, implType, implClass);
case MethodHandleInfo.REF_invokeStatic:
return lookup.findStatic(implClass, implMethodName, implType);
default:
throw new RuntimeException("Unsupported impl method kind " + implMethodKind);
}
}
开发者ID:almondtools,项目名称:testrecorder,代码行数:14,代码来源:LambdaSignature.java
示例8: testSerializeStaticNonCapturing
import java.lang.invoke.MethodHandleInfo; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testSerializeStaticNonCapturing() throws Exception {
SerializedLambda serializedLambda = Lambdas.serializeLambda(splus);
assertThat(serializedLambda.getCapturedArgCount(), equalTo(0));
LambdaSignature lambda = new LambdaSignature()
.withCapturingClass(serializedLambda.getCapturingClass())
.withInstantiatedMethodType(serializedLambda.getInstantiatedMethodType())
.withFunctionalInterface(serializedLambda.getFunctionalInterfaceClass(), serializedLambda.getFunctionalInterfaceMethodName(), serializedLambda.getFunctionalInterfaceMethodSignature())
.withImplMethod(serializedLambda.getImplClass(), serializedLambda.getImplMethodKind(), serializedLambda.getImplMethodName(), serializedLambda.getImplMethodSignature());
assertThat(lambda.getCapturingClass(), equalTo("net/amygdalum/testrecorder/values/LambdaSignatureTest"));
assertThat(lambda.getFunctionalInterfaceClass(), equalTo("java/util/function/BiFunction"));
assertThat(lambda.getFunctionalInterfaceMethod().getDeclaringClass(), equalTo(BiFunction.class));
assertThat(lambda.getFunctionalInterfaceMethodName(), equalTo("apply"));
assertThat(lambda.getFunctionalInterfaceMethodSignature(), equalTo("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"));
assertThat(lambda.getFunctionalInterfaceMethod().getName(), equalTo("apply"));
assertThat(lambda.getFunctionalInterfaceMethod().getParameterTypes(), arrayContaining(Object.class, Object.class));
assertThat(lambda.getImplClass(), equalTo("net/amygdalum/testrecorder/values/LambdaSignatureTest"));
assertThat(lambda.getImplMethod().getDeclaringClass(), equalTo(LambdaSignatureTest.class));
assertThat(lambda.getImplMethodKind(), equalTo(MethodHandleInfo.REF_invokeStatic));
assertThat(lambda.getImplMethodSignature(), equalTo("(Ljava/lang/Integer;Ljava/lang/Integer;)Ljava/lang/Integer;"));
assertThat(lambda.getImplMethod().getParameterTypes(), arrayContaining(Integer.class, Integer.class));
assertThat(lambda.getInstantiatedMethodType(), equalTo("(Ljava/lang/Integer;Ljava/lang/Integer;)Ljava/lang/Integer;"));
}
开发者ID:almondtools,项目名称:testrecorder,代码行数:31,代码来源:LambdaSignatureTest.java
示例9: testSerializeStaticCapturing
import java.lang.invoke.MethodHandleInfo; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testSerializeStaticCapturing() throws Exception {
SerializedLambda serializedLambda = Lambdas.serializeLambda(splusCapturing(42));
assertThat(serializedLambda.getCapturedArgCount(), equalTo(1));
assertThat(serializedLambda.getCapturedArg(0), equalTo(42));
LambdaSignature lambda = new LambdaSignature()
.withCapturingClass(serializedLambda.getCapturingClass())
.withInstantiatedMethodType(serializedLambda.getInstantiatedMethodType())
.withFunctionalInterface(serializedLambda.getFunctionalInterfaceClass(), serializedLambda.getFunctionalInterfaceMethodName(), serializedLambda.getFunctionalInterfaceMethodSignature())
.withImplMethod(serializedLambda.getImplClass(), serializedLambda.getImplMethodKind(), serializedLambda.getImplMethodName(), serializedLambda.getImplMethodSignature());
assertThat(lambda.getCapturingClass(), equalTo("net/amygdalum/testrecorder/values/LambdaSignatureTest"));
assertThat(lambda.getFunctionalInterfaceClass(), equalTo("java/util/function/Function"));
assertThat(lambda.getFunctionalInterfaceMethod().getDeclaringClass(), equalTo(Function.class));
assertThat(lambda.getFunctionalInterfaceMethodName(), equalTo("apply"));
assertThat(lambda.getFunctionalInterfaceMethodSignature(), equalTo("(Ljava/lang/Object;)Ljava/lang/Object;"));
assertThat(lambda.getFunctionalInterfaceMethod().getName(), equalTo("apply"));
assertThat(lambda.getFunctionalInterfaceMethod().getParameterTypes(), arrayContaining(Object.class));
assertThat(lambda.getImplClass(), equalTo("net/amygdalum/testrecorder/values/LambdaSignatureTest"));
assertThat(lambda.getImplMethodKind(), equalTo(MethodHandleInfo.REF_invokeStatic));
assertThat(lambda.getImplMethodSignature(), equalTo("(ILjava/lang/Integer;)Ljava/lang/Integer;"));
assertThat(lambda.getImplMethod().getParameterTypes(), arrayContaining(int.class, Integer.class));
assertThat(lambda.getInstantiatedMethodType(), equalTo("(Ljava/lang/Integer;)Ljava/lang/Integer;"));
}
开发者ID:almondtools,项目名称:testrecorder,代码行数:31,代码来源:LambdaSignatureTest.java
示例10: testSerializeInstanceCapturing
import java.lang.invoke.MethodHandleInfo; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testSerializeInstanceCapturing() throws Exception {
SerializedLambda serializedLambda = Lambdas.serializeLambda(this.splusInstanceCapturing());
assertThat(serializedLambda.getCapturedArgCount(), equalTo(1));
assertThat(serializedLambda.getCapturedArg(0), equalTo(this));
LambdaSignature lambda = new LambdaSignature()
.withCapturingClass(serializedLambda.getCapturingClass())
.withInstantiatedMethodType(serializedLambda.getInstantiatedMethodType())
.withFunctionalInterface(serializedLambda.getFunctionalInterfaceClass(), serializedLambda.getFunctionalInterfaceMethodName(), serializedLambda.getFunctionalInterfaceMethodSignature())
.withImplMethod(serializedLambda.getImplClass(), serializedLambda.getImplMethodKind(), serializedLambda.getImplMethodName(), serializedLambda.getImplMethodSignature());
assertThat(lambda.getCapturingClass(), equalTo("net/amygdalum/testrecorder/values/LambdaSignatureTest"));
assertThat(lambda.getFunctionalInterfaceClass(), equalTo("java/util/function/Function"));
assertThat(lambda.getFunctionalInterfaceMethod().getDeclaringClass(), equalTo(Function.class));
assertThat(lambda.getFunctionalInterfaceMethodName(), equalTo("apply"));
assertThat(lambda.getFunctionalInterfaceMethodSignature(), equalTo("(Ljava/lang/Object;)Ljava/lang/Object;"));
assertThat(lambda.getFunctionalInterfaceMethod().getName(), equalTo("apply"));
assertThat(lambda.getFunctionalInterfaceMethod().getParameterTypes(), arrayContaining(Object.class));
assertThat(lambda.getImplClass(), equalTo("net/amygdalum/testrecorder/values/LambdaSignatureTest"));
assertThat(lambda.getImplMethodKind(), equalTo(MethodHandleInfo.REF_invokeSpecial));
assertThat(lambda.getImplMethodSignature(), equalTo("(Ljava/lang/Integer;)Ljava/lang/Integer;"));
assertThat(lambda.getImplMethod().getParameterTypes(), arrayContaining(Integer.class));
assertThat(lambda.getInstantiatedMethodType(), equalTo("(Ljava/lang/Integer;)Ljava/lang/Integer;"));
}
开发者ID:almondtools,项目名称:testrecorder,代码行数:31,代码来源:LambdaSignatureTest.java
示例11: virtualInfo
import java.lang.invoke.MethodHandleInfo; //导入依赖的package包/类
public MethodHandleInfo virtualInfo(Class<?> target, String name, MethodType type) throws NoSuchMethodException, IllegalAccessException {
return lookup.revealDirect(virtualHandle(target, name, type));
}
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:4,代码来源:MethodResolver.java
示例12: isInstanceMethod
import java.lang.invoke.MethodHandleInfo; //导入依赖的package包/类
private boolean isInstanceMethod() {
return implMethodKind != MethodHandleInfo.REF_invokeStatic;
}
开发者ID:almondtools,项目名称:testrecorder,代码行数:4,代码来源:LambdaSignature.java
示例13: info
import java.lang.invoke.MethodHandleInfo; //导入依赖的package包/类
private MethodHandleInfo info() {
if (info == null) {
info = MethodHandles.publicLookup().revealDirect(handle);
}
return info;
}
开发者ID:anba,项目名称:es6draft,代码行数:7,代码来源:DebugInfo.java
示例14: validateMethodKind
import java.lang.invoke.MethodHandleInfo; //导入依赖的package包/类
/**
* Validates implementation method kind (for invoke virtual and invoke
* interface)
*
* @param lambda
* @return <code>boolean</code> validation result
*/
private static boolean validateMethodKind(LambdaInfo lambda) {
boolean valid;
int kind = lambda.getImplMethodKind();
valid = ((kind == MethodHandleInfo.REF_invokeVirtual) || (kind == MethodHandleInfo.REF_invokeInterface));
return valid;
}
开发者ID:levants,项目名称:lightmare,代码行数:17,代码来源:DirectFieldResolver.java
注:本文中的java.lang.invoke.MethodHandleInfo类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论