public abstract class LanguageProvider extends Object
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 LanguageProvider
s registered
in the Lookup.getDefault()
.
Language
s 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 LanguageProvider
s to
create the appropriate Language
.Modifier and Type | Field and Description |
---|---|
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. |
Modifier | Constructor and Description |
---|---|
protected |
LanguageProvider()
The default constructor for subclasses.
|
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(PropertyChangeListener l)
Add a listener for change notifications.
|
abstract Language<?> |
findLanguage(String mimeType)
Finds
Language for a given mime type. |
abstract LanguageEmbedding<?> |
findLanguageEmbedding(Token<?> 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.
|
public static final String PROP_LANGUAGE
Language
mapping changes.public static final String PROP_EMBEDDED_LANGUAGE
Language
mapping changes.protected LanguageProvider()
public abstract Language<?> findLanguage(String mimeType)
Language
for a given mime type.
The lexer framework uses this method to find a Language
for Document
s that are used as an input source. If the document
itself does not specify its Language
the framework
will consult registered LanguageProvider
s to find out the
Language
appropriate for the document's mime type.
mimeType
- The mime type of a Language
to find.Language
registered for the given
mime type or null
if no such Language
exists.public abstract LanguageEmbedding<?> findLanguageEmbedding(Token<?> token, LanguagePath languagePath, InputAttributes inputAttributes)
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 LanguageProvider
s. The LanguageProvider
s
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.
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.LanguageEmbedding
for the given Token
or null
if the token can't embedd any language
or the token is unknown to this LanguageProvider
.public final void addPropertyChangeListener(PropertyChangeListener l)
l
- The listener to add.public final void removePropertyChangeListener(PropertyChangeListener l)
l
- The listener to remove.protected final void firePropertyChange(String propertyName)