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


Java Constructor类代码示例

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


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

示例1: returnIOSGDXFacebookWhenOnIOS

import com.badlogic.gdx.utils.reflect.Constructor; //导入依赖的package包/类
@Test
public void returnIOSGDXFacebookWhenOnIOS() {
    Application mockApplication = mock(Application.class);
    when(mockApplication.getType()).thenReturn(Application.ApplicationType.iOS);
    Gdx.app = mockApplication;

    try {
        Constructor mockConstructor = PowerMockito.mock(Constructor.class);
        GDXFacebook mockFacebook = mock(IOSGDXFacebook.class);

        when(ClassReflection.forName(GDXFacebookVars.CLASSNAME_IOS)).thenReturn(IOSGDXFacebook.class);
        when(ClassReflection.getConstructor(IOSGDXFacebook.class, GDXFacebookConfig.class)).thenReturn(mockConstructor);
        when(mockConstructor.newInstance(anyObject())).thenReturn(mockFacebook);

    } catch (ReflectionException e) {
        e.printStackTrace();
    }

    facebook = GDXFacebookSystem.install(new GDXFacebookConfig());
    assertTrue(facebook instanceof IOSGDXFacebook);
}
 
开发者ID:TomGrill,项目名称:gdx-facebook,代码行数:22,代码来源:GDXFacebookLoaderUnitTests.java

示例2: returnDesktopGDXFacebookWhenOnDesktop

import com.badlogic.gdx.utils.reflect.Constructor; //导入依赖的package包/类
@Test
public void returnDesktopGDXFacebookWhenOnDesktop() {
    Application mockApplication = mock(Application.class);
    when(mockApplication.getType()).thenReturn(Application.ApplicationType.Desktop);
    Gdx.app = mockApplication;

    try {
        Constructor mockConstructor = PowerMockito.mock(Constructor.class);
        GDXFacebook mockFacebook = mock(DesktopGDXFacebook.class);

        when(ClassReflection.forName(GDXFacebookVars.CLASSNAME_DESKTOP)).thenReturn(DesktopGDXFacebook.class);
        when(ClassReflection.getConstructor(DesktopGDXFacebook.class, GDXFacebookConfig.class)).thenReturn(mockConstructor);
        when(mockConstructor.newInstance(anyObject())).thenReturn(mockFacebook);

    } catch (ReflectionException e) {
        e.printStackTrace();
    }

    facebook = GDXFacebookSystem.install(new GDXFacebookConfig());
    assertTrue(facebook instanceof DesktopGDXFacebook);
}
 
开发者ID:TomGrill,项目名称:gdx-facebook,代码行数:22,代码来源:GDXFacebookLoaderUnitTests.java

示例3: returnHTMLGDXFacebookWhenOnWebGL

import com.badlogic.gdx.utils.reflect.Constructor; //导入依赖的package包/类
@Test
public void returnHTMLGDXFacebookWhenOnWebGL() {
    Application mockApplication = mock(Application.class);
    when(mockApplication.getType()).thenReturn(Application.ApplicationType.WebGL);
    Gdx.app = mockApplication;

    try {
        Constructor mockConstructor = PowerMockito.mock(Constructor.class);
        GDXFacebook mockFacebook = mock(HTMLGDXFacebook.class);

        when(ClassReflection.forName(GDXFacebookVars.CLASSNAME_HTML)).thenReturn(HTMLGDXFacebook.class);
        when(ClassReflection.getConstructor(HTMLGDXFacebook.class, GDXFacebookConfig.class)).thenReturn(mockConstructor);
        when(mockConstructor.newInstance(anyObject())).thenReturn(mockFacebook);

    } catch (ReflectionException e) {
        e.printStackTrace();
    }

    facebook = GDXFacebookSystem.install(new GDXFacebookConfig());
    assertTrue(facebook instanceof HTMLGDXFacebook);
}
 
开发者ID:TomGrill,项目名称:gdx-facebook,代码行数:22,代码来源:GDXFacebookLoaderUnitTests.java

示例4: createComponents

import com.badlogic.gdx.utils.reflect.Constructor; //导入依赖的package包/类
/** @param types classes of components to initiate.
 * @param context will contain components mapped by their classes tree.
 * @return an array containing all created components. */
