}
private ExtensionWrapper createExtensionWrapper(Class<?> extensionClass) {
- ExtensionDescriptor descriptor = new ExtensionDescriptor();
int ordinal = 0;
if (extensionClass.isAnnotationPresent(Extension.class)) {
ordinal = extensionClass.getAnnotation(Extension.class).ordinal();
}
- descriptor.setOrdinal(ordinal);
- descriptor.setExtensionClass(extensionClass);
+ ExtensionDescriptor descriptor = new ExtensionDescriptor(ordinal, extensionClass);
- ExtensionWrapper extensionWrapper = new ExtensionWrapper<>(descriptor);
- extensionWrapper.setExtensionFactory(pluginManager.getExtensionFactory());
-
- return extensionWrapper;
+ return new ExtensionWrapper<>(descriptor, pluginManager.getExtensionFactory());
}
private void checkDifferentClassLoaders(Class<?> type, Class<?> extensionClass) {
*/
public class ExtensionDescriptor {
- private int ordinal;
- private Class<?> extensionClass;
+ public final int ordinal;
+ public final Class<?> extensionClass;
- public Class<?> getExtensionClass() {
- return extensionClass;
- }
-
- public int getOrdinal() {
- return ordinal;
- }
-
- void setExtensionClass(Class<?> extensionClass) {
- this.extensionClass = extensionClass;
- }
-
- void setOrdinal(int ordinal) {
+ public ExtensionDescriptor(int ordinal, Class<?> extensionClass) {
this.ordinal = ordinal;
+ this.extensionClass = extensionClass;
}
}
*/
public class ExtensionWrapper<T> implements Comparable<ExtensionWrapper<T>> {
- ExtensionDescriptor descriptor;
- ExtensionFactory extensionFactory;
- T extension; // cache
+ private final ExtensionDescriptor descriptor;
+ private final ExtensionFactory extensionFactory;
+ private T extension; // cache
- public ExtensionWrapper(ExtensionDescriptor descriptor) {
+ public ExtensionWrapper(ExtensionDescriptor descriptor, ExtensionFactory extensionFactory) {
this.descriptor = descriptor;
- }
+ this.extensionFactory = extensionFactory;
+ }
@SuppressWarnings("unchecked")
public T getExtension() {
if (extension == null) {
- extension = (T) extensionFactory.create(descriptor.getExtensionClass());
+ extension = (T) extensionFactory.create(descriptor.extensionClass);
}
return extension;
}
public int getOrdinal() {
- return descriptor.getOrdinal();
+ return descriptor.ordinal;
}
@Override
return (getOrdinal() - o.getOrdinal());
}
- void setExtensionFactory(ExtensionFactory extensionFactory) {
- this.extensionFactory = extensionFactory;
- }
-
}