Improved html rendering of obfuscation mapping
This commit is contained in:
parent
9c7a09faa9
commit
b90aaa6336
@ -170,8 +170,23 @@ public class NMSReflect {
|
|||||||
background-color: #555;
|
background-color: #555;
|
||||||
}
|
}
|
||||||
tr > *:first-child {
|
tr > *:first-child {
|
||||||
text-align: right;
|
|
||||||
padding-right: .5em;
|
padding-right: .5em;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.el-icon {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.el-icon.publ {
|
||||||
|
color: #0C0;
|
||||||
|
}
|
||||||
|
.el-icon.prot {
|
||||||
|
color: #F80;
|
||||||
|
}
|
||||||
|
.el-icon.prvt {
|
||||||
|
color: #C00;
|
||||||
|
}
|
||||||
|
.el-icon.pckg {
|
||||||
|
color: #44F;
|
||||||
}
|
}
|
||||||
td {
|
td {
|
||||||
padding-top: 0;
|
padding-top: 0;
|
||||||
@ -345,7 +360,8 @@ public class NMSReflect {
|
|||||||
|
|
||||||
|
|
||||||
private void printHTML(PrintStream out) {
|
private void printHTML(PrintStream out) {
|
||||||
out.println("<tr id='c" + id + "'><th class='kw'>" + classModifiers() + "</th><th>" + nameToHTML(true) + "</th><th>" + nameToHTML(false) + "</th></tr>");
|
String modifiersHTML = classModifiersToHTML(runtimeClass());
|
||||||
|
out.println("<tr id='c" + id + "'><th>" + modifiersHTML + "</th><th>" + nameToHTML(true) + "</th><th>" + nameToHTML(false) + "</th></tr>");
|
||||||
fieldsByObf.values().forEach(f -> f.printHTML(out));
|
fieldsByObf.values().forEach(f -> f.printHTML(out));
|
||||||
printConstructorsHTML(out);
|
printConstructorsHTML(out);
|
||||||
methodsByObf.values().forEach(m -> m.printHTML(out));
|
methodsByObf.values().forEach(m -> m.printHTML(out));
|
||||||
@ -386,27 +402,6 @@ public class NMSReflect {
|
|||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String classKind() {
|
|
||||||
Class<?> clazz = runtimeClass();
|
|
||||||
if (clazz.isEnum())
|
|
||||||
return "enum";
|
|
||||||
if (clazz.isAnnotation())
|
|
||||||
return "annotation";
|
|
||||||
if (clazz.isInterface())
|
|
||||||
return "interface";
|
|
||||||
if (clazz.isRecord())
|
|
||||||
return "record";
|
|
||||||
if (clazz.isPrimitive())
|
|
||||||
return "primitive";
|
|
||||||
return "class";
|
|
||||||
}
|
|
||||||
|
|
||||||
private String classModifiers() {
|
|
||||||
Class<?> clazz = runtimeClass();
|
|
||||||
int clModifiers = clazz.getModifiers();
|
|
||||||
return modifiersToString(clModifiers) + " " + classKind();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void printConstructorsHTML(PrintStream out) {
|
private void printConstructorsHTML(PrintStream out) {
|
||||||
String classObfSimpleName = obfName.substring(obfName.lastIndexOf('.') + 1);
|
String classObfSimpleName = obfName.substring(obfName.lastIndexOf('.') + 1);
|
||||||
@ -427,7 +422,7 @@ public class NMSReflect {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
out.println("<tr>"
|
out.println("<tr>"
|
||||||
+ "<td class='kw'>" + modifiersToString(ct.getModifiers()) + "</td>"
|
+ "<td>" + elementModifiersToHTML("c", ct.getModifiers()) + "</td>"
|
||||||
+ "<td><b class='mtd' title='Constructor'>" + classObfSimpleName + "</b>(" + obfParams.stream().map(t -> t.toHTML(true)).collect(Collectors.joining(", ")) + ")</td>"
|
+ "<td><b class='mtd' title='Constructor'>" + classObfSimpleName + "</b>(" + obfParams.stream().map(t -> t.toHTML(true)).collect(Collectors.joining(", ")) + ")</td>"
|
||||||
+ "<td><b class='mtd' title='Constructor'>" + classMojSimpleName + "</b>(" + mojParams.stream().map(t -> t.toHTML(false)).collect(Collectors.joining(", ")) + ")</td>"
|
+ "<td><b class='mtd' title='Constructor'>" + classMojSimpleName + "</b>(" + mojParams.stream().map(t -> t.toHTML(false)).collect(Collectors.joining(", ")) + ")</td>"
|
||||||
+ "</tr>");
|
+ "</tr>");
|
||||||
@ -473,7 +468,7 @@ public class NMSReflect {
|
|||||||
|
|
||||||
|
|
||||||
private static record MemberDesc<I extends Comparable<I>>(I identifier, Type returnType) {
|
private static record MemberDesc<I extends Comparable<I>>(I identifier, Type returnType) {
|
||||||
private String toHTML(boolean isObfClass, boolean isStatic, boolean isFinal) { // TODO
|
private String toHTML(boolean isObfClass, boolean isStatic, boolean isFinal) {
|
||||||
String identifierHTML = "";
|
String identifierHTML = "";
|
||||||
if (identifier instanceof MethodId mId)
|
if (identifier instanceof MethodId mId)
|
||||||
identifierHTML = mId.toHTML(isObfClass, isStatic, isFinal);
|
identifierHTML = mId.toHTML(isObfClass, isStatic, isFinal);
|
||||||
@ -521,9 +516,11 @@ public class NMSReflect {
|
|||||||
|
|
||||||
|
|
||||||
private static abstract class MemberMapping<I extends Comparable<I>, R extends ReflectMember<?, ?, ?, ?>> {
|
private static abstract class MemberMapping<I extends Comparable<I>, R extends ReflectMember<?, ?, ?, ?>> {
|
||||||
|
private String htmlTypeChar;
|
||||||
/* package */ MemberDesc<I> obfDesc, mojDesc;
|
/* package */ MemberDesc<I> obfDesc, mojDesc;
|
||||||
/* package */ ClassMapping declaringClass;
|
/* package */ ClassMapping declaringClass;
|
||||||
private MemberMapping(MemberDesc<I> obfDesc, MemberDesc<I> mojDesc) {
|
private MemberMapping(String htmlType, MemberDesc<I> obfDesc, MemberDesc<I> mojDesc) {
|
||||||
|
htmlTypeChar = htmlType;
|
||||||
this.obfDesc = obfDesc;
|
this.obfDesc = obfDesc;
|
||||||
this.mojDesc = mojDesc;
|
this.mojDesc = mojDesc;
|
||||||
}
|
}
|
||||||
@ -538,7 +535,7 @@ public class NMSReflect {
|
|||||||
boolean isStatic = Modifier.isStatic(mod);
|
boolean isStatic = Modifier.isStatic(mod);
|
||||||
boolean isFinal = Modifier.isFinal(mod);
|
boolean isFinal = Modifier.isFinal(mod);
|
||||||
out.println("<tr>"
|
out.println("<tr>"
|
||||||
+ "<td class='kw'>" + modifiersToString(mod) + "</td>"
|
+ "<td>" + elementModifiersToHTML(htmlTypeChar, mod) + "</td>"
|
||||||
+ "<td>" + obfDesc.toHTML(true, isStatic, isFinal) + "</td>"
|
+ "<td>" + obfDesc.toHTML(true, isStatic, isFinal) + "</td>"
|
||||||
+ "<td>" + mojDesc.toHTML(false, isStatic, isFinal) + "</td>"
|
+ "<td>" + mojDesc.toHTML(false, isStatic, isFinal) + "</td>"
|
||||||
+ "</tr>");
|
+ "</tr>");
|
||||||
@ -551,7 +548,7 @@ public class NMSReflect {
|
|||||||
/* package */ abstract R getReflectMember() throws ReflectiveOperationException;
|
/* package */ abstract R getReflectMember() throws ReflectiveOperationException;
|
||||||
|
|
||||||
private static MemberMapping<MethodId, ReflectMethod<?>> of(MappingTree.MethodMapping mioMapping) {
|
private static MemberMapping<MethodId, ReflectMethod<?>> of(MappingTree.MethodMapping mioMapping) {
|
||||||
return new MemberMapping<>(MemberDesc.of(mioMapping, OBF_NAMESPACE), MemberDesc.of(mioMapping, MOJ_NAMESPACE)) {
|
return new MemberMapping<>("⬤", MemberDesc.of(mioMapping, OBF_NAMESPACE), MemberDesc.of(mioMapping, MOJ_NAMESPACE)) {
|
||||||
@Override
|
@Override
|
||||||
ReflectMethod<?> getReflectMember() throws ClassNotFoundException, NoSuchMethodException {
|
ReflectMethod<?> getReflectMember() throws ClassNotFoundException, NoSuchMethodException {
|
||||||
MethodId id = getReflectDesc().identifier;
|
MethodId id = getReflectDesc().identifier;
|
||||||
@ -561,7 +558,7 @@ public class NMSReflect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static MemberMapping<String, ReflectField<?>> of(MappingTree.FieldMapping mioMapping) {
|
private static MemberMapping<String, ReflectField<?>> of(MappingTree.FieldMapping mioMapping) {
|
||||||
return new MemberMapping<>(MemberDesc.of(mioMapping, OBF_NAMESPACE), MemberDesc.of(mioMapping, MOJ_NAMESPACE)) {
|
return new MemberMapping<>("●", MemberDesc.of(mioMapping, OBF_NAMESPACE), MemberDesc.of(mioMapping, MOJ_NAMESPACE)) {
|
||||||
@Override
|
@Override
|
||||||
ReflectField<?> getReflectMember() throws NoSuchFieldException {
|
ReflectField<?> getReflectMember() throws NoSuchFieldException {
|
||||||
String id = getReflectDesc().identifier;
|
String id = getReflectDesc().identifier;
|
||||||
@ -582,28 +579,54 @@ public class NMSReflect {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private static String classModifiersToHTML(Class<?> clazz) {
|
||||||
|
String elementHTMLType;
|
||||||
|
|
||||||
private static String modifiersToString(int elModifiers) {
|
if (clazz.isEnum())
|
||||||
List<String> modifiers = new ArrayList<>();
|
elementHTMLType = "E";
|
||||||
|
else if (clazz.isAnnotation())
|
||||||
|
elementHTMLType = "@";
|
||||||
|
else if (clazz.isInterface())
|
||||||
|
elementHTMLType = "I";
|
||||||
|
else if (clazz.isRecord())
|
||||||
|
elementHTMLType = "R";
|
||||||
|
else if (clazz.isPrimitive())
|
||||||
|
elementHTMLType = "";
|
||||||
|
else
|
||||||
|
elementHTMLType = "C";
|
||||||
|
|
||||||
|
return elementModifiersToHTML(elementHTMLType, clazz.getModifiers());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private static String elementModifiersToHTML(String elementHTMLType, int elModifiers) {
|
||||||
|
String html = "<b class='el-icon";
|
||||||
|
|
||||||
if (Modifier.isPublic(elModifiers))
|
if (Modifier.isPublic(elModifiers))
|
||||||
modifiers.add("public");
|
html += " publ";
|
||||||
if (Modifier.isProtected(elModifiers))
|
else if (Modifier.isProtected(elModifiers))
|
||||||
modifiers.add("protected");
|
html += " prot";
|
||||||
if (Modifier.isPrivate(elModifiers))
|
else if (Modifier.isPrivate(elModifiers))
|
||||||
modifiers.add("private");
|
html += " prvt";
|
||||||
|
else
|
||||||
|
html += " pckg";
|
||||||
|
|
||||||
|
html += "'>" + elementHTMLType + "</b><sup>";
|
||||||
|
|
||||||
if (Modifier.isStatic(elModifiers))
|
if (Modifier.isStatic(elModifiers))
|
||||||
modifiers.add("static");
|
html += "S";
|
||||||
|
|
||||||
if (Modifier.isAbstract(elModifiers))
|
if (Modifier.isAbstract(elModifiers))
|
||||||
modifiers.add("abstract");
|
html += "A";
|
||||||
if (Modifier.isFinal(elModifiers))
|
if (Modifier.isFinal(elModifiers))
|
||||||
modifiers.add("final");
|
html += "F";
|
||||||
|
|
||||||
return String.join(" ", modifiers);
|
html += "</sup>";
|
||||||
|
|
||||||
|
return html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ● (field)
|
||||||
|
// ⬤ (method)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user