public final class JFormatter
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
JFormatter.Mode |
(package private) class |
JFormatter.ReferenceList
Used during the optimization of class imports.
|
Modifier and Type | Field and Description |
---|---|
private boolean |
atBeginningOfLine |
(package private) static char |
CLOSE_TYPE_ARGS
Special character token we use to differenciate '>' as an operator and
'>' as the end of the type arguments.
|
private java.util.HashMap<java.lang.String,JFormatter.ReferenceList> |
collectedReferences
map from short type name to ReferenceList (list of JClass and ids sharing that name)
|
private java.util.HashSet<JClass> |
importedClasses
set of imported types (including package java types, eventhough we won't generate imports for them)
|
private int |
indentLevel
Current number of indentation strings to print
|
private java.lang.String |
indentSpace
String to be used for each indentation.
|
private JPackage |
javaLang |
private char |
lastChar |
private JFormatter.Mode |
mode
The current running mode.
|
private java.io.PrintWriter |
pw
Stream associated with this JFormatter
|
Constructor and Description |
---|
JFormatter(java.io.PrintWriter s)
Creates a formatter with default incremental indentations of
four spaces.
|
JFormatter(java.io.PrintWriter s,
java.lang.String space)
Creates a JFormatter.
|
JFormatter(java.io.Writer w)
Creates a formatter with default incremental indentations of
four spaces.
|
Modifier and Type | Method and Description |
---|---|
JFormatter |
b(JVar v)
Cause the JVar to generate source for itself
|
void |
close()
Closes this formatter.
|
JFormatter |
d(JDeclaration d)
Cause the JDeclaration to generate source for itself
|
JFormatter |
g(java.util.Collection<? extends JGenerable> list)
Produces
JGenerable s separated by ',' |
JFormatter |
g(JGenerable g)
Cause the JGenerable object to generate source for iteself
|
JFormatter |
i()
Increment the indentation level.
|
JFormatter |
id(java.lang.String id)
Print an identifier
|
boolean |
isPrinting()
Returns true if we are in the printing mode,
where we actually produce text.
|
private boolean |
needSpace(char c1,
char c2) |
JFormatter |
nl()
Print a new line into the stream
|
JFormatter |
o()
Decrement the indentation level.
|
JFormatter |
p(char c)
Print a char into the stream
|
JFormatter |
p(java.lang.String s)
Print a String into the stream
|
JFormatter |
s(JStatement s)
Cause the JStatement to generate source for itself
|
private void |
spaceIfNeeded(char c) |
private boolean |
supressImport(JClass clazz,
JClass c)
determine if an import statement should be supressed
|
JFormatter |
t(JClass type)
Print a type name.
|
JFormatter |
t(JType type) |
(package private) void |
write(JDefinedClass c)
Generates the whole source code out of the specified class.
|
private java.util.HashMap<java.lang.String,JFormatter.ReferenceList> collectedReferences
private java.util.HashSet<JClass> importedClasses
private JFormatter.Mode mode
private int indentLevel
private final java.lang.String indentSpace
private final java.io.PrintWriter pw
private char lastChar
private boolean atBeginningOfLine
private JPackage javaLang
static final char CLOSE_TYPE_ARGS
public JFormatter(java.io.PrintWriter s, java.lang.String space)
s
- PrintWriter to JFormatter to use.space
- Incremental indentation string, similar to tab value.public JFormatter(java.io.PrintWriter s)
public JFormatter(java.io.Writer w)
public void close()
public boolean isPrinting()
public JFormatter o()
public JFormatter i()
private boolean needSpace(char c1, char c2)
private void spaceIfNeeded(char c)
public JFormatter p(char c)
c
- the charpublic JFormatter p(java.lang.String s)
s
- the Stringpublic JFormatter t(JType type)
public JFormatter t(JClass type)
In the collecting mode we use this information to decide what types to import and what not to.
public JFormatter id(java.lang.String id)
public JFormatter nl()
public JFormatter g(JGenerable g)
g
- the JGenerable objectpublic JFormatter g(java.util.Collection<? extends JGenerable> list)
JGenerable
s separated by ','public JFormatter d(JDeclaration d)
d
- the JDeclaration objectpublic JFormatter s(JStatement s)
s
- the JStatement objectpublic JFormatter b(JVar v)
v
- the JVar objectvoid write(JDefinedClass c)
private boolean supressImport(JClass clazz, JClass c)
clazz
- JType that may or may not have an importc
- JType that is the current class being processed