Class ElementFormat

  extended byjava.text.Format
      extended byorg.openide.src.ElementFormat
All Implemented Interfaces:
Cloneable, Serializable

public final class ElementFormat
extends Format

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:

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:

Example formats:

The default delimiter is a comma.

This class currently has a default property editor in the property editor search path for the IDE.

See Also:
Serialized Form

Nested Class Summary
Nested classes inherited from class java.text.Format
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)
Create a new format. See documentation for the class for the syntax of the format argument.

pattern - the pattern describing the format
Method Detail


public void setSourceFormat(boolean source)
Set whether the formating is used for code generation. Default value is 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()
Test if this format generate strings in source format or fully qualified format.

the source flag


public String getPattern()
Get the pattern.

the current pattern


public StringBuffer format(Object o,
                           StringBuffer toAppendTo,
                           FieldPosition pos)
Format an object.

o - should be an Element
toAppendTo - the string buffer to format to
pos - currently ignored
the same string buffer it was passed (for convenient chaining)
IllegalArgumentException - if the object was not really an Element


public String format(Element element)
Formats an element.

element - the element to be printed
the formatted string using the pattern


public boolean dependsOnProperty(String prop)
Test whether a property could affect the formatting. I.e., if that property would be read due to one of the control codes in the pattern.

prop - the property name from ElementProperties
true if so


public Object parseObject(String source,
                          ParsePosition status)
Don't parse objects.

source - ignored
status - ignored
null in the default implementation


Built on May 3 2007.  |  Portions Copyright 1997-2005 Sun Microsystems, Inc. All rights reserved.