public final class Decompiler
extends java.lang.Object
Decompiler
class is the main class in this Decompiler API.
This class is not thread-safe.
To use this class, consider the following example, that will print the decompiled source code to standard out:
Decompiler decompiler = new Decompiler(); decompiler.addClass(Integer.class); decompiler.decompile();
Constructor and Description |
---|
Decompiler()
Constructs a new default
Decompiler instance. |
Modifier and Type | Method and Description |
---|---|
void |
addClass(java.lang.Class<?> clazz)
Adds the given {@code Class
|
void |
addClass(java.lang.Class<?> clazz,
java.util.function.Consumer<java.lang.String> sourceConsumer)
Adds the given {@code Class
|
void |
addClass(java.lang.String className)
Adds the given {@code Class
|
void |
addClass(java.lang.String className,
java.util.function.Consumer<java.lang.String> sourceConsumer)
Adds the given {@code Class
|
void |
decompile()
Decompiles the class- and interface-types that were added to this
Decompiler instance. |
DecompilerObserver |
getDecompilerObserver()
Returns the currently assigned
DecompilerObserver instance. |
java.util.function.Consumer<java.lang.String> |
getDefaultSourceConsumer()
Returns the currently assigned default source
Consumer<String> . |
static Decompiler |
newInstance()
Returns a new default
Decompiler instance. |
void |
setDecompilerObserver(DecompilerObserver decompilerObserver)
Sets a new
DecompilerObserver for this Decompiler instance. |
void |
setDefaultSourceConsumer(java.util.function.Consumer<java.lang.String> defaultSourceConsumer)
Sets a new default source
Consumer<String> for this Decompiler instance. |
public Decompiler()
Decompiler
instance.
The initial default source Consumer<String>
will print the source to standard out via a call to System.out.println(source)
.
public java.util.function.Consumer<java.lang.String> getDefaultSourceConsumer()
Consumer<String>
.
If no default source Consumer<String>
has been explicitly set by the user of this API, the initial default source Consumer<String>
will print the source to standard out via a call to System.out.println(source)
.
This method will not return null
.
Consumer<String>
public DecompilerObserver getDecompilerObserver()
DecompilerObserver
instance.
If no DecompilerObserver
has been explicitly set by the user of this API, the initial DecompilerObserver
will not do anything.
This method will not return null
.
DecompilerObserver
instancepublic void addClass(java.lang.Class<?> clazz)
Class<?>
to be decompiled.
Calling this method is equivalent to calling decompiler.addClass(clazz, decompiler.getDefaultSourceConsumer())
.
If clazz
is null
, a NullPointerException
will be thrown.
clazz
- the Class<?>
to addjava.lang.NullPointerException
- thrown if, and only if, clazz
is null
public void addClass(java.lang.Class<?> clazz, java.util.function.Consumer<java.lang.String> sourceConsumer)
Class<?>
to be decompiled and the source Consumer<String>
to hand its decompiled source code.
If either clazz
or sourceConsumer
are null
, a NullPointerException
will be thrown.
clazz
- the Class<?>
to addsourceConsumer
- the source Consumer<String>
to hand the decompiled source code tojava.lang.NullPointerException
- thrown if, and only if, either clazz
or sourceConsumer
are null
public void addClass(java.lang.String className) throws java.lang.ClassNotFoundException
Class<?>
to be decompiled, given its fully qualified name.
Calling this method is equivalent to calling decompiler.addClass(className, decompiler.getDefaultSourceConsumer())
.
If className
is null
, a NullPointerException
will be thrown.
If no such class- or interface-type can be found, a ClassNotFoundException
will be thrown.
className
- the fully qualified name of the class- or interface-type to findjava.lang.ClassNotFoundException
- thrown if, and only if, no such class- or interface-type can be foundjava.lang.NullPointerException
- thrown if, and only if, className
is null
public void addClass(java.lang.String className, java.util.function.Consumer<java.lang.String> sourceConsumer) throws java.lang.ClassNotFoundException
Class<?>
to be decompiled, given its fully qualified name and the source Consumer<String>
to hand its decompiled source code.
Calling this method is equivalent to calling decompiler.addClass(Class.forName(className), sourceConsumer)
.
If either className
or sourceConsumer
are null
, a NullPointerException
will be thrown.
If no such class- or interface-type can be found, a ClassNotFoundException
will be thrown.
className
- the fully qualified name of the class- or interface-type to findsourceConsumer
- the source Consumer<String>
to hand the decompiled source code tojava.lang.ClassNotFoundException
- thrown if, and only if, no such class- or interface-type can be foundjava.lang.NullPointerException
- thrown if, and only if, either className
or sourceConsumer
are null
public void decompile()
Decompiler
instance.
The methods to add the class- and interface-types are the following:
addClass(Class<?>)
addClass(Class<?>, Consumer<String>)
addClass(String)
addClass(String, Consumer<String>)
Consumer<String>
instances that were given to each individual class- and interface-type, respectively.
If the decompilation process fails, a DecompilationException
will be thrown.
DecompilationException
- thrown if, and only if, the decompilation process failspublic void setDecompilerObserver(DecompilerObserver decompilerObserver)
DecompilerObserver
for this Decompiler
instance.
If no DecompilerObserver
has been explicitly set by the user of this API, the initial DecompilerObserver
will not do anything.
If decompilerObserver
is null
, a NullPointerException
will be thrown.
decompilerObserver
- the new DecompilerObserver
java.lang.NullPointerException
- thrown if, and only if, decompilerObserver
is null
public void setDefaultSourceConsumer(java.util.function.Consumer<java.lang.String> defaultSourceConsumer)
Consumer<String>
for this Decompiler
instance.
If no default source Consumer<String>
has been explicitly set by the user of this API, the initial default source Consumer<String>
will print the source to standard out via a call to System.out.println(source)
.
If defaultSourceConsumer
is null
, a NullPointerException
will be thrown.
defaultSourceConsumer
- the new default source Consumer<String>
java.lang.NullPointerException
- thrown if, and only if, defaultSourceConsumer
is null
public static Decompiler newInstance()
Decompiler
instance.
The initial default source Consumer<String>
will print the source to standard out via a call to System.out.println(source)
.
Decompiler
instance