Skip to content

Instantly share code, notes, and snippets.

@freshNfunky
Created December 13, 2024 15:51
Show Gist options
  • Select an option

  • Save freshNfunky/45ecc526f4e8ec4fc544a9fbba9e3d3c to your computer and use it in GitHub Desktop.

Select an option

Save freshNfunky/45ecc526f4e8ec4fc544a9fbba9e3d3c to your computer and use it in GitHub Desktop.
default ExtensionPointschema for Class instancing
<?xml version='1.0' encoding='UTF-8'?>
<schema targetNamespace="your.plugin.id" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
<meta.schema plugin="your.plugin.id" id="extensionPointId" name="Extension Point Name"/>
</appinfo>
<documentation>
[Enter description of this extension point.]
</documentation>
</annotation>
<element name="extension">
<annotation>
<appinfo>
<meta.element />
</appinfo>
</annotation>
<complexType>
<sequence>
<element ref="client" minOccurs="1" maxOccurs="unbounded"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>
The fully qualified identifier of the extension point.
</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>
An optional identifier of the extension instance.
</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>
An optional name of the extension instance.
</documentation>
</annotation>
</attribute>
</complexType>
</element>
<element name="client">
<complexType>
<sequence>
<element name="model" type="string" minOccurs="1" maxOccurs="1"/>
<element name="input" type="string" minOccurs="1" maxOccurs="1"/>
<element name="output" type="string" minOccurs="1" maxOccurs="1"/>
<element name="report" type="string" minOccurs="1" maxOccurs="1"/>
</sequence>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
The fully qualified name of a class that implements YourInterfaceOrClass.
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn="YourInterfaceOrClass"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appinfo>
<meta.section type="since"/>
</appinfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="examples"/>
</appinfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="apiinfo"/>
</appinfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>
<annotation>
<appinfo>
<meta.section type="implementation"/>
</appinfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>
</schema>
IExtensionRegistry registry = Platform.getExtensionRegistry();
IConfigurationElement[] config = registry.getConfigurationElementsFor("your.plugin.id.extensionPointId");
for (IConfigurationElement e : config) {
try {
ClassModel model = ...; // Initialize your model
File input = ...; // Initialize input file
File output = ...; // Initialize output file
Consumer<String> report = ...; // Initialize report consumer
Object obj = e.createExecutableExtension("class");
if (obj instanceof YourInterfaceOrClass) {
YourInterfaceOrClass instance = (YourInterfaceOrClass) obj;
instance.initialize(model, input, output, report);
// Use the instance here
}
} catch (CoreException ex) {
// Handle the exception
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment