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


Java TypeResolver.Unknown方法代码示例

本文整理汇总了Java中net.jodah.typetools.TypeResolver.Unknown方法的典型用法代码示例。如果您正苦于以下问题:Java TypeResolver.Unknown方法的具体用法?Java TypeResolver.Unknown怎么用?Java TypeResolver.Unknown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.jodah.typetools.TypeResolver的用法示例。


在下文中一共展示了TypeResolver.Unknown方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createAndInjectViewModel

import net.jodah.typetools.TypeResolver; //导入方法依赖的package包/类
/**
 * This method is used to create and inject the ViewModel for a given View
 * instance.
 * 
 * The following checks are done:
 * <ul>
 * <li>Check whether the View class specifies a ViewModel type as generic
 * type.</li>
 * <li>Check whether the View has a field with a matching ViewModel type and
 * the annotation {@link InjectViewModel}.</li>
 * 
 * <li>Check whether field in the view instance already contains a ViewModel
 * instance. In this case nothing will happen to the existing ViewModel
 * instance.</li>
 * 
 * </ul>
 * 
 * If a suitable field was found a new ViewModel instance will be created
 * and injected into the field. After that the given Consumer function will
 * be applied with the injected ViewModel instance as argument.
 * 
 * @param view
 *            the view instance.
 * @param <V>
 *            the generic type of the View.
 * @param <VM>
 *            the generic type of the ViewModel.
 * @param newVmConsumer
 *            a Consumer function that is applied when a new ViewModel
 *            instance is created.
 * 
 * @throws RuntimeException
 *             if there is a ViewModel field in the View with the
 *             {@link InjectViewModel} annotation whose type doesn't match
 *             the generic ViewModel type from the View class.
 */
public static <V extends View<? extends VM>, VM extends ViewModel> void createAndInjectViewModel(final V view,
        Consumer<ViewModel> newVmConsumer) {
    final Class<?> viewModelType = TypeResolver.resolveRawArgument(View.class, view.getClass());

    if (viewModelType == ViewModel.class) {
        // if no viewModel can be created, we have to check if the user has
        // tried to inject a ViewModel
        final List<Field> viewModelFields = ViewLoaderReflectionUtils.getViewModelFields(view.getClass());

        if (!viewModelFields.isEmpty()) {
            throw new RuntimeException("The given view of type <" + view.getClass()
                    + "> has no generic viewModel type declared but tries to inject a viewModel.");
        }
        return;
    }
    if (viewModelType == TypeResolver.Unknown.class) {
        return;
    }

    final Optional<Field> fieldOptional = getViewModelField(view.getClass(), viewModelType);
    if (fieldOptional.isPresent()) {
        Field field = fieldOptional.get();

        ReflectionUtils.accessField(field, () -> {
            Object existingViewModel = field.get(view);

            if (existingViewModel == null) {
                final Object newViewModel = DependencyInjector.getInstance().getInstanceOf(viewModelType);

                field.set(view, newViewModel);

                newVmConsumer.accept((ViewModel) newViewModel);
            }
        }, "Can't inject ViewModel of type <" + viewModelType + "> into the view <" + view + ">");

    }
}
 
开发者ID:cmlanche,项目名称:easyMvvmFx,代码行数:74,代码来源:ViewLoaderReflectionUtils.java

示例2: resolveType

import net.jodah.typetools.TypeResolver; //导入方法依赖的package包/类
protected static Class<?> resolveType(Type type, MethodWrapper src) {
    if (type instanceof Class) {
        return PrimitiveTypeResolver.resolve((Class<?>) type);
    } else if (type instanceof ParameterizedType) {
        return (Class<?>) ((ParameterizedType) type).getRawType();
    }
    Class<?> resolvedType = TypeResolver.resolveRawArgument(type, src.getTargetClass());
    if (resolvedType == TypeResolver.Unknown.class) {
        // TODO: Decide what exception to throw here
        throw new RuntimeException("Cannot infer type of method parameter");
    } else {
        return resolvedType;
    }
}
 
开发者ID:fnproject,项目名称:fdk-java,代码行数:15,代码来源:MethodTypeWrapper.java

示例3: getRequestClass

import net.jodah.typetools.TypeResolver; //导入方法依赖的package包/类
public Class<?> getRequestClass(Class<?> usecaseClass) {
    Class<?>[] typeArgs = TypeResolver.resolveRawArguments(Usecase.class, usecaseClass);
    Class<?> requestClass = typeArgs[0];
    if (requestClass == TypeResolver.Unknown.class) {
        throw new UsecaseExecutorException("Could not resolve usecase request type for class '" + usecaseClass.getName() + "'. Hint: The concrete usecase class is required to resolve the request class.");
    }

    return requestClass;
}
 
开发者ID:casid,项目名称:jusecase,代码行数:10,代码来源:UsecaseRequestResolver.java

示例4: Factory

import net.jodah.typetools.TypeResolver; //导入方法依赖的package包/类
/**
 * Creates a new factory with a constructor function that instantiates the factory object,
 * and with a processor that is capable of mutating the instantiated object after its initialization.
 *
 * A factory's processor may be modified to allow specific customization of instantiated objects before it is used.
 * @param id The identifier for this factory type
 * @param constructor The construction function
 * @param processor The processor function
 */
@SuppressWarnings("unchecked")
public Factory(String id, Supplier<T> constructor, Function<T, T> processor) {
	this.id = id;
	this.constructor = constructor;
	this.processor = processor;
	Class<?> type = TypeResolver.resolveRawArguments(Function.class, processor.getClass())[1];
	if (type == TypeResolver.Unknown.class || type == Identifiable.class) {
		type = TypeResolver.resolveRawArgument(Supplier.class, constructor.getClass());
	}
	this.type = (Class<? extends T>) type;
}
 
