當前位置: 首頁>>代碼示例>>Java>>正文


Java ClassReflection類代碼示例

本文整理匯總了Java中com.badlogic.gdx.utils.reflect.ClassReflection的典型用法代碼示例。如果您正苦於以下問題:Java ClassReflection類的具體用法?Java ClassReflection怎麽用?Java ClassReflection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ClassReflection類屬於com.badlogic.gdx.utils.reflect包,在下文中一共展示了ClassReflection類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: read

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入依賴的package包/類
@Override
public Object read(ByteBuffer byteBuffer) {
    try {
        byte id = byteBuffer.get();
        if(id == -2){
           return FrameworkSerializer.read(byteBuffer);
        }else {
            Class<?> type = Registrator.getByID(id);
            Packet packet = (Packet) ClassReflection.newInstance(type);
            packet.read(byteBuffer);
            return packet;
        }
    }catch (ReflectionException e){
        throw new RuntimeException(e);
    }
}
 
開發者ID:Anuken,項目名稱:Mindustry,代碼行數:17,代碼來源:ByteSerializer.java

示例2: save

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入依賴的package包/類
void save(SaveSlot slot){

		Vars.ui.loadfrag.show("$text.saveload");

		Timers.runTask(5f, () -> {
			hide();
			Vars.ui.loadfrag.hide();
			try{
				slot.save();
			}catch(Throwable e){
				e = (e.getCause() == null ? e : e.getCause());

				Vars.ui.showError("[orange]"+Bundles.get("text.savefail")+"\n[white]" + ClassReflection.getSimpleName(e.getClass()) + ": " + e.getMessage() + "\n" + "at " + e.getStackTrace()[0].getFileName() + ":" + e.getStackTrace()[0].getLineNumber());
			}
		});
	}
 
開發者ID:Anuken,項目名稱:Mindustry,代碼行數:17,代碼來源:SaveDialog.java

示例3: runExitSave

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入依賴的package包/類
private void runExitSave(){
	if(Vars.control.getSaves().getCurrent() == null ||
			!Vars.control.getSaves().getCurrent().isAutosave()){
		GameState.set(State.menu);
		Vars.control.getTutorial().reset();
		return;
	}

	Vars.ui.loadfrag.show("$text.saveload");

	Timers.runTask(5f, () -> {
		Vars.ui.loadfrag.hide();
		try{
			Vars.control.getSaves().getCurrent().save();
		}catch(Throwable e){
			e = (e.getCause() == null ? e : e.getCause());
			Vars.ui.showError("[orange]"+ Bundles.get("text.savefail")+"\n[white]" + ClassReflection.getSimpleName(e.getClass()) + ": " + e.getMessage() + "\n" + "at " + e.getStackTrace()[0].getFileName() + ":" + e.getStackTrace()[0].getLineNumber());
		}
		GameState.set(State.menu);
	});
}
 
開發者ID:Anuken,項目名稱:Mindustry,代碼行數:22,代碼來源:PausedDialog.java

示例4: getClass

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入依賴的package包/類
/**
 * Returns the Class matching the name of the JsonValue, or null if there is no match or it's nameless.
 */
private Class getClass(JsonValue value, ObjectMap<String, Class> tagsToClasses) {
    if (value.name() != null && value.name().length() > 0) {
        String className = value.name();
        Class type = tagsToClasses.get(className);
        if (type == null) {
            try {
                type = ClassReflection.forName(className);
            } catch (ReflectionException ex) {
                type = null;
            }
        }
        return type;
    }
    return null;
}
 
開發者ID:CypherCove,項目名稱:gdx-cclibs,代碼行數:19,代碼來源:JsonFieldUpdater.java

示例5: getStaticFields

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入依賴的package包/類
private OrderedMap<String, Field> getStaticFields(Class type) {
    if (staticFields.containsKey(type))
        return staticFields.get(type);
    Field[] fields = ClassReflection.getDeclaredFields(type);
    OrderedMap<String, Field> nameToField = new OrderedMap(fields.length);
    for (Field field : fields) {
        if (!field.isStatic())
            continue;
        if (!field.isAccessible()) {
            try {
                field.setAccessible(true);
            } catch (AccessControlException ex) {
                continue;
            }
        }

        nameToField.put(field.getName(), field);
    }
    staticFields.put(type, nameToField);
    return nameToField;
}
 
開發者ID:CypherCove,項目名稱:gdx-cclibs,代碼行數:22,代碼來源:JsonFieldUpdater.java

示例6: getNestedGenericTypeAnnotation

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入依賴的package包/類
/**
 * Gets {@code NestedGenericType} annotation from object.
 * <p>
 * Looks at all object methods and returns first encountered annotation.
 *
 * @param object Object to deal with, not null
 * @return Annotation, may be null
 */
public static NestedGenericType getNestedGenericTypeAnnotation(Object object)
{
    NestedGenericType result = null;
    Method[] methods = ClassReflection.getMethods(object.getClass());
    // TODO - use type annotation, not method?
    for (Method m : methods) {
        Annotation[] annotations = m.getDeclaredAnnotations();
        Annotation a = m.getDeclaredAnnotation(NestedGenericType.class);
        if (a != null) {
            result = a.getAnnotation(NestedGenericType.class);
            break;
        }
    }
    return result;
}
 
