com.badlogic.gdx.utils.reflect.Method Java Examples

The following examples show how to use com.badlogic.gdx.utils.reflect.Method. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractConsole.java    From libgdx-inGameConsole with Apache License 2.0 6 votes vote down vote up
@Override public void printCommands () {
	for (Method m : getAllMethods()) {
		if (m.isPublic() && ConsoleUtils.canDisplayCommand(this, m)) {
			String s = "";
			s += m.getName();
			s += " : ";

			Class<?>[] params = m.getParameterTypes();
			for (int i = 0; i < params.length; i++) {
				s += params[i].getSimpleName();
				if (i < params.length - 1) {
					s += ", ";
				}
			}

			log(s);
		}
	}
}
 
Example #2
Source File: GLTFBinaryExporter.java    From gdx-gltf with Apache License 2.0 5 votes vote down vote up
public static void savePNG(FileHandle file, Pixmap pixmap){
	if(Gdx.app.getType() == ApplicationType.WebGL){
		throw new GdxRuntimeException("saving pixmap not supported for WebGL");
	}else{
		// call PixmapIO.writePNG(file, pixmap); via reflection to
		// avoid compilation error with GWT.
		try {
			Class pixmapIO = ClassReflection.forName("com.badlogic.gdx.graphics.PixmapIO");
			Method pixmapIO_writePNG = ClassReflection.getMethod(pixmapIO, "writePNG", FileHandle.class, Pixmap.class);
			pixmapIO_writePNG.invoke(null, file, pixmap);
		} catch (ReflectionException e) {
			throw new GdxRuntimeException(e);
		} 
	}
}
 
Example #3
Source File: AnnotationFinder.java    From gdx-fireapp with Apache License 2.0 5 votes vote down vote up
public static <T extends java.lang.annotation.Annotation> T getMethodAnnotation(Class<T> annotationType, Object object) {
    T result = null;
    Method[] methods = ClassReflection.getMethods(object.getClass());
    for (Method m : methods) {
        Annotation[] annotations = m.getDeclaredAnnotations();
        Annotation a = m.getDeclaredAnnotation(annotationType);
        if (a != null) {
            result = a.getAnnotation(annotationType);
            break;
        }
    }
    return result;
}
 
Example #4
Source File: GDXFacebookLoaderUnitTests.java    From gdx-facebook with Apache License 2.0 5 votes vote down vote up
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();
        }
    }
 
Example #5
Source File: AbstractConsole.java    From libgdx-inGameConsole with Apache License 2.0 5 votes vote down vote up
private ArrayList<Method> getAllMethods () {
	ArrayList<Method> methods = new ArrayList<Method>();
	Class c = exec.getClass();
	while (c != Object.class) {
		Collections.addAll(methods, ClassReflection.getDeclaredMethods(c));
		c = c.getSuperclass();
	}
	return methods;
}
 
Example #6
Source File: CommandCompleter.java    From libgdx-inGameConsole with Apache License 2.0 5 votes vote down vote up
public void set (CommandExecutor ce, String s) {
	reset();
	setString = s.toLowerCase();
	Array<Method> methods = getAllMethods(ce);
	for (Method m : methods) {
		String name = m.getName();
		if (name.toLowerCase().startsWith(setString) && ConsoleUtils.canDisplayCommand(ce.console, m)) {
			possibleCommands.add(name);
		}
	}
	iterator = new ObjectSetIterator<>(possibleCommands);
}
 
Example #7
Source File: Skin.java    From gdx-skineditor with Apache License 2.0 5 votes vote down vote up
static private Method findMethod(Class type, String name) {
	Method[] methods = ClassReflection.getMethods(type);
	for (int i = 0, n = methods.length; i < n; i++) {
		Method method = methods[i];
		if (method.getName().equals(name))
			return method;
	}
	return null;
}
 
Example #8
Source File: ConsoleUtils.java    From libgdx-inGameConsole with Apache License 2.0 4 votes vote down vote up
public static boolean canExecuteCommand (Console console, Method method) {
	return console.isExecuteHiddenCommandsEnabled() || !method.isAnnotationPresent(HiddenCommand.class);
}
 
Example #9
Source File: ConsoleUtils.java    From libgdx-inGameConsole with Apache License 2.0 4 votes vote down vote up
public static boolean canDisplayCommand (Console console, Method method) {
	return console.isDisplayHiddenCommandsEnabled() || !method.isAnnotationPresent(HiddenCommand.class);
}