Java 类org.eclipse.xtext.util.ReflectionUtil 实例源码

项目:xtext-extras    文件:StaticImplicitMethodsFeatureForTypeProvider.java   
protected Map<String, Collection<String>> denormalize(Multimap<Class<?>, Class<?>> classMapping) {
    Multimap<String, String> result = LinkedHashMultimap.create();
    for(Map.Entry<Class<?>, Class<?>> entry: classMapping.entries()) {
        Class<?> key = entry.getKey();
        Class<?> keyObjectType = ReflectionUtil.getObjectType(key);
        Class<?> value = entry.getValue();
        for(Method method: value.getDeclaredMethods()) {
            if (Modifier.isStatic(method.getModifiers()) && method.getParameterTypes().length > 0) {
                Class<?> paramType = method.getParameterTypes()[0];
                Class<?> paramObjectType = ReflectionUtil.getObjectType(paramType);     
                if (keyObjectType.isAssignableFrom(paramObjectType)) {
                    result.put(paramObjectType.getCanonicalName(), value.getCanonicalName());
                }
            }
        }
    }
    return ImmutableMultimap.copyOf(result).asMap();
}
项目:xtext-extras    文件:XbaseInterpreter.java   
/**
 * @param context unused in this context but required for dispatching
 * @param indicator unused in this context but required for dispatching
 */
@SuppressWarnings("unchecked")
protected Object _doEvaluate(XNumberLiteral literal, IEvaluationContext context, CancelIndicator indicator) {
    IResolvedTypes resolvedTypes = typeResolver.resolveTypes(literal);
    LightweightTypeReference expectedType = resolvedTypes.getExpectedType(literal);
    Class<? extends Number> type = numberLiterals.getJavaType(literal);
    if (expectedType != null && expectedType.isSubtypeOf(Number.class)) {
        try {
            Class<?> expectedClassType = getJavaType(expectedType.toJavaCompliantTypeReference().getType());
            if (expectedClassType.isPrimitive()) {
                expectedClassType = ReflectionUtil.getObjectType(expectedClassType);
            }
            if (Number.class != expectedClassType && Number.class.isAssignableFrom(expectedClassType)) {
                type = (Class<? extends Number>) expectedClassType;
            }
        } catch (ClassNotFoundException e) {
        }
    }
    return numberLiterals.numberValue(literal, type);
}
项目:xtext-core    文件:GenericModuleTest.java   
protected boolean isConfigured(CompoundModule module, Class<?> from, Object to, boolean singleton,
        boolean eagerSingleton, boolean provider) {
    for(Module m: module.getModules()) {
        if (m instanceof MethodBasedModule) {
            MethodBasedModule mod = (MethodBasedModule) m;
            if (mod.isSingleton()!=singleton)
                continue;
            if (mod.isEager()!=eagerSingleton)
                continue;
            if (provider != m instanceof ProviderModule)
                continue;
            if (!ReflectionUtil.getRawType(mod.getKeyType()).equals(from))
                continue;
            Object object = mod.invokeMethod();
            if (object==null && to==null || object!=null && object.equals(to))
                return true;
        }
    }
    return false;
}
项目:xtext-core    文件:ProviderModule.java   
protected boolean isInstanceOf(Type keyType, Class<?> class1) {
    return class1.isAssignableFrom(ReflectionUtil.getRawType(keyType));
}