private Array<Object> createComponents(final Array<Class<?>> types, final Context context) {
    final Array<Object> components = GdxArrays.newArray();
    for (final Class<?> type : types) {
        final Constructor[] constructors = ClassReflection.getConstructors(type);
        if (constructors == null || constructors.length == 0) {
            throw new ContextInitiationException(
                    type + " has no available public constructors. Unable to create component.");
        } else if (constructors.length == 1) {
            // Single constructor - trying to invoke it:
            addIfNotNull(components, processConstructor(constructors[0], context));
        } else {
            // Multiple constructors - trying to find a suitable one:
            addIfNotNull(components, processConstructor(findSuitableConstructor(constructors), context));
        }
    }
    int initiationIterations = 0;
    while (GdxArrays.isNotEmpty(delayedConstructions)) {
        validateIterationsAmount(initiationIterations);
        processDelayedConstructions(context, components);
        initiationIterations++;
    }
    return components;
}
 
开发者ID:gdx-libs,项目名称:gdx-autumn,代码行数:27,代码来源:ContextInitializer.java

示例5: processConstructor

import com.badlogic.gdx.utils.reflect.Constructor; //导入依赖的package包/类
/** @param constructor if all its parameter types are available in context, will be invoked and the instance will be
 *            added to context.
 * @param context will be used to retrieve constructor parameters.
 * @return an instance of the component or null if it cannot be constructed yet. */
private Object processConstructor(final Constructor constructor, final Context context) {
    Object component;
    if (constructor.getParameterTypes().length == 0) {
        // Passing any empty object array avoid unnecessary array allocation.
        component = invokeConstructor(constructor, Strings.EMPTY_ARRAY);
    } else {
        if (areContructorParametersAvailable(constructor, context)) {
            final Object[] parameters = MethodInvocation.getParametersFromContext(constructor.getParameterTypes(),
                    context);
            component = invokeConstructor(constructor, parameters);
        } else {
            delayedConstructions.add(constructor);
            return null;
        }
    }
    context.map(component);
    return component;
}
 
开发者ID:gdx-libs,项目名称:gdx-autumn,代码行数:23,代码来源:ContextInitializer.java

示例6: createObject

import com.badlogic.gdx.utils.reflect.Constructor; //导入依赖的package包/类
/** @param constructor will be used to construct the instance.
 * @param parameterTypes will be used to extract constructor parameters from the context.
 * @return an instance of the class.
 * @throws RuntimeException due to reflection issues. */
protected Object createObject(final Constructor constructor, final Class<?>[] parameterTypes) {
    try {
        if (parameterTypes.length == 0) {
            return constructor.newInstance(Providers.EMPTY_ARRAY);
        }
        final Object[] dependencies = new Object[parameterTypes.length];
        for (int index = 0, length = dependencies.length; index < length; index++) {
            dependencies[index] = get(parameterTypes[index], null, new ConstructorMember(constructor));
        }
        return constructor.newInstance(dependencies);
    } catch (final Exception exception) {
        throw new RuntimeException("Unable to create an instance of: " + constructor.getDeclaringClass(),
                exception);
    }
}
 
开发者ID:czyzby,项目名称:gdx-lml,代码行数:20,代码来源:DefaultContext.java

示例7: processConstructor

import com.badlogic.gdx.utils.reflect.Constructor; //导入依赖的package包/类
/** @param constructor if all its parameter types are available in context, will be invoked and the instance will be
 *            added to context.
 * @param context will be used to retrieve constructor parameters.
 * @return an instance of the component or null if it cannot be constructed yet. */
private Object processConstructor(final Constructor constructor, final Context context) {
    Object component;
    if (constructor.getParameterTypes().length == 0) {
        // Passing any empty object array avoid unnecessary array allocation.
        component = invokeConstructor(constructor, Strings.EMPTY_ARRAY);
    } else {
        if (areContructorParametersAvailable(constructor, context)) {
            final Object[] parameters = MethodInvocation.getParametersFromContext(constructor.getParameterTypes(),
                    context);
            component = invokeConstructor(constructor, parameters);
        } else {
            return null;
        }
    }
    context.map(component);
    return component;
}
 
开发者ID:czyzby,项目名称:gdx-lml,代码行数:22,代码来源:ContextInitializer.java

示例8: getSystem

