org.netbeans.modules.lexer/2 1.39.1 1

org.netbeans.api.lexer
Class LanguagePath

java.lang.Object
  extended by org.netbeans.api.lexer.LanguagePath

public final class LanguagePath
extends Object

Language path describes a complete embedding of the languages starting from the root (top-level) language till the most embedded language.
Language path consists of one root language and zero or more embedded languages.
E.g. for javadoc embedded in java that is embedded in jsp then the language path lp would return the following:

  lp.size() == 3
  lp.language(0) == JspTokenId.language()
  lp.language(1) == JavaTokenId.language()
  lp.language(2) == JavadocTokenId.language()
 

The two language paths for the same languages in the same order represent a single object. Therefore language paths can be compared by using == operator.

Lifetime: Once a particular language path is created it is held by a soft reference from its "parent" language path.

This class may safely be used by multiple threads.


Method Summary
 LanguagePath embedded(Language<?> language)
          Get embedded path of this language path.
 LanguagePath embedded(LanguagePath suffix)
          Get language path corresponding to the suffix language path embedded in this path.
 boolean endsWith(LanguagePath languagePath)
          Check whether this language path ends with the given language path.
static LanguagePath get(Language<?> language)
          Get language path that contains a single language.
static LanguagePath get(LanguagePath prefix, Language<?> language)
          Get language path corresponding to the language embedded in the given context language path.
 Language<?> innerLanguage()
          Return the most inner language of this path.
 Language<?> language(int index)
          Get language of this language path at the given index.
 String mimePath()
          Gets the mime path equivalent of this language path.
 LanguagePath parent()
          Returns language path consisting of <0, size() - 1> languages (i.e.
 int size()
          Get total number of languages in this language path.
 LanguagePath subPath(int startIndex)
          Gets the path starting at the given index and ending after the last language contained in this path.
 LanguagePath subPath(int startIndex, int endIndex)
          Gets the path starting at the given index and ending after the last language contained in this path.
 Language<?> topLanguage()
          Return the top-level language of this language path.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

get

public static LanguagePath get(Language<?> language)
Get language path that contains a single language.

Parameters:
language - non-null language.
Returns:
non-null language path.

get

public static LanguagePath get(LanguagePath prefix,
                               Language<?> language)
Get language path corresponding to the language embedded in the given context language path.
This method has the same effect like using embedded(Language).
For example for java scriplet embedded in jsp the prefix would be a language-path for jsp language and language would be java language.
By using this method language paths with arbitrary depth can be created.

Parameters:
prefix - prefix language path determining the context in which the language is embedded or null if there is no prefix.
language - non-null language.
Returns:
non-null language path.

size

public int size()
Get total number of languages in this language path.

Returns:
>=1 number of languages contained in this language path.

language

public Language<?> language(int index)
Get language of this language path at the given index.
Index zero corresponds to the root language.

Parameters:
index - >=0 && < size().
Returns:
non-null language at the given index.
Throws:
IndexOutOfBoundsException - in case the index is not within required bounds.

embedded

public LanguagePath embedded(Language<?> language)
Get embedded path of this language path.
This method has the same effect like using get(LanguagePath,Language) but this one is usually preferred as it supports more readable code.
For example for java scriplet embedded in jsp the prefix would be a language-path for jsp language and language would be java language.
By using this method language paths with arbitrary depth can be created.

Parameters:
language - non-null language.
Returns:
non-null language path.

embedded

public LanguagePath embedded(LanguagePath suffix)
Get language path corresponding to the suffix language path embedded in this path.

Parameters:
suffix - non-null suffix to be added to this path.
Returns:
non-null language path consisting of this path with the suffix added to the end.

parent

public LanguagePath parent()
Returns language path consisting of <0, size() - 1> languages (i.e. the inner language is cut out). If size() == 1 then null is returned.


topLanguage

public Language<?> topLanguage()
Return the top-level language of this language path.
It's equivalent to language(0).

See Also:
language(int)

innerLanguage

public Language<?> innerLanguage()
Return the most inner language of this path.
It's equivalent to language(size() - 1).

See Also:
language(int)

endsWith

public boolean endsWith(LanguagePath languagePath)
Check whether this language path ends with the given language path.
This may be useful for checking whether a given input contains certain language (or language path) that may possibly be embedded somewhere in the input.

Parameters:
languagePath - non-null language path to be checked.
Returns:
true if this language path contains the given language path at its end (applies for this as well).

subPath

public LanguagePath subPath(int startIndex)
Gets the path starting at the given index and ending after the last language contained in this path.

See Also:
subPath(int, int)

subPath

public LanguagePath subPath(int startIndex,
                            int endIndex)
Gets the path starting at the given index and ending after the last language contained in this path.

Parameters:
startIndex - >=0 starting index of the requested path in this path.
endIndex - >startIndex index after the last item of the requested path.
Returns:
non-null language path containing items between startIndex and endIndex.

mimePath

public String mimePath()
Gets the mime path equivalent of this language path. The mime path is a concatenation of mime types of all the languages in this language path. The mime types are separated by the '/' character.

For example the language path of the java language embedded in the JSP language will return 'text/x-jsp/text/x-java' when this method is called.

The returned string path can be used in MimeLookup's operation to obtain a corresponding MimePath object by using MimePath.parse(returned-mime-path-string).

Returns:
The mime path string.
See Also:
LanguageHierarchy.mimeType()

toString

public String toString()
Overrides:
toString in class Object

org.netbeans.modules.lexer/2 1.39.1 1

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