From 9582651bc501bfe66cc6f39f0865de7ed415b9bf Mon Sep 17 00:00:00 2001 From: michaeloffner Date: Sat, 14 Oct 2023 20:55:12 +0200 Subject: [PATCH] improve dump output for classes --- .../java/lucee/runtime/dump/DumpUtil.java | 79 +++++++++++-------- loader/build.xml | 2 +- loader/pom.xml | 2 +- 3 files changed, 46 insertions(+), 37 deletions(-) diff --git a/core/src/main/java/lucee/runtime/dump/DumpUtil.java b/core/src/main/java/lucee/runtime/dump/DumpUtil.java index dbb7306a5c..1dd87710bb 100644 --- a/core/src/main/java/lucee/runtime/dump/DumpUtil.java +++ b/core/src/main/java/lucee/runtime/dump/DumpUtil.java @@ -22,6 +22,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.nio.charset.Charset; import java.sql.ResultSet; import java.text.SimpleDateFormat; @@ -56,6 +57,7 @@ import lucee.runtime.converter.WDDXConverter; import lucee.runtime.engine.ThreadLocalPageContext; import lucee.runtime.exp.PageException; +import lucee.runtime.functions.system.BundleInfo; import lucee.runtime.i18n.LocaleFactory; import lucee.runtime.op.Caster; import lucee.runtime.op.Decision; @@ -88,6 +90,10 @@ public class DumpUtil { ((DumpTable) MAX_LEVEL_REACHED).appendRow(new DumpRow(1, new SimpleDumpData("[Max Dump Level Reached]"))); } + public static void main(String[] args) { + toDumpData(new BundleInfo(), null, 1, DumpProperties.DEFAULT); + } + // FUTURE add to interface public static DumpData toDumpData(Object o, PageContext pageContext, int maxlevel, DumpProperties props) { if (maxlevel < 0) return MAX_LEVEL_REACHED; @@ -497,7 +503,7 @@ public static DumpData toDumpData(Object o, PageContext pageContext, int maxleve // reflect // else { - DumpTable table = new DumpTable(o.getClass().getName(), "#6289a3", "#dee3e9", "#000000"); + DumpTable table = new DumpTable(o.getClass().getName(), "#dee3e9", "#ffffff", "#000000"); Class clazz = o.getClass(); if (o instanceof Class) clazz = (Class) o; @@ -510,7 +516,7 @@ public static DumpData toDumpData(Object o, PageContext pageContext, int maxleve // Fields Field[] fields = clazz.getFields(); - DumpTable fieldDump = new DumpTable("#6289a3", "#dee3e9", "#000000"); + DumpTable fieldDump = new DumpTable("#dee3e9", "#ffffff", "#000000"); fieldDump.appendRow(-1, new SimpleDumpData("name"), new SimpleDumpData("pattern"), new SimpleDumpData("value")); for (int i = 0; i < fields.length; i++) { Field field = fields[i]; @@ -527,7 +533,7 @@ public static DumpData toDumpData(Object o, PageContext pageContext, int maxleve // Constructors Constructor[] constructors = clazz.getConstructors(); - DumpTable constrDump = new DumpTable("#6289a3", "#dee3e9", "#000000"); + DumpTable constrDump = new DumpTable("#dee3e9", "#ffffff", "#000000"); constrDump.appendRow(-1, new SimpleDumpData("interface"), new SimpleDumpData("exceptions")); for (int i = 0; i < constructors.length; i++) { Constructor constr = constructors[i]; @@ -549,7 +555,6 @@ public static DumpData toDumpData(Object o, PageContext pageContext, int maxleve sbParams.append(Caster.toClassName(parameters[p])); } sbParams.append(')'); - constrDump.appendRow(0, new SimpleDumpData(sbParams.toString()), new SimpleDumpData(sbExp.toString())); } if (constructors.length > 0) table.appendRow(1, new SimpleDumpData("constructors"), constrDump); @@ -557,42 +562,46 @@ public static DumpData toDumpData(Object o, PageContext pageContext, int maxleve // Methods StringBuilder objMethods = new StringBuilder(); Method[] methods = clazz.getMethods(); - DumpTable methDump = new DumpTable("#6289a3", "#dee3e9", "#000000"); - methDump.appendRow(-1, new SimpleDumpData("return"), new SimpleDumpData("interface"), new SimpleDumpData("exceptions")); - for (int i = 0; i < methods.length; i++) { - Method method = methods[i]; - - if (Object.class == method.getDeclaringClass()) { - if (objMethods.length() > 0) objMethods.append(", "); - objMethods.append(method.getName()); - continue; - } + DumpTable methDump = new DumpTable("#dee3e9", "#ffffff", "#000000"); + methDump.appendRow(-1, new SimpleDumpData("type"), new SimpleDumpData("interface"), new SimpleDumpData("exceptions")); + boolean isStatic; + for (int i = 0; i < 2; i++) { + for (Method method: methods) { + + isStatic = Modifier.isStatic(method.getModifiers()); + if ((i == 0 && !isStatic) || (i == 1 && isStatic)) continue; + if (Object.class == method.getDeclaringClass()) { + if (objMethods.length() > 0) objMethods.append(", "); + objMethods.append(method.getName()); + continue; + } - // exceptions - StringBuilder sbExp = new StringBuilder(); - Class[] exceptions = method.getExceptionTypes(); - for (int p = 0; p < exceptions.length; p++) { - if (p > 0) sbExp.append("\n"); - sbExp.append(Caster.toClassName(exceptions[p])); - } + // exceptions + StringBuilder sbExp = new StringBuilder(); + Class[] exceptions = method.getExceptionTypes(); + for (int p = 0; p < exceptions.length; p++) { + if (p > 0) sbExp.append("\n"); + sbExp.append(Caster.toClassName(exceptions[p])); + } - // parameters - StringBuilder sbParams = new StringBuilder(method.getName()); - sbParams.append('('); - Class[] parameters = method.getParameterTypes(); - for (int p = 0; p < parameters.length; p++) { - if (p > 0) sbParams.append(", "); - sbParams.append(Caster.toClassName(parameters[p])); - } - sbParams.append(')'); + // parameters + StringBuilder sbParams = new StringBuilder(method.getName()); + sbParams.append('('); + Class[] parameters = method.getParameterTypes(); + for (int p = 0; p < parameters.length; p++) { + if (p > 0) sbParams.append(", "); + sbParams.append(Caster.toClassName(parameters[p])); + } + sbParams.append("):").append(Caster.toClassName(method.getReturnType())); - methDump.appendRow(0, new SimpleDumpData(Caster.toClassName(method.getReturnType())), + methDump.appendRow(0, new SimpleDumpData(isStatic ? "static" : "instance"), new SimpleDumpData(sbParams.toString()), new SimpleDumpData(sbExp.toString())); - new SimpleDumpData(sbParams.toString()), new SimpleDumpData(sbExp.toString())); + } } + if (methods.length > 0) table.appendRow(1, new SimpleDumpData("methods"), methDump); - DumpTable inherited = new DumpTable("#6289a3", "#dee3e9", "#000000"); + DumpTable inherited = new DumpTable("#dee3e9", "#ffffff", "#000000"); inherited.appendRow(7, new SimpleDumpData("Methods inherited from java.lang.Object")); inherited.appendRow(0, new SimpleDumpData(objMethods.toString())); table.appendRow(1, new SimpleDumpData(""), inherited); @@ -610,7 +619,7 @@ public static DumpData toDumpData(Object o, PageContext pageContext, int maxleve sct.setEL(KeyConstants._location, b.getLocation()); sct.setEL(KeyConstants._version, b.getVersion().toString()); - DumpTable bd = new DumpTable("#6289a3", "#dee3e9", "#000000"); + DumpTable bd = new DumpTable("#dee3e9", "#ffffff", "#000000"); bd.appendRow(1, new SimpleDumpData("id"), new SimpleDumpData(b.getBundleId())); bd.appendRow(1, new SimpleDumpData("symbolic-name"), new SimpleDumpData(b.getSymbolicName())); bd.appendRow(1, new SimpleDumpData("version"), new SimpleDumpData(b.getVersion().toString())); @@ -645,7 +654,7 @@ private static void requiredBundles(DumpTable parent, Bundle b) { try { List list = OSGiUtil.getRequiredBundles(b); if (list.isEmpty()) return; - DumpTable dt = new DumpTable("#6289a3", "#dee3e9", "#000000"); + DumpTable dt = new DumpTable("#dee3e9", "#ffffff", "#000000"); dt.appendRow(-1, new SimpleDumpData("name"), new SimpleDumpData("version from"), new SimpleDumpData("operator from"), new SimpleDumpData("version to"), new SimpleDumpData("operator to")); diff --git a/loader/build.xml b/loader/build.xml index 89a264a124..5ad147ec3a 100644 --- a/loader/build.xml +++ b/loader/build.xml @@ -2,7 +2,7 @@ - + diff --git a/loader/pom.xml b/loader/pom.xml index 0d8dd1387a..5276fa814c 100644 --- a/loader/pom.xml +++ b/loader/pom.xml @@ -3,7 +3,7 @@ org.lucee lucee - 6.0.0.584-SNAPSHOT + 6.0.0.585-SNAPSHOT jar Lucee Loader Build