mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-18 20:49:12 +00:00
Fix handling of multi-dimensional array elements in the AP
This commit is contained in:
1 parent
d8c4f6f0a7
commit
2f63e40255
3 files changed
+18
-76
No files matched your search
@@ -37,6 +37,8 @@ import javax.lang.model.type.DeclaredType;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.lang.model.type.TypeVariable;
|
||||
|
||||
import org.spongepowered.asm.util.SignaturePrinter;
|
||||
|
||||
/**
|
||||
* Convenience functions for mirror types
|
||||
*/
|
||||
@@ -180,79 +182,7 @@ public abstract class TypeUtils {
|
||||
* @return java signature
|
||||
*/
|
||||
public static String getJavaSignature(String descriptor) {
|
||||
if (descriptor == null) {
|
||||
return null;
|
||||
}
|
||||
StringBuilder signature = new StringBuilder().append('(');
|
||||
char[] desc = descriptor.toCharArray();
|
||||
for (int pos = 1; pos < desc.length;) {
|
||||
pos += TypeUtils.appendToSignature(signature, desc, pos);
|
||||
if (pos < desc.length && desc[pos] != ')' && desc[pos - 1] != ')') {
|
||||
signature.append(',');
|
||||
}
|
||||
}
|
||||
return signature.toString();
|
||||
}
|
||||
|
||||
private static int appendToSignature(final StringBuilder signature, final char[] desc, int pos) {
|
||||
switch (desc[pos]) {
|
||||
case 'V':
|
||||
signature.append("void");
|
||||
return 1;
|
||||
case 'Z':
|
||||
signature.append("boolean");
|
||||
return 1;
|
||||
case 'C':
|
||||
signature.append("char");
|
||||
return 1;
|
||||
case 'B':
|
||||
signature.append("byte");
|
||||
return 1;
|
||||
case 'S':
|
||||
signature.append("short");
|
||||
return 1;
|
||||
case 'I':
|
||||
signature.append("int");
|
||||
return 1;
|
||||
case 'F':
|
||||
signature.append("float");
|
||||
return 1;
|
||||
case 'J':
|
||||
signature.append("long");
|
||||
return 1;
|
||||
case 'D':
|
||||
signature.append("double");
|
||||
return 1;
|
||||
case '[':
|
||||
int arraySize = 0;
|
||||
while (desc[pos] == '[') {
|
||||
++arraySize;
|
||||
++pos;
|
||||
}
|
||||
int length = TypeUtils.appendToSignature(signature, desc, pos);
|
||||
for (int i = 0; i < arraySize; i++) {
|
||||
signature.append("[]");
|
||||
}
|
||||
return length + arraySize;
|
||||
case 'L':
|
||||
length = 0;
|
||||
pos++;
|
||||
while (desc[pos] != ';') {
|
||||
++length;
|
||||
if (desc[pos] == '/') {
|
||||
signature.append('.');
|
||||
} else {
|
||||
signature.append(desc[pos]);
|
||||
}
|
||||
++pos;
|
||||
}
|
||||
return length + 2;
|
||||
case ')':
|
||||
signature.append(')');
|
||||
return 1;
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected character '" + desc[pos] + "' in signature");
|
||||
}
|
||||
return new SignaturePrinter("", descriptor).setFullyQualified(true).toDescriptor();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -458,7 +458,7 @@ public final class MemberInfo {
|
||||
}
|
||||
|
||||
if (this.desc != null) {
|
||||
if (!this.desc.matches("^(\\([\\w\\p{Sc}\\[/;]*\\))?\\[?[\\w\\p{Sc}/;]+$")) {
|
||||
if (!this.desc.matches("^(\\([\\w\\p{Sc}\\[/;]*\\))?\\[*[\\w\\p{Sc}/;]+$")) {
|
||||
throw new InvalidMemberDescriptorException("Invalid descriptor: " + this.desc);
|
||||
}
|
||||
if (this.isField()) {
|
||||
|
||||
@@ -229,7 +229,7 @@ public class SignaturePrinter {
|
||||
private StringBuilder appendType(StringBuilder sb, Type type, String name) {
|
||||
switch (type.getSort()) {
|
||||
case Type.ARRAY:
|
||||
return this.appendType(sb, type.getElementType(), name).append("[]");
|
||||
return SignaturePrinter.appendArraySuffix(this.appendType(sb, type.getElementType(), name), type);
|
||||
case Type.OBJECT:
|
||||
return this.appendType(sb, type.getClassName(), name);
|
||||
default:
|
||||
@@ -287,7 +287,7 @@ public class SignaturePrinter {
|
||||
case Type.FLOAT: return box ? "Float" : "float";
|
||||
case Type.LONG: return box ? "Long" : "long";
|
||||
case Type.DOUBLE: return box ? "Double" : "double";
|
||||
case Type.ARRAY: return SignaturePrinter.getTypeName(type.getElementType(), box, fullyQualified) + "[]";
|
||||
case Type.ARRAY: return SignaturePrinter.getTypeName(type.getElementType(), box, fullyQualified) + SignaturePrinter.arraySuffix(type);
|
||||
case Type.OBJECT:
|
||||
String typeName = type.getClassName();
|
||||
if (!fullyQualified) {
|
||||
@@ -298,4 +298,16 @@ public class SignaturePrinter {
|
||||
return "Object";
|
||||
}
|
||||
}
|
||||
|
||||
private static String arraySuffix(Type type) {
|
||||
return Strings.repeat("[]", type.getDimensions());
|
||||
}
|
||||
|
||||
|
||||
private static StringBuilder appendArraySuffix(StringBuilder sb, Type type) {
|
||||
for (int i = 0; i < type.getDimensions(); i++) {
|
||||
sb.append("[]");
|
||||
}
|
||||
return sb;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user