开发者ID:NOVA-Team,项目名称:NOVA-Core,代码行数:21,代码来源:Factory.java

示例5: validateSimpleFunctionGenericTypes

import net.jodah.typetools.TypeResolver; //导入方法依赖的package包/类
static void validateSimpleFunctionGenericTypes(Class<?>[] typeArgs, Class<?> subType) {
    if (typeArgs == null) {
        throw new IllegalStateException("Could not resolve any generic type information from the given " +
                "function of type: " + subType.getName() + ". " + GENERIC_TYPE_RESOLUTION_FAILURE_MESSAGE);
    }
    if (typeArgs.length != 2 || typeArgs[0] == TypeResolver.Unknown.class || typeArgs[1] == TypeResolver.Unknown.class) {
        throw new IllegalStateException("Could not resolve sufficient generic type information from the given " +
                "function of type: " + subType.getName() + ", resolved: " + Arrays.toString(typeArgs) + ". " +
                GENERIC_TYPE_RESOLUTION_FAILURE_MESSAGE);
    }
}
 
开发者ID:npgall,项目名称:cqengine,代码行数:12,代码来源:QueryFactory.java

示例6: validateMultiValueFunctionGenericTypes

import net.jodah.typetools.TypeResolver; //导入方法依赖的package包/类
static void validateMultiValueFunctionGenericTypes(Class<?>[] typeArgs, Class<?> subType) {
    if (typeArgs == null) {
        throw new IllegalStateException("Could not resolve any generic type information from the given " +
                "function of type: " + subType.getName() + ". " + GENERIC_TYPE_RESOLUTION_FAILURE_MESSAGE);
    }
    if (typeArgs.length != 3 || typeArgs[0] == TypeResolver.Unknown.class) {
        throw new IllegalStateException("Could not resolve sufficient generic type information from the given " +
                "function of type: " + subType.getName() + ", resolved: " + Arrays.toString(typeArgs) + ". " +
                GENERIC_TYPE_RESOLUTION_FAILURE_MESSAGE);
    }
}
 
开发者ID:npgall,项目名称:cqengine,代码行数:12,代码来源:QueryFactory.java

示例7: testValidateSimpleFunctionGenericTypes_InvalidTypeArgs1

import net.jodah.typetools.TypeResolver; //导入方法依赖的package包/类
@Test(expected = IllegalStateException.class)
public void testValidateSimpleFunctionGenericTypes_InvalidTypeArgs1() {
    Class<?>[] typeArgs = new Class<?>[] {TypeResolver.Unknown.class, Integer.class};
    validateSimpleFunctionGenericTypes(typeArgs, SimpleFunction.class);
}
 
开发者ID:npgall,项目名称:cqengine,代码行数:6,代码来源:QueryFactoryTest.java

示例8: testValidateSimpleFunctionGenericTypes_InvalidTypeArgs2

import net.jodah.typetools.TypeResolver; //导入方法依赖的package包/类
@Test(expected = IllegalStateException.class)
public void testValidateSimpleFunctionGenericTypes_InvalidTypeArgs2() {
    Class<?>[] typeArgs = new Class<?>[] {Car.class, TypeResolver.Unknown.class};
    validateSimpleFunctionGenericTypes(typeArgs, SimpleFunction.class);
}
 
开发者ID:npgall,项目名称:cqengine,代码行数:6,代码来源:QueryFactoryTest.java

示例9: testValidateMultiValueFunctionGenericTypes_InvalidTypeArgs

import net.jodah.typetools.TypeResolver; //导入方法依赖的package包/类
@Test(expected = IllegalStateException.class)
public void testValidateMultiValueFunctionGenericTypes_InvalidTypeArgs() {
    Class<?>[] typeArgs = new Class<?>[] {TypeResolver.Unknown.class, Integer.class, List.class};
    validateMultiValueFunctionGenericTypes(typeArgs, MultiValueFunction.class);
}
 
开发者ID:npgall,项目名称:cqengine,代码行数:6,代码来源:QueryFactoryTest.java

示例10: createViewModel

import net.jodah.typetools.TypeResolver; //导入方法依赖的package包/类
/**
 * Creates a viewModel instance for a View type. The type of the view is
 * determined by the given view instance.
 *
 * For the creation of the viewModel the {@link DependencyInjector} is used.
 * 
 * @param view
 *            the view instance that is used to find out the type of the
 *            ViewModel
 * @param <ViewType>
 *            the generic view type
 * @param <ViewModelType>
 *            the generic viewModel type
 * @return the viewModel instance or <code>null</code> if the viewModel type
 *         can't be found or the viewModel can't be created.
 */
@SuppressWarnings("unchecked")
public static <ViewType extends View<? extends ViewModelType>, ViewModelType extends ViewModel> ViewModelType createViewModel(
        ViewType view) {
    final Class<?> viewModelType = TypeResolver.resolveRawArgument(View.class, view.getClass());
    if (viewModelType == ViewModel.class) {
        return null;
    }
    if (TypeResolver.Unknown.class == viewModelType) {
        return null;
    }
    return (ViewModelType) DependencyInjector.getInstance().getInstanceOf(viewModelType);
}
 
开发者ID:cmlanche,项目名称:easyMvvmFx,代码行数:29,代码来源:ViewLoaderReflectionUtils.java


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