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


Java GroovyCastException类代码示例

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


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

示例1: asType

import org.codehaus.groovy.runtime.typehandling.GroovyCastException; //导入依赖的package包/类
/**
 * Coerces this map to the given type, using the map's keys as the public
 * method names, and values as the implementation.  Typically the value
 * would be a closure which behaves like the method implementation.
 *
 * @param map   this map
 * @param clazz the target type
 * @return a Proxy of the given type, which defers calls to this map's elements.
 * @since 1.0
 */
@SuppressWarnings("unchecked")
public static <T> T asType(Map map, Class<T> clazz) {
    if (!(clazz.isInstance(map)) && clazz.isInterface() && !Traits.isTrait(clazz)) {
        return (T) Proxy.newProxyInstance(
                clazz.getClassLoader(),
                new Class[]{clazz},
                new ConvertedMap(map));
    }
    try {
        return asType((Object) map, clazz);
    } catch (GroovyCastException ce) {
        try {
            return (T) ProxyGenerator.INSTANCE.instantiateAggregateFromBaseClass(map, clazz);
        } catch (GroovyRuntimeException cause) {
            throw new GroovyCastException("Error casting map to " + clazz.getName() +
                    ", Reason: " + cause.getMessage());
        }
    }
}
 
开发者ID:yajsw,项目名称:yajsw,代码行数:30,代码来源:DefaultGroovyMethods.java

示例2: instantiateAggregate

import org.codehaus.groovy.runtime.typehandling.GroovyCastException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public GroovyObject instantiateAggregate(Map closureMap, List<Class> interfaces, Class clazz, Object[] constructorArgs) {
    if (clazz != null && Modifier.isFinal(clazz.getModifiers())) {
        throw new GroovyCastException("Cannot coerce a map to class " + clazz.getName() + " because it is a final class");
    }
    Map<Object,Object> map = closureMap != null ? closureMap : EMPTY_CLOSURE_MAP;
    ProxyGeneratorAdapter adapter = createAdapter(map, interfaces, null, clazz);

    return adapter.proxy(map, constructorArgs);
}
 
开发者ID:apache,项目名称:groovy,代码行数:11,代码来源:ProxyGenerator.java

示例3: parseCastWrongClassScript_throwGroovyCastException

import org.codehaus.groovy.runtime.typehandling.GroovyCastException; //导入依赖的package包/类
@Test(expected = GroovyCastException.class)
public void parseCastWrongClassScript_throwGroovyCastException() {
  //when
  parseClassFromScript("def plot = new Plot() \n" + "Line line = (Line) Plot ");
}
 
开发者ID:twosigma,项目名称:beaker-notebook-archive,代码行数:6,代码来源:GroovyEvaluatorExceptionTest.java


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