Reading code
Look at a type, list what you can call on it, read one method, or search the whole classpath — each with one command that returns only what was asked. This guide covers show, members, outline, signature, doc, body, source, search, resolve, ls, tree, and Kotlin.
The examples use Gson by Maven coordinate; any classpath works the same way (Classpath & workspaces).
A type at a glance: show#
jdx show com.google.gson.JsonArray --coord com.google.code.gson:gson:2.14.0
class com.google.gson.JsonArray
public final class JsonArray
extends com.google.gson.JsonElement
implements java.lang.Iterable
members: 2 constructors, 32 methods, 1 field
warning MULTI_RELEASE_VARIANT: multi-release gson-2.14.0.jar serves version-specific variants for this JDK (21)
source: gson-2.14.0.jar (bytecode)
next: jdx members com.google.gson.JsonArray --inheritedReal output — this example ran against the current jdx when the page was built.
What can I call? members and outline#
members is the . completion of an IDE: inherited members are included and grouped by the
type that declares them, with java.lang.Object collapsed to one line.
jdx members com.google.gson.JsonArray --kind method --limit 10 --coord com.google.code.gson:gson:2.14.0
members of com.google.gson.JsonArray
methods declared on com.google.gson.JsonArray:
method public boolean contains(com.google.gson.JsonElement element)
method public boolean equals(java.lang.Object o)
method public boolean getAsBoolean()
method public boolean isEmpty()
method public boolean remove(com.google.gson.JsonElement element)
method public byte getAsByte()
method public char getAsCharacter()
method public com.google.gson.JsonArray deepCopy()
method public com.google.gson.JsonElement get(int i)
method public com.google.gson.JsonElement remove(int index)
+ 8 from java.lang.Object (--from java.lang.Object to expand)
10 of 50 members shown (--limit 50 to see more)
warning MULTI_RELEASE_VARIANT: multi-release gson-2.14.0.jar serves version-specific variants for this JDK (21)
source: gson-2.14.0.jar (bytecode)Real output — this example ran against the current jdx when the page was built.
Narrow it down instead of reading more:
| Want | Flag |
|---|---|
| only this type's own members | --declared (or use jdx outline) |
| methods / fields / constructors | --kind method|field|ctor|property |
| visibility | --access public|protected|package|private|all |
| statics or instances | --static / --instance |
| members from one supertype | --from java.util.AbstractList |
| names matching a regex | --grep '^get' |
| the first javadoc sentence per member | --with-doc |
| a hard token budget | --brief, --max-lines N |
jdx members com.google.gson.JsonArray --grep '^as' --declared --coord com.google.code.gson:gson:2.14.0
members of com.google.gson.JsonArray
methods declared on com.google.gson.JsonArray:
method public java.util.List<com.google.gson.JsonElement> asList()
warning MULTI_RELEASE_VARIANT: multi-release gson-2.14.0.jar serves version-specific variants for this JDK (21)
source: gson-2.14.0.jar (bytecode)Real output — this example ran against the current jdx when the page was built.
outline prints one dense line per declared member — the file-structure view.
One member: signature, doc, body#
signature shows every overload with real parameter names, generics, throws and defaults:
jdx signature 'com.google.gson.JsonParser#parseString' --coord com.google.code.gson:gson:2.14.0
signatures of com.google.gson.JsonParser#parseString
public static com.google.gson.JsonElement parseString(java.lang.String json) throws com.google.gson.JsonSyntaxException
warning MULTI_RELEASE_VARIANT: multi-release gson-2.14.0.jar serves version-specific variants for this JDK (21)
source: gson-2.14.0.jar (bytecode)
next: jdx show com.google.gson.JsonParserReal output — this example ran against the current jdx when the page was built.
doc renders the javadoc as plain text; an undocumented override falls back to the nearest
documented supertype (and says so):
jdx doc 'com.google.gson.JsonParser#parseString(String)' --coord com.google.code.gson:gson:2.14.0
com.google.gson.JsonParser#parseString(java.lang.String)
source: gson-2.14.0-sources.jar · com/google/gson/JsonParser.java:80-90
Parses the specified JSON string into a parse tree. An exception is thrown if the JSON string
has multiple top-level JSON elements, or if there is trailing data.
The JSON string is parsed in lenient mode.
@param json JSON text
@return a parse tree of JsonElements corresponding to the specified JSON
@throws JsonParseException if the specified text is not valid JSON
@since 2.8.6
warning MULTI_RELEASE_VARIANT: multi-release gson-2.14.0.jar serves version-specific variants for this JDK (21)
… 1 more lines (run it yourself to see them all)Real output — this example ran against the current jdx when the page was built.
body shows exactly one method — tens of lines instead of a whole file:
jdx body 'com.google.gson.JsonParser#parseString(String)' --coord com.google.code.gson:gson:2.14.0
com.google.gson.JsonParser#parseString(java.lang.String)
source: gson-2.14.0-sources.jar · com/google/gson/JsonParser.java:91-93
public static JsonElement parseString(String json) throws JsonSyntaxException {
return parseReader(new StringReader(json));
}
warning MULTI_RELEASE_VARIANT: multi-release gson-2.14.0.jar serves version-specific variants for this JDK (21)
next: jdx show com.google.gson.JsonParserReal output — this example ran against the current jdx when the page was built.
Useful flags: --line-numbers, --context N (lines around the body), --with-doc,
--with-signature, --max-lines N.
A whole file, sliced: source#
When you do need more than one member, slice the file instead of dumping it:
jdx source com.google.gson.Gson --lines 120:160
jdx source com.google.gson.Gson --around 'com.google.gson.Gson#toJson(Object)' --context 5Sources, decompilation, bytecode#
jdx always prefers real sources (a paired -sources.jar, a source directory, the JDK's
src.zip). Without them it decompiles with Vineflower and marks the result
⚠ reconstructed; --engine javap shows raw bytecode instead:
jdx body 'java.util.HashMap#get(java.lang.Object)' --engine javap
java.util.HashMap#get(java.lang.Object)
source: disassembled by javap from java.base · java/util/HashMap.java:346-359 ⚠ reconstructed
public V get(java.lang.Object);
descriptor: (Ljava/lang/Object;)Ljava/lang/Object;
Code:
0: aload_0
1: aload_1
2: invokevirtual #158 // Method getNode:(Ljava/lang/Object;)Ljava/util/HashMap$Node;
5: dup
6: astore_2
7: ifnonnull 14
10: aconst_null
… 5 more lines (run it yourself to see them all)Real output — this example ran against the current jdx when the page was built.
When sources and binary disagree, jdx warns SOURCES_VERSION_MISMATCH — bytecode is the
truth for structure, sources supply bodies, names and docs.
Search the classpath: search, resolve, ls, tree#
jdx search 'JsonParser*' --coord com.google.code.gson:gson:2.14.0
search results for 'JsonParser*'
class com.google.gson.JsonParser gson-2.14.0.jar
warning MULTI_RELEASE_VARIANT: multi-release gson-2.14.0.jar serves version-specific variants for this JDK (21)
jdx search 'parse*' --kind method --in 'gson*' --coord com.google.code.gson:gson:2.14.0
search results for 'parse*'
method com.google.gson.JsonParser#parse(com.google.gson.stream.JsonReader) gson-2.14.0.jar
method com.google.gson.JsonParser#parse(java.io.Reader) gson-2.14.0.jar
method com.google.gson.JsonParser#parse(java.lang.String) gson-2.14.0.jar
method com.google.gson.JsonParser#parseReader(com.google.gson.stream.JsonReader) gson-2.14.0.jar
method com.google.gson.JsonParser#parseReader(java.io.Reader) gson-2.14.0.jar
method com.google.gson.JsonParser#parseString(java.lang.String) gson-2.14.0.jar
method com.google.gson.ToNumberPolicy$3#parseAsDouble(java.lang.String, com.google.gson.stream.JsonReader) gson-2.14.0.jar
method com.google.gson.internal.JavaVersion#parseDotted(java.lang.String) gson-2.14.0.jar
method com.google.gson.internal.JavaVersion#parseMajorJavaVersion(java.lang.String) gson-2.14.0.jar
… 6 more lines (run it yourself to see them all)Real output — this example ran against the current jdx when the page was built.
Globs by default, --regex for regular expressions; bare words match case-insensitively or as
camel humps (HMap finds HashMap); --fuzzy retries a miss by edit distance. --kind
narrows to classes, interfaces, methods, fields, packages or modules.
jdx resolve <name>— every candidate for a simple name, with kind and artifact.jdx ls 'com.google.*'— packages with type counts; an exact package lists its types.jdx tree 'gson*'— the package tree of an artifact (--depth,--counts).
Kotlin#
Kotlin binaries are read through their @Metadata, so jdx shows true Kotlin declarations —
suspend functions, properties, default arguments, @JvmName mappings — rather than the JVM
projection. --view jvm shows the raw JVM view (getters, Continuation parameters, mangled
names) when that is what you need.
Reading Kotlin sources (body, source, doc on .kt files) uses the Kotlin compiler's
parser, which is installed separately on demand to keep jdx small:
jdx kotlin installWithout it, Kotlin binaries still render from metadata and source queries degrade with a label.