本文整理汇总了Java中java.lang.invoke.MethodType.equals方法的典型用法代码示例。如果您正苦于以下问题:Java MethodType.equals方法的具体用法?Java MethodType.equals怎么用?Java MethodType.equals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.invoke.MethodType
的用法示例。
在下文中一共展示了MethodType.equals方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: check
import java.lang.invoke.MethodType; //导入方法依赖的package包/类
public static void check(MethodType ideal, MethodType actual) {
if (!ideal.equals(actual)) {
String idealString = (ideal==null)? "null" : ideal.toString();
String actualString = (actual==null)? "null" : actual.toString();
throw new Error("ERROR: Expected " + idealString + "; found " + actualString);
}
}
示例2: matchesCallSite
import java.lang.invoke.MethodType; //导入方法依赖的package包/类
boolean matchesCallSite(final MethodType other, final boolean pickVarArg) {
if (other.equals(this.callSiteType)) {
return true;
}
final MethodType type = type();
final int fnParamCount = getParamCount(type);
final boolean isVarArg = fnParamCount == Integer.MAX_VALUE;
if (isVarArg) {
return pickVarArg;
}
final int csParamCount = getParamCount(other);
final boolean csIsVarArg = csParamCount == Integer.MAX_VALUE;
final int thisThisIndex = needsCallee() ? 1 : 0; // Index of "this" parameter in this function's type
final int fnParamCountNoCallee = fnParamCount - thisThisIndex;
final int minParams = Math.min(csParamCount - 1, fnParamCountNoCallee); // callSiteType always has callee, so subtract 1
// We must match all incoming parameters, except "this". Starting from 1 to skip "this".
for(int i = 1; i < minParams; ++i) {
final Type fnType = Type.typeFor(type.parameterType(i + thisThisIndex));
final Type csType = csIsVarArg ? Type.OBJECT : Type.typeFor(other.parameterType(i + 1));
if(!fnType.isEquivalentTo(csType)) {
return false;
}
}
// Must match any undefined parameters to Object type.
for(int i = minParams; i < fnParamCountNoCallee; ++i) {
if(!Type.typeFor(type.parameterType(i + thisThisIndex)).isEquivalentTo(Type.OBJECT)) {
return false;
}
}
return true;
}
示例3: testEquals_Object
import java.lang.invoke.MethodType; //导入方法依赖的package包/类
/**
* Test of equals method, of class MethodType.
*/
@Test
public void testEquals_Object() {
System.out.println("equals");
Object x = null;
MethodType instance = mt_viS;
boolean expResult = false;
boolean result = instance.equals(x);
assertEquals(expResult, result);
}
示例4: testEquals_MethodType
import java.lang.invoke.MethodType; //导入方法依赖的package包/类
/**
* Test of equals method, of class MethodType.
*/
@Test
public void testEquals_MethodType() {
System.out.println("equals");
MethodType that = mt_viS;
MethodType instance = mt_viS;
boolean expResult = true;
boolean result = instance.equals(that);
assertEquals(expResult, result);
}
示例5: matchesCallSite
import java.lang.invoke.MethodType; //导入方法依赖的package包/类
boolean matchesCallSite(final MethodType other, final boolean pickVarArg) {
if (other.equals(this.callSiteType)) {
return true;
}
final MethodType type = type();
final int fnParamCount = getParamCount(type);
final boolean isVarArg = fnParamCount == Integer.MAX_VALUE;
if (isVarArg) {
return pickVarArg;
}
final int csParamCount = getParamCount(other);
final boolean csIsVarArg = csParamCount == Integer.MAX_VALUE;
final int thisThisIndex = needsCallee() ? 1 : 0; // Index of "this" parameter in this function's type
final int fnParamCountNoCallee = fnParamCount - thisThisIndex;
final int minParams = Math.min(csParamCount - 1, fnParamCountNoCallee); // callSiteType always has callee, so subtract 1
// We must match all incoming parameters, including "this". "this" will usually be Object, but there
// are exceptions, e.g. when calling functions with primitive "this" in strict mode or through call/apply.
for(int i = 0; i < minParams; ++i) {
final Type fnType = Type.typeFor(type.parameterType(i + thisThisIndex));
final Type csType = csIsVarArg ? Type.OBJECT : Type.typeFor(other.parameterType(i + 1));
if(!fnType.isEquivalentTo(csType)) {
return false;
}
}
// Must match any undefined parameters to Object type.
for(int i = minParams; i < fnParamCountNoCallee; ++i) {
if(!Type.typeFor(type.parameterType(i + thisThisIndex)).isEquivalentTo(Type.OBJECT)) {
return false;
}
}
return true;
}
示例6: pairArguments
import java.lang.invoke.MethodType; //导入方法依赖的package包/类
/**
* Make sure arguments are paired correctly, with respect to more parameters than declared,
* fewer parameters than declared and other things that JavaScript allows. This might involve
* creating collectors.
*
* Make sure arguments are paired correctly.
* @param methodHandle MethodHandle to adjust.
* @param callType MethodType of the call site.
* @param callerVarArg true if the caller is vararg, false otherwise, null if it should be inferred from the
* {@code callType}; basically, if the last parameter type of the call site is an array, it'll be considered a
* variable arity call site. These are ordinarily rare; Nashorn code generator creates variable arity call sites
* when the call has more than {@link LinkerCallSite#ARGLIMIT} parameters.
*
* @return method handle with adjusted arguments
*/
public static MethodHandle pairArguments(final MethodHandle methodHandle, final MethodType callType, final Boolean callerVarArg) {
final MethodType methodType = methodHandle.type();
if (methodType.equals(callType.changeReturnType(methodType.returnType()))) {
return methodHandle;
}
final int parameterCount = methodType.parameterCount();
final int callCount = callType.parameterCount();
final boolean isCalleeVarArg = parameterCount > 0 && methodType.parameterType(parameterCount - 1).isArray();
final boolean isCallerVarArg = callerVarArg != null ? callerVarArg.booleanValue() : callCount > 0 &&
callType.parameterType(callCount - 1).isArray();
if (isCalleeVarArg) {
return isCallerVarArg ?
methodHandle :
MH.asCollector(methodHandle, Object[].class, callCount - parameterCount + 1);
}
if (isCallerVarArg) {
return adaptHandleToVarArgCallSite(methodHandle, callCount);
}
if (callCount < parameterCount) {
final int missingArgs = parameterCount - callCount;
final Object[] fillers = new Object[missingArgs];
Arrays.fill(fillers, UNDEFINED);
if (isCalleeVarArg) {
fillers[missingArgs - 1] = ScriptRuntime.EMPTY_ARRAY;
}
return MH.insertArguments(
methodHandle,
parameterCount - missingArgs,
fillers);
}
if (callCount > parameterCount) {
final int discardedArgs = callCount - parameterCount;
final Class<?>[] discards = new Class<?>[discardedArgs];
Arrays.fill(discards, Object.class);
return MH.dropArguments(methodHandle, callCount - discardedArgs, discards);
}
return methodHandle;
}
示例7: pairArguments
import java.lang.invoke.MethodType; //导入方法依赖的package包/类
/**
* Make sure arguments are paired correctly, with respect to more parameters than declared,
* fewer parameters than declared and other things that JavaScript allows. This might involve
* creating collectors.
*
* Make sure arguments are paired correctly.
* @param methodHandle MethodHandle to adjust.
* @param callType MethodType of the call site.
* @param callerVarArg true if the caller is vararg, false otherwise, null if it should be inferred from the
* {@code callType}; basically, if the last parameter type of the call site is an array, it'll be considered a
* variable arity call site. These are ordinarily rare; Nashorn code generator creates variable arity call sites
* when the call has more than {@link LinkerCallSite#ARGLIMIT} parameters.
*
* @return method handle with adjusted arguments
*/
public static MethodHandle pairArguments(final MethodHandle methodHandle, final MethodType callType, final Boolean callerVarArg) {
final MethodType methodType = methodHandle.type();
if (methodType.equals(callType.changeReturnType(methodType.returnType()))) {
return methodHandle;
}
final int parameterCount = methodType.parameterCount();
final int callCount = callType.parameterCount();
final boolean isCalleeVarArg = parameterCount > 0 && methodType.parameterType(parameterCount - 1).isArray();
final boolean isCallerVarArg = callerVarArg != null ? callerVarArg : callCount > 0 &&
callType.parameterType(callCount - 1).isArray();
if (isCalleeVarArg) {
return isCallerVarArg ?
methodHandle :
MH.asCollector(methodHandle, Object[].class, callCount - parameterCount + 1);
}
if (isCallerVarArg) {
return adaptHandleToVarArgCallSite(methodHandle, callCount);
}
if (callCount < parameterCount) {
final int missingArgs = parameterCount - callCount;
final Object[] fillers = new Object[missingArgs];
Arrays.fill(fillers, UNDEFINED);
if (isCalleeVarArg) {
fillers[missingArgs - 1] = ScriptRuntime.EMPTY_ARRAY;
}
return MH.insertArguments(
methodHandle,
parameterCount - missingArgs,
fillers);
}
if (callCount > parameterCount) {
final int discardedArgs = callCount - parameterCount;
final Class<?>[] discards = new Class<?>[discardedArgs];
Arrays.fill(discards, Object.class);
return MH.dropArguments(methodHandle, callCount - discardedArgs, discards);
}
return methodHandle;
}
示例8: makeGenericMethod
import java.lang.invoke.MethodType; //导入方法依赖的package包/类
/**
* Takes a method handle, and returns a potentially different method handle that can be used in
* {@code ScriptFunction#invoke(Object, Object...)} or {code ScriptFunction#construct(Object, Object...)}.
* The returned method handle will be sure to return {@code Object}, and will have all its parameters turned into
* {@code Object} as well, except for the following ones:
* <ul>
* <li>a last parameter of type {@code Object[]} which is used for vararg functions,</li>
* <li>the first argument, which is forced to be {@link ScriptFunction}, in case the function receives itself
* (callee) as an argument.</li>
* </ul>
*
* @param mh the original method handle
*
* @return the new handle, conforming to the rules above.
*/
private static MethodHandle makeGenericMethod(final MethodHandle mh) {
final MethodType type = mh.type();
final MethodType newType = makeGenericType(type);
return type.equals(newType) ? mh : mh.asType(newType);
}