org.netbeans.modules.editor.codetemplates/1 1.2.22

org.netbeans.lib.editor.codetemplates.spi
Class CodeTemplateParameter

java.lang.Object
  extended by org.netbeans.lib.editor.codetemplates.spi.CodeTemplateParameter

public final class CodeTemplateParameter
extends Object

Code template parameter describes parsed parameter in the template's text.
A first occurrence of the parameter in the parametrized text of the code template define a master parameter. All other occurrences of the parameter with the same name will become slave parameters.
The value of the master parameter will be used for the slaves as well automatically and document modifications to master parameter's value will be propagated to slaves as well.

Master parameters can have additional hints in the form

 ${param hint=value [hint2=value2] ... }
 ${param hint="string-literal" ... }
 ${param hint ... }
 
The hints give additional specification of what the parameter's value should be.
The slave parameters inherit their value from their master so it has no sense to define any hints for slave parameters.
The hints without explicit =value are assigned with string value "true".


Field Summary
static String CURSOR_PARAMETER_NAME
          Name of the parameter corresponding to the caret position parameter.
static String DEFAULT_VALUE_HINT_NAME
          Name of the hint that defines an explicit default value of a parameter.
static String EDITABLE_HINT_NAME
          Name of the hint that defines whether the given parameter is editable by the user or not.
 
Method Summary
 Map getHints()
          Get map of the [String,String] hints in the parameter.
 int getInsertTextOffset()
          Get starting offset of this parameter in the CodeTemplateInsertRequest.getInsertText().
 CodeTemplateParameter getMaster()
          Get the master parameter of this parameter.
 String getName()
          Get name of this parameter as parsed from the code template description's text.
 int getParametrizedTextEndOffset()
          Get the ending offset of this parameter in the parametrized text.
 int getParametrizedTextStartOffset()
          Get starting offset of this parameter in the parametrized text.
 Collection getSlaves()
          Get unmodifiable collection of the slave parameters.
 String getValue()
          Get the present value of this parameter.
 boolean isEditable()
          Check whether this parameter is editable by the user.
 boolean isSlave()
          Check whether this parameter is slave or not.
 boolean isUserModified()
          Check whether the value of this parameter was modified by the user.
 void setValue(String newValue)
          Set a new value for this parameter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CURSOR_PARAMETER_NAME

public static final String CURSOR_PARAMETER_NAME
Name of the parameter corresponding to the caret position parameter.

See Also:
Constant Field Values

DEFAULT_VALUE_HINT_NAME

public static final String DEFAULT_VALUE_HINT_NAME
Name of the hint that defines an explicit default value of a parameter.

See Also:
Constant Field Values

EDITABLE_HINT_NAME

public static final String EDITABLE_HINT_NAME
Name of the hint that defines whether the given parameter is editable by the user or not.
If the parameter is not editable the user cannot jump to it by TAB key during the post-insert editing. The value however can be changed by the code template processor(s).
Example of non-editable parameter:
 ${param editable=false}
 

See Also:
Constant Field Values
Method Detail

getName

public String getName()
Get name of this parameter as parsed from the code template description's text.


getValue

public String getValue()
Get the present value of this parameter.

Returns:
non-null text value of this parameter.
The default value of the parameter is set to the name of the parameter.
If the parameter has hint of name DEFAULT_VALUE_HINT_NAME then the default value is taken from the hint.

Once the code template gets inserted into the document (can be checked by CodeTemplateInsertRequest.isInserted()) then the user may modify the parameter's value explicitly and this method will reflect these changes.


setValue

public void setValue(String newValue)
Set a new value for this parameter.
The value can only be set to the master parameters because slave parameters will inherit values from their masters.
If the code template was not yet inserted into the text the value will be remembered and used as a default value during insertion.
If the code template was already inserted and it's still actively being changed then the value is propagated directly to the document's text.

See Also:
CodeTemplateInsertRequest.isInserted()

isEditable

public boolean isEditable()
Check whether this parameter is editable by the user.

Returns:
true if this parameter is editable or false if it will be skipped during parameters user's editing.

isUserModified

public boolean isUserModified()
Check whether the value of this parameter was modified by the user.

Returns:
true if the user has explicitly modify value of this parameter by typing or false if not.

getInsertTextOffset

public int getInsertTextOffset()
Get starting offset of this parameter in the CodeTemplateInsertRequest.getInsertText().

Returns:
>=0 starting offset of this parameter in the text being inserted into the document.
After the code template gets inserted into the document the value continues to be updated if the user changes the value by typing until the code template gets released which can be determined by CodeTemplateInsertRequest.isReleased().

getParametrizedTextStartOffset

public int getParametrizedTextStartOffset()
Get starting offset of this parameter in the parametrized text.
The parametrized text can be obtained by CodeTemplateInsertRequest.getParametrizedText().

Returns:
>=0 index of the '${' in the parametrized text.
See Also:
getParametrizedTextEndOffset()

getParametrizedTextEndOffset

public int getParametrizedTextEndOffset()
Get the ending offset of this parameter in the parametrized text.
The parametrized text can be obtained by CodeTemplateInsertRequest.getParametrizedText().

Returns:
>=0 end offset of the parameter in the parametrized text pointing right after the closing '}' of the parameter.
See Also:
getParametrizedTextStartOffset()

getHints

public Map getHints()
Get map of the [String,String] hints in the parameter.
For example the hints map for ${param hint1 hint2="defaultValue"} will contain ["hint1","true"] and ["hint2","defaultValue"].


getMaster

public CodeTemplateParameter getMaster()
Get the master parameter of this parameter.

Returns:
master parameter for this parameter or null if this parameter is master parameter.

getSlaves

public Collection getSlaves()
Get unmodifiable collection of the slave parameters.

Returns:
non-null collection of the slave parameters for this parameter.
The collection will be empty if this is a slave parameter or a master with no slaves.

isSlave

public boolean isSlave()
Check whether this parameter is slave or not.


org.netbeans.modules.editor.codetemplates/1 1.2.22

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