mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 00:07:45 +00:00
Fix names in JSON annotation data not matching expected format. Closes #4953
This commit is contained in:
1 parent
32438d2e00
commit
b30540f20c
2 files changed
+42
-7
No files matched your search
@@ -25,6 +25,7 @@ import java.util.function.Function;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
@@ -49,6 +50,16 @@ class ASMInfo
|
||||
return byID.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return MoreObjects.toStringHelper("")
|
||||
.add("name", name)
|
||||
.add("itf", interfaces)
|
||||
.add("ann", annotations)
|
||||
.toString();
|
||||
}
|
||||
|
||||
public enum TargetType { CLASS, FIELD, METHOD, SUBTYPE };
|
||||
public enum ValueType
|
||||
{
|
||||
@@ -62,7 +73,7 @@ class ASMInfo
|
||||
DOUBLE(Double::valueOf, v -> {double[] ret = new double[v.length]; for (int x = 0; x < v.length; x++) ret[x] = Double.parseDouble(v[x]); return ret; }),
|
||||
STRING(x -> x, x -> x),
|
||||
CLASS(Type::getType, v -> {Type[] ret = new Type[v.length]; for (int x = 0; x < v.length; x++) ret[x] = Type.getType(v[x]); return ret; }),
|
||||
ENUM(ValueType::getEnumHolder, v -> {EnumHolder[] ret = new EnumHolder[v.length]; for (int x = 0; x < v.length; x++) ret[x] = ValueType.getEnumHolder(v[x]); return ret; }),
|
||||
ENUM(ValueType::getEnumHolder, v -> {List<EnumHolder> ret = Lists.newArrayList(); for (int x = 0; x < v.length; x++) ret.add(ValueType.getEnumHolder(v[x])); return ret; }),
|
||||
ANNOTATION(null, null),
|
||||
NULL(x -> null, x -> null);
|
||||
|
||||
@@ -80,7 +91,11 @@ class ASMInfo
|
||||
int idx = value.lastIndexOf('/');
|
||||
if (idx <= 1)
|
||||
throw new IllegalArgumentException("Can not create a EnumHolder for value: " + value);
|
||||
return new EnumHolder(value.substring(0, idx - 1), value.substring(idx));
|
||||
String field = value.substring(idx + 1);
|
||||
value = value.substring(0, idx);
|
||||
idx = value.indexOf(';'); //Legacy internal name.
|
||||
value = value.substring(1, idx);
|
||||
return new EnumHolder(value, field);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -102,11 +117,23 @@ class ASMInfo
|
||||
if (values != null)
|
||||
values.forEach((k, v) -> _values.put(k, v.get(pool)));
|
||||
else
|
||||
_values.put("value", value);
|
||||
_values.put("value", value == null ? null : value.get(pool));
|
||||
}
|
||||
|
||||
return _values;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return MoreObjects.toStringHelper("")
|
||||
.add("type", type)
|
||||
.add("name", name)
|
||||
.add("target", target)
|
||||
.add("id", id)
|
||||
.add("value", value)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
static class ValueHolder
|
||||
|
||||
+12
-4
@@ -20,11 +20,12 @@ package net.minecraftforge.fml.common.discovery.json;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.gson.Gson;
|
||||
@@ -35,12 +36,13 @@ import net.minecraftforge.fml.common.discovery.ASMDataTable;
|
||||
import net.minecraftforge.fml.common.discovery.ASMDataTable.ASMData;
|
||||
import net.minecraftforge.fml.common.discovery.ModCandidate;
|
||||
import net.minecraftforge.fml.common.discovery.json.ASMInfo.Annotation;
|
||||
import net.minecraftforge.fml.common.discovery.json.ASMInfo.TargetType;
|
||||
|
||||
public class JsonAnnotationLoader
|
||||
{
|
||||
public static final String ANNOTATION_JSON = "META-INF/fml_cache_annotation.json";
|
||||
private static final Gson GSON = new GsonBuilder().create();
|
||||
private static final Type INFO_TABLE = new TypeToken<Map<String, ASMInfo>>(){}.getType();
|
||||
private static final java.lang.reflect.Type INFO_TABLE = new TypeToken<Map<String, ASMInfo>>(){}.getType();
|
||||
|
||||
public static Multimap<String, ASMData> loadJson(InputStream data, ModCandidate candidate, ASMDataTable table)
|
||||
{
|
||||
@@ -58,17 +60,23 @@ public class JsonAnnotationLoader
|
||||
{
|
||||
for (String type : asm_info.interfaces)
|
||||
{
|
||||
//Interfaces use internal name, but annotations use source names. See ASMModParser.sendToTable
|
||||
table.addASMData(candidate, type, asm_info.name, null, null);
|
||||
ret.put(type, new ASMData(candidate, type, asm_info.name, null, null));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String owner_name = asm_info.name.replace('/', '.');
|
||||
if (asm_info.annotations != null)
|
||||
{
|
||||
for (Annotation anno : asm_info.annotations)
|
||||
{
|
||||
table.addASMData(candidate, anno.name, asm_info.name, anno.target, anno.getValues(asm_info));
|
||||
ret.put(anno.name, new ASMData(candidate, anno.name, asm_info.name, anno.target, anno.getValues(asm_info)));
|
||||
String name = anno.name.indexOf(';') > 0 ? Type.getType(anno.name).getClassName() : anno.name;
|
||||
String target = anno.target != null && (anno.type == TargetType.CLASS || anno.type == TargetType.SUBTYPE) ? anno.target.replace('/', '.') : anno.target;
|
||||
|
||||
table.addASMData(candidate, name, owner_name, target, anno.getValues(asm_info));
|
||||
ret.put(name, new ASMData(candidate, name, owner_name, target, anno.getValues(asm_info)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user