Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of ServiceLoader for ease of adding new languages #28

Closed
wants to merge 6 commits into from
Closed

Use of ServiceLoader for ease of adding new languages #28

wants to merge 6 commits into from

Conversation

ZenHarbinger
Copy link

I have gone through for my own purposes and added some interfaces and classes which can be loaded using the Java ServiceLoader class.

I have added this functionality to LanguageSupportFactory for finding supported languages.
A new interface LanguageSupportRegistration is added with methods:

String getLanguage();
String getLanguageSupportType();

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.

Similarly I have added org.fife.ui.rsyntaxtextarea.TokenMakerRegistration in the RSyntaxTextArea project.
From here each language then implements a class that derives from this interface.
The interface provides 3 methods.

String getLanguage();
String getTokenMaker();
FoldParser getFoldParser();

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.

@bobbylight bobbylight added this to the java6 milestone Sep 19, 2015
@bobbylight bobbylight self-assigned this Sep 19, 2015
@bobbylight
Copy link
Owner

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.

@ZenHarbinger
Copy link
Author

I was able to set the compiler settings in the pom.xml file for maven to use java 1.5 and it worked.
<maven.compiler.source>1.5</maven.compiler.source>
<maven.compiler.target>1.5</maven.compiler.target>

@bobbylight
Copy link
Owner

Unfortunately the ServiceLoader class was added in 1.6.

@ZenHarbinger ZenHarbinger mentioned this pull request Jan 12, 2017
@ZenHarbinger
Copy link
Author

Close in reference to using: #35
With less intermediary files (pom.xml) and no changes to existing gradle build process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants