Use of ServiceLoader for ease of adding new languages#142
Use of ServiceLoader for ease of adding new languages#142ZenHarbinger wants to merge 35 commits into
Conversation
|
This would be slick, but I'm old and crotchety and want RSTA to stay buildable/runnable with JDK 5. For this reason I won't be merging this pull request until I decide to get with the times. I'm creating a milestone for things like this just so I don't lose track of them. |
|
Same as RSTALanguage... |
|
Yes, but the java.util.ServiceLoader class was not added until 1.6, so compiling with |
|
Maybe now is a good time to move to Java 6? |
|
That would be awesome. |
|
Is there anyone writing Desktop applications not using Java 8 at this point? Ant 1.10 just moved from 1.5 to 1.8 compatibility. |
Cleaned up SyntaxConstants to remove 'final public static'
|
RSTA actually moved to Java 6 last year; I just forgot about this pull request. Concerns I have with this pull request currently include stuff not related to the feature itself:
/*
* 01/11/2017 (whatever your the current date is)
*
* This library is distributed under a modified BSD license. See the included
* RSyntaxTextArea.License.txt file for details.
*/
One concern I have with merging this is that there's no longer one handy-dandy place to look for a listing of supported lanaguages, such as SyntaxConstants today. Perhaps that's mitigated by the fact that it's one step toward aggregating all information specific to a language into one place: syntax highlighting, code folding, etc. Stuff like language-specific code formatting, and language-support features like you mention, could be included as well. |
|
I'm going to rebase and resubmit. |
|
Rebased pull: #223 |
I have gone through for my own purposes and added some interfaces and classes which can be loaded using the Java ServiceLoader class.
I added:
org.fife.ui.rsyntaxtextarea.TokenMakerRegistration
From here each language then implements a class that derives from this interface.
The interface provides 3 methods.
which are used in DefaultTokenMakerFactory. Instead of manually specifying every language, the ServiceLoader class can find the files from the META-INF.services/org.fife.ui.rsyntaxtextarea.TokenMakerRegistration file which keeps a record of all implementing classes. Using maven (not sure about gradle) there are plugins which will automatically fill in this file when building.
Simlarly, I have added this functionality to LanguageSupportFactory in RSTALanguageSupport for finding supported languages.
A new interface LanguageSupportRegistration is added with methods:
The ServiceLoader will then find all implemented classes in LanguageSupportFactory and add them on the fly.
META-INF.services/org.fife.rsta.ac.LanguageSupportRegistration keeps the record of all implementing classes similar to the above TokenMakerRegistration.