開發者ID:mk-5,項目名稱:gdx-fireapp,代碼行數:24,代碼來源:AnnotationProcessor.java

示例7: process

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入依賴的package包/類
/**
 * Converts json string into java object.
 *
 * @param wantedType        Wanted type
 * @param genericTypeKeeper Object with wanted type inside generic argument
 * @param jsonString        Json string data
 * @param <R>               Return type
 * @return
 */
public static <R> R process(Class<?> wantedType, Object genericTypeKeeper, String jsonString)
{
    Json json = new Json();
    json.setIgnoreUnknownFields(true);
    json.setTypeName(null);
    R result = null;
    if (ClassReflection.isAssignableFrom(List.class, wantedType)
            || ClassReflection.isAssignableFrom(Map.class, wantedType)) {
        NestedGenericType nestedGenericType = AnnotationProcessor.getNestedGenericTypeAnnotation(genericTypeKeeper);
        if (nestedGenericType == null) throw new NestedGenericTypeAnnotationMissingException();
        json.setDefaultSerializer(new JsonListMapDeserializer(wantedType, nestedGenericType.value()));
        result = (R) json.fromJson(wantedType, jsonString);
    } else {
        result = (R) json.fromJson(wantedType, jsonString);
    }
    return result;
}
 
開發者ID:mk-5,項目名稱:gdx-fireapp,代碼行數:27,代碼來源:JsonProcessor.java

示例8: PlatformDistributor

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入依賴的package包/類
/**
 * Creates platform specific object by reflection.
 * <p>
 * Uses class names given by {@link #getAndroidClassName()} and {@link #getIOSClassName()}
 * <p>
 * If you need to run project on different platform use {@link #setMockObject(Object)} to polyfill platform object.
 *
 * @throws PlatformDistributorException Throws when something is wrong with environment
 */
@SuppressWarnings("unchecked")
protected PlatformDistributor() throws PlatformDistributorException
{
    String className = null;
    if (Gdx.app.getType() == Application.ApplicationType.Android) {
        className = getAndroidClassName();
    } else if (Gdx.app.getType() == Application.ApplicationType.iOS) {
        className = getIOSClassName();
    } else if (Gdx.app.getType() == Application.ApplicationType.WebGL) {
        className = getWebGLClassName();
    } else {
        return;
    }
    try {
        Class objClass = ClassReflection.forName(className);
        platformObject = (T) ClassReflection.getConstructor(objClass).newInstance();
    } catch (ReflectionException e) {
        e.printStackTrace();
        throw new PlatformDistributorException("Something wrong with environment");
    }
}
 
開發者ID:mk-5,項目名稱:gdx-fireapp,代碼行數:31,代碼來源:PlatformDistributor.java

示例9: get

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入依賴的package包/類
private Bundlable get() {
	try {
		String clName = getString( CLASS_NAME );
		if (aliases.containsKey( clName )) {
			clName = aliases.get( clName );
		}
		
		Class<?> cl = ClassReflection.forName( clName );
		if (cl != null) {
			Bundlable object = (Bundlable) ClassReflection.newInstance(cl);
			object.restoreFromBundle( this );
			return object;
		} else {
			return null;
		}
	} catch (Exception e) {
		e = null;
		return null;
	}	
}
 
開發者ID:kurtyu,項目名稱:PixelDungeonTC,代碼行數:21,代碼來源:Bundle.java

示例10: invoke

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入依賴的package包/類
public void invoke(JGameObject clickTarget) {
	for (Component component : clickTarget.getAllComponents()) {
		if (component.getClass().getName().equals(invokeComponent)) {
			Object[] parameters = args.toArray(new Object[args.size()]);
			Class[] parametersType = new Class[args.size()];
			for (int x = 0; x < parameters.length; x++) {
				parametersType[x] = parameters[x].getClass();
			}

			try {
				Method method = ClassReflection.getDeclaredMethod(component.getClass(), invokeMethod,
						parametersType);
				method.invoke(component, parameters);
			} catch (ReflectionException e) {
				e.printStackTrace();
			}
		}
	}
}
 
開發者ID:Radomiej,項目名稱:JavityEngine,代碼行數:20,代碼來源:RemoteInvoker.java

示例11: read

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入依賴的package包/類
@Override
public void read(Json json, JsonValue jsonValue) {
    try {
        name = jsonValue.getString("name");
        optional = jsonValue.getBoolean("optional");
        if (jsonValue.get("value").isNumber()) {
            type = Float.TYPE;
            value = Double.parseDouble(jsonValue.getString("value"));
        } else {
            type = ClassReflection.forName(jsonValue.getString("type"));
            if (jsonValue.get("value").isNull()) {
                value = null;
            } else {
                value = jsonValue.getString("value");
            }
        }
    } catch (ReflectionException ex) {
        Gdx.app.error(getClass().toString(), "Error reading from serialized object" , ex);
        DialogFactory.showDialogErrorStatic("Read Error...","Error reading from serialized object.\n\nOpen log?");
    }
}
 
開發者ID:raeleus,項目名稱:skin-composer,代碼行數:22,代碼來源:StyleProperty.java

示例12: read

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入依賴的package包/類
@Override
public void read(Json json, JsonValue jsonData) {
    try {
        colors = json.readValue("colors", Array.class, jsonData);
        fonts = json.readValue("fonts", Array.class, jsonData);
        classStyleMap = new OrderedMap<>();
        for (JsonValue data : jsonData.get("classStyleMap").iterator()) {
            classStyleMap.put(ClassReflection.forName(data.name), json.readValue(Array.class, data));
        }
        for (Array<StyleData> styleDatas : classStyleMap.values()) {
            for (StyleData styleData : styleDatas) {
                styleData.jsonData = this;
            }
        }
        customClasses = json.readValue("customClasses", Array.class, CustomClass.class, new Array<>(), jsonData);
        for (CustomClass customClass : customClasses) {
            customClass.setMain(main);
        }
    } catch (ReflectionException e) {
        Gdx.app.log(getClass().getName(), "Error parsing json data during file read", e);
        main.getDialogFactory().showDialogError("Error while reading file...", "Error while attempting to read save file.\nPlease ensure that file is not corrupted.\n\nOpen error log?");
    }
}
 
開發者ID:raeleus,項目名稱:skin-composer,代碼行數:24,代碼來源:JsonData.java

示例13: addListener

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入依賴的package包/類
/** Registers a listener for the specified message code. Messages without an explicit receiver are broadcasted to all its
 * registered listeners.
 * @param listener the listener to add
 * @param msg the message code */
public void addListener (Telegraph listener, int msg) {
	Array<Telegraph> listeners = msgListeners.get(msg);
	if (listeners == null) {
		// Associate an empty unordered array with the message code
		listeners = new Array<Telegraph>(false, 16);
		msgListeners.put(msg, listeners);
	}
	listeners.add(listener);

	// Dispatch messages from registered providers
	Array<TelegramProvider> providers = msgProviders.get(msg);
	if (providers != null) {
		for (int i = 0, n = providers.size; i < n; i++) {
			TelegramProvider provider = providers.get(i);
			Object info = provider.provideMessageInfo(msg, listener);
			if (info != null) {
				Telegraph sender = ClassReflection.isInstance(Telegraph.class, provider) ? (Telegraph)provider : null;
				dispatchMessage(0, sender, listener, msg, info, false);
			}
		}
	}
}
 
開發者ID:Mignet,項目名稱:Inspiration,代碼行數:27,代碼來源:MessageDispatcher.java

示例14: cloneTask

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入依賴的package包/類
/** Clones this task to a new one. If you don't specify a clone strategy through {@link #TASK_CLONER} the new task is
 * instantiated via reflection and {@link #copyTo(Task)} is invoked.
 * @return the cloned task
 * @throws TaskCloneException if the task cannot be successfully cloned. */
@SuppressWarnings("unchecked")
public Task<E> cloneTask () {
	if (TASK_CLONER != null) {
		try {
			return TASK_CLONER.cloneTask(this);
		} catch (Throwable t) {
			throw new TaskCloneException(t);
		}
	}
	try {
		Task<E> clone = copyTo(ClassReflection.newInstance(this.getClass()));
		clone.guard = guard == null ? null : guard.cloneTask();
		return clone;
	} catch (ReflectionException e) {
		throw new TaskCloneException(e);
	}
}
 
開發者ID:Mignet,項目名稱:Inspiration,代碼行數:22,代碼來源:Task.java

示例15: findMetadata

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入依賴的package包/類
private Metadata findMetadata (Class<?> clazz) {
	Metadata metadata = metadataCache.get(clazz);
	if (metadata == null) {
		Annotation tca = ClassReflection.getAnnotation(clazz, TaskConstraint.class);
		if (tca != null) {
			TaskConstraint taskConstraint = tca.getAnnotation(TaskConstraint.class);
			ObjectMap<String, AttrInfo> taskAttributes = new ObjectMap<String, AttrInfo>();
			Field[] fields = ClassReflection.getFields(clazz);
			for (Field f : fields) {
				Annotation a = f.getDeclaredAnnotation(TaskAttribute.class);
				if (a != null) {
					AttrInfo ai = new AttrInfo(f.getName(), a.getAnnotation(TaskAttribute.class));
					taskAttributes.put(ai.name, ai);
				}
			}
			metadata = new Metadata(taskConstraint.minChildren(), taskConstraint.maxChildren(), taskAttributes);
			metadataCache.put(clazz, metadata);
		}
	}
	return metadata;
}
 
開發者ID:Mignet,項目名稱:Inspiration,代碼行數:22,代碼來源:BehaviorTreeParser.java


注:本文中的com.badlogic.gdx.utils.reflect.ClassReflection類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。