import com.badlogic.gdx.utils.reflect.Constructor; //导入依赖的package包/类
private <ES extends EntitySystem> ES getSystem(Class<ES> clazz) {
    ES entitySystem = engine.getSystem(clazz);
    if (entitySystem == null) {
        try {
            Constructor constructor = findConstructor(clazz);
            entitySystem = (ES) constructor.newInstance((Object[]) null);
        } catch (Exception ex) {
            Log.debug(tag, "Error instance entitySystem %s", clazz.getSimpleName());

        }
        if (entitySystem != null) {
            engine.addSystem(entitySystem);
        } else {
            Log.debug(tag, "Error instance entitySystem %s", clazz.getSimpleName());
        }


    }
    return entitySystem;

}
 
开发者ID:Rubentxu,项目名称:GDX-Logic-Bricks,代码行数:22,代码来源:EntityBuilder.java

示例9: getBrickBuilder

import com.badlogic.gdx.utils.reflect.Constructor; //导入依赖的package包/类
public <B extends BrickBuilder> B getBrickBuilder(Class<B> clazzBuilder) {
    B builder = (B) bricksBuilders.get(clazzBuilder);
    if (builder == null) {
        synchronized (clazzBuilder) {
            try {
                Constructor constructor = findConstructor(clazzBuilder);
                builder = (B) constructor.newInstance((Object[]) null);
                bricksBuilders.put(clazzBuilder, builder);
            } catch (Exception e) {
                Log.debug(tag, "Error instance actuatorBuilder %s" + clazzBuilder.getSimpleName());
            }
        }
    }
    return builder;

}
 
开发者ID:Rubentxu,项目名称:GDX-Logic-Bricks,代码行数:17,代码来源:LBBuilders.java

示例10: newValueController

import com.badlogic.gdx.utils.reflect.Constructor; //导入依赖的package包/类
/**
 * 
 * @param clazz
 *            class of the value
 * @param widget
 *            the widget for the value
 * @param args
 *            arguments are interpreted as a list of objects paired in
 *            class, value ([class, value, class, value]), and they would be
 *            use to find the right constructor
 */
@SuppressWarnings("unchecked")
private <V extends ValueController<T, S>, T extends Actor, W extends T, S> V newValueController(
		Class<V> clazz, W widget, Object... args) {
	try {
		V value;
		if (args.length == 0) {
			value = ClassReflection.newInstance(clazz);
		} else {
			Class[] argsClass = new Class[args.length / 2];
			Object[] argsObject = new Object[args.length / 2];
			for (int i = 0; i < args.length; i += 2) {
				argsClass[i] = (Class) args[i];
				argsObject[i] = args[i + 1];
			}
			Constructor constructor = ClassReflection
					.getDeclaredConstructor(clazz, argsClass);
			value = (V) constructor.newInstance(argsObject);
		}
		value.build(controller, widget);
		return value;
	} catch (ReflectionException e) {
		Gdx.app.error("OptionsController", "No value", e);
	}
	return null;
}
 
开发者ID:e-ucm,项目名称:ead,代码行数:37,代码来源:OptionsController.java

示例11: setup

import com.badlogic.gdx.utils.reflect.Constructor; //导入依赖的package包/类
@SuppressWarnings("static-access")
@Before
public void setup() {

	Gdx.app = Mockito.mock(HeadlessApplication.class);

	when(Gdx.app.getPreferences(anyString())).thenReturn(new PreferencesStub());

	config = new TwitterConfig();

	PowerMockito.mockStatic(ClassReflection.class);
	classReflectionMock = Mockito.mock(ClassReflection.class);

	PowerMockito.mockStatic(Field.class);
	fieldMock = Mockito.mock(Field.class);

	PowerMockito.mockStatic(Constructor.class);
	constructorMock = Mockito.mock(Constructor.class);

	PowerMockito.mockStatic(Method.class);
	methodMock = Mockito.mock(Method.class);

	activityStub = new ActivityStub();
	twitterAPIStub = new TwitterAPIStub(config);
	gdxStub = new GdxStub();
	supportFragmentStub = new SupportFragmentStub();
	fragmentStub = new FragmentStub();
	gdxLifecycleListenerStub = new GdxLifecycleListenerStub();

	try {
		Mockito.when(classReflectionMock.forName("com.badlogic.gdx.Gdx")).thenReturn(gdxStub.getClass());
		Mockito.when(classReflectionMock.getField(gdxStub.getClass(), "app")).thenReturn(fieldMock);
		Mockito.when(fieldMock.get(null)).thenReturn(Gdx.app);

	} catch (ReflectionException e) {
	}
}
 
