From 4b58f8af7cf7282b8412390510c4b4b3220f63a1 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Wed, 15 Jun 2022 17:05:28 +0200 Subject: [PATCH] HTML render of mapping improved again --- .../lib/paper/reflect/NMSReflect.java | 103 ++++++++++++------ pom.xml | 10 +- 2 files changed, 76 insertions(+), 37 deletions(-) diff --git a/Paper/src/main/java/fr/pandacube/lib/paper/reflect/NMSReflect.java b/Paper/src/main/java/fr/pandacube/lib/paper/reflect/NMSReflect.java index f66affd..325872b 100644 --- a/Paper/src/main/java/fr/pandacube/lib/paper/reflect/NMSReflect.java +++ b/Paper/src/main/java/fr/pandacube/lib/paper/reflect/NMSReflect.java @@ -156,12 +156,15 @@ public class NMSReflect { background-color: #2F2F2F; color: white; font-size: 14px; + font-family: Consolas, monospace; + } + a:not(.cl) { + color: #1290C3; } table { border-collapse: collapse; width: 100%; margin: auto; - font-family: Consolas, monospace; } tr:nth-child(2n) { background-color: #373737; @@ -173,20 +176,18 @@ public class NMSReflect { padding-right: .5em; white-space: nowrap; } - .el-icon { - font-weight: bold; - } - .el-icon.publ { + + b.pu { color: #0C0; } - .el-icon.prot { - color: #F80; + b.pt { + color: #FC0; } - .el-icon.prvt { - color: #C00; + b.pv { + color: #F00; } - .el-icon.pckg { - color: #44F; + b.pk { + color: #66F; } td { padding-top: 0; @@ -216,10 +217,29 @@ public class NMSReflect { font-weight: bold; } + """ - + "\n" + "

" + title + "

\n" - + ""); + + """ +

+ C: class   + E: enum   + I: interface   + @: @interface   + R: record
+ : field   + c: constructor   + : method
+ : public   + : protected   + : package   + : private
+ S: static   + A: abstract   + F: final +

+
+ """); out.println(""); for (ClassMapping clazz : CLASSES_BY_OBF.values()) { clazz.printHTML(out); @@ -362,9 +382,11 @@ public class NMSReflect { private void printHTML(PrintStream out) { String modifiersHTML = classModifiersToHTML(runtimeClass()); out.println(""); - fieldsByObf.values().forEach(f -> f.printHTML(out)); + fieldsByObf.values().stream().filter(mm -> mm.isStatic()).forEach(f -> f.printHTML(out)); + methodsByObf.values().stream().filter(mm -> mm.isStatic()).forEach(m -> m.printHTML(out)); printConstructorsHTML(out); - methodsByObf.values().forEach(m -> m.printHTML(out)); + fieldsByObf.values().stream().filter(mm -> !mm.isStatic()).forEach(f -> f.printHTML(out)); + methodsByObf.values().stream().filter(mm -> !mm.isStatic()).forEach(m -> m.printHTML(out)); } private String nameToHTML(boolean obf) { @@ -423,8 +445,8 @@ public class NMSReflect { } out.println("" + "" - + "" - + "" + + "" + + "" + ""); } @@ -547,6 +569,15 @@ public class NMSReflect { /* package */ abstract R getReflectMember() throws ReflectiveOperationException; + /* package */ boolean isStatic() { + try { + return Modifier.isStatic(getReflectMember().getModifiers()); + } catch (ReflectiveOperationException e) { + Log.severe(e); + return false; + } + } + private static MemberMapping> of(MappingTree.MethodMapping mioMapping) { return new MemberMapping<>("⬤", MemberDesc.of(mioMapping, OBF_NAMESPACE), MemberDesc.of(mioMapping, MOJ_NAMESPACE)) { @Override @@ -566,6 +597,8 @@ public class NMSReflect { } }; } + + } @@ -601,27 +634,33 @@ public class NMSReflect { private static String elementModifiersToHTML(String elementHTMLType, int elModifiers) { - String html = ""; - - if (Modifier.isStatic(elModifiers)) - html += "S"; - if (Modifier.isAbstract(elModifiers)) - html += "A"; - if (Modifier.isFinal(elModifiers)) - html += "F"; - - html += ""; + html += "'>" + elementHTMLType + ""; + + boolean isStatic = Modifier.isStatic(elModifiers); + boolean isAbstract = Modifier.isAbstract(elModifiers); + boolean isFinal = Modifier.isFinal(elModifiers); + + if (isStatic || isAbstract || isFinal) { + html += ""; + if (isStatic) + html += "S"; + if (isAbstract) + html += "A"; + if (isFinal) + html += "F"; + html += ""; + } return html; } diff --git a/pom.xml b/pom.xml index c886124..684deb5 100644 --- a/pom.xml +++ b/pom.xml @@ -54,11 +54,11 @@ - - org.junit.jupiter - junit-jupiter-api - 5.7.2 - test + + junit + junit + 4.12 + test
ns" + OBF_NAMESPACE + "" + MOJ_NAMESPACE + "
" + modifiersHTML + "" + nameToHTML(true) + "" + nameToHTML(false) + "
" + elementModifiersToHTML("c", ct.getModifiers()) + "" + classObfSimpleName + "(" + obfParams.stream().map(t -> t.toHTML(true)).collect(Collectors.joining(", ")) + ")" + classMojSimpleName + "(" + mojParams.stream().map(t -> t.toHTML(false)).collect(Collectors.joining(", ")) + ")" + classObfSimpleName + "(" + obfParams.stream().map(t -> t.toHTML(true)).collect(Collectors.joining(", ")) + ")" + classMojSimpleName + "(" + mojParams.stream().map(t -> t.toHTML(false)).collect(Collectors.joining(", ")) + ")