net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData Java Examples

The following examples show how to use net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData. 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: TypeVariableHolderHandler.java    From OpenModsLib with MIT License 6 votes vote down vote up
private static void findTargets(ASMData target, Map<Field, Class<?>> classTargetToSource, Map<Field, Class<?>> fieldTargetToSource) {
	final String targetClassName = target.getClassName();
	final String targetObject = target.getObjectName();
	final Type sourceClassName = (Type)target.getAnnotationInfo().get("value");

	try {
		final Class<?> targetClass = Class.forName(targetClassName);
		final Class<?> sourceClass;
		if (sourceClassName == null || sourceClassName.equals(USE_DECLARING_TYPE_MARKER))
			sourceClass = targetClass;
		else
			sourceClass = Class.forName(sourceClassName.getClassName());

		if (targetClassName.equals(targetObject))
			addClassFields(classTargetToSource, targetClass, sourceClass);
		else
			addField(fieldTargetToSource, targetClass, targetObject, sourceClass);
	} catch (Exception e) {
		Log.warn(e, "Failed to fill type variable holder at %s:%s", targetClassName, targetObject);
	}
}
 
Example #2
Source File: TypeVariableHolderHandler.java    From OpenModsLib with MIT License 5 votes vote down vote up
public void fillAllHolders(ASMDataTable data) {
	final Map<Field, Class<?>> classTargetToSource = Maps.newHashMap();
	final Map<Field, Class<?>> fieldTargetToSource = Maps.newHashMap();

	for (ASMData target : data.getAll(TypeVariableHolder.class.getName()))
		findTargets(target, classTargetToSource, fieldTargetToSource);

	fillFields(classTargetToSource, fieldTargetToSource);
}
 
Example #3
Source File: ApiFactory.java    From OpenModsLib with MIT License 5 votes vote down vote up
private static <A> void fillTargetField(ClassInfoCache clsCache, ApiProviderRegistry<A> registry, ASMData data, Class<A> interfaceMarker) {
	final String targetClassName = data.getClassName();
	final String targetObjectName = data.getObjectName();

	final ClassInfo targetCls = clsCache.getOrCreate(targetClassName);
	final Setter setter = targetCls.get(targetObjectName);
	Preconditions.checkArgument(setter != null, "Entry '%s' in class '%s' is not valid target for API annotation", targetObjectName, targetClassName);

	final Class<?> acceptedType = setter.getType();
	Preconditions.checkState(interfaceMarker.isAssignableFrom(acceptedType), "Failed to set API object on %s:%s - invalid type, expected %s",
			targetClassName, targetObjectName, interfaceMarker);

	final Class<? extends A> castAcceptedType = acceptedType.asSubclass(interfaceMarker);
	final A api = registry.getApi(castAcceptedType);

	if (api != null) {
		try {
			setter.set(api);
		} catch (Throwable t) {
			throw new RuntimeException(String.format("Failed to set entry '%s' in class '%s'", targetObjectName, targetClassName), t);
		}
		Log.trace("Injecting instance of %s from mod %s to field %s:%s from file %s",
				castAcceptedType,
				Loader.instance().activeModContainer().getModId(),
				targetClassName,
				targetObjectName,
				data.getCandidate().getModContainer());
	} else {
		Log.info("Can't set API field %s:%s - no API for type %s",
				targetClassName, targetObjectName, castAcceptedType);
	}
}
 
Example #4
Source File: ApiFactory.java    From OpenModsLib with MIT License 5 votes vote down vote up
private static <A> void fillTargetFields(final ApiProviderRegistry<A> registry, ASMDataTable table, Class<? extends Annotation> fieldMarker, Class<A> interfaceMarker) {
	final ClassInfoCache clsCache = new ClassInfoCache();
	final Set<ASMData> targets = table.getAll(fieldMarker.getName());

	for (ASMData data : targets)
		fillTargetField(clsCache, registry, data, interfaceMarker);
}