Interface to be implemented by all generators inserting their code snippets into documents using the Insert Code editor action.
Factory creating code generators.
The factory instances are looked up by the
Serves for adding an additonal content to the context which is passed as a parameter to the
Instances of this interface are looked up by the
Represents the task passed to the
The Code Generator SPI gives modules a chance to plug their own code generators into the popup that appears in the editor on the Insert Code action invocation.
The whole SPI is organized around the
interface, which is the ultimate thing that modules need to implement in order to generate
code snippets and insert them into a document on the Insert Code action invocation.
CodeGenerators are created by
The registration of
CodeGenerators has to be done through an
instance of the
CodeGenerator.Factory class. The factory should
be registered in
MimeLookup under the mime-type of documents, which
CodeGenerator should be used for, in the
folder. For example, if a module wants to provide
text/x-something documents, it should implement its own
class) and register it in
MimeLookup using its XML layer as it is
shown on the example below.
<folder name="Editors"> <folder name="text"> <folder name="x-something"> <folder name="CodeGenerators"> <file name="org-some-module-CGFactory.instance" /> </folder> </folder> </folder> </folder>
CGFactory class will simply return a new instance of
the module's implementation of the
CodeGenerator interface from its
method. The method can create and return multiple
The parameter of the
create method provides by default access to
JTextComponent, which the generator is being created for. However,
a group of factories could exist for a mime-type which require access to
an additional data (e.g. some parser result, etc.) when creating their
CodeGenerators. To that purpose, an instance of
CodeGeneratorContextProvider interface could be created and registered
MimeLookup under the mime-type in the
folder. For example, if a module wants to provide an additional context for
CodeGenerator.Factory it should
implement its own
org.some.module.CGContextProvider class) and register it in
MimeLookup using its XML layer as it is shown on the example below.
<folder name="Editors"> <folder name="text"> <folder name="x-something"> <folder name="CodeGeneratorContextProviders"> <file name="org-some-module-CGContextProvider.instance" /> </folder> </folder> </folder> </folder>
CGContextProvider class in its
method creates the new context by merging the original context content
with the additional data and runs the task obtained as the parameter with the newly
Built on January 19 2018. | Portions Copyright 1997-2018 Oracle. All rights reserved.