|
org.openide.src 1.8.31 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.text.Format org.openide.src.ElementFormat
public final class ElementFormat
A format used to print members of the source hierarchy. It is sometimes used for code generation of elements, and also for formatting the display names of the nodes representing the hierarchy.
This format is similar to MessageFormat
.
It also uses special characters in the pattern and replaces them with strings,
depending on the code.
For example:
ElementFormat fmt = new ElementFormat ("{m} {r} {n} ({p})");
MethodElement method = getMethodSomewhere ();
System.out.println (fmt.format (method));
...should print something like this: "public int method(int,char)"
The substitution codes are:
{m}
Modifiers
{n}
Name
{C}
Name of class (with all outerclasses)
{f}
Full name of element with package
{t}
Type
{r}
Return type
{s}
Superclass
{c}
Static (for initializers)
{p}
Parameters with types but not variable names (e.g. "int,char"
).
{a}
Parameters with types and names (e.g. "int x,char c"
).
{i}
Interfaces
{e}
Exceptions
The following table shows which codes may be used to format which kinds of element. An asterisk means the code may be used, a hyphen means it cannot:
character | m n f C t r s c p a i e
----------------------------------------------------
Initializer | - - - - - - - * - - - -
Field | * * * - * - - - - - - -
Constructor | * * * - - - - - * * - *
Method | * * * - - * - - * * - *
Class | * * * * - - * - - - * -
Interface | * * * * - - - - - - * -
The grammar for expressions:
messageFormatPattern := string ( "{" messageFormatElement "}" string )*
messageFormatElement := simple_argument { "," prefix "," suffix }
messageFormatElement := array_argument { "," prefix "," suffix { "," delim } }
simple_argument := "m" | "n" | "f" | "C" | "t" | "r" | "s" | "c"
array_argument := "p" | "a" | "i" | "e"
prefix := string
suffix := string
delim := string
Comments on the previous grammar:
simple_argument
- arguments which are replaced by a single string
array_argument
- arguments for arrays (parameters, ...)
prefix
- prefix before the format element if nonempty
suffix
- suffix after the format element if nonempty
delim
- delimiter between the members of the array
string
- a bare string, or enclosed in double quotes if necessary
(e.g. if it contains a comma)
Example formats:
{e,throws ,}
=> ""
IOException
: {e,throws ,
} => "throws IOException"
{p,,,-}
=> "int-int-int"
{p,(,),", "}
=> "(int, int, int)"
The default delimiter is a comma.
This class currently has a default property editor in the property editor search path for the IDE.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.text.Format |
---|
Format.Field |
Constructor Summary | |
---|---|
ElementFormat(String pattern)
Create a new format. |
Method Summary | |
---|---|
boolean |
dependsOnProperty(String prop)
Test whether a property could affect the formatting. |
String |
format(Element element)
Formats an element. |
StringBuffer |
format(Object o,
StringBuffer toAppendTo,
FieldPosition pos)
Format an object. |
String |
getPattern()
Get the pattern. |
boolean |
isSourceFormat()
Test if this format generate strings in source format or fully qualified format. |
Object |
parseObject(String source,
ParsePosition status)
Don't parse objects. |
void |
setSourceFormat(boolean source)
Set whether the formating is used for code generation. |
Methods inherited from class java.text.Format |
---|
clone, format, formatToCharacterIterator, parseObject |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ElementFormat(String pattern)
pattern
- the pattern describing the formatMethod Detail |
---|
public void setSourceFormat(boolean source)
true
.
source
- true
means that all Identifier and Type objects
used in formating are evaluated by getSourceName
method. Otherwise (false
) the getFullName() is
called.public boolean isSourceFormat()
public String getPattern()
public StringBuffer format(Object o, StringBuffer toAppendTo, FieldPosition pos)
o
- should be an Element
toAppendTo
- the string buffer to format topos
- currently ignored
IllegalArgumentException
- if the object was not really an Element
public String format(Element element)
element
- the element to be printed
public boolean dependsOnProperty(String prop)
prop
- the property name from ElementProperties
true
if sopublic Object parseObject(String source, ParsePosition status)
parseObject
in class Format
source
- ignoredstatus
- ignored
null
in the default implementation
|
org.openide.src 1.8.31 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |