-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to have different implementations of extensions #1152
Conversation
Coverage is done is #1153 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I request at least the adding of the license header
protected T extendable; | ||
|
||
protected AbstractExtensionAdder(T extendable) { | ||
this.extendable = extendable; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 questions: do we allow null values and is extendable final?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no problem with forbidding null values (this is always called by doing extendable.newExtensionAdder(..)) so the extendable is never null.
We can also make the extendable final, even private if we want (and pass it to the createExtension method.
You think we should do these changes ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's cleaner if you declare it private
, final
and if you assert the extendable is not null
commons/src/main/java/com/powsybl/commons/extensions/Extendable.java
Outdated
Show resolved
Hide resolved
commons/src/main/java/com/powsybl/commons/extensions/ExtensionAdderProviders.java
Show resolved
Hide resolved
commons/src/main/java/com/powsybl/commons/extensions/ExtensionAdderProviders.java
Outdated
Show resolved
Hide resolved
Will add a few tests in this PR by extracting the static state of ExtendableProviders |
c4c5b97
to
cebfc1a
Compare
I added tests in the same module as the code instead of relying on cross module testing. Also this improves the test coverage. One problem with the current design is that it allows a compilation (with a warning) of the following code: public void bad(VoltageLevel vl) {
vl.newExtension(ConnectablePositionBuilder.class).add();//bad: compiles but shouldn't
} The previous API was better (although not perfect) public void bad(VoltageLevel vl) {
vl.addExtension(ConnectablePosition.class, new ConnectablePosition<>());//good: compile error
vl.addExtension(ConnectablePosition.class, new ConnectablePosition());//bad, compiles but shouldn't. But you are using raw types
} |
The previous API also allowed to compile the following: vl.getExtension(ConnectablePosition.class); // should not compile; there is a warning though I think we have to use the same trick as Collections.emptyList() vs Collections.EMPTY_LIST to allow the type checker to check the generic types |
@mathbagu What do you think of my proposed "clazz" static method ? It fixes the holes in the previous and new APIS. It is only needed for generic extensions and generic extension adders, but should we say that every extension and extension adder should implement it ? |
We can also discuss to find a better solution to the asymetry introduced by the new API: // before it was symmetric:
extendable.addExtension(ExtensionAdder.class, ...);
extendable.getExtension(Extension.class);
//now it is asymetric
extendable.newExtension(ExtensionAdder.class);
extendable.getExtension(Extension.class); |
commons/src/main/java/com/powsybl/commons/extensions/AbstractExtensionAdder.java
Outdated
Show resolved
Hide resolved
commons/src/main/java/com/powsybl/commons/extensions/ExtensionAdderProvider.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
private static interface SimpleExtensionAdder extends ExtensionAdder<SimpleExtendable, SimpleExtension> { | ||
default Class<SimpleExtension> getExtensionClass() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's dirty but I assume we can write dirty code in tests... Default should not be used to avoid duplications
This is only in eclipse. Using maven (ie javac) or intellij, we get the expected compile error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok apart some cosmetic Java & doc issues
commons/src/main/java/com/powsybl/commons/extensions/AbstractExtensionAdder.java
Outdated
Show resolved
Hide resolved
commons/src/test/java/com/powsybl/commons/extensions/ExtensionAdderProvidersTest.java
Outdated
Show resolved
Hide resolved
commons/src/test/java/com/powsybl/commons/extensions/ExtensionAdderProvidersTest.java
Outdated
Show resolved
Hide resolved
commons/src/test/java/com/powsybl/commons/extensions/ExtensionAdderProvidersTest.java
Outdated
Show resolved
Hide resolved
commons/src/test/java/com/powsybl/commons/extensions/ExtensionAdderProvidersTest.java
Outdated
Show resolved
Hide resolved
commons/src/test/java/com/powsybl/commons/extensions/ExtensionAdderProvidersTest.java
Show resolved
Hide resolved
commons/src/test/java/com/powsybl/commons/extensions/ExtensionAdderProvidersTest.java
Outdated
Show resolved
Hide resolved
commons/src/test/java/com/powsybl/commons/extensions/ExtensionAdderProvidersTest.java
Outdated
Show resolved
Hide resolved
commons/src/test/java/com/powsybl/commons/extensions/ExtensionAdderProvidersTest.java
Outdated
Show resolved
Hide resolved
commons/src/test/java/com/powsybl/commons/extensions/ExtensionAdderProvidersTest.java
Outdated
Show resolved
Hide resolved
86e7e43
to
d6b5719
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jonenst Could you check my last comment please?
"Multiple ExtensionAdderProviders found for ExtensionAdder {} for implementation {} : {}", | ||
type.getSimpleName(), name, providers); | ||
throw new PowsyblException( | ||
"Multiple platform configuration providers found"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a copy/past error: are you sure about this message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Signed-off-by: Jon Harper <jon.harper87@gmail.com>
Kudos, SonarCloud Quality Gate passed!
|
Signed-off-by: Jon Harper jon.harper87@gmail.com
Please check if the PR fulfills these requirements (please use
'[x]'
to check the checkboxes, or submit the PR and then click the checkboxes)Does this PR already have an issue describing the problem ? If so, link to this issue using
'#XXX'
and skip the rest#828
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Feature
What is the current behavior? (You can also link to an open issue here)
It's not possible to have multiple implementations of an extension
What is the new behavior (if this is a feature change)?
it is possible to have multiple implementations of an extension
Does this PR introduce a breaking change or deprecate an API? If yes, check the following:
NO
Other information:
(if any of the questions/checkboxes don't apply, please delete them entirely)