Skip to content

Commit

Permalink
improve dump output for classes
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Oct 14, 2023
1 parent e795eeb commit 9582651
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 37 deletions.
79 changes: 44 additions & 35 deletions core/src/main/java/lucee/runtime/dump/DumpUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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];
Expand All @@ -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];
Expand All @@ -549,50 +555,53 @@ 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);

// 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);
Expand All @@ -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()));
Expand Down Expand Up @@ -645,7 +654,7 @@ private static void requiredBundles(DumpTable parent, Bundle b) {
try {
List<BundleRange> 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"));

Expand Down
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="6.0.0.584-SNAPSHOT"/>
<property name="version" value="6.0.0.585-SNAPSHOT"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>6.0.0.584-SNAPSHOT</version>
<version>6.0.0.585-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit 9582651

Please sign in to comment.