站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc (Current Development Version)

LanguageProvider (Lexer) - NetBeans API Javadoc (Current Development Version)

org.netbeans.modules.lexer/2 1.19.0 1

org.netbeans.spi.lexer
Class LanguageProvider

java.lang.Object
  extended by org.netbeans.spi.lexer.LanguageProvider

public abstract class LanguageProvider
extends Object

The Language provider. This class is a hook into the lexer framework allowing modules to provide a language resolution service. Whenever a Language is not explicitly known the framework tries to determine it by asking LanguageProviders registered in the Lookup.getDefault(). Languages might be needed for a mime type or mime path of a Document used as an input source or they might be needed for some tokens that contain text in an another (embedded) language. In both cases a Language can either be explicitely provided by setting the document's property or implementing the LanguageHierarchy.embedded() method respectively or the framework will use LanguageProviders to create the appropriate Language.


Field Summary
static String PROP_EMBEDDED_LANGUAGE
          The name of the property, which should be fired when the embedded language to Language mapping changes.
static String PROP_LANGUAGE
          The name of the property, which should be fired when the mime paths to Language mapping changes.
 
Constructor Summary
protected LanguageProvider()
          The default constructor for subclasses.
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener l)
          Add a listener for change notifications.
abstract  Language<? extends TokenId> findLanguage(String mimePath)
          Finds Language for a given mime path.
abstract  LanguageEmbedding<? extends TokenId> findLanguageEmbedding(Token<? extends TokenId> token, LanguagePath languagePath, InputAttributes inputAttributes)
          Finds LanguageEmbedding that will define what language is embedded in a given token.
protected  void firePropertyChange(String propertyName)
           
 void removePropertyChangeListener(PropertyChangeListener l)
          Remove a listener.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_LANGUAGE

public static final String PROP_LANGUAGE
The name of the property, which should be fired when the mime paths to Language mapping changes.

See Also:
Constant Field Values

PROP_EMBEDDED_LANGUAGE

public static final String PROP_EMBEDDED_LANGUAGE
The name of the property, which should be fired when the embedded language to Language mapping changes.

See Also:
Constant Field Values
Constructor Detail

LanguageProvider

protected LanguageProvider()
The default constructor for subclasses.

Method Detail

findLanguage

public abstract Language<? extends TokenId> findLanguage(String mimePath)
Finds Language for a given mime path.

The lexer framework uses this method to find a Language for Documents that are used as an input source. If the document itself does not specify its Language the framework will consult registered LanguageProviders to find out the Language appropriate for the document's mime type.

Parameters:
mimePath - The mime path or mime type to get a Language for. It is allowed to pass in an empty string or null.
Returns:
The Language registered for the given mime path or null if no such Language exists.

findLanguageEmbedding

public abstract LanguageEmbedding<? extends TokenId> findLanguageEmbedding(Token<? extends TokenId> token,
                                                                           LanguagePath languagePath,
                                                                           InputAttributes inputAttributes)
Finds LanguageEmbedding that will define what language is embedded in a given token.

If a Token contains text in a different language that could further be used for lexing of this Token the framework will try to find out the Language of that language by asking the Token's own Language first and then by consulting registered LanguageProviders. The LanguageProviders are expected to return a LanguageEmbedding for tokens they care about and null for the rest. The first non-null LanguageEmbedding found will be used.

LanguageEmbedding instances returned from this method must not reference any of the attributes passed in and especially not the token instance.

Parameters:
token - The Token to get the Language for.
languagePath - The LanguagePath of the token, which embedded language should be returned.
inputAttributes - The attributes that could affect the creation of the embedded Language. It may be null if there are no extra attributes.
Returns:
The LanguageEmbedding for the given Token or null if the token can't embedd any language or the token is unknown to this LanguageProvider.

addPropertyChangeListener

public final void addPropertyChangeListener(PropertyChangeListener l)
Add a listener for change notifications.

Parameters:
l - The listener to add.

removePropertyChangeListener

public final void removePropertyChangeListener(PropertyChangeListener l)
Remove a listener.

Parameters:
l - The listener to remove.

firePropertyChange

protected final void firePropertyChange(String propertyName)

org.netbeans.modules.lexer/2 1.19.0 1

Built on May 28 2007.  |  Portions Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.