• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java WrongMethodTypeException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中java.lang.invoke.WrongMethodTypeException的典型用法代码示例。如果您正苦于以下问题:Java WrongMethodTypeException类的具体用法?Java WrongMethodTypeException怎么用?Java WrongMethodTypeException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



WrongMethodTypeException类属于java.lang.invoke包,在下文中一共展示了WrongMethodTypeException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: adjustArity

import java.lang.invoke.WrongMethodTypeException; //导入依赖的package包/类
static MethodHandle adjustArity(MethodHandle mh, int arity) {
    MethodType mt = mh.type();
    int posArgs = mt.parameterCount() - 1;
    Class<?> reptype = mt.parameterType(posArgs).getComponentType();
    MethodType mt1 = mt.dropParameterTypes(posArgs, posArgs+1);
    while (mt1.parameterCount() < arity) {
        Class<?> pt = reptype;
        if (pt == Object.class && posArgs > 0)
            // repeat types cyclically if possible:
            pt = mt1.parameterType(mt1.parameterCount() - posArgs);
        mt1 = mt1.appendParameterTypes(pt);
    }
    try {
        return mh.asType(mt1);
    } catch (WrongMethodTypeException | IllegalArgumentException ex) {
        throw new IllegalArgumentException("cannot convert to type "+mt1+" from "+mh, ex);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:PermuteArgsTest.java


示例2: invoke

import java.lang.invoke.WrongMethodTypeException; //导入依赖的package包/类
@Override
public void invoke(Object[] parameters) {
    try {
        methodHandle.invokeExact(parameters);
    } catch (WrongMethodTypeException e) {
        throw new TomokoException("Problem with Tomoko itself.", e);
    } catch (Throwable throwable) {
        if (throwable instanceof Error) {
            throw (Error) throwable;
        } else if (throwable instanceof RuntimeException) {
            throw (RuntimeException) throwable;
        } else {
            throw new HandlerExecutionException((Exception) throwable);
        }
    }
}
 
开发者ID:Qubite,项目名称:tomoko,代码行数:17,代码来源:MethodHandleInvocation.java


示例3: buildBolt

import java.lang.invoke.WrongMethodTypeException; //导入依赖的package包/类
@Override
public WorkberchGenericBolt buildBolt(final String guid) {
	
	WorkberchGenericBolt ret = null;
   	switch (nodeType) {
   		case XPATH:
   			ret = new XPathBolt(guid, getInputs(), getOutputs(), config);
   			break;
   		case REST:
   			ret = new RestBolt(guid, getInputs(), getOutputs(), config);
   			break;
   		case BEANSHELL:
   			ret = new BeanshellBolt(guid, getInputs(), getOutputs(), config);
   			break;
   		default:
   			throw new WrongMethodTypeException("No se ha implementado el tipo de processor de taverna: " + nodeType);
   	}
   	
   	return ret;
}
 
开发者ID:matiasf,项目名称:workberch-tolopogy,代码行数:21,代码来源:WorkberchTavernaNode.java


示例4: processor2NodeInput

import java.lang.invoke.WrongMethodTypeException; //导入依赖的package包/类
public static WorkberchNodeInput processor2NodeInput(final Processor processor, final Configuration config) {
	final String processorType = config.getType().toString();
	DataGenerator dg = null;

	switch (TavernaNodeType.fromString(processorType)) {
	case TEXT_CONSTANT:
		dg = new TextDataGenerator(config.getJson().get("string").asText());
		break;
	default:
		throw new WrongMethodTypeException("No se ha implementado el tipo de processor de taverna: " + processorType);
	}

	final List<String> outputFields = new ArrayList<String>();

	for (final OutputProcessorPort outputPort : processor.getOutputPorts()) {
		outputFields.add(processor.getName() + WorkberchConstants.NAME_DELIMITER + outputPort.getName());
	}

	// FIXME: El parametro isSimple en la creacion de este nodo podria ser
	// mejorado para los casos que
	// se pueda determinar si esto envia solo un valor.
	return new WorkberchNodeInput(processor.getName(), dg, outputFields);
}
 
开发者ID:matiasf,项目名称:workberch-tolopogy,代码行数:24,代码来源:WorkberchTavernaFactory.java


示例5: testArities

import java.lang.invoke.WrongMethodTypeException; //导入依赖的package包/类
private void testArities(Class<? extends Object[]> cls,
                         int minArity,
                         int maxArity,
                         int iterations) throws Throwable {
    boolean verbose = (cls == Object[].class);
    for (int arity = minArity; arity <= maxArity; arity++) {
        if (verbose)  System.out.println("arity="+arity);
        MethodHandle mh = MH_hashArguments(cls, arity);
        MethodHandle mh_VA = mh.asSpreader(cls, arity);
        assert(mh_VA.type().parameterType(0) == cls);
        testArities(cls, arity, iterations, verbose, mh, mh_VA);
        if (cls != Object[].class) {
            // mh_CA will collect arguments of a particular type and pass them to mh_VA
            MethodHandle mh_CA = mh_VA.asCollector(cls, arity);
            MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity);
            try {
                mh_VA2.invokeWithArguments(new Object[arity]);
                throw new AssertionError("should not reach");
            } catch (ClassCastException | WrongMethodTypeException ex) {
            }
            assert(mh_CA.type().equals(mh.type()));
            assert(mh_VA2.type().equals(mh_VA.type()));
            testArities(cls, arity, iterations, false, mh_CA, mh_VA2);
        }
    }
}
 
开发者ID:greghaskins,项目名称:openjdk-jdk7u-jdk,代码行数:27,代码来源:BigArityTest.java


示例6: forSpreadCall

import java.lang.invoke.WrongMethodTypeException; //导入依赖的package包/类
private static MethodHandle forSpreadCall(MethodHandle mh, MethodType type) {
    int expectedParameters = mh.type().parameterCount();
    int actualParameters = type.parameterCount();
    if (!mh.isVarargsCollector() || !mh.type().parameterType(expectedParameters - 1).equals(Object[].class)) {
        throw new WrongMethodTypeException("Not Object[] var-args collector");
    }
    if (expectedParameters > actualParameters) {
        throw new WrongMethodTypeException("Too few arguments");
    }
    if (expectedParameters < actualParameters) {
        int fixedCount = actualParameters - expectedParameters;
        int firstFixed = expectedParameters - 1;
        List<Class<?>> fixed = type.parameterList().subList(firstFixed, firstFixed + fixedCount);
        mh = MethodHandles.collectArguments(mh, firstFixed, combineArraysMH);
        mh = MethodHandles.collectArguments(mh, firstFixed, toObjectArray(fixed));
    }
    return mh.asType(type);
}
 
开发者ID:anba,项目名称:es6draft,代码行数:19,代码来源:NativeCalls.java


示例7: checkForWrongMethodTypeException

import java.lang.invoke.WrongMethodTypeException; //导入依赖的package包/类
private static void checkForWrongMethodTypeException(MethodHandle mh, MethodType mt) {
    try {
        MethodHandles.explicitCastArguments(mh, mt);
        throw new AssertionError("Expected WrongMethodTypeException is not thrown");
    } catch (WrongMethodTypeException wmte) {
        if (VERBOSE) {
            System.out.printf("Expected exception %s: %s\n",
                    wmte.getClass(), wmte.getMessage());
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:ExplicitCastArgumentsTest.java


示例8: testArities

import java.lang.invoke.WrongMethodTypeException; //导入依赖的package包/类
private void testArities(Class<? extends Object[]> cls,
                         int minArity,
                         int maxArity,
                         int iterations) throws Throwable {
    boolean verbose = (cls == Object[].class);
    for (int arity = minArity; arity <= maxArity; arity++) {
        if (verbose)  System.out.println("arity="+arity);
        MethodHandle mh = MH_hashArguments(cls, arity);
        MethodHandle mh_VA = mh.asSpreader(cls, arity);
        assert(mh_VA.type().parameterType(0) == cls);
        testArities(cls, arity, iterations, verbose, mh, mh_VA);
        // mh_CA will collect arguments of a particular type and pass them to mh_VA
        MethodHandle mh_CA = mh_VA.asCollector(cls, arity);
        MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity);
        assert(mh_CA.type().equals(mh.type()));
        assert(mh_VA2.type().equals(mh_VA.type()));
        if (cls != Object[].class) {
            try {
                mh_VA2.invokeWithArguments(new Object[arity]);
                throw new AssertionError("should not reach");
            } catch (ClassCastException | WrongMethodTypeException ex) {
            }
        }
        int iterations_VA = iterations / 100;
        testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:28,代码来源:BigArityTest.java


示例9: testArities

import java.lang.invoke.WrongMethodTypeException; //导入依赖的package包/类
private void testArities(Class<? extends Object[]> cls,
                         int minArity,
                         int maxArity,
                         int iterations) throws Throwable {
    boolean verbose = (cls == Object[].class);
    for (int arity = minArity; arity <= maxArity; arity++) {
        if (verbose)  System.out.println("arity="+arity);
        MethodHandle mh = MH_hashArguments(cls, arity);
        MethodHandle mh_VA = mh.asSpreader(cls, arity);
        MethodHandle mh_VA_h = mh.asSpreader(0, cls, arity-1);
        assert(mh_VA.type().parameterType(0) == cls);
        assert(mh_VA_h.type().parameterType(0) == cls);
        testArities(cls, arity, iterations, verbose, mh, mh_VA, mh_VA_h);
        // mh_CA will collect arguments of a particular type and pass them to mh_VA
        MethodHandle mh_CA = mh_VA.asCollector(cls, arity);
        MethodHandle mh_VA2 = mh_CA.asSpreader(cls, arity);
        MethodHandle mh_VA2_h = mh_CA.asSpreader(0, cls, arity-1);
        assert(mh_CA.type().equals(mh.type()));
        assert(mh_VA2.type().equals(mh_VA.type()));
        if (cls != Object[].class) {
            try {
                mh_VA2.invokeWithArguments(new Object[arity]);
                throw new AssertionError("should not reach");
            } catch (ClassCastException | WrongMethodTypeException ex) {
            }
        }
        int iterations_VA = iterations / 100;
        testArities(cls, arity, iterations_VA, false, mh_CA, mh_VA2, mh_VA2_h);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:BigArityTest.java


示例10: test_asInterfaceInstance_wrong_target_type

import java.lang.invoke.WrongMethodTypeException; //导入依赖的package包/类
@Test(expectedExceptions = WrongMethodTypeException.class)
public void test_asInterfaceInstance_wrong_target_type() throws Throwable {
  MethodHandles.Lookup lookup = MethodHandles.lookup();
  MethodHandle handle = lookup.findStatic(MyCallable.class, "hello", genericMethodType(0));
  assertThat((String) handle.invoke(), is("Hello!"));
  Predefined.asInterfaceInstance(ActionListener.class, new FunctionReference(handle));
}
 
开发者ID:dynamid,项目名称:golo-lang-insa-citilab-historical-reference,代码行数:8,代码来源:PredefinedTest.java


示例11: invoker_call_any_type_mismatch

import java.lang.invoke.WrongMethodTypeException; //导入依赖的package包/类
@Test(expectedExceptions = WrongMethodTypeException.class)
public void invoker_call_any_type_mismatch() throws Throwable {
  DynamicObject object = new DynamicObject();
  MethodHandle invoker = object.invoker("foo", genericMethodType(4));
  object.define("foo", new FunctionReference(lookup().findStatic(DynamicObjectTest.class, "inAList", genericMethodType(3))));
  invoker.invoke(object, "plop", "da", "plop");
}
 
开发者ID:dynamid,项目名称:golo-lang-insa-citilab-historical-reference,代码行数:8,代码来源:DynamicObjectTest.java


示例12: unreflect

import java.lang.invoke.WrongMethodTypeException; //导入依赖的package包/类
/**
 * Create a method handle that will apply all transformations specified by the current method builder
 * and then call the {@code method} method. 
 * This method uses a cache if the method is a virtual method (either on class or interface)
 * 
 * @param lookup the lookup object used to find the @code method}
 * @param method the method called at the end of the transformation.
 * @return a new method handle constructed by applying all transformations on the target method.
 * @throws NoSuchMethodException throws is a method is not visible.
 * @throws NoSuchFieldException throws if a field is not visible.
 * @throws IllegalAccessException throws if a type or a member of a type is not visible.
 */
public MethodHandle unreflect(Lookup lookup, Method method) throws NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
  MethodHandle target = lookup.unreflect(method);
  MethodType targetType = target.type();
  if (!targetType.equals(sig)) {
    throw new WrongMethodTypeException("target type " + targetType + " is not equals to current type " + sig);
  }
  
  int modifiers = method.getModifiers();
  if (!Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers)) { // can be virtual
    target = new InliningCacheCallSite(target).dynamicInvoker();
  }
  return call(target);
}
 
开发者ID:forax,项目名称:proxy2,代码行数:26,代码来源:MethodBuilder.java


示例13: testBoundaryValues

import java.lang.invoke.WrongMethodTypeException; //导入依赖的package包/类
@Test
public void testBoundaryValues() throws Throwable {
    for (int badArity : new int[]{ -1, MAX_JVM_ARITY+1, MAX_JVM_ARITY }) {
        try {
            MethodHandle badmh = MH_hashArguments(badArity);
            throw new AssertionError("should not be able to build a 255-arity MH: "+badmh);
        } catch (IllegalArgumentException | WrongMethodTypeException ex) {
            System.out.println("OK: "+ex);
        }
    }
}
 
开发者ID:greghaskins,项目名称:openjdk-jdk7u-jdk,代码行数:12,代码来源:BigArityTest.java


示例14: testDynamicWrongArgs

import java.lang.invoke.WrongMethodTypeException; //导入依赖的package包/类
public void testDynamicWrongArgs() {
    expectScriptThrows(WrongMethodTypeException.class, () -> {
        exec("def x = new ArrayList(); return x.get('bogus');");
    });
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:6,代码来源:WhenThingsGoWrongTests.java


示例15: testDynamicArrayWrongIndex

import java.lang.invoke.WrongMethodTypeException; //导入依赖的package包/类
public void testDynamicArrayWrongIndex() {
    expectScriptThrows(WrongMethodTypeException.class, () -> {
        exec("def x = new long[1]; x[0]=1; return x['bogus'];");
    });
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:6,代码来源:WhenThingsGoWrongTests.java


示例16: testDynamicListWrongIndex

import java.lang.invoke.WrongMethodTypeException; //导入依赖的package包/类
public void testDynamicListWrongIndex() {
    expectScriptThrows(WrongMethodTypeException.class, () -> {
        exec("def x = new ArrayList(); x.add('foo'); return x['bogus'];");
    });
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:6,代码来源:WhenThingsGoWrongTests.java


示例17: assertType

import java.lang.invoke.WrongMethodTypeException; //导入依赖的package包/类
private static void assertType(final MethodHandle mh, final MethodType type) {
    if(!mh.type().equals(type)) {
        throw new WrongMethodTypeException("Expected type: " + type + " actual type: " + mh.type());
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:6,代码来源:GuardedInvocation.java


示例18: expectedThrowableClasses

import java.lang.invoke.WrongMethodTypeException; //导入依赖的package包/类
@Override
List<Class<? extends Throwable>> expectedThrowableClasses() {
    return List.of(BootstrapMethodError.class, WrongMethodTypeException.class);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:BootstrapMethodErrorTest.java


示例19: checkWMTE

import java.lang.invoke.WrongMethodTypeException; //导入依赖的package包/类
static void checkWMTE(ThrowingRunnable r) {
    checkWithThrowable(WrongMethodTypeException.class, null, r);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:4,代码来源:VarHandleBaseTest.java


示例20: getWMTEOOrOther

import java.lang.invoke.WrongMethodTypeException; //导入依赖的package包/类
Class<? extends Throwable> getWMTEOOrOther(Class<? extends Throwable> c) {
    return f.isExact ? WrongMethodTypeException.class : c;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:4,代码来源:VarHandleBaseTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java UnixNumericUserPrincipal类代码示例发布时间:2022-05-21
下一篇:
Java DecimalFormat类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap