当前位置: 首页>>代码示例>>Java>>正文


Java MethodType.equals方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-systemtest,代码行数:8,代码来源:BasicStaticTest.java

示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:36,代码来源:CompiledFunction.java

示例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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:13,代码来源:MethodTypeTest.java

示例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);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:13,代码来源:MethodTypeTest.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:CompiledFunction.java

示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:66,代码来源:ScriptObject.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:66,代码来源:ScriptObject.java

示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:ScriptFunctionData.java


注:本文中的java.lang.invoke.MethodType.equals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。