public abstract class Format extends Object implements Cloneable, Serializable, Formattable
Format.Compound
provides methods for optimal cloning and clean re-calculating of the
internal attributes.Modifier and Type | Class and Description |
---|---|
static class |
Format.Annotated<A>
Foreseen for data annotations, like the metajava
reference format. |
static class |
Format.Append
Prints contained sub-formats horizontally adjacent.
|
static class |
Format.Beneath
Prints its sub-formats vertically aligned one beneath the other.
|
static class |
Format.Beside
Prints all sub-formats directly adjacent, even if they are multi-line.
|
static class |
Format.Block
Prints all sub-formats in the same line as long as possible, and starts a new
line for every sub-format which would (probably) exceeded the page width.
|
static class |
Format.BoundVariable
Variable identified by a number, resolved by un-named arguments
by counting their positions.
|
static class |
Format.Comment
Arranges all sub-formats with leading asterisks, like a javadoc comment.
|
static class |
Format.Compound
The base class for all formats which combine (= "contain") sub-formats.
|
static class |
Format.Context
Realizes a binding from identifiers to formats, for
resolving
Format.FreeVariable s-
bt [__] FIXME DOK FEHLT, NEVER TESTED !?!? NEVER USED !?!? |
static class |
Format.Empty
Needed eg for case distinctions, when one alternative shall produce
nothing.
|
static class |
Format.Forester
Swing tree Generation ONLY for debugging purposes.
|
static class |
Format.FormatPrinter
Central Visitor for formatted printing.
|
static class |
Format.FreeVariable
Variable indetified by a alphanumeric name which can be
bound explicitly.
|
static class |
Format.Line
Prints all sub-formats in the same horizional line if this is possible within
the page width, otherwise it prints all sub-formats in one vertical line.
|
static class |
Format.Literal
Printed literally to the output.
|
static class |
Format.Markup
Printed literally to the output, but not included in width calculation.
|
static class |
Format.Matcher
Base class for Visitor and Rewriter, Classifier.
|
static class |
Format.MayBreak
Abstract superclass of all compound formats which possibly
generate multi-line output when printed.
|
protected static class |
Format.NonFormatPrinter
Prints a format discarding all formatting, producing non-human-readable
output.
|
static class |
Format.Prior
This format prints the "parens" format, if it is (directly or indirectly)
contained in a Prior Format with a higher priority 'level" (numerically larger
priority code).
|
static class |
Format.Rewriter
General purpose Rewriter
|
static class |
Format.Space
Required for horizontal space (of variable size) or for
blank lines (always only one at a time!).
|
static class |
Format.Subst
bt [__] FIXME DOK FEHLT, NEVER TESTED !?!? NEVER USED !?!?
|
static class |
Format.Tabular
Realizes ONE line of a table, and prints sub-formats starting in the column
indicated by the value of their
indent . |
static class |
Format.Variable
Common abstract base class for
Format.FreeVariable and Format.BoundVariable |
static class |
Format.Visitor
General purpose Visitor
|
Modifier and Type | Field and Description |
---|---|
static Format |
comma
A public constant reference to a literal format containing a comma.
|
static int |
contentPrefixPrinted |
static int |
DEFAULT_WIDTH
Default page width used by
printFormat(PrintWriter) |
static Format |
dot
A public constant reference to a literal format containing a dot.
|
static Format |
empty
A constant reference to an empty format.
|
protected boolean |
ground
Reflects that this format does not contain variables.
|
protected int |
indent
The indentation value explicitly assigned by the user.
|
static int |
INDENT_NOT_SET |
protected boolean |
invalid
|
protected boolean |
isAlwaysMultiline
Reflects whether format contains any (non-singleton)
Format.Beneath formats. |
protected static int |
LENGTH_PREFIX |
static Function<String,Format> |
literal
|
protected int |
maxWidth
Contains maximal width, ie assumes that
no single optional line-break is inserted.
|
protected int |
minWidth
Contains minimal width, if not directly at start of line,
ie respecting blanks and not including indentation.
|
static Pattern |
pattern_illegal_literal
Characters which are currently not allowed in
Format.Literal s. |
static Pattern |
pattern_newline |
static Pattern |
pattern_ws |
static Pattern |
pattern_wsWithVars |
static Format |
space
A constant reference to a space of one(1) column/line.
|
format
Modifier | Constructor and Description |
---|---|
protected |
Format() |
protected |
Format(int i,
int a,
boolean mult,
boolean ground) |
Modifier and Type | Method and Description |
---|---|
static <A> Format |
annotated(Format format,
A annotation)
Creates an
Format.Annotated format. |
static Format |
append(Format... f)
Same as
append(Iterable) |
static Format |
append(Iterable<? extends Format> f)
Creates an
Format.Append format. |
static Format |
apply(Format body,
Format... args) |
static Format |
apply(Format body,
Format.Context c,
boolean partial) |
static Format |
apply(Format body,
Formattable... args) |
static Format |
apply(Format body,
String name,
Format value) |
Format |
applyPartial(Formattable... args) |
Format |
applyTo(Format... args)
Central and only tested method for resolving
variables.
|
Format |
applyTo(Formattable... args) |
static Format |
beneath(Format... f)
Same as
beneath(Iterable) |
static Format |
beneath(Iterable<? extends Format> f)
Creates an
Format.Beneath format. |
static Format |
beside(Format... f)
Same as
beside(Iterable) |
static Format |
beside(Iterable<? extends Format> f)
Creates an
Format.Beside format. |
static Format |
block(Format... f)
Same as
block(Iterable) |
static Format |
block(Iterable<? extends Format> f)
Creates an
Format.Block format. |
protected boolean |
calcground()
Calculate whether not containing variables.
|
protected int |
calcmax()
Calculate maximal width.
|
protected int |
calcmin()
Calculate minimal width.
|
protected boolean |
calcmult()
Calculate whether more than one line of output.
|
static Format |
comment(String linePrefix,
Format... f) |
static Format |
comment(String linePrefix,
Iterable<? extends Format> f) |
static Format |
comment(@Opt String prefix,
String linePrefix,
@Opt String suffix,
Format... f)
Creates an
Format.Comment format. |
static Format |
comment(@Opt String prefix,
String linePrefix,
@Opt String suffix,
Iterable<? extends Format> f)
Creates an
Format.Comment format. |
abstract String |
debugPrefix(int n) |
protected abstract void |
doprint(Format.FormatPrinter v)
Over-ridden by concrete sub-classes of Format, for performing
the adquate print operations.
|
Format |
eval(Format.Context c,
boolean partial) |
Format |
format() |
Format |
indent(int i)
|
protected boolean |
indentIsSet() |
protected void |
invalidate()
|
protected boolean |
isSpace() |
static boolean |
isValidContentForLiteral(String s)
Returns true iff argument is valid as content of a "literal"
format, i.e.
|
static Format |
line(Format... f)
Same as
line(Iterable) |
static Format |
line(Iterable<? extends Format> f)
Creates an
Format.Line format. |
static Format |
list(Format open,
CompoundConstructor outerCombinator,
Format delim,
CompoundConstructor innerCombinator,
Format close,
Format... formats)
|
static Format |
list(Format open,
CompoundConstructor outerCombinator,
Format delim,
CompoundConstructor innerCombinator,
Format close,
Iterable<? extends Format> formats)
|
static Format |
list(Format open,
CompoundConstructor outerCombinator,
Format delim,
CompoundConstructor innerCombinator,
Format close,
List<Format> formats)
Convenience method, creates a complex format for
sequences of
Format a. |
static Format |
list(Format open,
Format delim,
Format close,
Format... formats)
Same as
list(Format,CompoundConstructor,Format,CompoundConstructor,Format,List) ,
where outerCombinator defaults to CompoundConstructor.beside
and innerCombinator defaults to CompoundConstructor.line |
static Format |
list(Format open,
Format delim,
Format close,
List<Format> formats)
Same as
list(Format,CompoundConstructor,Format,CompoundConstructor,Format,List) ,
where outerCombinator defaults to CompoundConstructor.beside
and innerCombinator defaults to CompoundConstructor.line |
static Format |
literal(String s)
Create a literal or return an already cached one.
|
static void |
main(String[] args)
Some test method calls.
|
protected static Format |
makeAppend(List<Format> f) |
protected static Format |
makeBeneath(List<Format> f) |
protected static Format |
makeBeside(List<Format> f) |
protected static Format |
makeBlock(List<Format> f) |
protected static Format |
makeLine(List<Format> f) |
protected static Format |
makeTabular(List<Format> f) |
static Format |
markup(String s)
Creates a mark-up format (not occupying any space).
|
static Format |
markupLeft(String s)
Creates a mark-up format (not occupying any space).
|
static Format |
markupRight(String s)
Creates a mark-up format (not occupying any space).
|
void |
printFormat(PrintWriter pw)
Central public function for printing a formst with a default page width..
|
void |
printFormat(PrintWriter pw,
int width)
Central public function for printing a formst with the explicitly
given page width..
|
void |
printNonFormat(PrintWriter pw)
print a format without any formatting, not intended for human readers.
|
static Format |
prior(int level,
Format noparens,
Format parens)
Creates a
Format.Prior format. |
static Format |
prior(int level,
int alternative,
Format noparens,
Format parens) |
static Format |
quoteDTDstyle(Format f)
Creates a literal format which chooses quote symbols not appearing in the
data.
|
static Format |
quoteJavaStyle(Format f)
Creates a literal format which quoted doublequotes by escaping them with a
backslash.
|
static String |
showLn(Format f,
int depth)
creates a debugging representation of a form term, showing the
top "depth" levels.
|
static String |
showLn(Format f,
int depth,
int nesting) |
static void |
showSwingTree(Format f,
String windowname,
boolean isHtml)
Generate a swing tree representation and display it ONLY for debugging.
|
static Format |
space(int i)
Creates a space format.
|
static Format |
subst(Format body,
Format... args) |
static Format |
subst(Format body,
Format.Context c,
boolean partial) |
static Format |
subst(Format body,
String name,
Format value) |
static Format |
tabular(Format... f)
Same as
tabular(Iterable) |
static Format |
tabular(Iterable<? extends Format> f)
Creates an
Format.Tabular format. |
static Format |
text(String txt)
Convenience method for translating multi-line text into a complex
format hierarchy.
|
static Format |
textWithVars(String txt) |
Format |
toFormat(Format... args)
Deprecated.
|
String |
toObjString()
call "toString()" from the "Object" superclass, for debugging only !
|
String |
toString()
Print the format in an unformatted way to a string.
|
String |
toString(int width)
Print the format in a formatted way to a string (include linefeeds!),
with the specified maximal column width.
|
protected void |
update()
Just local calculation, assumes that all sub-objects are already valid.
|
protected void |
validate()
Re-calculates all parameters
by calling
update() , iff necessary. |
static Format |
variable(int index)
Creates a new
Format.BoundVariable with the given number. |
static Format |
variable(String name)
Creates a new
Format.FreeVariable with the given name. |
public static final Pattern pattern_illegal_literal
Format.Literal
s.public static final Format comma
public static final Format dot
public static final Format space
public static final Format empty
public static final Pattern pattern_newline
public static final Pattern pattern_ws
public static final Pattern pattern_wsWithVars
protected static final int LENGTH_PREFIX
public static final int INDENT_NOT_SET
protected int indent
protected transient int minWidth
protected transient int maxWidth
protected transient boolean isAlwaysMultiline
Format.Beneath
formats.
Needed for "line" and "block", which propagate line breaks contained
therein to their own layout.protected transient boolean ground
protected boolean invalid
public static final int DEFAULT_WIDTH
printFormat(PrintWriter)
public static final int contentPrefixPrinted
protected Format(int i, int a, boolean mult, boolean ground)
protected Format()
public final Format format()
format
in interface Formattable
public static boolean isValidContentForLiteral(String s)
public static Format literal(String s)
IllegalArgumentException
- in case the string argument contains
tabs or newline pattern_illegal_literal
.public static Format markupRight(String s)
public static Format markupLeft(String s)
public static Format space(int i)
public static Format prior(int level, Format noparens, Format parens)
Format.Prior
format.public static Format append(Iterable<? extends Format> f)
Format.Append
format.
Format.Empty
format instead.
public static Format block(Iterable<? extends Format> f)
Format.Block
format.
Format.Empty
format instead.
public static Format line(Iterable<? extends Format> f)
Format.Line
format.
Format.Empty
format instead.
public static Format beside(Iterable<? extends Format> f)
Format.Beside
format.
Format.Empty
format instead.
public static Format beneath(Iterable<? extends Format> f)
Format.Beneath
format.
Format.Empty
format instead.
public static Format tabular(Iterable<? extends Format> f)
Format.Tabular
format.
Format.Empty
format instead.
public static Format comment(@Opt @Opt String prefix, String linePrefix, @Opt @Opt String suffix, Iterable<? extends Format> f)
Format.Comment
format.public static Format comment(@Opt @Opt String prefix, String linePrefix, @Opt @Opt String suffix, Format... f)
Format.Comment
format.public static Format append(Format... f)
append(Iterable)
public static Format block(Format... f)
block(Iterable)
public static Format line(Format... f)
line(Iterable)
public static Format beside(Format... f)
beside(Iterable)
public static Format beneath(Format... f)
beneath(Iterable)
public static Format tabular(Format... f)
tabular(Iterable)
public Format indent(int i)
public static <A> Format annotated(Format format, A annotation)
Format.Annotated
format.public static Format variable(String name)
Format.FreeVariable
with the given name.public static Format variable(int index)
Format.BoundVariable
with the given number.public static Format subst(Format body, Format.Context c, boolean partial)
public static Format apply(Format body, Format.Context c, boolean partial)
public static Format apply(Format body, Formattable... args)
public final Format applyTo(Format... args)
Format.BoundVariable
s, ie
variables identified by numbers.
This is the only one of the many methods of dealing with variables
which is ubiquituously applied in meta-tools. It requires that
the mapping is total, ie that at least as much parameters
are supplied as the highest number of all contained variables plus one (+1).public final Format applyTo(Formattable... args)
public final Format applyPartial(Formattable... args)
@Deprecated public Format toFormat(Format... args)
public static Format quoteDTDstyle(Format f)
Format.Append
with single quotes as first and last character.public static Format quoteJavaStyle(Format f)
public static Format text(String txt)
Beneath | | Block | | Literal | | Space | | Literal | | Space | | Literal | Space | Block | | Literal | | Space | | LiteralThe limits of blocks will be given by hard "newlines" contained in the text.
public static Format list(Format open, CompoundConstructor outerCombinator, Format delim, CompoundConstructor innerCombinator, Format close, Iterable<? extends Format> formats)
public static Format list(Format open, Format delim, Format close, Format... formats)
list(Format,CompoundConstructor,Format,CompoundConstructor,Format,List)
,
where outerCombinator
defaults to CompoundConstructor.beside
and innerCombinator
defaults to CompoundConstructor.line
public static Format list(Format open, Format delim, Format close, List<Format> formats)
list(Format,CompoundConstructor,Format,CompoundConstructor,Format,List)
,
where outerCombinator
defaults to CompoundConstructor.beside
and innerCombinator
defaults to CompoundConstructor.line
public static Format list(Format open, CompoundConstructor outerCombinator, Format delim, CompoundConstructor innerCombinator, Format close, Format... formats)
public static Format list(Format open, CompoundConstructor outerCombinator, Format delim, CompoundConstructor innerCombinator, Format close, List<Format> formats)
Format
a.
The structure which is created is determinded to
outer combinator | | | | | close | | | inner comb.-----+--- .... ---+ | | | | | Append Append f[last] | | | | | | f[0] delim f[1] delim | open
open
- the format at the very left of the result, like an open parenthesisouterCombinator
- how to combine open, the inner list, and closedelim
- the format to separate the elements of the list, like a commainnerCombinator
- how to combine the elements of the inner listclose
- the format at the very right of the result,
like a closing parenthesisformats
- the sequence of inner elements.public static String showLn(Format f, int depth)
public abstract String debugPrefix(int n)
protected boolean indentIsSet()
protected boolean isSpace()
protected final void invalidate()
protected void validate()
update()
, iff necessary.
Is over-ridden by Format.Compound
for prior descending to sub-formats.protected void update()
Format.Compound
, testing not being a
temporary copy). Instead, the differente "calc<..>
" methods
are overridden individually.protected int calcmin()
protected int calcmax()
protected boolean calcmult()
protected boolean calcground()
public Format eval(Format.Context c, boolean partial)
protected abstract void doprint(Format.FormatPrinter v)
public void printFormat(PrintWriter pw)
public void printFormat(PrintWriter pw, int width)
public void printNonFormat(PrintWriter pw)
public String toString()
public String toString(int width)
public String toObjString()
public static void showSwingTree(Format f, String windowname, boolean isHtml)
f
- the Format to displaywindowname
- the Title of the windowisHtml
- if tree labels use html featurespublic static void main(String[] args)
see also the complete user documentation .