开发者ID:TomGrill,项目名称:gdx-twitter,代码行数:38,代码来源:TwitterSystemUnitTests.java

示例12: androidPremocking

import com.badlogic.gdx.utils.reflect.Constructor; //导入依赖的package包/类
private void androidPremocking() {

        Application mockApplication = mock(Application.class);
        when(mockApplication.getType()).thenReturn(Application.ApplicationType.Android);
        Gdx.app = mockApplication;

        try {
            mockConstructor = PowerMockito.mock(Constructor.class);
            mockFacebook = mock(AndroidGDXFacebook.class);
            mockField = mock(Field.class);
            mockObject = mock(Object.class);
            mockMethod = mock(Method.class);

            when(ClassReflection.forName(GDXFacebookVars.CLASSNAME_ANDROID)).thenReturn(AndroidGDXFacebook.class);
            when(ClassReflection.getConstructor(AndroidGDXFacebook.class, GDXFacebookConfig.class)).thenReturn(mockConstructor);
            when(mockConstructor.newInstance(anyObject())).thenReturn(mockFacebook);


            when(ClassReflection.forName("com.badlogic.gdx.Gdx")).thenReturn(Gdx.class);
            when(ClassReflection.getField(Gdx.class, "app")).thenReturn(mockField);
            when(mockField.get(null)).thenReturn(mockObject);


            when(ClassReflection.forName("com.badlogic.gdx.backends.android.AndroidEventListener")).thenReturn(AndroidEventListener.class);
            when(ClassReflection.forName("android.app.Activity")).thenReturn(Activity.class);

        } catch (ReflectionException e) {
            e.printStackTrace();
        }
    }
 
开发者ID:TomGrill,项目名称:gdx-facebook,代码行数:31,代码来源:GDXFacebookLoaderUnitTests.java

示例13: areContructorParametersAvailable

import com.badlogic.gdx.utils.reflect.Constructor; //导入依赖的package包/类
/** @param constructor its parameters will be validated.
 * @param context contains components.
 * @return true if all constructor parameters can be injected. */
private static boolean areContructorParametersAvailable(final Constructor constructor, final Context context) {
    for (final Class<?> parameterType : constructor.getParameterTypes()) {
        if (!context.isPresent(parameterType) && !context.isProviderPresentFor(parameterType)) {
            return false;
        }
    }
    return true;
}
 
开发者ID:gdx-libs,项目名称:gdx-autumn,代码行数:12,代码来源:ContextInitializer.java

示例14: invokeConstructor

import com.badlogic.gdx.utils.reflect.Constructor; //导入依赖的package包/类
/** @param constructor will be invoked.
 * @param parameters will be used to invoke the constructor.
 * @return a new instance of the class.
 * @throws ContextInitiationException if unable to invoke the constructor. */
private static Object invokeConstructor(final Constructor constructor, final Object[] parameters) {
    try {
        return constructor.newInstance(parameters);
    } catch (final ReflectionException exception) {
        throw new ContextInitiationException("Unable to create a new instance of class: "
                + constructor.getDeclaringClass() + " with constructor: " + constructor + " with parameters: "
                + GdxArrays.newArray(parameters), exception);
    }
}
 
开发者ID:gdx-libs,项目名称:gdx-autumn,代码行数:14,代码来源:ContextInitializer.java

示例15: processDelayedConstructions

import com.badlogic.gdx.utils.reflect.Constructor; //导入依赖的package包/类
/** @param context used to get constructor parameters.
 * @param components will contain created components. */
private void processDelayedConstructions(final Context context, final Array<Object> components) {
    final Array<Constructor> stillMissingConstructions = GdxArrays.newArray();
    for (final Constructor constructor : delayedConstructions) {
        final Object component = processConstructor(constructor, context);
        if (component != null) {
            components.add(component);
        } else {
            stillMissingConstructions.add(constructor);
        }
    }
    delayedConstructions = stillMissingConstructions;
}
 
开发者ID:gdx-libs,项目名称:gdx-autumn,代码行数:15,代码来源:ContextInitializer.java


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