vertx-rx icon indicating copy to clipboard operation
vertx-rx copied to clipboard

Extension methods

Open vietj opened this issue 7 years ago • 4 comments

Support extension methods in a similar fashion than Groovy or Kotlin provide.

package foo.bar;

@VertxGen
public interface Foo {
  // Some methods
}

If on the classpath we have:

public interface FooHelper /* Convention */ {
   public static String bar(Foo foo, String s) {
      return foo.toString + s;
   }
}

Then the generated Foo rx wrapper can be augmented with this method:

public class Foo {
   private foo.bar.Foo delegate;
   public String bar(String s) {
      return FooHelper.bar(delegate, s);
   }
}

vietj avatar Jul 20 '18 16:07 vietj

@vietj you piqued my curiosity :) Can you elaborate on a concrete use case you had in mind?

tsegismont avatar Jul 23 '18 13:07 tsegismont

retrofit some existing helper method, for instance:

  public static Scheduler scheduler(io.vertx.core.Vertx vertx) {
    return new ContextScheduler(vertx, false);
  }

we get then a scheduler() method on io.vertx.reactivex.core.Vertx, etc...

vietj avatar Jul 23 '18 14:07 vietj

so the goal is to provide a more oo-ish experience when using vertx-rx

vietj avatar Jul 23 '18 14:07 vietj

Thanks for the details. Indeed, great idea :)

tsegismont avatar Jul 23 '18 15:07 tsegismont