}.
13 | *
14 | *
15 | * @param observable the observable to adapt
16 | * @return the adapted stream
17 | */
18 | public static ReadStream toReadStream(Multi observable) {
19 | return ReadStreamSubscriber.asReadStream(observable, Function.identity());
20 | }
21 |
22 | /**
23 | * Like {@link #toMulti(ReadStream)} but with a {@code mapping} function
24 | */
25 | public static Multi toMulti(ReadStream stream, Function mapping) {
26 | return new MultiReadStream<>(stream, mapping);
27 | }
28 |
29 | /**
30 | * Adapts a Vert.x {@link ReadStream} to an Mutiny {@link Multi}. After
31 | * the stream is adapted to a Multi, the original stream handlers should not be used anymore
32 | * as they will be used by the Multi adapter.
33 | *
34 | *
35 | * @param stream the stream to adapt
36 | * @return the adapted observable
37 | */
38 | public static Multi toMulti(ReadStream stream) {
39 | return new MultiReadStream<>(stream, Function.identity());
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-runtime/src/main/java/io/smallrye/mutiny/vertx/MutinyDelegate.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx;
2 |
3 | /**
4 | * Interface implemented by every generated Mutiny type.
5 | */
6 | public interface MutinyDelegate {
7 |
8 | /**
9 | * @return the delegate used by this Mutiny object of generated type
10 | */
11 | Object getDelegate();
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-runtime/src/main/java/io/smallrye/mutiny/vertx/MutinyGen.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Associate an Mutiny generated class with its original type,used for mapping the generated classes to their original type.
10 | */
11 |
12 | @Target(ElementType.TYPE)
13 | @Retention(RetentionPolicy.RUNTIME)
14 | public @interface MutinyGen {
15 |
16 | /**
17 | * @return the wrapped class
18 | */
19 | Class value();
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-runtime/src/main/java/io/smallrye/mutiny/vertx/TypeArg.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx;
2 |
3 | import java.lang.reflect.Field;
4 | import java.util.function.Function;
5 |
6 | @SuppressWarnings("unchecked")
7 | public class TypeArg {
8 |
9 | private static final TypeArg UNKNOWN = new TypeArg<>(Function.identity(), Function.identity());
10 |
11 | public static TypeArg of(Class type) {
12 | MutinyGen gen = type.getAnnotation(MutinyGen.class);
13 | if (gen != null) {
14 | try {
15 | Field field = type.getField("__TYPE_ARG");
16 | return (TypeArg) field.get(null);
17 | } catch (Exception ignore) {
18 | }
19 | }
20 | return unknown();
21 | }
22 |
23 | public static TypeArg unknown() {
24 | return (TypeArg) UNKNOWN;
25 | }
26 |
27 | public final Function wrap;
28 | public final Function unwrap;
29 |
30 | public TypeArg(Function wrap, Function unwrap) {
31 | this.wrap = wrap;
32 | this.unwrap = unwrap;
33 | }
34 |
35 | public T wrap(Object o) {
36 | return o != null ? (T) wrap.apply(o) : null;
37 | }
38 |
39 | public X unwrap(T o) {
40 | return o != null ? (X) unwrap.apply(o) : null;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-runtime/src/main/java/io/smallrye/mutiny/vertx/WriteStreamSubscriber.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx;
2 |
3 | import java.util.concurrent.Flow.Subscriber;
4 | import java.util.function.Consumer;
5 |
6 | /**
7 | * A {@link io.vertx.core.streams.WriteStream} to {@link Subscriber} adapter.
8 | *
9 | * @param the type of item.
10 | */
11 | @SuppressWarnings("SubscriberImplementation")
12 | public interface WriteStreamSubscriber extends Subscriber {
13 |
14 | /**
15 | * Sets the handler to invoke on failure events.
16 | *
17 | * The underlying {@link io.vertx.core.streams.WriteStream#end()} method is not invoked in this case.
18 | *
19 | * @param callback the callback invoked with the failure
20 | * @return a reference to this, so the API can be used fluently
21 | */
22 | WriteStreamSubscriber onFailure(Consumer super Throwable> callback);
23 |
24 | /**
25 | * Sets the handler to invoke on completion events.
26 | *
27 | * The underlying {@link io.vertx.core.streams.WriteStream#end()} method is invoked before the
28 | * given {@code callback}.
29 | *
30 | * @param callback the callback invoked when the completion event is received
31 | * @return a reference to this, so the API can be used fluently
32 | */
33 | WriteStreamSubscriber onComplete(Runnable callback);
34 |
35 | /**
36 | * Sets the handler to invoke if the adapted {@link io.vertx.core.streams.WriteStream} fails.
37 | *
38 | * The underlying {@link io.vertx.core.streams.WriteStream#end()} method is not invoked in this case.
39 | *
40 | * @param callback the callback invoked with the failure
41 | * @return a reference to this, so the API can be used fluently
42 | */
43 | WriteStreamSubscriber onWriteStreamError(Consumer super Throwable> callback);
44 | }
45 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-runtime/src/main/java/io/smallrye/mutiny/vertx/impl/MappingIterator.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx.impl;
2 |
3 | import java.util.Iterator;
4 | import java.util.function.Function;
5 |
6 | /**
7 | * @author Thomas Segismont
8 | */
9 | public class MappingIterator implements Iterator {
10 |
11 | private final Iterator iterator;
12 | private final Function mapping;
13 |
14 | public MappingIterator(Iterator iterator, Function mapping) {
15 | this.iterator = iterator;
16 | this.mapping = mapping;
17 | }
18 |
19 | @Override
20 | public boolean hasNext() {
21 | return iterator.hasNext();
22 | }
23 |
24 | @Override
25 | public V next() {
26 | return mapping.apply(iterator.next());
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-service-discovery/src/test/java/io/vertx/mutiny/discovery/ServiceDiscoveryTest.java:
--------------------------------------------------------------------------------
1 | package io.vertx.mutiny.discovery;
2 |
3 | import org.junit.After;
4 | import org.junit.Before;
5 | import org.junit.Test;
6 |
7 | import io.vertx.core.json.JsonObject;
8 | import io.vertx.mutiny.core.Vertx;
9 | import io.vertx.mutiny.servicediscovery.ServiceDiscovery;
10 | import io.vertx.mutiny.servicediscovery.types.HttpEndpoint;
11 | import io.vertx.servicediscovery.Record;
12 | import io.vertx.servicediscovery.ServiceDiscoveryOptions;
13 |
14 | public class ServiceDiscoveryTest {
15 |
16 | private Vertx vertx;
17 |
18 | @Before
19 | public void setUp() {
20 | vertx = Vertx.vertx();
21 | }
22 |
23 | @After
24 | public void tearDown() {
25 | vertx.closeAndAwait();
26 | }
27 |
28 | @Test
29 | public void test() {
30 | ServiceDiscovery discovery = ServiceDiscovery.create(vertx);
31 |
32 | discovery = ServiceDiscovery.create(vertx,
33 | new ServiceDiscoveryOptions()
34 | .setAnnounceAddress("service-announce")
35 | .setName("my-name"));
36 |
37 | Record record = new Record()
38 | .setType("eventbus-service-proxy")
39 | .setLocation(new JsonObject().put("endpoint", "the-service-address"))
40 | .setName("my-service")
41 | .setMetadata(new JsonObject().put("some-label", "some-value"));
42 |
43 | discovery.publishAndAwait(record);
44 |
45 | record = HttpEndpoint.createRecord("some-rest-api", "localhost", 8080, "/api");
46 | discovery.publishAndAwait(record);
47 |
48 | discovery.close();
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-sql-client-templates/src/test/java/io/vertx/mutiny/circuitbreaker/SqlClientTemplateTest.java:
--------------------------------------------------------------------------------
1 | package io.vertx.mutiny.circuitbreaker;
2 |
3 | import static org.assertj.core.api.Assertions.assertThatThrownBy;
4 |
5 | import java.util.Collections;
6 | import java.util.Map;
7 |
8 | import org.junit.After;
9 | import org.junit.Before;
10 | import org.junit.Rule;
11 | import org.junit.Test;
12 | import org.testcontainers.containers.PostgreSQLContainer;
13 |
14 | import io.vertx.mutiny.core.Vertx;
15 | import io.vertx.mutiny.pgclient.PgPool;
16 | import io.vertx.mutiny.sqlclient.Pool;
17 | import io.vertx.mutiny.sqlclient.templates.SqlTemplate;
18 | import io.vertx.pgclient.PgConnectOptions;
19 | import io.vertx.pgclient.PgException;
20 | import io.vertx.sqlclient.PoolOptions;
21 |
22 | public class SqlClientTemplateTest {
23 |
24 | @Rule
25 | public PostgreSQLContainer> container = new PostgreSQLContainer<>();
26 |
27 | private Vertx vertx;
28 |
29 | @Before
30 | public void setUp() {
31 | vertx = Vertx.vertx();
32 | }
33 |
34 | @After
35 | public void tearDown() {
36 | vertx.closeAndAwait();
37 | }
38 |
39 | @Test
40 | public void test() {
41 | PgConnectOptions options = new PgConnectOptions()
42 | .setPort(container.getMappedPort(5432))
43 | .setHost(container.getContainerIpAddress())
44 | .setDatabase(container.getDatabaseName())
45 | .setUser(container.getUsername())
46 | .setPassword(container.getPassword());
47 |
48 | Pool client = PgPool.pool(vertx, options, new PoolOptions().setMaxSize(5));
49 |
50 | Map parameters = Collections.singletonMap("id", 1);
51 |
52 | assertThatThrownBy(() -> SqlTemplate
53 | .forQuery(client, "SELECT * FROM users WHERE id=#{id}")
54 | .executeAndAwait(parameters)).isInstanceOf(PgException.class); // Table not created.
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-sql-client/src/test/java/io/vertx/mutiny/sqlclient/SqlClientHelperTestBase.java:
--------------------------------------------------------------------------------
1 | package io.vertx.mutiny.sqlclient;
2 |
3 | import static java.util.stream.Collectors.toList;
4 | import static org.assertj.core.api.Assertions.assertThat;
5 |
6 | import java.util.Arrays;
7 | import java.util.List;
8 | import java.util.stream.Stream;
9 |
10 | import io.smallrye.mutiny.Multi;
11 | import io.smallrye.mutiny.Uni;
12 |
13 | public abstract class SqlClientHelperTestBase {
14 |
15 | protected static final List NAMES = Arrays.asList("John", "Paul", "Peter", "Andrew", "Steven");
16 |
17 | protected static final String UNIQUE_NAMES_SQL = "select distinct firstname from folks order by firstname asc";
18 |
19 | protected static final String INSERT_FOLK_SQL = "insert into folks (firstname) values ('%s')";
20 |
21 | protected Pool pool;
22 |
23 | public void initDb() {
24 | pool.query("drop table if exists folks").executeAndAwait();
25 | pool.query("create table folks (firstname varchar(255) not null unique)").executeAndAwait();
26 | for (String name : NAMES) {
27 | pool.query(String.format(INSERT_FOLK_SQL, name)).executeAndAwait();
28 | }
29 | }
30 |
31 | protected void assertTableContainsInitDataOnly() throws Exception {
32 | List actual = uniqueNames(pool).collect().asList().await().indefinitely();
33 | assertThat(actual).isEqualTo(NAMES.stream().sorted().distinct().collect(toList()));
34 | }
35 |
36 | protected static Multi uniqueNames(SqlClient client) {
37 | return client.query(UNIQUE_NAMES_SQL).execute()
38 | .onItem().transformToMulti(RowSet::toMulti)
39 | .onItem().transform(row -> row.getString(0));
40 | }
41 |
42 | protected static Uni insertExtraFolks(SqlClient client) {
43 | return client.query(String.format(INSERT_FOLK_SQL, "Georges")).execute()
44 | .onItem().transformToUni(v -> client.query(String.format(INSERT_FOLK_SQL, "Henry")).execute())
45 | .onItem().ignore().andContinueWithNull();
46 | }
47 |
48 | protected static List namesWithExtraFolks() {
49 | return Stream.concat(NAMES.stream(), Stream.of("Georges", "Henry")).sorted().distinct().collect(toList());
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-sql-client/src/test/java/io/vertx/mutiny/sqlclient/TransactionMultiTest.java:
--------------------------------------------------------------------------------
1 | package io.vertx.mutiny.sqlclient;
2 |
3 | import static org.assertj.core.api.Assertions.assertThat;
4 |
5 | import java.util.ArrayList;
6 | import java.util.Collections;
7 | import java.util.List;
8 | import java.util.concurrent.CompletionException;
9 |
10 | import org.junit.Test;
11 |
12 | import io.smallrye.mutiny.Multi;
13 |
14 | public abstract class TransactionMultiTest extends SqlClientHelperTestBase {
15 |
16 | List emitted = Collections.synchronizedList(new ArrayList<>());
17 |
18 | @Test
19 | public void inTransactionSuccess() throws Exception {
20 | inTransaction(false, null);
21 | assertThat(emitted).isEqualTo(namesWithExtraFolks());
22 | }
23 |
24 | @Test
25 | public void inTransactionUserFailure() throws Exception {
26 | Exception failure = new Exception();
27 | try {
28 | inTransaction(true, failure);
29 | } catch (Exception e) {
30 | assertThat(e).isInstanceOf(CompletionException.class).getCause().isEqualTo(failure);
31 | assertThat(emitted).isEqualTo(namesWithExtraFolks());
32 | }
33 | assertTableContainsInitDataOnly();
34 | }
35 |
36 | @Test
37 | public void inTransactionDBFailure() throws Exception {
38 | try {
39 | inTransaction(true, null);
40 | } catch (Exception e) {
41 | verifyDuplicateException(e);
42 | assertThat(emitted).isEqualTo(namesWithExtraFolks());
43 | }
44 | assertTableContainsInitDataOnly();
45 | }
46 |
47 | protected abstract void verifyDuplicateException(Exception e);
48 |
49 | private void inTransaction(boolean fail, Exception e) throws Exception {
50 | SqlClientHelper.inTransactionMulti(pool, transaction -> {
51 | Multi upstream = insertExtraFolks(transaction)
52 | .onItem().transformToMulti(v -> uniqueNames(transaction));
53 | if (!fail) {
54 | return upstream;
55 | }
56 | if (e != null) {
57 | return Multi.createBy().concatenating().streams(upstream, Multi.createFrom().failure(e));
58 | }
59 | return Multi.createBy().concatenating().streams(upstream, upstream);
60 | }).onItem().invoke(emitted::add).collect().last().await().indefinitely();
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-sql-client/src/test/java/io/vertx/mutiny/sqlclient/UsingConnectionSafetyTest.java:
--------------------------------------------------------------------------------
1 | package io.vertx.mutiny.sqlclient;
2 |
3 | import static org.assertj.core.api.Assertions.assertThat;
4 | import static org.junit.Assert.fail;
5 |
6 | import java.util.function.Function;
7 |
8 | import org.junit.Test;
9 |
10 | import io.smallrye.mutiny.Uni;
11 |
12 | public abstract class UsingConnectionSafetyTest {
13 |
14 | protected Pool pool;
15 |
16 | @Test
17 | public void testUsingConnectionMulti() throws Exception {
18 | doTest(throwable -> SqlClientHelper.usingConnectionMulti(pool, conn -> {
19 | throw throwable;
20 | }).collect().first());
21 | }
22 |
23 | @Test
24 | public void testUsingConnectionUni() throws Exception {
25 | doTest(throwable -> SqlClientHelper.usingConnectionUni(pool, conn -> {
26 | throw throwable;
27 | }));
28 | }
29 |
30 | private void doTest(Function> function) {
31 | for (int i = 0; i < getMaxPoolSize() + 1; i++) {
32 | RuntimeException expected = new RuntimeException();
33 | try {
34 | function.apply(expected).await().indefinitely();
35 | fail("Should not complete succesfully");
36 | } catch (Exception e) {
37 | assertThat(e).isEqualTo(expected);
38 | }
39 | }
40 | }
41 |
42 | protected abstract int getMaxPoolSize();
43 | }
44 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-stomp/src/test/java/io/vertx/mutiny/stomp/StompTest.java:
--------------------------------------------------------------------------------
1 | package io.vertx.mutiny.stomp;
2 |
3 | import static org.assertj.core.api.Assertions.assertThat;
4 |
5 | import java.util.concurrent.CompletableFuture;
6 |
7 | import org.junit.After;
8 | import org.junit.Before;
9 | import org.junit.Test;
10 |
11 | import io.vertx.ext.stomp.StompClientOptions;
12 | import io.vertx.ext.stomp.StompServerOptions;
13 | import io.vertx.mutiny.core.Vertx;
14 | import io.vertx.mutiny.core.buffer.Buffer;
15 | import io.vertx.mutiny.ext.stomp.StompClient;
16 | import io.vertx.mutiny.ext.stomp.StompServer;
17 | import io.vertx.mutiny.ext.stomp.StompServerHandler;
18 |
19 | public class StompTest {
20 |
21 | private static final int PORT = 62613;
22 | private Vertx vertx;
23 |
24 | @Before
25 | public void setUp() {
26 | vertx = Vertx.vertx();
27 | }
28 |
29 | @After
30 | public void tearDown() {
31 | vertx.closeAndAwait();
32 | }
33 |
34 | @Test
35 | public void test() {
36 | CompletableFuture future = new CompletableFuture<>();
37 | StompServerHandler handler = StompServerHandler.create(vertx);
38 | StompServer server = StompServer.create(vertx, new StompServerOptions().setPort(PORT)).handler(handler)
39 | .listenAndAwait();
40 |
41 | StompClient client = StompClient.create(vertx, new StompClientOptions().setPort(PORT));
42 | client
43 | .connectAndAwait()
44 | .subscribeAndAwait("/q", frame -> future.complete(frame.getBodyAsString()));
45 |
46 | StompClient client2 = StompClient.create(vertx, new StompClientOptions().setPort(PORT));
47 | client2
48 | .connectAndAwait()
49 | .sendAndAwait("/q", Buffer.buffer("hello"));
50 |
51 | String s = future.join();
52 | assertThat(s).isEqualTo("hello");
53 | client.close();
54 | server.closeAndAwait();
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-uri-template/src/test/java/io/vertx/mutiny/uritemplate/UriTemplateTest.java:
--------------------------------------------------------------------------------
1 | package io.vertx.mutiny.uritemplate;
2 |
3 | import org.assertj.core.api.Assertions;
4 | import org.junit.Test;
5 |
6 | import io.vertx.uritemplate.UriTemplate;
7 | import io.vertx.uritemplate.Variables;
8 |
9 | public class UriTemplateTest {
10 |
11 | /**
12 | * Example taken from https://en.wikipedia.org/wiki/URI_Template.
13 | */
14 | @Test
15 | public void test() {
16 | String string = UriTemplate.of("http://example.com/people/{firstName}-{lastName}/SSN")
17 | .expandToString(Variables.variables().set("firstName", "foo").set("lastName", "bar"));
18 | Assertions.assertThat(string).isEqualTo("http://example.com/people/foo-bar/SSN");
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-web-client/src/test/java/io/vertx/mutiny/web/WebClientTest.java:
--------------------------------------------------------------------------------
1 | package io.vertx.mutiny.web;
2 |
3 | import static org.hamcrest.CoreMatchers.is;
4 | import static org.hamcrest.CoreMatchers.notNullValue;
5 | import static org.hamcrest.MatcherAssert.assertThat;
6 |
7 | import org.junit.After;
8 | import org.junit.Before;
9 | import org.junit.Rule;
10 | import org.junit.Test;
11 | import org.testcontainers.containers.BindMode;
12 | import org.testcontainers.containers.GenericContainer;
13 |
14 | import io.vertx.core.json.JsonObject;
15 | import io.vertx.ext.web.client.WebClientOptions;
16 | import io.vertx.mutiny.core.Vertx;
17 | import io.vertx.mutiny.ext.web.client.HttpResponse;
18 | import io.vertx.mutiny.ext.web.client.WebClient;
19 |
20 | public class WebClientTest {
21 |
22 | @Rule
23 | public GenericContainer> container = new GenericContainer<>("kennethreitz/httpbin:latest")
24 | .withExposedPorts(80)
25 | .withFileSystemBind("target", "/tmp/fakemail", BindMode.READ_WRITE);
26 |
27 | private Vertx vertx;
28 |
29 | @Before
30 | public void setUp() {
31 | vertx = Vertx.vertx();
32 | assertThat(vertx, is(notNullValue()));
33 | }
34 |
35 | @After
36 | public void tearDown() {
37 | vertx.closeAndAwait();
38 | }
39 |
40 | @Test
41 | public void testWebClient() {
42 | WebClient client = WebClient.create(vertx, new WebClientOptions()
43 | .setDefaultPort(container.getMappedPort(80))
44 | .setDefaultHost(container.getContainerIpAddress()));
45 | assertThat(client, is(notNullValue()));
46 |
47 | JsonObject object = client.get("/get?msg=hello").send()
48 | .subscribeAsCompletionStage()
49 | .thenApply(HttpResponse::bodyAsJsonObject)
50 | .toCompletableFuture().join();
51 | assertThat(object.getJsonObject("args").getString("msg"), is("hello"));
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-web-client/src/test/java/io/vertx/mutiny/web/WineAndCheese.java:
--------------------------------------------------------------------------------
1 | package io.vertx.mutiny.web;
2 |
3 | import java.util.Objects;
4 |
5 | public class WineAndCheese {
6 |
7 | private String wine;
8 | private String cheese;
9 |
10 | public String getWine() {
11 | return wine;
12 | }
13 |
14 | public WineAndCheese setWine(String wine) {
15 | this.wine = wine;
16 | return this;
17 | }
18 |
19 | public String getCheese() {
20 | return cheese;
21 | }
22 |
23 | public WineAndCheese setCheese(String cheese) {
24 | this.cheese = cheese;
25 | return this;
26 | }
27 |
28 | @Override
29 | public boolean equals(Object obj) {
30 | if (obj instanceof WineAndCheese) {
31 | WineAndCheese that = (WineAndCheese) obj;
32 | return Objects.equals(wine, that.wine) && Objects.equals(cheese, that.cheese);
33 | }
34 | return false;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-web-templ-freemarker/src/test/java/io/vertx/mutiny/web/FreemarkerTemplateTest.java:
--------------------------------------------------------------------------------
1 | package io.vertx.mutiny.web;
2 |
3 | import static org.assertj.core.api.Assertions.assertThat;
4 |
5 | import org.junit.After;
6 | import org.junit.Before;
7 | import org.junit.Test;
8 |
9 | import io.vertx.core.json.JsonObject;
10 | import io.vertx.mutiny.core.Vertx;
11 | import io.vertx.mutiny.core.buffer.Buffer;
12 | import io.vertx.mutiny.ext.web.templ.freemarker.FreeMarkerTemplateEngine;
13 |
14 | public class FreemarkerTemplateTest {
15 |
16 | private Vertx vertx;
17 |
18 | @Before
19 | public void setUp() {
20 | vertx = Vertx.vertx();
21 | }
22 |
23 | @After
24 | public void tearDown() {
25 | vertx.closeAndAwait();
26 | }
27 |
28 | @Test
29 | public void testTemplate() {
30 | FreeMarkerTemplateEngine engine = FreeMarkerTemplateEngine.create(vertx);
31 | Buffer buffer = engine.render(new JsonObject().put("foo", "hello"), "template").await().indefinitely();
32 | assertThat(buffer.toString()).contains("hello").doesNotContain("foo");
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-web-templ-freemarker/src/test/resources/template.ftl:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-web-templ-handlebars/src/test/java/io/vertx/mutiny/web/HandlebarsTemplateTest.java:
--------------------------------------------------------------------------------
1 | package io.vertx.mutiny.web;
2 |
3 | import static org.assertj.core.api.Assertions.assertThat;
4 |
5 | import org.junit.After;
6 | import org.junit.Before;
7 | import org.junit.Test;
8 |
9 | import io.vertx.core.json.JsonObject;
10 | import io.vertx.mutiny.core.Vertx;
11 | import io.vertx.mutiny.core.buffer.Buffer;
12 | import io.vertx.mutiny.ext.web.templ.handlebars.HandlebarsTemplateEngine;
13 |
14 | public class HandlebarsTemplateTest {
15 |
16 | private Vertx vertx;
17 |
18 | @Before
19 | public void setUp() {
20 | vertx = Vertx.vertx();
21 | }
22 |
23 | @After
24 | public void tearDown() {
25 | vertx.closeAndAwait();
26 | }
27 |
28 | @Test
29 | public void testTemplate() {
30 | HandlebarsTemplateEngine engine = HandlebarsTemplateEngine.create(vertx);
31 | Buffer buffer = engine.render(new JsonObject().put("foo", "hello"), "src/test/resources/template.hbs").await()
32 | .indefinitely();
33 | assertThat(buffer.toString()).contains("hello").doesNotContain("foo");
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-web-templ-handlebars/src/test/resources/template.hbs:
--------------------------------------------------------------------------------
1 | {{ foo }}
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-web-templ-jade/src/test/java/io/vertx/mutiny/web/JadeTemplateTest.java:
--------------------------------------------------------------------------------
1 | package io.vertx.mutiny.web;
2 |
3 | import static org.assertj.core.api.Assertions.assertThat;
4 |
5 | import org.junit.After;
6 | import org.junit.Before;
7 | import org.junit.Test;
8 |
9 | import io.vertx.core.json.JsonObject;
10 | import io.vertx.mutiny.core.Vertx;
11 | import io.vertx.mutiny.core.buffer.Buffer;
12 | import io.vertx.mutiny.ext.web.templ.jade.JadeTemplateEngine;
13 |
14 | public class JadeTemplateTest {
15 |
16 | private Vertx vertx;
17 |
18 | @Before
19 | public void setUp() {
20 | vertx = Vertx.vertx();
21 | }
22 |
23 | @After
24 | public void tearDown() {
25 | vertx.closeAndAwait();
26 | }
27 |
28 | @Test
29 | public void testTemplate() {
30 | JadeTemplateEngine engine = JadeTemplateEngine.create(vertx);
31 | Buffer buffer = engine.render(new JsonObject().put("foo", "hello"), "template.jade").await()
32 | .indefinitely();
33 | assertThat(buffer.toString()).contains("hello").doesNotContain("foo");
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-web-templ-jade/src/test/resources/template.jade:
--------------------------------------------------------------------------------
1 | #{foo}
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-web-templ-mvel/src/test/java/io/vertx/mutiny/web/MvelTemplateTest.java:
--------------------------------------------------------------------------------
1 | package io.vertx.mutiny.web;
2 |
3 | import static org.assertj.core.api.Assertions.assertThat;
4 |
5 | import org.junit.After;
6 | import org.junit.Before;
7 | import org.junit.Test;
8 |
9 | import io.vertx.core.json.JsonObject;
10 | import io.vertx.mutiny.core.Vertx;
11 | import io.vertx.mutiny.core.buffer.Buffer;
12 | import io.vertx.mutiny.ext.web.templ.mvel.MVELTemplateEngine;
13 |
14 | public class MvelTemplateTest {
15 |
16 | private Vertx vertx;
17 |
18 | @Before
19 | public void setUp() {
20 | vertx = Vertx.vertx();
21 | }
22 |
23 | @After
24 | public void tearDown() {
25 | vertx.closeAndAwait();
26 | }
27 |
28 | @Test
29 | public void testTemplate() {
30 | MVELTemplateEngine engine = MVELTemplateEngine.create(vertx);
31 | Buffer buffer = engine.render(new JsonObject().put("foo", "hello"), "template.templ").await()
32 | .indefinitely();
33 | assertThat(buffer.toString()).contains("hello").doesNotContain("foo");
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-web-templ-mvel/src/test/resources/template.templ:
--------------------------------------------------------------------------------
1 | @{foo}
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-web-templ-pebble/src/test/java/io/vertx/mutiny/web/PebbleTemplateTest.java:
--------------------------------------------------------------------------------
1 | package io.vertx.mutiny.web;
2 |
3 | import static org.assertj.core.api.Assertions.assertThat;
4 |
5 | import org.junit.After;
6 | import org.junit.Before;
7 | import org.junit.Test;
8 |
9 | import io.vertx.core.json.JsonObject;
10 | import io.vertx.mutiny.core.Vertx;
11 | import io.vertx.mutiny.core.buffer.Buffer;
12 | import io.vertx.mutiny.ext.web.templ.pebble.PebbleTemplateEngine;
13 |
14 | public class PebbleTemplateTest {
15 |
16 | private Vertx vertx;
17 |
18 | @Before
19 | public void setUp() {
20 | vertx = Vertx.vertx();
21 | }
22 |
23 | @After
24 | public void tearDown() {
25 | vertx.closeAndAwait();
26 | }
27 |
28 | @Test
29 | public void testTemplate() {
30 | PebbleTemplateEngine engine = PebbleTemplateEngine.create(vertx);
31 | Buffer buffer = engine.render(new JsonObject().put("foo", "hello"), "template.peb").await()
32 | .indefinitely();
33 | assertThat(buffer.toString()).contains("hello").doesNotContain("foo");
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-web-templ-pebble/src/test/resources/template.peb:
--------------------------------------------------------------------------------
1 | {{ foo }}
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-web-templ-pug/src/test/java/io/vertx/mutiny/web/PugTemplateTest.java:
--------------------------------------------------------------------------------
1 | package io.vertx.mutiny.web;
2 |
3 | import static org.assertj.core.api.Assertions.assertThat;
4 |
5 | import org.junit.After;
6 | import org.junit.Before;
7 | import org.junit.Test;
8 |
9 | import io.vertx.core.json.JsonObject;
10 | import io.vertx.mutiny.core.Vertx;
11 | import io.vertx.mutiny.core.buffer.Buffer;
12 | import io.vertx.mutiny.ext.web.templ.pug.PugTemplateEngine;
13 |
14 | public class PugTemplateTest {
15 |
16 | private Vertx vertx;
17 |
18 | @Before
19 | public void setUp() {
20 | vertx = Vertx.vertx();
21 | }
22 |
23 | @After
24 | public void tearDown() {
25 | vertx.closeAndAwait();
26 | }
27 |
28 | @Test
29 | public void testTemplate() {
30 | PugTemplateEngine engine = PugTemplateEngine.create(vertx);
31 | Buffer buffer = engine.renderAndAwait(new JsonObject().put("foo", "hello"), "template.pug");
32 | assertThat(buffer.toString()).contains("hello
");
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-web-templ-pug/src/test/resources/template.pug:
--------------------------------------------------------------------------------
1 | p= foo
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-web-templ-rocker/src/test/java/io/vertx/mutiny/web/RockerTemplateTest.java:
--------------------------------------------------------------------------------
1 | package io.vertx.mutiny.web;
2 |
3 | import static org.assertj.core.api.Assertions.assertThat;
4 |
5 | import org.junit.After;
6 | import org.junit.Before;
7 | import org.junit.Test;
8 |
9 | import io.vertx.core.json.JsonObject;
10 | import io.vertx.mutiny.core.Vertx;
11 | import io.vertx.mutiny.core.buffer.Buffer;
12 | import io.vertx.mutiny.ext.web.templ.rocker.RockerTemplateEngine;
13 |
14 | public class RockerTemplateTest {
15 |
16 | private Vertx vertx;
17 |
18 | @Before
19 | public void setUp() {
20 | vertx = Vertx.vertx();
21 | }
22 |
23 | @After
24 | public void tearDown() {
25 | vertx.closeAndAwait();
26 | }
27 |
28 | @Test
29 | public void testTemplate() {
30 | RockerTemplateEngine engine = RockerTemplateEngine.create();
31 |
32 | Buffer buffer = engine.render(new JsonObject().put("foo", "hello"), "templates/MyTemplate.rocker.html")
33 | .await().indefinitely();
34 | assertThat(buffer.toString()).contains("hello").doesNotContain("foo");
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-web-templ-rocker/src/test/resources/templates/MyTemplate.rocker.html:
--------------------------------------------------------------------------------
1 | @args (String foo)
2 | @foo
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-web-templ-thymeleaf/src/test/java/io/vertx/mutiny/web/ThymeleafTemplateTest.java:
--------------------------------------------------------------------------------
1 | package io.vertx.mutiny.web;
2 |
3 | import static org.assertj.core.api.Assertions.assertThat;
4 |
5 | import org.junit.After;
6 | import org.junit.Before;
7 | import org.junit.Test;
8 |
9 | import io.vertx.core.json.JsonObject;
10 | import io.vertx.mutiny.core.Vertx;
11 | import io.vertx.mutiny.core.buffer.Buffer;
12 | import io.vertx.mutiny.ext.web.templ.thymeleaf.ThymeleafTemplateEngine;
13 |
14 | public class ThymeleafTemplateTest {
15 |
16 | private Vertx vertx;
17 |
18 | @Before
19 | public void setUp() {
20 | vertx = Vertx.vertx();
21 | }
22 |
23 | @After
24 | public void tearDown() {
25 | vertx.closeAndAwait();
26 | }
27 |
28 | @Test
29 | public void testTemplate() {
30 | ThymeleafTemplateEngine engine = ThymeleafTemplateEngine.create(vertx);
31 | Buffer buffer = engine.render(new JsonObject().put("foo", "hello"), "template.html").await()
32 | .indefinitely();
33 | assertThat(buffer.toString()).contains("hello").doesNotContain("foo");
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-web-templ-thymeleaf/src/test/resources/template.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-web/src/test/java/io/vertx/mutiny/web/TestRouteHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2024 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version 2.0
5 | * (the "License"); you may not use this file except in compliance with the
6 | * License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package io.vertx.mutiny.web;
18 |
19 | import io.vertx.codegen.annotations.VertxGen;
20 | import io.vertx.core.Handler;
21 | import io.vertx.ext.web.RoutingContext;
22 | import io.vertx.mutiny.web.impl.TestRouteHandlerImpl;
23 |
24 | @VertxGen
25 | public interface TestRouteHandler extends Handler {
26 | static TestRouteHandler create() {
27 | return new TestRouteHandlerImpl();
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-web/src/test/java/io/vertx/mutiny/web/impl/TestRouteHandlerImpl.java:
--------------------------------------------------------------------------------
1 | package io.vertx.mutiny.web.impl;
2 |
3 | import java.util.concurrent.atomic.AtomicBoolean;
4 |
5 | import io.vertx.ext.web.RoutingContext;
6 | import io.vertx.ext.web.impl.OrderListener;
7 | import io.vertx.mutiny.web.TestRouteHandler;
8 |
9 | public class TestRouteHandlerImpl implements TestRouteHandler, OrderListener {
10 |
11 | private final AtomicBoolean called = new AtomicBoolean();
12 |
13 | @Override
14 | public void handle(RoutingContext rc) {
15 | if (called.get()) {
16 | rc.response().end();
17 | } else {
18 | rc.fail(500);
19 | }
20 | }
21 |
22 | @Override
23 | public void onOrder(int order) {
24 | called.set(true);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-web/src/test/java/io/vertx/mutiny/web/package-info.java:
--------------------------------------------------------------------------------
1 | @ModuleGen(name = "webtest", groupPackage = "io.vertx")
2 | package io.vertx.mutiny.web;
3 |
4 | import io.vertx.codegen.annotations.ModuleGen;
5 |
--------------------------------------------------------------------------------
/vertx-mutiny-clients/vertx-mutiny-web/src/test/resources/assets/test.txt:
--------------------------------------------------------------------------------
1 | This is a test.
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/main/java/io/smallrye/mutiny/vertx/codegen/MutinyGeneratorLoader.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx.codegen;
2 |
3 | import java.util.stream.Stream;
4 |
5 | import javax.annotation.processing.ProcessingEnvironment;
6 |
7 | import io.vertx.codegen.Generator;
8 | import io.vertx.codegen.GeneratorLoader;
9 |
10 | public class MutinyGeneratorLoader implements GeneratorLoader {
11 | @Override
12 | public Stream> loadGenerators(ProcessingEnvironment processingEnv) {
13 | return Stream.of(new MutinyGenerator());
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/main/java/io/smallrye/mutiny/vertx/codegen/lang/BufferRelatedMethodCodeWriter.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx.codegen.lang;
2 |
3 | import java.io.PrintWriter;
4 |
5 | import io.vertx.codegen.ClassModel;
6 | import io.vertx.core.buffer.Buffer;
7 |
8 | /**
9 | * Add the buffer specific methods.
10 | */
11 | public class BufferRelatedMethodCodeWriter implements ConditionalCodeWriter {
12 |
13 | @Override
14 | public void generate(ClassModel model, PrintWriter writer) {
15 | writer.println(" @Override");
16 | writer.println(" public void writeToBuffer(io.vertx.core.buffer.Buffer buffer) {");
17 | writer.println(" delegate.writeToBuffer(buffer);");
18 | writer.println(" }");
19 | writer.println();
20 | writer.println(" @Override");
21 | writer.println(" public int readFromBuffer(int pos, io.vertx.core.buffer.Buffer buffer) {");
22 | writer.println(" return delegate.readFromBuffer(pos, buffer);");
23 | writer.println(" }");
24 | writer.println();
25 | }
26 |
27 | @Override
28 | public boolean test(ClassModel model) {
29 | return model.isConcrete() && model.getType().getName().equals(Buffer.class.getName());
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/main/java/io/smallrye/mutiny/vertx/codegen/lang/ClassJavadocCodeWriter.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx.codegen.lang;
2 |
3 | import java.io.PrintWriter;
4 |
5 | import io.vertx.codegen.ClassModel;
6 | import io.vertx.codegen.doc.Doc;
7 | import io.vertx.codegen.doc.Token;
8 | import io.vertx.codegen.type.ClassTypeInfo;
9 |
10 | public class ClassJavadocCodeWriter implements CodeWriter {
11 | @Override
12 | public void generate(ClassModel model, PrintWriter writer) {
13 | ClassTypeInfo type = model.getType();
14 | Doc doc = model.getDoc();
15 | if (doc != null) {
16 | writer.println("/**");
17 | Token.toHtml(doc.getTokens(), " *", CodeGenHelper::renderLinkToHtml, "\n", writer);
18 | writer.println(" *");
19 | writer.println(" *
");
20 | writer.print(" * NOTE: This class has been automatically generated from the {@link ");
21 | writer.print(type.getName());
22 | writer.println(" original} non Mutiny-ified interface using Vert.x codegen.");
23 | writer.println(" */");
24 | writer.println();
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/main/java/io/smallrye/mutiny/vertx/codegen/lang/CodeWriter.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx.codegen.lang;
2 |
3 | import io.smallrye.mutiny.vertx.codegen.MutinyGenerator;
4 | import io.vertx.codegen.ClassModel;
5 | import io.vertx.codegen.type.ClassKind;
6 | import io.vertx.codegen.type.ParameterizedTypeInfo;
7 | import io.vertx.codegen.type.TypeInfo;
8 |
9 | import java.io.PrintWriter;
10 | import java.util.function.BiFunction;
11 |
12 | import static java.util.stream.Collectors.joining;
13 |
14 | public interface CodeWriter extends BiFunction {
15 |
16 | void generate(ClassModel model, PrintWriter writer);
17 |
18 | default Void apply(ClassModel model, PrintWriter writer) {
19 | generate(model, writer);
20 | return null;
21 | }
22 |
23 | default String genTypeName(TypeInfo type) {
24 | if (type.isParameterized()) {
25 | ParameterizedTypeInfo pt = (ParameterizedTypeInfo) type;
26 | return genTypeName(pt.getRaw()) + pt.getArgs().stream().map(this::genTypeName)
27 | .collect(joining(", ", "<", ">"));
28 | } else if (type.getKind() == ClassKind.API) {
29 | return type.translateName(MutinyGenerator.ID);
30 | } else {
31 | return type.getSimpleName();
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/main/java/io/smallrye/mutiny/vertx/codegen/lang/ConditionalCodeWriter.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx.codegen.lang;
2 |
3 | import java.io.PrintWriter;
4 | import java.util.function.Predicate;
5 |
6 | import io.vertx.codegen.ClassModel;
7 |
8 | public interface ConditionalCodeWriter extends Predicate, CodeWriter {
9 |
10 | default Void apply(ClassModel model, PrintWriter writer) {
11 | if (test(model)) {
12 | generate(model, writer);
13 | }
14 | return null;
15 | }
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/main/java/io/smallrye/mutiny/vertx/codegen/lang/ConstantCodeWriter.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx.codegen.lang;
2 |
3 |
4 | import java.io.PrintWriter;
5 | import java.util.Map;
6 |
7 | import io.vertx.codegen.ClassModel;
8 | import io.vertx.codegen.ConstantInfo;
9 | import io.vertx.codegen.MethodInfo;
10 | import io.vertx.codegen.doc.Doc;
11 | import io.vertx.codegen.doc.Token;
12 | import io.vertx.codegen.type.TypeInfo;
13 |
14 | import static io.smallrye.mutiny.vertx.codegen.lang.CodeGenHelper.genConvReturn;
15 |
16 | public class ConstantCodeWriter implements CodeWriter {
17 |
18 | private final Map> methodTypeArgMap;
19 |
20 | public ConstantCodeWriter(Map> methodTypeArgMap) {
21 | this.methodTypeArgMap = methodTypeArgMap;
22 | }
23 |
24 | @Override
25 | public void generate(ClassModel model, PrintWriter writer) {
26 | for (ConstantInfo constant : model.getConstants()) {
27 | genConstant(model, constant, writer);
28 | }
29 | }
30 |
31 | private void genConstant(ClassModel model, ConstantInfo constant, PrintWriter writer) {
32 | Doc doc = constant.getDoc();
33 | if (doc != null) {
34 | writer.println(" /**");
35 | Token.toHtml(doc.getTokens(), " *", CodeGenHelper::renderLinkToHtml, "\n", writer);
36 | writer.println(" */");
37 | }
38 | writer.print(model.isConcrete() ? " public static final" : "");
39 | writer.format(" %s %s = %s;%n",
40 | genTypeName(constant.getType()),
41 | constant.getName(),
42 | genConvReturn(methodTypeArgMap, constant.getType(), null, model.getType().getName() + "." + constant.getName()));
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/main/java/io/smallrye/mutiny/vertx/codegen/lang/ConstructorWithDelegateParameterCodeWriter.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx.codegen.lang;
2 |
3 | import io.vertx.codegen.ClassModel;
4 | import io.vertx.codegen.Helper;
5 | import io.vertx.codegen.TypeParamInfo;
6 |
7 | import java.io.PrintWriter;
8 | import java.util.List;
9 |
10 | public class ConstructorWithDelegateParameterCodeWriter implements ConditionalCodeWriter {
11 |
12 | private final String constructor;
13 |
14 | public ConstructorWithDelegateParameterCodeWriter(String constructor) {
15 | this.constructor = constructor;
16 | }
17 |
18 | public ConstructorWithDelegateParameterCodeWriter() {
19 | this.constructor = null;
20 | }
21 |
22 | @Override
23 | public void generate(ClassModel model, PrintWriter writer) {
24 | // Constructor taking delegate as parameter.
25 | String cst = constructor;
26 | if (cst == null) {
27 | cst = model.getIfaceSimpleName();
28 | }
29 |
30 | List typeParams = model.getTypeParams();
31 | writer.print(" public ");
32 | writer.print(cst);
33 | writer.print("(");
34 | writer.print(Helper.getNonGenericType(model.getIfaceFQCN()));
35 | writer.println(" delegate) {");
36 |
37 | if (model.isConcrete() && CodeGenHelper.hasParentClass(model)) {
38 | writer.println(" super(delegate);");
39 | }
40 | writer.println(" this.delegate = delegate;");
41 | for (TypeParamInfo.Class typeParam : typeParams) {
42 | writer.print(" this.__typeArg_");
43 | writer.print(typeParam.getIndex());
44 | writer.print(" = io.smallrye.mutiny.vertx.TypeArg.unknown();");
45 | }
46 | writer.println(" }");
47 | writer.println();
48 | }
49 |
50 | @Override
51 | public boolean test(ClassModel classModel) {
52 | return classModel.isConcrete();
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/main/java/io/smallrye/mutiny/vertx/codegen/lang/ConstructorWithGenericTypesCodeWriter.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx.codegen.lang;
2 |
3 | import io.vertx.codegen.ClassModel;
4 | import io.vertx.codegen.Helper;
5 | import io.vertx.codegen.TypeParamInfo;
6 |
7 | import java.io.PrintWriter;
8 | import java.util.List;
9 |
10 | public class ConstructorWithGenericTypesCodeWriter implements ConditionalCodeWriter {
11 | private final String constructor;
12 |
13 | public ConstructorWithGenericTypesCodeWriter(String constructor) {
14 | this.constructor = constructor;
15 | }
16 |
17 | public ConstructorWithGenericTypesCodeWriter() {
18 | this.constructor = null;
19 | }
20 |
21 | @Override
22 | public void generate(ClassModel model, PrintWriter writer) {
23 | String cst = constructor;
24 | if (cst == null) {
25 | cst = model.getIfaceSimpleName();
26 | }
27 | List typeParams = model.getTypeParams();
28 | if (typeParams.size() > 0) {
29 | writer.print(" public ");
30 | writer.print(cst);
31 | writer.print("(");
32 | writer.print(Helper.getNonGenericType(model.getIfaceFQCN()));
33 | writer.print(" delegate");
34 | for (TypeParamInfo.Class typeParam : typeParams) {
35 | writer.print(", io.smallrye.mutiny.vertx.TypeArg<");
36 | writer.print(typeParam.getName());
37 | writer.print("> typeArg_");
38 | writer.print(typeParam.getIndex());
39 | }
40 | writer.println(") {");
41 | if (model.isConcrete() && CodeGenHelper.hasParentClass(model)) {
42 | writer.println(" super(delegate);");
43 | }
44 | writer.println(" this.delegate = delegate;");
45 | for (TypeParamInfo.Class typeParam : typeParams) {
46 | writer.print(" this.__typeArg_");
47 | writer.print(typeParam.getIndex());
48 | writer.print(" = typeArg_");
49 | writer.print(typeParam.getIndex());
50 | writer.println(";");
51 | }
52 | writer.println(" }");
53 | writer.println();
54 | }
55 | }
56 |
57 | @Override
58 | public boolean test(ClassModel classModel) {
59 | return classModel.isConcrete();
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/main/java/io/smallrye/mutiny/vertx/codegen/lang/ConsumerMethodCodeWriter.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx.codegen.lang;
2 |
3 | import io.vertx.codegen.ClassModel;
4 |
5 | import java.io.PrintWriter;
6 |
7 | /**
8 | * If the class implements {@code Handler}, we added {@code Consumer} and so we need to implement that method.
9 | */
10 | public class ConsumerMethodCodeWriter implements ConditionalCodeWriter {
11 | @Override
12 | public void generate(ClassModel model, PrintWriter writer) {
13 | if (model.isConcrete()) {
14 | writer.println(" public void accept(" + genTypeName(model.getHandlerArg()) + " item) {");
15 | writer.println(" handle(item);");
16 | writer.println(" }");
17 | } else {
18 | writer.println(" default public void accept(" + genTypeName(model.getHandlerArg()) + " item) {");
19 | writer.println(" handle(item);");
20 | writer.println(" }");
21 | }
22 | }
23 |
24 | @Override
25 | public boolean test(ClassModel classModel) {
26 | return classModel.isHandler();
27 | }
28 |
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/main/java/io/smallrye/mutiny/vertx/codegen/lang/DelegateFieldCodeWriter.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx.codegen.lang;
2 |
3 | import io.smallrye.mutiny.vertx.TypeArg;
4 | import io.vertx.codegen.ClassModel;
5 | import io.vertx.codegen.Helper;
6 | import io.vertx.codegen.TypeParamInfo;
7 |
8 | import java.io.PrintWriter;
9 | import java.util.List;
10 |
11 | import static java.util.stream.Collectors.joining;
12 |
13 | public class DelegateFieldCodeWriter implements ConditionalCodeWriter {
14 | @Override
15 | public void generate(ClassModel model, PrintWriter writer) {
16 | writer.print(" private final ");
17 | writer.print(Helper.getNonGenericType(model.getIfaceFQCN()));
18 | List typeParams = model.getTypeParams();
19 | if (typeParams.size() > 0) {
20 | writer.print(typeParams.stream().map(TypeParamInfo.Class::getName).collect(joining(",", "<", ">")));
21 | }
22 | writer.println(" delegate;");
23 |
24 | for (TypeParamInfo.Class typeParam : typeParams) {
25 | writer.print(" public final " + TypeArg.class.getName() + "<");
26 | writer.print(typeParam.getName());
27 | writer.print("> __typeArg_");
28 | writer.print(typeParam.getIndex());
29 | writer.println(";");
30 | }
31 | writer.println(" ");
32 | }
33 |
34 | @Override
35 | public boolean test(ClassModel classModel) {
36 | return classModel.isConcrete();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/main/java/io/smallrye/mutiny/vertx/codegen/lang/DelegateMethodDeclarationCodeWriter.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx.codegen.lang;
2 |
3 | import java.io.PrintWriter;
4 |
5 | import io.vertx.codegen.ClassModel;
6 |
7 | public class DelegateMethodDeclarationCodeWriter implements ConditionalCodeWriter {
8 | @Override
9 | public void generate(ClassModel model, PrintWriter writer) {
10 | writer.print(" ");
11 | writer.print(model.getType().getName());
12 | writer.println(" getDelegate();");
13 | writer.println();
14 | }
15 |
16 | @Override
17 | public boolean test(ClassModel classModel) {
18 | return !classModel.isConcrete();
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/main/java/io/smallrye/mutiny/vertx/codegen/lang/GetDelegateMethodCodeWriter.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx.codegen.lang;
2 |
3 | import io.vertx.codegen.ClassModel;
4 |
5 | import java.io.PrintWriter;
6 |
7 | public class GetDelegateMethodCodeWriter implements ConditionalCodeWriter {
8 | @Override
9 | public void generate(ClassModel model, PrintWriter writer) {
10 | writer.println(" @Override");
11 | writer.print(" public ");
12 | writer.print(model.getType().getName());
13 | writer.println(" getDelegate() {");
14 | writer.println(" return delegate;");
15 | writer.println(" }");
16 | writer.println();
17 | }
18 |
19 | @Override
20 | public boolean test(ClassModel classModel) {
21 | return classModel.isConcrete();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/main/java/io/smallrye/mutiny/vertx/codegen/lang/HashCodeAndEqualsMethodsCodeWriter.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx.codegen.lang;
2 |
3 | import java.io.PrintWriter;
4 |
5 | import io.vertx.codegen.ClassModel;
6 | import io.vertx.codegen.type.ClassTypeInfo;
7 |
8 | /**
9 | * Add the equals and hashCode methods.
10 | */
11 | public class HashCodeAndEqualsMethodsCodeWriter implements ConditionalCodeWriter {
12 |
13 | @Override
14 | public void generate(ClassModel model, PrintWriter writer) {
15 | ClassTypeInfo type = model.getType();
16 | writer.println(" @Override");
17 | writer.println(" public boolean equals(Object o) {");
18 | writer.println(" if (this == o) return true;");
19 | writer.println(" if (o == null || getClass() != o.getClass()) return false;");
20 | writer.print(" ");
21 | writer.print(type.getSimpleName());
22 | writer.print(" that = (");
23 | writer.print(type.getSimpleName());
24 | writer.println(") o;");
25 | writer.println(" return delegate.equals(that.delegate);");
26 | writer.println(" }");
27 | writer.println(" ");
28 |
29 | writer.println(" @Override");
30 | writer.println(" public int hashCode() {");
31 | writer.println(" return delegate.hashCode();");
32 | writer.println(" }");
33 | writer.println();
34 | }
35 |
36 | @Override
37 | public boolean test(ClassModel model) {
38 | return model.isConcrete();
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/main/java/io/smallrye/mutiny/vertx/codegen/lang/ImplClassCodeWriter.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx.codegen.lang;
2 |
3 | import io.smallrye.mutiny.vertx.codegen.MutinyGenerator;
4 | import io.vertx.codegen.ClassModel;
5 | import io.vertx.codegen.Helper;
6 | import io.vertx.codegen.type.ClassTypeInfo;
7 |
8 | import java.io.PrintWriter;
9 |
10 | public class ImplClassCodeWriter implements ConditionalCodeWriter {
11 | private final MutinyGenerator generator;
12 |
13 | public ImplClassCodeWriter(MutinyGenerator mutinyGenerator) {
14 | this.generator = mutinyGenerator;
15 | }
16 |
17 | @Override
18 | public void generate(ClassModel model, PrintWriter writer) {
19 | ClassTypeInfo type = model.getType();
20 | writer.println();
21 | writer.print("class ");
22 | writer.print(type.getSimpleName());
23 | writer.print("Impl");
24 | writer.print(CodeGenHelper.genOptTypeParamsDecl(type, ""));
25 | writer.print(" implements ");
26 | writer.print(Helper.getSimpleName(model.getIfaceFQCN()));
27 | writer.println(" {");
28 |
29 | // By-pass conditions
30 | new DelegateFieldCodeWriter().generate(model, writer);
31 | new GetDelegateMethodCodeWriter().generate(model, writer);
32 | new NoArgConstructorCodeWriter(type.getSimpleName() + "Impl").generate(model, writer);
33 | new ConstructorWithDelegateParameterCodeWriter(type.getSimpleName() + "Impl").generate(model, writer);
34 | new ConstructorWithGenericTypesCodeWriter(type.getSimpleName() + "Impl").generate(model, writer);
35 | if (model.isReadStream()) {
36 | new ToMultiMethodCodeWriter().generate(model, writer);
37 | }
38 |
39 | generator.generateClassBody(model, writer);
40 | writer.println("}");
41 | }
42 |
43 | @Override
44 | public boolean test(ClassModel classModel) {
45 | return !classModel.isConcrete();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/main/java/io/smallrye/mutiny/vertx/codegen/lang/ImportDeclarationCodeWriter.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx.codegen.lang;
2 |
3 | import java.io.PrintWriter;
4 | import java.util.HashSet;
5 | import java.util.Map;
6 | import java.util.Set;
7 | import java.util.stream.Collectors;
8 |
9 | import io.smallrye.common.annotation.CheckReturnValue;
10 | import io.smallrye.mutiny.vertx.TypeArg;
11 | import io.vertx.codegen.annotations.Fluent;
12 |
13 | import io.smallrye.mutiny.Multi;
14 | import io.smallrye.mutiny.Uni;
15 | import io.vertx.codegen.ClassModel;
16 | import io.vertx.codegen.type.ClassKind;
17 | import io.vertx.codegen.type.ClassTypeInfo;
18 |
19 | public class ImportDeclarationCodeWriter implements CodeWriter {
20 | @Override
21 | public void generate(ClassModel model, PrintWriter writer) {
22 | writer.println("import " + Map.class.getName() + ";");
23 | writer.println("import " + Collectors.class.getName() + ";");
24 | writer.println("import " + Multi.class.getName() + ";");
25 | writer.println("import " + Uni.class.getName() + ";");
26 | writer.println("import " + TypeArg.class.getName() + ";");
27 | writer.println("import " + Fluent.class.getName() + ";");
28 | writer.println("import " + CheckReturnValue.class.getName() + ";");
29 |
30 | Set imported = new HashSet<>();
31 | for (ClassTypeInfo importedType : model.getImportedTypes()) {
32 | if (importedType.getKind() != ClassKind.API) {
33 | if (!importedType.getPackageName().equals("java.lang")) {
34 | if (imported.add(importedType.getSimpleName())) {
35 | writer.println("import " + importedType + ";");
36 | }
37 | }
38 | }
39 | }
40 | writer.println();
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/main/java/io/smallrye/mutiny/vertx/codegen/lang/MutinyGenAnnotationCodeWriter.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx.codegen.lang;
2 |
3 | import java.io.PrintWriter;
4 |
5 | import io.vertx.codegen.ClassModel;
6 |
7 | public class MutinyGenAnnotationCodeWriter implements CodeWriter {
8 | @Override
9 | public void generate(ClassModel model, PrintWriter writer) {
10 | writer.print("@io.smallrye.mutiny.vertx.MutinyGen(");
11 | writer.print(model.getType().getName());
12 | writer.println(".class)");
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/main/java/io/smallrye/mutiny/vertx/codegen/lang/NewInstanceMethodCodeWriter.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx.codegen.lang;
2 |
3 | import java.io.PrintWriter;
4 |
5 | import io.vertx.codegen.ClassModel;
6 | import io.vertx.codegen.type.ClassTypeInfo;
7 |
8 | public class NewInstanceMethodCodeWriter implements CodeWriter {
9 | @Override
10 | public void generate(ClassModel model, PrintWriter writer) {
11 | ClassTypeInfo type = model.getType();
12 | writer.print(" public static ");
13 | writer.print(CodeGenHelper.genOptTypeParamsDecl(type, " "));
14 | writer.print(type.getSimpleName());
15 | writer.print(CodeGenHelper.genOptTypeParamsDecl(type, ""));
16 | writer.print(" newInstance(");
17 | writer.print(type.getName());
18 | writer.println(" arg) {");
19 |
20 | writer.print(" return arg != null ? new ");
21 | writer.print(type.getSimpleName());
22 | if (!model.isConcrete()) {
23 | writer.print("Impl");
24 | }
25 | writer.print(CodeGenHelper.genOptTypeParamsDecl(type, ""));
26 | writer.println("(arg) : null;");
27 | writer.println(" }");
28 | writer.println();
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/main/java/io/smallrye/mutiny/vertx/codegen/lang/NewInstanceWithGenericsMethodCodeWriter.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx.codegen.lang;
2 |
3 | import io.smallrye.mutiny.vertx.TypeArg;
4 | import io.vertx.codegen.ClassModel;
5 | import io.vertx.codegen.TypeParamInfo;
6 | import io.vertx.codegen.type.ClassTypeInfo;
7 |
8 | import java.io.PrintWriter;
9 |
10 | import static io.smallrye.mutiny.vertx.codegen.lang.CodeGenHelper.genOptTypeParamsDecl;
11 |
12 | public class NewInstanceWithGenericsMethodCodeWriter implements ConditionalCodeWriter {
13 | @Override
14 | public void generate(ClassModel model, PrintWriter writer) {
15 | ClassTypeInfo type = model.getType();
16 | writer.println();
17 | writer.print(" public static ");
18 | writer.print(genOptTypeParamsDecl(type, " "));
19 | writer.print(type.getSimpleName());
20 | writer.print(genOptTypeParamsDecl(type, ""));
21 | writer.print(" newInstance(");
22 | writer.print(type.getName());
23 | writer.print(" arg");
24 | for (TypeParamInfo typeParam : type.getParams()) {
25 | writer.print(", " + TypeArg.class.getName() + "<");
26 | writer.print(typeParam.getName());
27 | writer.print("> __typeArg_");
28 | writer.print(typeParam.getName());
29 | }
30 | writer.println(") {");
31 |
32 | writer.print(" return arg != null ? new ");
33 | writer.print(type.getSimpleName());
34 | if (!model.isConcrete()) {
35 | writer.print("Impl");
36 | }
37 | writer.print(genOptTypeParamsDecl(type, ""));
38 | writer.print("(arg");
39 | for (TypeParamInfo typeParam : type.getParams()) {
40 | writer.print(", __typeArg_");
41 | writer.print(typeParam.getName());
42 | }
43 | writer.println(") : null;");
44 | writer.println(" }");
45 | writer.println();
46 | }
47 |
48 | @Override
49 | public boolean test(ClassModel classModel) {
50 | return !classModel.getType().getParams().isEmpty();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/main/java/io/smallrye/mutiny/vertx/codegen/lang/NoArgConstructorCodeWriter.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx.codegen.lang;
2 |
3 | import io.vertx.codegen.ClassModel;
4 | import io.vertx.codegen.TypeParamInfo;
5 |
6 | import java.io.PrintWriter;
7 | import java.util.List;
8 |
9 | public class NoArgConstructorCodeWriter implements ConditionalCodeWriter {
10 | private String constructor;
11 |
12 | public NoArgConstructorCodeWriter(String constructor) {
13 | this.constructor = constructor;
14 | }
15 |
16 | public NoArgConstructorCodeWriter() {
17 | this.constructor = null;
18 | }
19 |
20 | @Override
21 | public void generate(ClassModel model, PrintWriter writer) {
22 | String cst = constructor;
23 | if (cst == null) {
24 | cst = model.getIfaceSimpleName();
25 | }
26 |
27 | List typeParams = model.getTypeParams();
28 | // Constructor without parameter, used by CDI
29 | writer.println(" /**");
30 | writer.println(" * Empty constructor used by CDI, do not use this constructor directly.");
31 | writer.println(" **/");
32 | writer.print(" ");
33 | writer.print(cst);
34 | writer.println("() {");
35 | if (model.isConcrete() && CodeGenHelper.hasParentClass(model)) {
36 | writer.println(" super(null);");
37 | }
38 | writer.println(" this.delegate = null;");
39 | for (TypeParamInfo.Class typeParam : typeParams) {
40 | writer.print(" this.__typeArg_");
41 | writer.print(typeParam.getIndex());
42 | writer.print(" = io.smallrye.mutiny.vertx.TypeArg.unknown();");
43 | }
44 | writer.println(" }");
45 | writer.println();
46 | }
47 |
48 | @Override
49 | public boolean test(ClassModel classModel) {
50 | return classModel.isConcrete();
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/main/java/io/smallrye/mutiny/vertx/codegen/lang/PackageDeclarationCodeWriter.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx.codegen.lang;
2 |
3 | import io.smallrye.mutiny.vertx.codegen.MutinyGenerator;
4 | import io.vertx.codegen.ClassModel;
5 |
6 | import java.io.PrintWriter;
7 |
8 | public class PackageDeclarationCodeWriter implements CodeWriter {
9 |
10 | @Override
11 | public void generate(ClassModel model, PrintWriter writer) {
12 | writer.print("package ");
13 | writer.print(model.getType().translatePackageName(MutinyGenerator.ID));
14 | writer.println(";");
15 | writer.println();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/main/java/io/smallrye/mutiny/vertx/codegen/lang/ReadStreamMethodDeclarationCodeWriter.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx.codegen.lang;
2 |
3 | import java.io.PrintWriter;
4 | import java.util.List;
5 |
6 | import io.smallrye.mutiny.Multi;
7 | import io.vertx.codegen.ClassModel;
8 | import io.vertx.codegen.TypeParamInfo;
9 |
10 | public class ReadStreamMethodDeclarationCodeWriter implements ConditionalCodeWriter {
11 | @Override
12 | public void generate(ClassModel model, PrintWriter writer) {
13 | List params = model.getType().getParams();
14 | writer.print(" @CheckReturnValue\n");
15 | writer.print(" " + Multi.class.getName() + "<");
16 | writer.print(params.get(0).getName());
17 | writer.println("> toMulti();");
18 | writer.println();
19 | }
20 |
21 | @Override
22 | public boolean test(ClassModel classModel) {
23 | return !classModel.isConcrete()
24 | && classModel.getType().getRaw().getName().equals("io.vertx.core.streams.ReadStream");
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/main/java/io/smallrye/mutiny/vertx/codegen/lang/ToStringMethodCodeWriter.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx.codegen.lang;
2 |
3 | import java.io.PrintWriter;
4 | import java.util.List;
5 |
6 | import io.vertx.codegen.ClassModel;
7 | import io.vertx.codegen.MethodInfo;
8 |
9 | /**
10 | * Add toString if not in the list of method
11 | */
12 | public class ToStringMethodCodeWriter implements ConditionalCodeWriter {
13 |
14 | @Override
15 | public void generate(ClassModel model, PrintWriter writer) {
16 | writer.println(" @Override");
17 | writer.println(" public String toString() {");
18 | writer.println(" return delegate.toString();");
19 | writer.println(" }");
20 | writer.println();
21 | }
22 |
23 | @Override
24 | public boolean test(ClassModel model) {
25 | List methods = model.getMethods();
26 | return model.isConcrete()
27 | && methods.stream().noneMatch(it -> it.getParams().isEmpty() && "toString".equals(it.getName()));
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/main/java/io/smallrye/mutiny/vertx/codegen/lang/ToSubscriberCodeWriter.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx.codegen.lang;
2 |
3 | import java.io.PrintWriter;
4 |
5 | import io.vertx.codegen.ClassModel;
6 | import io.vertx.codegen.type.ClassKind;
7 | import io.vertx.codegen.type.TypeInfo;
8 |
9 | public class ToSubscriberCodeWriter implements ConditionalCodeWriter {
10 | @Override
11 | public void generate(ClassModel model, PrintWriter writer) {
12 | TypeInfo itemType = model.getWriteStreamArg();
13 | writer.format(" private io.smallrye.mutiny.vertx.WriteStreamSubscriber<%s> subscriber;%n",
14 | genTypeName(itemType));
15 |
16 | writer.println();
17 |
18 | genToSubscriber(itemType, writer);
19 | }
20 |
21 | private void genToSubscriber(TypeInfo itemType, PrintWriter writer) {
22 | writer.format(" @CheckReturnValue\n");
23 | writer.format(" public synchronized io.smallrye.mutiny.vertx.WriteStreamSubscriber<%s> toSubscriber() {%n",
24 | genTypeName(itemType));
25 | writer.format(" if (%s == null) {%n", "subscriber");
26 |
27 | if (itemType.getKind() == ClassKind.API) {
28 | writer.format(" java.util.function.Function<%s, %s> conv = %s::getDelegate;%n", genTypeName(itemType.getRaw()),
29 | itemType.getName(), genTypeName(itemType));
30 | writer.format(" %s = io.smallrye.mutiny.vertx.MutinyHelper.toSubscriber(getDelegate(), conv);%n",
31 | "subscriber");
32 | } else if (itemType.isVariable()) {
33 | String typeVar = itemType.getSimpleName();
34 | writer.format(
35 | " java.util.function.Function<%s, %s> conv = (java.util.function.Function<%s, %s>) __typeArg_0.unwrap;%n",
36 | typeVar, typeVar, typeVar, typeVar);
37 | writer.format(" %s = io.smallrye.mutiny.vertx.MutinyHelper.toSubscriber(getDelegate(), conv);%n",
38 | "subscriber");
39 | } else {
40 | writer.format(" %s = io.smallrye.mutiny.vertx.MutinyHelper.toSubscriber(getDelegate());%n", "subscriber");
41 | }
42 |
43 | writer.println(" }");
44 | writer.format(" return %s;%n", "subscriber");
45 | writer.println(" }");
46 | writer.println();
47 | }
48 |
49 | @Override
50 | public boolean test(ClassModel classModel) {
51 | return classModel.isConcrete() && classModel.isWriteStream();
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/main/java/io/smallrye/mutiny/vertx/codegen/lang/TypeArgsConstantCodeWriter.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx.codegen.lang;
2 |
3 | import io.smallrye.mutiny.vertx.TypeArg;
4 | import io.vertx.codegen.ClassModel;
5 | import io.vertx.codegen.type.ClassTypeInfo;
6 |
7 | import java.io.PrintWriter;
8 |
9 | public class TypeArgsConstantCodeWriter implements ConditionalCodeWriter {
10 | @Override
11 | public void generate(ClassModel model, PrintWriter writer) {
12 | ClassTypeInfo type = model.getType();
13 | String simpleName = type.getSimpleName();
14 |
15 | writer.print(" public static final " + TypeArg.class.getName() + "<");
16 | writer.print(simpleName);
17 | writer.print("> __TYPE_ARG = new " + TypeArg.class.getName() + "<>(");
18 | writer.print(" obj -> new ");
19 | writer.print(simpleName);
20 | writer.print("((");
21 | writer.print(type.getName());
22 | writer.println(") obj),");
23 | writer.print(" ");
24 | writer.print(simpleName);
25 | writer.println("::getDelegate");
26 | writer.println(" );");
27 | writer.println();
28 | }
29 |
30 | @Override
31 | public boolean test(ClassModel classModel) {
32 | return classModel.isConcrete();
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/main/java/io/smallrye/mutiny/vertx/codegen/lang/TypeHelper.java:
--------------------------------------------------------------------------------
1 | package io.smallrye.mutiny.vertx.codegen.lang;
2 |
3 | import io.vertx.codegen.ParamInfo;
4 | import io.vertx.codegen.type.ParameterizedTypeInfo;
5 | import io.vertx.codegen.type.TypeInfo;
6 | import io.vertx.core.Handler;
7 | import io.vertx.core.Promise;
8 |
9 | import java.util.function.Consumer;
10 |
11 | public class TypeHelper {
12 |
13 | public static boolean isHandlerOfPromise(ParamInfo it) {
14 | boolean parameterized = it.getType().isParameterized();
15 | if (! parameterized) {
16 | return false;
17 | }
18 | ParameterizedTypeInfo type = (ParameterizedTypeInfo) it.getType();
19 | if (! type.getRaw().getName().equals(Handler.class.getName())) {
20 | return false;
21 | }
22 | TypeInfo arg = type.getArg(0);
23 | if (arg.isParameterized()) {
24 | return arg.getRaw().getName().equals(Promise.class.getName());
25 | } else {
26 | return arg.getName().equals(Promise.class.getName());
27 | }
28 | }
29 |
30 | public static boolean isConsumerOfPromise(ParamInfo it) {
31 | return isConsumerOfPromise(it.getType());
32 | }
33 |
34 | public static boolean isConsumerOfPromise(TypeInfo type) {
35 | if (! type.isParameterized()) {
36 | return false;
37 | }
38 | ParameterizedTypeInfo parameterized = (ParameterizedTypeInfo) type;
39 | if (! parameterized.getRaw().getName().equals(Consumer.class.getName())) {
40 | return false;
41 | }
42 | TypeInfo arg = parameterized.getArg(0);
43 | if (arg.isParameterized()) {
44 | return arg.getRaw().getName().equals(Promise.class.getName());
45 | } else {
46 | return arg.getName().equals(Promise.class.getName());
47 | }
48 | }
49 |
50 | public static boolean isConsumerOfVoid(TypeInfo type) {
51 | if (! type.isParameterized()) {
52 | return false;
53 | }
54 | ParameterizedTypeInfo parameterized = (ParameterizedTypeInfo) type;
55 | if (! parameterized.getRaw().getName().equals(Consumer.class.getName())) {
56 | return false;
57 | }
58 | TypeInfo arg = parameterized.getArg(0);
59 | return arg.isVoid() || arg.getName().equals(Void.class.getName());
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/main/resources/META-INF/services/io.vertx.codegen.GeneratorLoader:
--------------------------------------------------------------------------------
1 | io.smallrye.mutiny.vertx.codegen.MutinyGeneratorLoader
2 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Created-By: Plexus Archiver 3.5
3 |
4 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/META-INF/vertx/json-mappers.properties:
--------------------------------------------------------------------------------
1 | io.vertx.codegen.testmodel.MyPojoToInteger.serializer=io.vertx.codegen.testmodel.JsonMapperTCK#serializeMyPojoToInteger
2 | io.vertx.codegen.testmodel.MyPojoToInteger.deserializer=io.vertx.codegen.testmodel.JsonMapperTCK#deserializeMyPojoToInteger
3 | io.vertx.codegen.testmodel.MyPojoToJsonObject.serializer=io.vertx.codegen.testmodel.JsonMapperTCK#serializeMyPojoToJsonObject
4 | io.vertx.codegen.testmodel.MyPojoToJsonObject.deserializer=io.vertx.codegen.testmodel.JsonMapperTCK#deserializeMyPojoToJsonObject
5 | io.vertx.codegen.testmodel.MyPojoToJsonArray.serializer=io.vertx.codegen.testmodel.JsonMapperTCK#serializeMyPojoToJsonArray
6 | io.vertx.codegen.testmodel.MyPojoToJsonArray.deserializer=io.vertx.codegen.testmodel.JsonMapperTCK#deserializeMyPojoToJsonArray
7 | java.time.ZonedDateTime.serializer=io.vertx.codegen.testmodel.JsonMapperTCK#serializeZonedDateTime
8 | java.time.ZonedDateTime.deserializer=io.vertx.codegen.testmodel.JsonMapperTCK#deserializeZonedDateTime
9 | io.vertx.codegen.testmodel.TestCustomEnum.serializer=io.vertx.codegen.testmodel.JsonMapperTCK#serializeCustomEnum
10 | io.vertx.codegen.testmodel.TestCustomEnum.deserializer=io.vertx.codegen.testmodel.JsonMapperTCK#deserializeCustomEnum
11 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/com/acme/pkg/MyInterface.java:
--------------------------------------------------------------------------------
1 | package com.acme.pkg;
2 |
3 | import com.acme.pkg.sub.SubInterface;
4 | import io.vertx.codegen.annotations.VertxGen;
5 | import io.vertx.codegen.testmodel.TestInterface;
6 |
7 | /**
8 | * @author Julien Viet
9 | */
10 | @VertxGen
11 | public interface MyInterface {
12 |
13 | static MyInterface create() {
14 | return new MyInterfaceImpl();
15 | }
16 |
17 | SubInterface sub();
18 |
19 | TestInterface method();
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/com/acme/pkg/MyInterfaceImpl.java:
--------------------------------------------------------------------------------
1 | package com.acme.pkg;
2 |
3 | import com.acme.pkg.sub.SubInterface;
4 | import com.acme.pkg.sub.SubInterfaceImpl;
5 | import io.vertx.codegen.testmodel.TestInterface;
6 | import io.vertx.codegen.testmodel.TestInterfaceImpl;
7 |
8 | /**
9 | * @author Julien Viet
10 | */
11 | public class MyInterfaceImpl implements MyInterface {
12 |
13 | @Override
14 | public SubInterface sub() {
15 | return new SubInterfaceImpl();
16 | }
17 |
18 | @Override
19 | public TestInterface method() {
20 | return new TestInterfaceImpl();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/com/acme/pkg/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Julien Viet
3 | */
4 | @ModuleGen(name = "acme", groupPackage = "com.acme")
5 | package com.acme.pkg;
6 |
7 | import io.vertx.codegen.annotations.ModuleGen;
8 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/com/acme/pkg/sub/SubInterface.java:
--------------------------------------------------------------------------------
1 | package com.acme.pkg.sub;
2 |
3 | import io.vertx.codegen.annotations.VertxGen;
4 |
5 | /**
6 | * @author Julien Viet
7 | */
8 | @VertxGen
9 | public interface SubInterface {
10 |
11 | String reverse(String s);
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/com/acme/pkg/sub/SubInterfaceImpl.java:
--------------------------------------------------------------------------------
1 | package com.acme.pkg.sub;
2 |
3 | /**
4 | * @author Julien Viet
5 | */
6 | public class SubInterfaceImpl implements SubInterface {
7 |
8 | @Override
9 | public String reverse(String s) {
10 | return new StringBuilder(s).reverse().toString();
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/AbstractHandlerUserType.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import io.vertx.codegen.annotations.VertxGen;
4 | import io.vertx.core.Handler;
5 |
6 | /**
7 | * @author Julien Viet
8 | */
9 | @VertxGen(concrete = false)
10 | public interface AbstractHandlerUserType extends Handler {
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/AnyJavaTypeTCK.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import io.vertx.codegen.annotations.GenIgnore;
4 | import io.vertx.codegen.annotations.VertxGen;
5 | import io.vertx.core.AsyncResult;
6 | import io.vertx.core.Handler;
7 |
8 | import java.net.Socket;
9 | import java.util.List;
10 | import java.util.Map;
11 | import java.util.Set;
12 |
13 | @VertxGen()
14 | public interface AnyJavaTypeTCK {
15 |
16 | @GenIgnore(GenIgnore.PERMITTED_TYPE) void methodWithJavaTypeParam(Socket socket);
17 | @GenIgnore(GenIgnore.PERMITTED_TYPE) void methodWithListOfJavaTypeParam(List socketList);
18 | @GenIgnore(GenIgnore.PERMITTED_TYPE) void methodWithSetOfJavaTypeParam(Set socketSet);
19 | @GenIgnore(GenIgnore.PERMITTED_TYPE) void methodWithMapOfJavaTypeParam(Map socketMap);
20 |
21 | @GenIgnore(GenIgnore.PERMITTED_TYPE) Socket methodWithJavaTypeReturn();
22 | @GenIgnore(GenIgnore.PERMITTED_TYPE) List methodWithListOfJavaTypeReturn();
23 | @GenIgnore(GenIgnore.PERMITTED_TYPE) Set methodWithSetOfJavaTypeReturn();
24 | @GenIgnore(GenIgnore.PERMITTED_TYPE) Map methodWithMapOfJavaTypeReturn();
25 |
26 | @GenIgnore(GenIgnore.PERMITTED_TYPE) void methodWithHandlerJavaTypeParam(Handler socketHandler);
27 | @GenIgnore(GenIgnore.PERMITTED_TYPE) void methodWithHandlerListOfJavaTypeParam(Handler> socketListHandler);
28 | @GenIgnore(GenIgnore.PERMITTED_TYPE) void methodWithHandlerSetOfJavaTypeParam(Handler> socketSetHandler);
29 | @GenIgnore(GenIgnore.PERMITTED_TYPE) void methodWithHandlerMapOfJavaTypeParam(Handler> socketMapHandler);
30 |
31 | @GenIgnore(GenIgnore.PERMITTED_TYPE) void methodWithHandlerAsyncResultJavaTypeParam(Handler> socketHandler);
32 | @GenIgnore(GenIgnore.PERMITTED_TYPE) void methodWithHandlerAsyncResultListOfJavaTypeParam(Handler>> socketListHandler);
33 | @GenIgnore(GenIgnore.PERMITTED_TYPE) void methodWithHandlerAsyncResultSetOfJavaTypeParam(Handler>> socketSetHandler);
34 | @GenIgnore(GenIgnore.PERMITTED_TYPE) void methodWithHandlerAsyncResultMapOfJavaTypeParam(Handler>> socketMapHandler);
35 | }
36 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/ConcreteHandlerUserType.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import io.vertx.codegen.annotations.VertxGen;
4 | import io.vertx.core.Handler;
5 |
6 | /**
7 | * @author Julien Viet
8 | */
9 | @VertxGen
10 | public interface ConcreteHandlerUserType extends Handler {
11 | }
12 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/ConcreteHandlerUserTypeExtension.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import io.vertx.codegen.annotations.VertxGen;
4 |
5 | /**
6 | * @author Julien Viet
7 | */
8 | @VertxGen
9 | public interface ConcreteHandlerUserTypeExtension extends ConcreteHandlerUserType {
10 | }
11 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/DataObjectTCK.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import io.vertx.codegen.annotations.VertxGen;
4 |
5 | /**
6 | * todo:
7 | * - Buffer support
8 | *
9 | * @author Julien Viet
10 | */
11 | @VertxGen
12 | public interface DataObjectTCK {
13 |
14 | DataObjectWithValues getDataObjectWithValues();
15 |
16 | void setDataObjectWithValues(DataObjectWithValues dataObject);
17 |
18 | DataObjectWithLists getDataObjectWithLists();
19 |
20 | void setDataObjectWithLists(DataObjectWithLists dataObject);
21 |
22 | DataObjectWithMaps getDataObjectWithMaps();
23 |
24 | void setDataObjectWithMaps(DataObjectWithMaps dataObject);
25 |
26 | void methodWithOnlyJsonObjectConstructorDataObject(DataObjectWithOnlyJsonObjectConstructor dataObject);
27 |
28 | void setDataObjectWithBuffer(DataObjectWithNestedBuffer dataObject);
29 |
30 | void setDataObjectWithListAdders(DataObjectWithListAdders dataObject);
31 |
32 | void setDataObjectWithMapAdders(DataObjectWithMapAdders dataObject);
33 |
34 | void setDataObjectWithRecursion(DataObjectWithRecursion dataObject);
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/DataObjectWithBuffer.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import io.vertx.codegen.annotations.DataObject;
4 | import io.vertx.core.buffer.Buffer;
5 | import io.vertx.core.json.JsonArray;
6 | import io.vertx.core.json.JsonObject;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | /**
12 | * @author Julien Viet
13 | */
14 | @DataObject(generateConverter = true)
15 | public class DataObjectWithBuffer {
16 |
17 | private Buffer buffer;
18 |
19 | public DataObjectWithBuffer() {
20 | }
21 |
22 | public DataObjectWithBuffer(JsonObject json) {
23 | byte[] buffer = json.getBinary("buffer");
24 | this.buffer = buffer != null ? Buffer.buffer(buffer) : null;
25 |
26 | }
27 |
28 | public Buffer getBuffer() {
29 | return buffer;
30 | }
31 |
32 | public void setBuffer(Buffer buffer) {
33 | this.buffer = buffer;
34 | }
35 |
36 | public JsonObject toJson() {
37 | JsonObject json = new JsonObject();
38 | if (buffer != null) {
39 | json.put("buffer", buffer.getBytes());
40 | }
41 | return json;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/DataObjectWithNestedBuffer.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import io.vertx.codegen.annotations.DataObject;
4 | import io.vertx.core.buffer.Buffer;
5 | import io.vertx.core.json.JsonArray;
6 | import io.vertx.core.json.JsonObject;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | /**
12 | * @author Julien Viet
13 | */
14 | @DataObject(generateConverter = true)
15 | public class DataObjectWithNestedBuffer {
16 |
17 | private Buffer buffer;
18 | private DataObjectWithBuffer nested;
19 | private List buffers;
20 |
21 | public DataObjectWithNestedBuffer() {
22 | }
23 |
24 | public DataObjectWithNestedBuffer(JsonObject json) {
25 | byte[] buffer = json.getBinary("buffer");
26 | this.buffer = buffer != null ? Buffer.buffer(buffer) : null;
27 | JsonObject nested = json.getJsonObject("nested");
28 | this.nested = nested != null ? new DataObjectWithBuffer(nested) : null;
29 | JsonArray buffers_ = json.getJsonArray("buffers");
30 | if (buffers_ != null) {
31 | this.buffers = new ArrayList<>();
32 | for (int i = 0;i < buffers_.size();i++) {
33 | buffers.add(Buffer.buffer(buffers_.getBinary(i)));
34 | }
35 | }
36 |
37 | }
38 |
39 | public Buffer getBuffer() {
40 | return buffer;
41 | }
42 |
43 | public void setBuffer(Buffer buffer) {
44 | this.buffer = buffer;
45 | }
46 |
47 | public List getBuffers() {
48 | return buffers;
49 | }
50 |
51 | public void setBuffers(List buffers) {
52 | this.buffers = buffers;
53 | }
54 |
55 | public DataObjectWithBuffer getNested() {
56 | return nested;
57 | }
58 |
59 | public void setNested(DataObjectWithBuffer nested) {
60 | this.nested = nested;
61 | }
62 |
63 | public JsonObject toJson() {
64 | JsonObject json = new JsonObject();
65 | if (buffer != null) {
66 | json.put("buffer", buffer.getBytes());
67 | }
68 | if (buffers != null) {
69 | JsonArray arr = new JsonArray();
70 | for (Buffer b : buffers) {
71 | arr.add(b.getBytes());
72 | }
73 | json.put("buffers", arr);
74 | }
75 | if (nested != null) {
76 | json.put("nested", nested.toJson());
77 | }
78 | return json;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/DataObjectWithOnlyJsonObjectConstructor.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import io.vertx.codegen.annotations.DataObject;
4 | import io.vertx.core.json.JsonObject;
5 |
6 | /**
7 | * @author Dan O'Reilly
8 | */
9 | @DataObject(generateConverter = true)
10 | public class DataObjectWithOnlyJsonObjectConstructor {
11 | private String foo;
12 |
13 | public DataObjectWithOnlyJsonObjectConstructor(JsonObject jsonObject) {
14 | this.foo = jsonObject.getString("foo");
15 | }
16 |
17 | public JsonObject toJson() {
18 | return new JsonObject().put("foo", foo);
19 | }
20 |
21 | public String getFoo() {
22 | return foo;
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/DataObjectWithRecursion.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import io.vertx.codegen.annotations.DataObject;
4 | import io.vertx.core.json.JsonObject;
5 |
6 | /**
7 | * @author Julien Viet
8 | */
9 | @DataObject(generateConverter = true)
10 | public class DataObjectWithRecursion {
11 |
12 | private String data;
13 | private DataObjectWithRecursion next;
14 |
15 | public DataObjectWithRecursion(JsonObject json) {
16 | data = json.getString("data");
17 | if (json.getJsonObject("next") != null) {
18 | next = new DataObjectWithRecursion(json.getJsonObject("next"));
19 | }
20 | }
21 |
22 | public String getData() {
23 | return data;
24 | }
25 |
26 | public DataObjectWithRecursion setData(String data) {
27 | this.data = data;
28 | return this;
29 | }
30 |
31 | public DataObjectWithRecursion getNext() {
32 | return next;
33 | }
34 |
35 | public DataObjectWithRecursion setNext(DataObjectWithRecursion next) {
36 | this.next = next;
37 | return this;
38 | }
39 |
40 | public JsonObject toJson() {
41 | JsonObject json = new JsonObject();
42 | if (data != null) {
43 | json.put("data", data);
44 | }
45 | if (next != null) {
46 | json.put("next", next.toJson());
47 | }
48 | return json;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/DeprecatedType.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import io.vertx.codegen.annotations.VertxGen;
4 |
5 | @VertxGen
6 | @Deprecated
7 | public interface DeprecatedType {
8 |
9 | void someMethod();
10 |
11 | @Deprecated
12 | void someOtherMethod();
13 | }
14 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/Factory.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import io.vertx.codegen.annotations.VertxGen;
4 | import io.vertx.core.Handler;
5 |
6 | /**
7 | * @author Julien Viet
8 | */
9 | @VertxGen
10 | public interface Factory {
11 |
12 | static ConcreteHandlerUserType createConcreteHandlerUserType(Handler handler) {
13 | return handler::handle;
14 | }
15 |
16 | static AbstractHandlerUserType createAbstractHandlerUserType(Handler handler) {
17 | return handler::handle;
18 | }
19 |
20 | static ConcreteHandlerUserTypeExtension createConcreteHandlerUserTypeExtension(Handler handler) {
21 | return handler::handle;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/FutureTCK.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import io.vertx.codegen.annotations.VertxGen;
4 | import io.vertx.core.AsyncResult;
5 | import io.vertx.core.Future;
6 | import io.vertx.core.Handler;
7 |
8 | /**
9 | * @author Julien Viet
10 | */
11 | @VertxGen
12 | public interface FutureTCK {
13 |
14 | Future asyncMethod();
15 | void asyncMethod(Handler> handler);
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/GenericNullableRefedInterface.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import io.vertx.codegen.annotations.Fluent;
4 | import io.vertx.codegen.annotations.Nullable;
5 | import io.vertx.codegen.annotations.VertxGen;
6 |
7 | /**
8 | * @author Julien Viet
9 | */
10 | @VertxGen
11 | public interface GenericNullableRefedInterface {
12 |
13 | @Nullable T getValue();
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/GenericRefedInterface.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import io.vertx.codegen.annotations.Fluent;
4 | import io.vertx.codegen.annotations.VertxGen;
5 |
6 | /**
7 | * @author Julien Viet
8 | */
9 | @VertxGen
10 | public interface GenericRefedInterface {
11 |
12 | @Fluent
13 | GenericRefedInterface setValue(T value);
14 |
15 | T getValue();
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/GenericRefedInterfaceImpl.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | /**
4 | * @author Julien Viet
5 | */
6 | public class GenericRefedInterfaceImpl implements GenericRefedInterface {
7 |
8 | private T value;
9 |
10 | @Override
11 | public GenericRefedInterface setValue(T value) {
12 | this.value = value;
13 | return this;
14 | }
15 |
16 | @Override
17 | public T getValue() {
18 | return value;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/InterfaceWithApiArg.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import io.vertx.codegen.annotations.VertxGen;
4 |
5 | /**
6 | * @author Julien Viet
7 | */
8 | @VertxGen
9 | public interface InterfaceWithApiArg extends GenericRefedInterface {
10 |
11 | void meth();
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/InterfaceWithStringArg.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import io.vertx.codegen.annotations.VertxGen;
4 |
5 | /**
6 | * @author Julien Viet
7 | */
8 | @VertxGen
9 | public interface InterfaceWithStringArg extends GenericRefedInterface {
10 |
11 | void meth();
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/InterfaceWithVariableArg.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import io.vertx.codegen.annotations.VertxGen;
4 |
5 | /**
6 | * @author Julien Viet
7 | */
8 | @VertxGen
9 | public interface InterfaceWithVariableArg extends GenericRefedInterface {
10 |
11 | void setOtherValue(T value);
12 |
13 | T getOtherValue();
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/MyPojoToInteger.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import java.util.Objects;
4 |
5 | public class MyPojoToInteger {
6 |
7 | int a;
8 |
9 | public MyPojoToInteger() {
10 | }
11 |
12 | public MyPojoToInteger(int a) {
13 | this.a = a;
14 | }
15 |
16 | public int getA() {
17 | return a;
18 | }
19 |
20 | public void setA(int a) {
21 | this.a = a;
22 | }
23 |
24 | @Override
25 | public boolean equals(Object o) {
26 | if (this == o) return true;
27 | if (o == null || getClass() != o.getClass()) return false;
28 | MyPojoToInteger that = (MyPojoToInteger) o;
29 | return a == that.a;
30 | }
31 |
32 | @Override
33 | public int hashCode() {
34 | return Objects.hash(a);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/MyPojoToJsonArray.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import java.util.List;
4 | import java.util.Objects;
5 |
6 | public class MyPojoToJsonArray {
7 |
8 | List stuff;
9 |
10 | public MyPojoToJsonArray() { }
11 |
12 | public MyPojoToJsonArray(List stuff) {
13 | this.stuff = stuff;
14 | }
15 |
16 | public List getStuff() {
17 | return stuff;
18 | }
19 |
20 | public void setStuff(List stuff) {
21 | this.stuff = stuff;
22 | }
23 |
24 | @Override
25 | public boolean equals(Object o) {
26 | if (this == o) return true;
27 | if (o == null || getClass() != o.getClass()) return false;
28 | MyPojoToJsonArray that = (MyPojoToJsonArray) o;
29 | return Objects.equals(stuff, that.stuff);
30 | }
31 |
32 | @Override
33 | public int hashCode() {
34 | return Objects.hash(stuff);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/MyPojoToJsonObject.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import java.util.Objects;
4 |
5 | public class MyPojoToJsonObject {
6 |
7 | int v;
8 |
9 | public MyPojoToJsonObject() { }
10 |
11 | public MyPojoToJsonObject(int v) {
12 | this.v = v;
13 | }
14 |
15 | public int getV() {
16 | return v;
17 | }
18 |
19 | public void setV(int v) {
20 | this.v = v;
21 | }
22 |
23 | @Override
24 | public boolean equals(Object o) {
25 | if (this == o) return true;
26 | if (o == null || getClass() != o.getClass()) return false;
27 | MyPojoToJsonObject that = (MyPojoToJsonObject) o;
28 | return v == that.v;
29 | }
30 |
31 | @Override
32 | public int hashCode() {
33 | return Objects.hash(v);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/RefedInterface1.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import io.vertx.codegen.annotations.Fluent;
4 | import io.vertx.codegen.annotations
5 | .VertxGen;
6 |
7 | /**
8 | * @author Tim Fox
9 | */
10 | @VertxGen
11 | public interface RefedInterface1 {
12 |
13 | String getString();
14 |
15 | @Fluent
16 | RefedInterface1 setString(String str);
17 | }
18 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/RefedInterface1Impl.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | /**
4 | * @author Tim Fox
5 | */
6 | public class RefedInterface1Impl implements RefedInterface1 {
7 |
8 | private String str;
9 |
10 | @Override
11 | public String getString() {
12 | return str;
13 | }
14 |
15 | @Override
16 | public RefedInterface1 setString(String str) {
17 | this.str = str;
18 | return this;
19 | }
20 |
21 | @Override
22 | public boolean equals(Object obj) {
23 | if (!(obj instanceof RefedInterface1Impl))
24 | return false;
25 | return ((RefedInterface1Impl) obj).str.equals(str);
26 | }
27 |
28 | @Override
29 | public int hashCode() {
30 | return str != null ? str.hashCode() : 0;
31 | }
32 |
33 | @Override
34 | public String toString() {
35 | return "TestInterface1[str=" + str + "]";
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/RefedInterface2.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import io.vertx.codegen.annotations.Fluent;
4 | import io.vertx.codegen.annotations.VertxGen;
5 |
6 | /**
7 | * @author Tim Fox
8 | */
9 | @VertxGen(concrete = false)
10 | public interface RefedInterface2 {
11 |
12 | String getString();
13 |
14 | @Fluent
15 | RefedInterface2 setString(String str);
16 | }
17 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/RefedInterface2Impl.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | /**
4 | * @author Tim Fox
5 | */
6 | public class RefedInterface2Impl implements RefedInterface2 {
7 |
8 | private String str;
9 |
10 | @Override
11 | public String getString() {
12 | return str;
13 | }
14 |
15 | @Override
16 | public RefedInterface2 setString(String str) {
17 | this.str = str;
18 | return this;
19 | }
20 |
21 | @Override
22 | public boolean equals(Object obj) {
23 | return ((RefedInterface2Impl) obj).str.equals(str);
24 | }
25 |
26 | @Override
27 | public String toString() {
28 | return "TestInterface2[str=" + str + "]";
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/SuperInterface1.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import io.vertx.codegen.annotations.VertxGen;
4 |
5 | /**
6 | * @author Tim Fox
7 | */
8 | @VertxGen
9 | public interface SuperInterface1 {
10 |
11 | void superMethodWithBasicParams(byte b, short s, int i, long l, float f, double d, boolean bool, char ch, String str);
12 |
13 | int superMethodOverloadedBySubclass();
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/SuperInterface2.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import io.vertx.codegen.annotations.VertxGen;
4 |
5 | /**
6 | * @author Tim Fox
7 | */
8 | @VertxGen(concrete = false)
9 | public interface SuperInterface2 {
10 |
11 | void otherSuperMethodWithBasicParams(byte b, short s, int i, long l, float f, double d, boolean bool, char ch, String str);
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/TestCustomEnum.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | public enum TestCustomEnum {
4 |
5 | DEV("dev", "development"),
6 |
7 | ITEST("itest", "integration-test");
8 |
9 | public static TestCustomEnum of(String pName) {
10 | for (TestCustomEnum item : TestCustomEnum.values()) {
11 | if (item.names[0].equalsIgnoreCase(pName) || item.names[1].equalsIgnoreCase(pName)
12 | || pName.equalsIgnoreCase(item.name())) {
13 | return item;
14 | }
15 | }
16 | return DEV;
17 | }
18 |
19 | private String[] names = new String[2];
20 |
21 | TestCustomEnum(String pShortName, String pLongName) {
22 | names[0] = pShortName;
23 | names[1] = pLongName;
24 | }
25 |
26 | public String getLongName() {
27 | return names[1];
28 | }
29 |
30 | public String getShortName() {
31 | return names[0];
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/TestDataObject.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import io.vertx.codegen.annotations.DataObject;
4 | import io.vertx.core.json.JsonObject;
5 |
6 | import java.util.Objects;
7 |
8 | /**
9 | * @author Tim Fox
10 | */
11 | @DataObject
12 | public class TestDataObject {
13 |
14 | private String foo;
15 | private int bar;
16 | private double wibble;
17 |
18 | public TestDataObject() {
19 | }
20 |
21 | public TestDataObject(TestDataObject other) {
22 | this.foo = other.foo;
23 | this.bar = other.bar;
24 | this.wibble = other.wibble;
25 | }
26 |
27 | public TestDataObject(JsonObject json) {
28 | this.foo = json.getString("foo", null);
29 | this.bar = json.getInteger("bar", 0);
30 | this.wibble = json.getDouble("wibble", 0d);
31 | }
32 |
33 | public String getFoo() {
34 | return foo;
35 | }
36 |
37 | public TestDataObject setFoo(String foo) {
38 | this.foo = foo;
39 | return this;
40 | }
41 |
42 | public int getBar() {
43 | return bar;
44 | }
45 |
46 | public TestDataObject setBar(int bar) {
47 | this.bar = bar;
48 | return this;
49 | }
50 |
51 | public double getWibble() {
52 | return wibble;
53 | }
54 |
55 | public TestDataObject setWibble(double wibble) {
56 | this.wibble = wibble;
57 | return this;
58 | }
59 |
60 | @Override
61 | public boolean equals(Object obj) {
62 | if (obj instanceof TestDataObject) {
63 | TestDataObject that = (TestDataObject) obj;
64 | return Objects.equals(foo, that.foo) && bar == that.bar && wibble == that.wibble;
65 | }
66 | return false;
67 | }
68 |
69 | @Override
70 | public int hashCode() {
71 | return Objects.hash(getFoo(), getBar(), getWibble());
72 | }
73 |
74 | public JsonObject toJson() {
75 | JsonObject json = new JsonObject();
76 | json.put("foo", this.foo);
77 | json.put("bar", this.bar);
78 | json.put("wibble", this.wibble);
79 | return json;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/TestEnum.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | /**
4 | * @author Tim Fox
5 | */
6 | public enum TestEnum {
7 | TIM, JULIEN, NICK, WESTON
8 | }
9 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/TestGenEnum.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import io.vertx.codegen.annotations.VertxGen;
4 |
5 | /**
6 | * @author Tim Fox
7 | */
8 | @VertxGen
9 | public enum TestGenEnum {
10 | LAURA, BOB, MIKE, LELAND
11 | }
12 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/TestStringDataObject.java:
--------------------------------------------------------------------------------
1 | package io.vertx.codegen.testmodel;
2 |
3 | import io.vertx.codegen.annotations.DataObject;
4 |
5 | import java.util.Objects;
6 |
7 | /**
8 | * @author Tim Fox
9 | */
10 | @DataObject
11 | public class TestStringDataObject {
12 |
13 | private String value;
14 |
15 | public TestStringDataObject() {
16 | }
17 |
18 | public TestStringDataObject(TestStringDataObject other) {
19 | this.value = other.value;
20 | }
21 |
22 | public TestStringDataObject(String value) {
23 | this.value = value;
24 | }
25 |
26 | public String getValue() {
27 | return value;
28 | }
29 |
30 | public TestStringDataObject setValue(String value) {
31 | this.value = value;
32 | return this;
33 | }
34 |
35 |
36 | @Override
37 | public boolean equals(Object obj) {
38 | if (obj instanceof TestStringDataObject) {
39 | TestStringDataObject that = (TestStringDataObject) obj;
40 | return Objects.equals(value, that.value);
41 | }
42 | return false;
43 | }
44 |
45 | @Override
46 | public int hashCode() {
47 | return Objects.hash(value);
48 | }
49 |
50 | public String toJson() {
51 | return value;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/codegen/testmodel/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * @author Julien Viet
3 | */
4 | @ModuleGen(
5 | name = "testmodel",
6 | groupPackage = "io.vertx")
7 | package io.vertx.codegen.testmodel;
8 |
9 | import io.vertx.codegen.annotations.ModuleGen;
10 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/core/streams/StreamBase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2011-2019 Contributors to the Eclipse Foundation
3 | *
4 | * This program and the accompanying materials are made available under the
5 | * terms of the Eclipse Public License 2.0 which is available at
6 | * http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7 | * which is available at https://www.apache.org/licenses/LICENSE-2.0.
8 | *
9 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10 | */
11 |
12 | package io.vertx.core.streams;
13 |
14 | import io.vertx.codegen.annotations.Fluent;
15 | import io.vertx.codegen.annotations.Nullable;
16 | import io.vertx.codegen.annotations.VertxGen;
17 | import io.vertx.core.Handler;
18 |
19 | /**
20 | * Base interface for a stream.
21 | *
22 | * @author Tim Fox
23 | */
24 | @VertxGen(concrete = false)
25 | public interface StreamBase {
26 |
27 | /**
28 | * Set an exception handler.
29 | *
30 | * @param handler the handler
31 | * @return a reference to this, so the API can be used fluently
32 | */
33 | @Fluent
34 | StreamBase exceptionHandler(@Nullable Handler handler);
35 | }
36 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/io/vertx/core/streams/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2011-2019 Contributors to the Eclipse Foundation
3 | *
4 | * This program and the accompanying materials are made available under the
5 | * terms of the Eclipse Public License 2.0 which is available at
6 | * http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7 | * which is available at https://www.apache.org/licenses/LICENSE-2.0.
8 | *
9 | * SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10 | */
11 |
12 | package io.vertx.core.streams;
13 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/org/extra/AnotherInterface.java:
--------------------------------------------------------------------------------
1 | package org.extra;
2 |
3 | import io.vertx.codegen.annotations.VertxGen;
4 |
5 | /**
6 | * @author Clement Escoffier
7 | */
8 | @VertxGen
9 | public interface AnotherInterface {
10 |
11 | static AnotherInterface create() {
12 | return new AnotherInterfaceImpl();
13 | }
14 |
15 | T methodWithClassParam(Class tClass);
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/org/extra/AnotherInterfaceImpl.java:
--------------------------------------------------------------------------------
1 | package org.extra;
2 |
3 | import java.util.Objects;
4 |
5 | /**
6 | * @author Clement Escoffier
7 | */
8 | public class AnotherInterfaceImpl implements AnotherInterface {
9 | @Override
10 | public T methodWithClassParam(Class tClass) {
11 | Objects.requireNonNull(tClass);
12 | try {
13 | return tClass.getDeclaredConstructor().newInstance();
14 | } catch (Exception e) {
15 | throw new RuntimeException(e);
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/org/extra/Bar.java:
--------------------------------------------------------------------------------
1 | package org.extra;
2 |
3 | import io.vertx.codegen.annotations.GenIgnore;
4 | import io.vertx.codegen.annotations.VertxGen;
5 |
6 | /**
7 | * @author Clement Escoffier
8 | */
9 | @VertxGen
10 | public interface Bar {
11 | @GenIgnore
12 | class Impl implements Bar {
13 | }
14 | }
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/org/extra/ConcreteInheritsToString.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version 2.0
5 | * (the "License"); you may not use this file except in compliance with the
6 | * License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package org.extra;
18 |
19 | import io.vertx.codegen.annotations.VertxGen;
20 |
21 | /**
22 | * @author Thomas Segismont
23 | */
24 | @VertxGen
25 | public interface ConcreteInheritsToString extends NonConcreteWithToString {
26 | void doSomething();
27 | }
28 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/org/extra/ConcreteOverridesToString.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version 2.0
5 | * (the "License"); you may not use this file except in compliance with the
6 | * License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package org.extra;
18 |
19 | import io.vertx.codegen.annotations.VertxGen;
20 |
21 | /**
22 | * @author Thomas Segismont
23 | */
24 | @VertxGen
25 | public interface ConcreteOverridesToString extends NonConcreteWithToString {
26 | void doSomething();
27 |
28 | /**
29 | * My even more special toString method
30 | */
31 | String toString();
32 | }
33 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/org/extra/ExtendsWithSameSimpleName.java:
--------------------------------------------------------------------------------
1 | package org.extra;
2 |
3 | import io.vertx.codegen.annotations.CacheReturn;
4 | import io.vertx.codegen.annotations.VertxGen;
5 | import io.vertx.core.AsyncResult;
6 | import io.vertx.core.Handler;
7 | import io.vertx.core.streams.ReadStream;
8 | import org.extra.sub.UseVertxGenNameDeclarationsWithSameSimpleName;
9 |
10 | import java.util.function.Function;
11 |
12 | @VertxGen
13 | public interface ExtendsWithSameSimpleName extends
14 | UseVertxGenNameDeclarationsWithSameSimpleName,
15 | Handler,
16 | ReadStream {
17 |
18 | @CacheReturn
19 | UseVertxGenNameDeclarationsWithSameSimpleName foo(UseVertxGenNameDeclarationsWithSameSimpleName arg);
20 |
21 | void function(
22 | Function function);
23 |
24 | void asyncResult(Handler> handler);
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/org/extra/Foo.java:
--------------------------------------------------------------------------------
1 | package org.extra;
2 |
3 | import io.vertx.codegen.annotations.GenIgnore;
4 | import io.vertx.codegen.annotations.VertxGen;
5 |
6 | /**
7 | * @author Clement Escoffier
8 | */
9 | @VertxGen
10 | public interface Foo {
11 | @GenIgnore
12 | class Impl implements Foo {
13 | }
14 | }
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/org/extra/Generic1.java:
--------------------------------------------------------------------------------
1 | package org.extra;
2 |
3 | import io.vertx.codegen.annotations.Fluent;
4 | import io.vertx.codegen.annotations.GenIgnore;
5 | import io.vertx.codegen.annotations.VertxGen;
6 |
7 | @VertxGen
8 | public interface Generic1 {
9 |
10 | T getValue();
11 | @Fluent
12 | Generic1 setValue(T value);
13 |
14 | @GenIgnore
15 | class Impl implements Generic1 {
16 | T value;
17 | @Override
18 | public T getValue() {
19 | return value;
20 | }
21 | @Override
22 | public Impl setValue(T value) {
23 | this.value = value;
24 | return this;
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/org/extra/Generic2.java:
--------------------------------------------------------------------------------
1 | package org.extra;
2 |
3 | import io.vertx.codegen.annotations.Fluent;
4 | import io.vertx.codegen.annotations.GenIgnore;
5 | import io.vertx.codegen.annotations.VertxGen;
6 |
7 | @VertxGen
8 | public interface Generic2 {
9 |
10 | T getValue1();
11 | @Fluent
12 | Generic2 setValue1(T value);
13 | U getValue2();
14 | @Fluent
15 | Generic2 setValue2(U value);
16 |
17 | @GenIgnore
18 | class Impl implements Generic2 {
19 | T value1 = null;
20 | U value2 = null;
21 | @Override
22 | public T getValue1() {
23 | return value1;
24 | }
25 | @Override
26 | public Impl setValue1(T value) {
27 | value1 = value;
28 | return this;
29 | }
30 | @Override
31 | public U getValue2() {
32 | return value2;
33 | }
34 | @Override
35 | public Impl setValue2(U value) {
36 | value2 = value;
37 | return this;
38 | }
39 | }
40 | }
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/org/extra/JavadocTest.java:
--------------------------------------------------------------------------------
1 | package org.extra;
2 |
3 | import io.vertx.codegen.annotations.VertxGen;
4 | import io.vertx.core.AsyncResult;
5 | import io.vertx.core.Handler;
6 |
7 | import java.util.Collection;
8 | import java.util.List;
9 | import java.util.Map;
10 |
11 | @VertxGen
12 | public interface JavadocTest {
13 |
14 |
15 | /**
16 | * Do something.
17 | * @param list list
18 | * @param handler handler
19 | */
20 | void doSomething(List list, Handler> handler);
21 |
22 | /**
23 | * Do something.
24 | * @param list1 list
25 | * @param list2 list
26 | * @param handler handler
27 | */
28 | void doSomething2(List list1, List list2, Handler> handler);
29 |
30 |
31 | /**
32 | * Do something.
33 | * @param list list
34 | */
35 | void doSomething3(List list, Handler> handler);
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/org/extra/MethodWithCompletable.java:
--------------------------------------------------------------------------------
1 | package org.extra;
2 |
3 | import io.vertx.codegen.annotations.VertxGen;
4 | import io.vertx.core.AsyncResult;
5 | import io.vertx.core.Handler;
6 |
7 | /**
8 | * @author Julien Viet
9 | */
10 | @VertxGen
11 | public interface MethodWithCompletable {
12 |
13 | void doSomethingWithResult(Handler> handler);
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/org/extra/MethodWithGenericFunctionArg.java:
--------------------------------------------------------------------------------
1 | package org.extra;
2 |
3 | import io.vertx.codegen.annotations.VertxGen;
4 | import io.vertx.core.json.JsonObject;
5 |
6 | import java.util.function.Function;
7 |
8 | /**
9 | * @author Julien Viet
10 | */
11 | @VertxGen
12 | public interface MethodWithGenericFunctionArg {
13 | MethodWithGenericFunctionArg doSomething(Function, T> theFunction);
14 | }
15 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/org/extra/MethodWithMaybeString.java:
--------------------------------------------------------------------------------
1 | package org.extra;
2 |
3 | import io.vertx.codegen.annotations.Nullable;
4 | import io.vertx.codegen.annotations.VertxGen;
5 | import io.vertx.core.AsyncResult;
6 | import io.vertx.core.Handler;
7 |
8 | /**
9 | * @author Julien Viet
10 | */
11 | @VertxGen
12 | public interface MethodWithMaybeString {
13 | void doSomethingWithMaybeResult(Handler> handler);
14 | }
15 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/org/extra/MethodWithMultiCallback.java:
--------------------------------------------------------------------------------
1 | package org.extra;
2 |
3 | import io.vertx.codegen.annotations.Nullable;
4 | import io.vertx.codegen.annotations.VertxGen;
5 | import io.vertx.core.AsyncResult;
6 | import io.vertx.core.Handler;
7 |
8 | /**
9 | * @author Julien Viet
10 | */
11 | @VertxGen
12 | public interface MethodWithMultiCallback {
13 | void multiCompletable(Handler> handler);
14 |
15 | void multiMaybe(Handler> handler);
16 |
17 | void multiSingle(Handler> handler);
18 | }
19 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/org/extra/MethodWithNullableTypeVariable.java:
--------------------------------------------------------------------------------
1 | package org.extra;
2 |
3 | import io.vertx.codegen.annotations.Nullable;
4 | import io.vertx.codegen.annotations.VertxGen;
5 | import io.vertx.core.AsyncResult;
6 | import io.vertx.core.Handler;
7 |
8 | /**
9 | * @author Julien Viet
10 | */
11 | @VertxGen
12 | public interface MethodWithNullableTypeVariable {
13 | void doSomethingWithMaybeResult(Handler> handler);
14 | }
15 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/org/extra/MethodWithNullableTypeVariableParamByVoidArg.java:
--------------------------------------------------------------------------------
1 | package org.extra;
2 |
3 | import io.vertx.codegen.annotations.VertxGen;
4 |
5 | /**
6 | * Special case : we need to generate {@code Maybe} because of covariant return type and because
7 | * {@code Completable} does not extend {@code Maybe}.
8 | *
9 | * @author Julien Viet
10 | */
11 | @VertxGen
12 | public interface MethodWithNullableTypeVariableParamByVoidArg extends MethodWithNullableTypeVariable {
13 | }
14 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/org/extra/MethodWithSingleString.java:
--------------------------------------------------------------------------------
1 | package org.extra;
2 |
3 | import io.vertx.codegen.annotations.VertxGen;
4 | import io.vertx.core.AsyncResult;
5 | import io.vertx.core.Handler;
6 |
7 | /**
8 | * @author Julien Viet
9 | */
10 | @VertxGen
11 | public interface MethodWithSingleString {
12 |
13 | void doSomethingWithResult(Handler> handler);
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/org/extra/NestedParameterizedType.java:
--------------------------------------------------------------------------------
1 | package org.extra;
2 |
3 | import io.vertx.codegen.annotations.VertxGen;
4 |
5 | @VertxGen
6 | public interface NestedParameterizedType {
7 |
8 | static Generic2, Generic2> someGeneric() {
9 | return new Generic2.Impl, Generic2>()
10 | .setValue1(new Generic1.Impl().setValue(new Foo.Impl()))
11 | .setValue2(new Generic2.Impl().setValue1(new Foo.Impl()).setValue2(new Bar.Impl()));
12 | }
13 | }
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/org/extra/NonConcreteWithToString.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Red Hat, Inc.
3 | *
4 | * Red Hat licenses this file to you under the Apache License, version 2.0
5 | * (the "License"); you may not use this file except in compliance with the
6 | * License. You may obtain a copy of the License at:
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 | * License for the specific language governing permissions and limitations
14 | * under the License.
15 | */
16 |
17 | package org.extra;
18 |
19 | import io.vertx.codegen.annotations.VertxGen;
20 |
21 | /**
22 | * @author Thomas Segismont
23 | */
24 | @VertxGen(concrete = false)
25 | public interface NonConcreteWithToString {
26 | /**
27 | * My very special toString method
28 | */
29 | String toString();
30 | }
31 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/org/extra/UseVertxGenDeclarationsFromAnotherPackage.java:
--------------------------------------------------------------------------------
1 | package org.extra;
2 |
3 | import io.vertx.codegen.annotations.CacheReturn;
4 | import io.vertx.codegen.annotations.VertxGen;
5 | import org.extra.sub.SomeType;
6 | import io.vertx.core.AsyncResult;
7 | import io.vertx.core.Handler;
8 | import io.vertx.core.streams.ReadStream;
9 |
10 | import java.util.function.Function;
11 |
12 | @VertxGen
13 | public interface UseVertxGenDeclarationsFromAnotherPackage extends
14 | SomeType,
15 | Handler,
16 | ReadStream {
17 | @CacheReturn
18 | SomeType foo(SomeType arg);
19 |
20 | void function(Function function);
21 |
22 | void asyncResult(Handler> handler);
23 |
24 | Handler returnHandler();
25 |
26 | Handler> returnHandlerAsyncResult();
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/org/extra/UseVertxGenNameDeclarationsWithSameSimpleName.java:
--------------------------------------------------------------------------------
1 | package org.extra;
2 |
3 | import io.vertx.codegen.annotations.CacheReturn;
4 | import io.vertx.codegen.annotations.VertxGen;
5 | import io.vertx.core.AsyncResult;
6 | import io.vertx.core.Handler;
7 | import io.vertx.core.streams.ReadStream;
8 |
9 | import java.util.function.Function;
10 |
11 | @VertxGen
12 | public interface UseVertxGenNameDeclarationsWithSameSimpleName extends
13 | org.extra.sub.UseVertxGenNameDeclarationsWithSameSimpleName,
14 | Handler,
15 | ReadStream {
16 | @CacheReturn
17 | org.extra.sub.UseVertxGenNameDeclarationsWithSameSimpleName foo(
18 | org.extra.sub.UseVertxGenNameDeclarationsWithSameSimpleName arg);
19 |
20 | void function(
21 | Function function);
22 |
23 | void asyncResult(
24 | Handler> handler);
25 |
26 | Handler returnHandler();
27 |
28 | Handler> returnHandlerAsyncResult();
29 | }
30 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/org/extra/package-info.java:
--------------------------------------------------------------------------------
1 |
2 | @ModuleGen(name = "extra", groupPackage = "org.extra")
3 | package org.extra;
4 |
5 | import io.vertx.codegen.annotations.ModuleGen;
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/org/extra/sub/ExtendsWithSameSimpleName.java:
--------------------------------------------------------------------------------
1 | package org.extra.sub;
2 |
3 | import io.vertx.codegen.annotations.VertxGen;
4 |
5 | @VertxGen
6 | public interface ExtendsWithSameSimpleName {
7 | }
8 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/org/extra/sub/SomeType.java:
--------------------------------------------------------------------------------
1 | package org.extra.sub;
2 |
3 | import io.vertx.codegen.annotations.VertxGen;
4 |
5 | @VertxGen
6 | public interface SomeType {
7 | }
8 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/tck/java/org/extra/sub/UseVertxGenNameDeclarationsWithSameSimpleName.java:
--------------------------------------------------------------------------------
1 | package org.extra.sub;
2 |
3 | import io.vertx.codegen.annotations.VertxGen;
4 |
5 | @VertxGen
6 | public interface UseVertxGenNameDeclarationsWithSameSimpleName {
7 | }
8 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/test/java/tck/AnyJavaTypeTCKTest.java:
--------------------------------------------------------------------------------
1 | package tck;
2 |
3 | import io.vertx.codegen.testmodel.AnyJavaTypeTCKImpl;
4 | import org.junit.Test;
5 |
6 | import java.net.Socket;
7 | import java.util.List;
8 | import java.util.Map;
9 | import java.util.Set;
10 |
11 | import static org.junit.Assert.assertEquals;
12 | import static org.junit.Assert.assertFalse;
13 |
14 | public class AnyJavaTypeTCKTest {
15 |
16 | final io.vertx.mutiny.codegen.testmodel.AnyJavaTypeTCK obj = new io.vertx.mutiny.codegen.testmodel.AnyJavaTypeTCK(new AnyJavaTypeTCKImpl());
17 |
18 | @Test
19 | public void testHandlersWithAsyncResult() throws Exception {
20 | List socketsRxList = obj.methodWithHandlerAsyncResultListOfJavaTypeParam().await().indefinitely();
21 |
22 | Set socketSetRx = obj.methodWithHandlerAsyncResultSetOfJavaTypeParam().await().indefinitely();
23 |
24 | Map stringSocketMapRx = obj.methodWithHandlerAsyncResultMapOfJavaTypeParam().await().indefinitely();
25 |
26 | for (Socket socket : socketsRxList) {
27 | assertFalse(socket.isConnected());
28 | }
29 |
30 | for (Socket socket : socketSetRx) {
31 | assertFalse(socket.isConnected());
32 | }
33 |
34 | for (Map.Entry entry : stringSocketMapRx.entrySet()) {
35 | assertEquals("1", entry.getKey());
36 | assertFalse(entry.getValue().isConnected());
37 | }
38 |
39 | assertEquals(1, socketsRxList.size());
40 | assertEquals(1, socketSetRx.size());
41 | assertEquals(1, stringSocketMapRx.size());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/test/java/tck/AsyncResultAdapterTest.java:
--------------------------------------------------------------------------------
1 | package tck;
2 |
3 | import org.extra.mutiny.MethodWithCompletable;
4 | import org.extra.mutiny.MethodWithMaybeString;
5 | import org.extra.mutiny.MethodWithSingleString;
6 | import io.vertx.test.core.VertxTestBase;
7 | import org.junit.Test;
8 |
9 | import java.util.concurrent.CompletionStage;
10 |
11 | public class AsyncResultAdapterTest extends VertxTestBase {
12 |
13 | @Test
14 | public void testSingleReportingSubscribeUncheckedException() {
15 | RuntimeException cause = new RuntimeException();
16 | MethodWithSingleString meth = new MethodWithSingleString(handler -> {
17 | throw cause;
18 | });
19 | CompletionStage single = meth.doSomethingWithResult().subscribeAsCompletionStage();
20 | single.whenComplete((result, err) -> {
21 | assertNull(result);
22 | assertNotNull(err);
23 | testComplete();
24 | });
25 | await();
26 | }
27 |
28 | @Test
29 | public void testMaybeReportingSubscribeUncheckedException() {
30 | RuntimeException cause = new RuntimeException();
31 | MethodWithMaybeString meth = new MethodWithMaybeString(handler -> {
32 | throw cause;
33 | });
34 | CompletionStage single = meth.doSomethingWithMaybeResult().subscribeAsCompletionStage();
35 | single.whenComplete((result, err) -> {
36 | assertNull(result);
37 | assertNotNull(err);
38 | testComplete();
39 | });
40 | await();
41 | }
42 |
43 | @Test
44 | public void testCompletableReportingSubscribeUncheckedException() {
45 | RuntimeException cause = new RuntimeException();
46 | MethodWithCompletable meth = new MethodWithCompletable(handler -> {
47 | throw cause;
48 | });
49 | CompletionStage single = meth.doSomethingWithResult().subscribeAsCompletionStage();
50 | single.whenComplete((result, err) -> {
51 | assertNull(result);
52 | assertNotNull(err);
53 | testComplete();
54 | });
55 | await();
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/test/java/tck/DeprecationTest.java:
--------------------------------------------------------------------------------
1 | package tck;
2 |
3 | import io.vertx.mutiny.codegen.testmodel.DeprecatedType;
4 | import org.junit.Test;
5 |
6 | import static org.junit.Assert.*;
7 |
8 | public class DeprecationTest {
9 |
10 | @Test
11 | public void checkThatAnnotationsAreForwarded() throws NoSuchMethodException {
12 | Deprecated[] annotationsByType = DeprecatedType.class.getAnnotationsByType(Deprecated.class);
13 | assertEquals(1, annotationsByType.length);
14 |
15 | Deprecated deprecated = DeprecatedType.class.getMethod("someMethod").getAnnotation(Deprecated.class);
16 | assertNull(deprecated);
17 |
18 | deprecated = DeprecatedType.class.getMethod("someOtherMethod").getAnnotation(Deprecated.class);
19 | assertNotNull(deprecated);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/test/java/tck/GenericsTest.java:
--------------------------------------------------------------------------------
1 | package tck;
2 |
3 | import org.extra.mutiny.Bar;
4 | import org.extra.mutiny.Foo;
5 | import org.extra.mutiny.Generic1;
6 | import org.extra.mutiny.Generic2;
7 | import org.extra.mutiny.NestedParameterizedType;
8 | import org.junit.Test;
9 |
10 | public class GenericsTest {
11 |
12 | @Test
13 | public void testNestedParameterizedTypes() {
14 | // Test we don't get class cast when types are unwrapped or rewrapped
15 | Generic2, Generic2> o = NestedParameterizedType.someGeneric();
16 | Generic1 value1 = o.getValue1();
17 | Foo nested1 = value1.getValue();
18 | value1.setValue(nested1);
19 | Generic2 value2 = o.getValue2();
20 | o.setValue2(value2);
21 | Foo nested2 = value2.getValue1();
22 | value2.setValue1(nested2);
23 | Bar nested3 = value2.getValue2();
24 | value2.setValue2(nested3);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/test/java/tck/ReadStreamSubscriberTest.java:
--------------------------------------------------------------------------------
1 | package tck;
2 |
3 | import io.smallrye.mutiny.vertx.ReadStreamSubscriber;
4 | import java.util.concurrent.Flow.Subscription;
5 |
6 | import java.util.function.Function;
7 |
8 | /**
9 | * @author Julien Viet
10 | */
11 | public class ReadStreamSubscriberTest extends ReadStreamSubscriberTestBase {
12 |
13 | @Override
14 | public long bufferSize() {
15 | return ReadStreamSubscriber.BUFFER_SIZE;
16 | }
17 |
18 | @Override
19 | protected Sender sender() {
20 | return new Sender() {
21 |
22 | private ReadStreamSubscriber subscriber = new ReadStreamSubscriber<>(Function.identity());
23 |
24 | {
25 | stream = subscriber;
26 | subscriber.onSubscribe(new Subscription() {
27 | @Override
28 | public void request(long n) {
29 | requested += n;
30 | }
31 |
32 | @Override
33 | public void cancel() {
34 | }
35 | });
36 | }
37 |
38 | protected void emit() {
39 | subscriber.onNext("" + seq++);
40 | }
41 |
42 | protected void complete() {
43 | subscriber.onComplete();
44 | }
45 |
46 | protected void fail(Throwable cause) {
47 | subscriber.onError(cause);
48 | }
49 |
50 | };
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/vertx-mutiny-generator/src/test/java/tck/TestUtils.java:
--------------------------------------------------------------------------------
1 | package tck;
2 |
3 | import java.util.concurrent.Flow.Publisher;
4 | import java.util.concurrent.Flow.Subscriber;
5 | import java.util.concurrent.Flow;
6 |
7 | /**
8 | * @author Julien Viet
9 | */
10 | public class TestUtils {
11 |
12 | public static void subscribe(Publisher obs, TestSubscriber sub) {
13 | obs.subscribe(new Subscriber() {
14 | boolean unsubscribed;
15 |
16 | @Override
17 | public void onSubscribe(Flow.Subscription s) {
18 | sub.onSubscribe(new TestSubscriber.Subscription() {
19 | @Override
20 | public void fetch(long val) {
21 | if (val > 0) {
22 | s.request(val);
23 | }
24 | }
25 |
26 | @Override
27 | public void unsubscribe() {
28 | unsubscribed = true;
29 | s.cancel();
30 | }
31 |
32 | @Override
33 | public boolean isUnsubscribed() {
34 | return unsubscribed;
35 | }
36 | });
37 |
38 | }
39 |
40 | @Override
41 | public void onNext(T buffer) {
42 | sub.onNext(buffer);
43 | }
44 |
45 | @Override
46 | public void onError(Throwable t) {
47 | unsubscribed = true;
48 | sub.onError(t);
49 | }
50 |
51 | @Override
52 | public void onComplete() {
53 | unsubscribed = true;
54 | sub.onCompleted();
55 | }
56 | });
57 | }
58 | }
59 |
--------------------------------------------------------------------------------