org.openide.src
Class ElementFormat

java.lang.Object
  |
  +--java.text.Format
        |
        +--org.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

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, parseObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ElementFormat

public ElementFormat(String pattern)
Create a new format. See documentation for the class for the syntax of the format argument.
Parameters:
pattern - the pattern describing the format
Method Detail

setSourceFormat

public void setSourceFormat(boolean source)
Set whether the formating is used for code generation. Default value is true.
Parameters:
source - true means that all Identifier and Type objects used in formating are evaluated by getSourceName method. Otherwise (false) the getFullName() is called.

isSourceFormat

public boolean isSourceFormat()
Test if this format generate strings in source format or fully qualified format.
Returns:
the source flag

getPattern

public String getPattern()
Get the pattern.
Returns:
the current pattern

format

public StringBuffer format(Object o,
                           StringBuffer toAppendTo,
                           FieldPosition pos)
Format an object.
Overrides:
format in class Format
Parameters:
o - should be an Element
toAppendTo - the string buffer to format to
pos - currently ignored
Returns:
the same string buffer it was passed (for convenient chaining)
Throws:
IllegalArgumentException - if the object was not really an Element

format

public String format(Element element)
Formats an element.
Parameters:
element - the element to be printed
Returns:
the formatted string using the pattern

dependsOnProperty

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.
Parameters:
prop - the property name from ElementProperties
Returns:
true if so

parseObject

public Object parseObject(String source,
                          ParsePosition status)
Don't parse objects.
Overrides:
parseObject in class Format
Parameters:
source - ignored
status - ignored
Returns:
null in the default implementation


Built on December 12 2001.  |  Portions Copyright 1997-2001 Sun Microsystems, Inc. All rights reserved.