Over a million developers have joined DZone.

@MimeLocation, @MimeRegistration and @MimeRegistrations added

· Java Zone

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

This is how code completion providers are registered in NetBeans IDE 7.0, take note of the @MimeRegistration annotation (which comes from the Mime Lookup API) on the class:

import javax.swing.text.Document;
import javax.swing.text.JTextComponent;
import org.netbeans.api.editor.mimelookup.MimeRegistration;
import org.netbeans.spi.editor.completion.CompletionProvider;
import org.netbeans.spi.editor.completion.CompletionResultSet;
import org.netbeans.spi.editor.completion.CompletionTask;
import org.netbeans.spi.editor.completion.support.AsyncCompletionQuery;
import org.netbeans.spi.editor.completion.support.AsyncCompletionTask;

@MimeRegistration(mimeType = "text/html", service = CompletionProvider.class)
public class DemoCompletionProvider implements CompletionProvider {

    @Override
    public CompletionTask createTask(int i, JTextComponent jTextComponent) {
        return new AsyncCompletionTask(new AsyncCompletionQuery() {
            @Override
            protected void query(CompletionResultSet resultSet, Document doc, int caretOffset) {
                throw new UnsupportedOperationException("Not supported yet.");
            }
        });
    }

    @Override
    public int getAutoQueryTypes(JTextComponent jTextComponent, String string) {
        return 0;
    }
    
}

 

When you compile the module that contains the class above, you'll have a file named "generated-layer.xml" in "build/classes/META-INF", with this content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN"
                            "http://www.netbeans.org/dtds/filesystem-1_2.dtd">
<filesystem>
    <folder name="Editors">
        <folder name="text">
            <folder name="html">
                <folder name="CompletionProviders">
                    <file name="org-demo-DemoCompletionProvider.instance">
                        <!--org.demo.DemoCompletionProvider-->
                    </file>
                </folder>
            </folder>
        </folder>
    </folder>
</filesystem>
 

 

Sometimes one implementation can be used in different contexts, i.e., in different editors, in which case you would annotate like this instead:

@MimeRegistrations({
    @MimeRegistration(mimeType="text/html", service=CompletionProvider.class),
    @MimeRegistration(mimeType="text/x-java", service=CompletionProvider.class)
})
public class DemoCompletionProvider implements CompletionProvider {
 

 

Therefore, you will no longer need to manually register editor service providers manually in the layer file anymore. In the case of completion providers, that's all possible because the CompletionProvider class has this annotation:

@MimeLocation(subfolderName="CompletionProviders")
public interface CompletionProvider {
...
...
...

 

The above is just an example. Anything else that is registered per MIME type in the "Editors" folder can now be registered as shown above. As shown above, you can use the same approach when requiring contributors to register implementations per MIME type in the "Editors" folder.

For details, see this issue:https://netbeans.org/bugzilla/show_bug.cgi?id=190606

 

Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}