org.netbeans.modules.editor.settings/1 1.12.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 parameter 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();
 

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.
 
Method Summary
 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 getParametrizedText()
          Gets the code text of this code template.
 String getUniqueId()
          Gets an id that can be used for identifying this template.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, 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.
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

toString

public String toString()
Overrides:
toString in class Object

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

Built on January 29 2008.  |  Portions Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.