diff --git a/src/main/java/net/minecraftforge/fml/common/discovery/json/ASMInfo.java b/src/main/java/net/minecraftforge/fml/common/discovery/json/ASMInfo.java index bd8019a6b..7236b042e 100644 --- a/src/main/java/net/minecraftforge/fml/common/discovery/json/ASMInfo.java +++ b/src/main/java/net/minecraftforge/fml/common/discovery/json/ASMInfo.java @@ -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 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 diff --git a/src/main/java/net/minecraftforge/fml/common/discovery/json/JsonAnnotationLoader.java b/src/main/java/net/minecraftforge/fml/common/discovery/json/JsonAnnotationLoader.java index 21eb2d588..1f59983a5 100644 --- a/src/main/java/net/minecraftforge/fml/common/discovery/json/JsonAnnotationLoader.java +++ b/src/main/java/net/minecraftforge/fml/common/discovery/json/JsonAnnotationLoader.java @@ -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>(){}.getType(); + private static final java.lang.reflect.Type INFO_TABLE = new TypeToken>(){}.getType(); public static Multimap 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))); } } }