diff --git a/pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java b/pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java index 49be73b..7aa64ca 100644 --- a/pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java +++ b/pf4j/src/main/java/org/pf4j/AbstractExtensionFinder.java @@ -219,18 +219,13 @@ public abstract class AbstractExtensionFinder implements ExtensionFinder, Plugin } 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) { diff --git a/pf4j/src/main/java/org/pf4j/ExtensionDescriptor.java b/pf4j/src/main/java/org/pf4j/ExtensionDescriptor.java index cb0ebc1..4894046 100644 --- a/pf4j/src/main/java/org/pf4j/ExtensionDescriptor.java +++ b/pf4j/src/main/java/org/pf4j/ExtensionDescriptor.java @@ -20,23 +20,12 @@ package org.pf4j; */ 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; } } diff --git a/pf4j/src/main/java/org/pf4j/ExtensionWrapper.java b/pf4j/src/main/java/org/pf4j/ExtensionWrapper.java index 50c9612..22a2c53 100644 --- a/pf4j/src/main/java/org/pf4j/ExtensionWrapper.java +++ b/pf4j/src/main/java/org/pf4j/ExtensionWrapper.java @@ -22,18 +22,19 @@ package org.pf4j; */ public class ExtensionWrapper implements Comparable> { - 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; @@ -44,7 +45,7 @@ public class ExtensionWrapper implements Comparable> { } public int getOrdinal() { - return descriptor.getOrdinal(); + return descriptor.ordinal; } @Override @@ -52,8 +53,4 @@ public class ExtensionWrapper implements Comparable> { return (getOrdinal() - o.getOrdinal()); } - void setExtensionFactory(ExtensionFactory extensionFactory) { - this.extensionFactory = extensionFactory; - } - }