org.netbeans.modules.editor.settings/1 1.36.1

org.netbeans.api.editor.settings
Class CodeTemplateDescription

java.lang.Object
  extended by org.netbeans.api.editor.settings.CodeTemplateDescription

public final class CodeTemplateDescription
extends Object

The definition of a code template. A code template is basically a piece of code with an abbreviation associated to it. When a user types the abbreviation to the editor and presses the expansion key the code associated with the abbreviation gets expanded. The code can contain various parameters that the user can enter during the expansion.

The CodeTemplateDescriptions can be obtained from CodeTemplateSettings class that can be loaded from MimeLookup for a particular mime type. See the example below.

 Lookup l = MimeLookup.getLookup(MimePath.parse(mimePath));
 CodeTemplateSettings cds = l.lookup(CodeTemplateSettings.class);
 List codeTemplates = cds.getCodeTemplateDescriptions();
 

IMPORTANT: There is a much more powerful API for working with editor code templates in Editor Code Templates module. If you are retrieving this class from MimeLookup you should probably use the Editor Code Templates API instead.

See Also:
CodeTemplateSettings

Constructor Summary
CodeTemplateDescription(String abbreviation, String description, String parametrizedText)
          Creates a new code template description.
CodeTemplateDescription(String abbreviation, String description, String parametrizedText, List<String> contexts, String uniqueId)
          Creates a new code template description.
CodeTemplateDescription(String abbreviation, String description, String parametrizedText, List<String> contexts, String uniqueId, String mimePath)
          Creates a new code template description.
 
Method Summary
 boolean equals(Object obj)
          Checks whether this code template is equal with a code template passed in as the obj parameter.
 String getAbbreviation()
          Gets the abbreviation text that triggers expansion of this code template.
 List<String> getContexts()
          Gets the list of contexts that apply for this code template.
 String getDescription()
          Gets textual description of this code template.
 String getMimePath()
          Gets the mime path where this code template was registered.
 String getParametrizedText()
          Gets the code text of this code template.
 String getUniqueId()
          Gets an id that can be used for identifying this template.
 int hashCode()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CodeTemplateDescription

public CodeTemplateDescription(String abbreviation,
                               String description,
                               String parametrizedText)
Creates a new code template description. It call the other constructor passing null for the contexts parameter.

Parameters:
abbreviation - The abbreviation text that expands this code template.
description - The code template's display text.
parametrizedText - The actual code template that will get expanded when a user writes the abbreviation in the editor.

CodeTemplateDescription

public CodeTemplateDescription(String abbreviation,
                               String description,
                               String parametrizedText,
                               List<String> contexts,
                               String uniqueId)
Creates a new code template description.

Usually clients do not need to create CodeTemplateDescriptions by themselvs. Instead they use MimeLookup and CodeTemplateSettings to access code templates registered in the system.

Parameters:
abbreviation - The abbreviation text that expands this code template.
description - The code template's display text. Can be null
parametrizedText - The actual code template that will get expanded when a user writes the abbreviation in the editor.
contexts - The list of context ids that apply for this code template. Can be null
uniqueId - The id uniquely identifying this template. If you pass non-null value, please make sure that it is really a unique id for this template. Can be null.

CodeTemplateDescription

public CodeTemplateDescription(String abbreviation,
                               String description,
                               String parametrizedText,
                               List<String> contexts,
                               String uniqueId,
                               String mimePath)
Creates a new code template description. The same as #CodeTemplates(String, String, String, List, String, but with additional mimePath parameter.

Parameters:
abbreviation - The abbreviation text that expands this code template.
description - The code template's display text. Can be null
parametrizedText - The actual code template that will get expanded when a user writes the abbreviation in the editor.
contexts - The list of context ids that apply for this code template. Can be null
uniqueId - The id uniquely identifying this template. If you pass non-null value, please make sure that it is really a unique id for this template. Can be null.
mimePath - The mime path where this code template description was registered for.
Since:
1.15
Method Detail

getAbbreviation

public String getAbbreviation()
Gets the abbreviation text that triggers expansion of this code template.

The abbreviation text should be unique among all code templates defined for a one mime type so that each code template can be expanded individually.

Returns:
The abbreviation text that expands this code template.

getDescription

public String getDescription()
Gets textual description of this code template. It's a display text that can be shown in UI such as the code completion window or Tools-Options dialog.

Returns:
The display text for this code template or null if this code template has no descriptions.

getParametrizedText

public String getParametrizedText()
Gets the code text of this code template. This is the text that will be expanded when a user types the abbreviation in the editor and presses the expansion key. The text can contain parameters in the form of "${...}".

Returns:
The code text with parameters.

getContexts

public List<String> getContexts()
Gets the list of contexts that apply for this code template. The contexts are simply unique identifiers used by the infrastructure to filter out code templates that are not suitable for the editor context, where a user types.

The actual identifiers are defined by each particular language (mime type) and can be different for different languages. The language defines contexts for its constructs such as loops, methods, classes, if-else blocks, etc. and than tags each code template available for that language with a context, where it is meaningful to apply the template.

Returns:
The contexts for this code template.

getUniqueId

public String getUniqueId()
Gets an id that can be used for identifying this template. A code template does not generally have to have a unique id, but if it has one it is guaranteed to uniquely identify the template.

Unique ids can be useful for tools importing and exporting code templates from other applications such as TextMate, etc.

Returns:
The unique id or null.
Since:
1.11

getMimePath

public String getMimePath()
Gets the mime path where this code template was registered.

Returns:
The mime path string or null if the registration mime path is unknown.
Since:
1.15

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object obj)
Checks whether this code template is equal with a code template passed in as the obj parameter. By definition two code templates are equal if all their fields are equal - ie. all abbreviation, description, parametrizedText, contexts, uniqueId and mimePath fields are equal.

Overrides:
equals in class Object
Parameters:
obj - The code template to compare with.
Returns:
true if and only if this code template is equal to the obj code template.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

org.netbeans.modules.editor.settings/1 1.36.1

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