|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--Trans
Trans is a container of indented text objects used alone or with JavaCC tool from WebGain for easy and rapid design and development of high-to-high language translators, scripting and template engines, macro expanders, format transformers...
'Trans
formized' grammar seems hard to read, because it's
packed and powerfull.
If good source code standards are used, it is consistent and easy to change.
Jjdoc-generated html grammar tree is used for orientation in whole grammar.
add(Object), conc(Object),
toString()
is
indented by depth of their level
and newline character(s) are replaced by system newline character(s).
toString()
and saved to file, written from servlet to TCP packet...
this
ret.add( "//Assignment on next line" ).
preadd(..), preconc(..)
should be used with care and not very
often, otherwise they decrease readability. 'Local root' container
of unshifted subcontainers is used for more complicated compositions.
toString(),
equals(Object)
checks whether parameter is Trans and has
equal text represenation. Because result of toString() is uncachable, this
shouldn't be used often.
Trans empty(), unshifted(), error(String), unfinished;
Trans.empty()...
or subclassing Trans. So it's left up to user.
Trans(int)
is used to specify offset other than default.
Trans(Object)
is used to specify first Object, String or Trans item.
void
.
Trans ret= new Trans().
Constructor for ret
ret
always from end of production. Even if translation result is
finally known before getting to end, where next optional
statements are 'not important' or actual statement can be
repeated more time, result must be returned after parsing those parts. Otherwise,
translator will 'sometimes' fails when those 'unimportant' parts appear,
because parser won't consume them after production method already returned.
Trans
formize' higher statements first,
starting from root and its direct substatements, to
develop and debug root parts. And/Or write debugging results
to standard output from leaf statements if designing
customized classes for them first, or when using up-down approach.
Token
objects are not handled specially by default, as they
have good default toString()
method.
Token.toString()
to return
item.toLowerCase()
or item.toUpperCase()
, according
to contract you choose.
equals(Object)
that compares
container's items as objects. See comments in source.
Field Summary | |
protected static Trans |
concatenate
Internal flag object for concatenation of items, never to be printed itself neither used by user. |
static java.lang.String |
cr
System newline character(s) that are used when Trans is transformed to String. |
static int |
defaultOffset
Default number of spaces before each nested level for all new containers. |
protected java.util.ArrayList |
list
Physical container. |
protected int |
offset
Number of spaces written before each line of this container. |
Constructor Summary | |
Trans()
Creates container with default offset. |
|
Trans(int offs)
Creates container with specified offset. |
|
Trans(java.lang.Object obj)
Created container with default offset and specified item, if not null. |
Method Summary | |
Trans |
add(boolean par)
|
Trans |
add(byte par)
|
Trans |
add(double par)
|
Trans |
add(float par)
|
Trans |
add(char par)
|
Trans |
add(int par)
|
Trans |
add(long par)
|
Trans |
add(java.lang.Object next)
Adds object to the end of container, if not null. |
Trans |
add(short par)
|
Trans |
conc(boolean par)
|
Trans |
conc(byte par)
|
Trans |
conc(double par)
|
Trans |
conc(float par)
|
Trans |
conc(char par)
|
Trans |
conc(int par)
|
Trans |
conc(long par)
|
Trans |
conc(java.lang.Object next)
Object is concatenated, if not null. |
Trans |
conc(short par)
|
boolean |
equals(java.lang.Object obj)
Compares whether parameter is also Trans and their toString() representation is same. |
int |
hashCode()
Returns a constant (0). |
Trans |
newLine()
Adds system newline character(s). |
Trans |
preadd(boolean par)
|
Trans |
preadd(byte par)
|
Trans |
preadd(double par)
|
Trans |
preadd(float par)
|
Trans |
preadd(char par)
|
Trans |
preadd(int par)
|
Trans |
preadd(long par)
|
Trans |
preadd(java.lang.Object next)
Adds object at the first place of container, if not null. |
Trans |
preadd(short par)
|
Trans |
preconc(boolean par)
|
Trans |
preconc(byte par)
|
Trans |
preconc(double par)
|
Trans |
preconc(float par)
|
Trans |
preconc(char par)
|
Trans |
preconc(int par)
|
Trans |
preconc(long par)
|
Trans |
preconc(java.lang.Object next)
Object is preconcatenated, if not null. |
Trans |
preconc(short par)
|
java.lang.String |
toString()
Transforms to String, no first level offset made in this function, so direct items aren't indented. |
java.lang.StringBuffer |
write(java.lang.StringBuffer buffer)
Writes content to end of passed buffer, and appends system newline character(s) to it. |
protected java.lang.StringBuffer |
write(java.lang.StringBuffer buffer,
int offs,
boolean conc)
Transforms container's content - all its items to String in recursion, managing indentation level and concatenation. |
void |
writeFile(java.lang.String name)
Writes content to file, and appends system newline character(s) to it. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final java.lang.String cr
toString(), write(..)
, not when containers are composed.protected static final Trans concatenate
public static int defaultOffset
Trans(int).
protected int offset
protected java.util.ArrayList list
Constructor Detail |
public Trans()
defaultOffset
public Trans(int offs)
offs
- sets number of spaces before each line of this containerpublic Trans(java.lang.Object obj)
obj
- first itemMethod Detail |
public Trans add(java.lang.Object next)
obj
- item to be addedpublic Trans preadd(java.lang.Object next)
new Trans("Third line").preadd("Second line").preadd("First line")
obj
- item to be added.public Trans conc(java.lang.Object next)
obj
- item to be added at end of containerpublic Trans preconc(java.lang.Object next)
obj
- item to be added at first place of containerpublic Trans newLine()
write(..)
engine puts there cr
newline
character(s) when it is called.public Trans add(boolean par)
public Trans preadd(boolean par)
public Trans conc(boolean par)
public Trans preconc(boolean par)
public Trans add(byte par)
public Trans preadd(byte par)
public Trans conc(byte par)
public Trans preconc(byte par)
public Trans add(char par)
public Trans preadd(char par)
public Trans conc(char par)
public Trans preconc(char par)
public Trans add(short par)
public Trans preadd(short par)
public Trans conc(short par)
public Trans preconc(short par)
public Trans add(int par)
public Trans preadd(int par)
public Trans conc(int par)
public Trans preconc(int par)
public Trans add(long par)
public Trans preadd(long par)
public Trans conc(long par)
public Trans preconc(long par)
public Trans add(float par)
public Trans preadd(float par)
public Trans conc(float par)
public Trans preconc(float par)
public Trans add(double par)
public Trans preadd(double par)
public Trans conc(double par)
public Trans preconc(double par)
public java.lang.String toString()
equals(Object).
toString
in class java.lang.Object
equals(Object)
protected java.lang.StringBuffer write(java.lang.StringBuffer buffer, int offs, boolean conc)
"\n", "\r"
and couples of
"\n\r", "\r\n"
to one presence of system
newline character(s). Couples are transformed together only if they are
printed from the same Object with its toString()
.buffer
- Buffer of upper container (caller), ending by newline character.buffer
with added content, newline character at
end of each line, but not of last one (so concatenation can be made
to it by the successor).public java.lang.StringBuffer write(java.lang.StringBuffer buffer)
buffer
- Buffer to add content.buffer
with added content.write(StringBuffer,int,boolean)
public void writeFile(java.lang.String name) throws java.io.IOException
file
- File to write content.public boolean equals(java.lang.Object obj)
toString()
and it can't be cached, because Trans subnodes can be accessed and
changed later by 'reservation'. There is no way to cache
equality or object status in principle. Unchanged hashCode()
means only that object probably didn't change. Anyway, it's not used
often. See source for faster restricted version that compares subnodes as Objects.
User can redefine equals(Object)
in any way, as
standard Trans mechanism that generates its string representation
(write(...)
) doesn't use it.
equals
in class java.lang.Object
public int hashCode()
hashCode()
of string representation generated by toString().hashCode
in class java.lang.Object
equals(Object)
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |