duchess-rs / duchess

Silky smooth Java-Rust interop

Home Page:https://duchess-rs.github.io/duchess/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

generate a "prelude" from `java_package`

nikomatsakis opened this issue · comments

It's annoying to import all the FooExt traits manually. Let's create a "prelude", I .. guess for each java package?

Then you can do something like

duchess::java_package! {
    package foo.bar;
}

use foo::bar::prelude::*;

If we include the subpackages too, then you can do

use duchess::java::prelude::*;
use foo::prelude::*;

which would be nice.

Mentoring tips

Tokens for a package are created here:

fn to_tokens(
&self,
parents: &[Id],
root_map: &RootMap,
reflector: &mut Reflector,
) -> Result<TokenStream, SpanError> {

You will need to modify that to generate a pub mod prelude with pub use statements for the Ext traits. But you'll also need to modify the code that generates a class declaration to return back a list of Ext traits and collect them here.

To include subpackages, you'd need to return the Ext traits from SpannedPackageInfo::to_tokens and collect them here.

This is no longer relevant as we are using inherent method dispatch.