-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pacmak/java): emit default interface implementations (#2076)
It should be possible to add properties or methods to interfaces that are only meant to be returned by APIs (i.e: non-`@sublassable`) without breaking extensions of those interfaces in other modules. Unfortunatley, when such an interface is extended in another module, it's generated proxy class would previously not have implementations for the new member, creating the potential for a `NoSuchMethodException` at runtime. This PR changes the code generation so that a new `Jsii$Default` nested interface is generated for each interface, which contains default implementations (that forward calls to the *jsii kernel*) for all of its members. > *Note:* members whose name collide with members declared on > `java.lang.Object` cannot have `default` implementations, since these > would always be overridden by `java.lang.Object` implementations. The new `Jsii$Default` interface is implemented (and the default implementations used) by the `Jsii$Proxy` class. When an interface extends one or more bases, its `Jsii$Default` implementation extends those of it's parent interfaces (and inherits their implementations). In order to support backwards compatibility with libraries generated with versions of `jsii-pacmak` that do not implement this feature, a new `metadata.jsii.pacmak.hasDefaultInterfaces` entry is added to the *jsii assembly* at compilation time. It's value is used to determine whether `jsii-pacmak` can rely on the existence of the `Jsii$Default` interface being present. Finally, new elements were added to the Java runtime library for jsii: - The `@Internal` annotation is used to designate API elements that are not meant for public usage - The `IJsiiObject` interface is the base interface of all `Jsii$Default` interfaces, and is implemented by `JsiiObject`. Since interface members need be `public`, the methods declared by this interface have been maked `@Internal`, and were renamed from `jsiiFoo` to `$jsii$foo` (in order to completely remove the risk for name clashes with user-defined APIs) Fixes #2014 --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
- Loading branch information
1 parent
3f84daf
commit c618de3
Showing
29 changed files
with
2,919 additions
and
1,331 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/@jsii/java-runtime/project/src/main/java/software/amazon/jsii/Internal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package software.amazon.jsii; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Annotates API elements that are intended for jsii's internal use only. Such APIs elements are not public by design | ||
* and likely to be removed or renamed, have their signature change, or have their access level decreased in future | ||
* versions of the library without notice. | ||
* | ||
* Annotated elements are eligible for immediate modification or removal and are not subject to semantic versioning. | ||
*/ | ||
@Documented | ||
@Retention(RetentionPolicy.SOURCE) | ||
@Target({ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, ElementType.PACKAGE, ElementType.TYPE}) | ||
public @interface Internal { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.