Skip to content

Commit

Permalink
- Parameterized type fixes.
Browse files Browse the repository at this point in the history
- Adapter version naming fix.
  • Loading branch information
jjzazuet committed Dec 9, 2023
1 parent f52dc89 commit 7683a73
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 32 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins { id("io.vacco.oss.gitflow") version "0.9.8" apply(false) }
subprojects {
apply(plugin = "io.vacco.oss.gitflow")
group = "io.vacco.ronove"
version = "1.2.2"
version = "1.2.3"

configure<io.vacco.oss.gitflow.GsPluginProfileExtension> {
addJ8Spec()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,48 +54,52 @@ public RvTsContext add(Collection<Type> types) {

private RvTsType map(Type t) {
if (t instanceof TypeVariable) {
return new RvTsType(null, mapTail(t));
return new RvTsType(null, mapReturn(t));
} else if (t instanceof Class) {
var c = (Class<?>) t;
if (isPrimitiveOrWrapper(c) || isVoid(c) || isString(c) || isCollection(c) || c.isArray()) {
return new RvTsType(null, mapTail(c));
return new RvTsType(null, mapReturn(c));
} else if (c.isEnum()) {
var tse = new RvTsType(c.getSimpleName(), mapTail(c));
var tse = new RvTsType(c.getSimpleName(), mapReturn(c));
for (var ec : c.getEnumConstants()) {
tse.enumValues.add(ec.toString());
}
return tse;
} else {
var ts = new RvTsType(c.getSimpleName(), mapTail(c));
var ts = new RvTsType(c.getSimpleName(), mapReturn(c));
for (var f : c.getFields()) {
var fts = map(f.getGenericType()).withName(f.getName());
ts.properties.add(fts);
}
return ts;
}
} else if (t instanceof ParameterizedType) {
return new RvTsType(null, mapTail(t));
return new RvTsType(null, mapReturn(t));
}
throw new IllegalStateException(
format("Unable to map type [%s], please file a bug at https://github.com/vaccovecrana/ronove/issues", t)
);
}

public List<RvTsType> schemaTypes() {
return types.stream()
.filter(t -> t instanceof Class)
.map(t -> (Class<?>) t)
.filter(c -> !(isVoid(c) || isString(c) || isPrimitiveOrWrapper(c) || isCollection(c) || c.isArray()))
.map(c -> {
var ts = map(c);
if (!ts.enumValues.isEmpty()) {
ts.type = "const enum";
} else {
ts.type = "interface";
}
return ts;
})
.collect(Collectors.toList());
var out = new ArrayList<RvTsType>();
for (var t : types) {
if (t instanceof Class) {
var ts = map(t);
if (((Class<?>) t).getTypeParameters().length > 0) {
ts.name = ts.type;
}
if (!ts.enumValues.isEmpty()) {
ts.type = "const enum";
} else {
ts.type = "interface";
}
if (ts.name != null && !ts.name.isEmpty()) {
out.add(ts);
}
}
}
return out;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.vacco.ronove.plugin;

import io.vacco.ronove.RvAnnotations;
import io.vacco.ronove.RvDescriptor;
import io.vacco.ronove.*;
import java.lang.reflect.*;

import static io.vacco.ronove.RvPrimitives.*;
Expand Down Expand Up @@ -29,10 +28,13 @@ private static String mapGeneric(Type gt, Type[] gtArgs) {
}

private static String mapGeneric(ParameterizedType pt) {
if (pt.getRawType() == RvResponse.class) {
return mapTail(pt.getActualTypeArguments()[0]);
}
return mapGeneric(pt.getRawType(), genericTypesOf(pt));
}

public static String mapTail(Type t) {
private static String mapTail(Type t) {
if (t instanceof Class) {
var c = (Class<?>) t;
if (isPrimitiveOrWrapper(c) || isVoid(c) || isString(c)) {
Expand All @@ -56,6 +58,10 @@ public static String mapTail(Type t) {
);
}

public static String mapReturn(Type t) {
return mapTail(t);
}

public static String mapParams(RvDescriptor d) {
return d.allParams.stream()
.filter(prm -> !RvAnnotations.isRvAttachmentParam(prm.paramType))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package io.vacco.ronove.plugin;

import io.marioslab.basis.template.*;
import io.vacco.ronove.RvContext;
import io.vacco.ronove.RvDescriptor;
import io.vacco.ronove.*;
import org.gradle.api.logging.*;

import java.lang.reflect.Type;
Expand All @@ -27,12 +26,13 @@ public String render(List<Class<?>> controllers) {
.flatMap(RvDescriptor::allTypes)
.collect(Collectors.toSet())
);
var tsTypes = tsCtx.schemaTypes();

context.set("rvControllers", controllers.stream().map(Class::getCanonicalName).collect(Collectors.toList()));
context.set("rvDescriptors", idx.values());
context.set("tsSchemaTypes", tsCtx.schemaTypes());
context.set("decl", (Function<Type, String>) RvTsDeclarations::mapTail);
context.set("declList", (Function<RvDescriptor, String>) RvTsDeclarations::mapParams);
context.set("tsSchemaTypes", tsTypes);
context.set("retFn", (Function<Type, String>) RvTsDeclarations::mapReturn);
context.set("paramFn", (Function<RvDescriptor, String>) RvTsDeclarations::mapParams);

return template.render(context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Source controllers:
{{for ctl in rvControllers}}- {{ctl}}{{"\n"}}{{end}}
*/
{{for rvd in rvDescriptors}}
export const {{rvd.javaMethod.getName()}} = ({{declList.apply(rvd)}}): Promise<{{decl.apply(rvd.responseType)}}> => {
export const {{rvd.javaMethod.getName()}} = ({{paramFn.apply(rvd)}}): Promise<{{retFn.apply(rvd.responseType)}}> => {
let path = "{{rvd.path.value()}}"
{{for pp in rvd.pathParams}}
path = path.replace("\{ {{pp.name}} \}".replace(/\s+/g, ""), {{pp.name}}.toString()){{"\n "}}
Expand Down
4 changes: 3 additions & 1 deletion rv-kit-murmux/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ configure<io.vacco.oss.gitflow.GsPluginProfileExtension> { sharedLibrary(true, f

val api by configurations
val murmuxVer = "2.2.2"
version = murmuxVer
val mxp = project(":rv-core")

version = "${mxp.version}_${murmuxVer}"

dependencies {
api(project(":rv-core"))
Expand Down
6 changes: 4 additions & 2 deletions rv-kit-undertow/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ configure<io.vacco.oss.gitflow.GsPluginProfileExtension> { sharedLibrary(true, f

val api by configurations
val undertowVer = "2.3.8.Final"
version = undertowVer
val mxp = project(":rv-core")

version = "${mxp.version}_${undertowVer}"

dependencies {
api(project(":rv-core"))
api(mxp)
api("io.undertow:undertow-core:${undertowVer}")
}

0 comments on commit 7683a73

Please sign in to comment.