本文整理匯總了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);
}