Skip to content

Commit dadaca4

Browse files
committed
router: remove deprecated code
- returnType
1 parent 5ff899a commit dadaca4

19 files changed

Lines changed: 42 additions & 100 deletions

File tree

jooby/src/main/java/io/jooby/Jooby.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -728,14 +728,14 @@ public Map<String, Object> getAttributes() {
728728
}
729729

730730
@NonNull @Override
731-
public Jooby attribute(@NonNull String key, @NonNull Object value) {
732-
router.attribute(key, value);
731+
public Jooby setAttribute(@NonNull String key, @NonNull Object value) {
732+
router.setAttribute(key, value);
733733
return this;
734734
}
735735

736736
@NonNull @Override
737-
public <T> T attribute(@NonNull String key) {
738-
return router.attribute(key);
737+
public <T> T getAttribute(@NonNull String key) {
738+
return router.getAttribute(key);
739739
}
740740

741741
@NonNull @Override

jooby/src/main/java/io/jooby/Route.java

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.lang.invoke.MethodHandles;
1111
import java.lang.invoke.MethodType;
1212
import java.lang.reflect.Method;
13-
import java.lang.reflect.Type;
1413
import java.util.ArrayList;
1514
import java.util.Arrays;
1615
import java.util.Collection;
@@ -443,8 +442,6 @@ public MethodHandle toMethodHandle() {
443442

444443
private MessageEncoder encoder;
445444

446-
private Type returnType;
447-
448445
private Object handle;
449446

450447
private List<MediaType> produces = EMPTY_LIST;
@@ -693,30 +690,6 @@ public boolean isNonBlockingSet() {
693690
return this;
694691
}
695692

696-
/**
697-
* Route return type.
698-
*
699-
* @return Return type.
700-
* @deprecated Marked for removal on 4.0
701-
*/
702-
@Deprecated
703-
public @Nullable Type getReturnType() {
704-
return returnType;
705-
}
706-
707-
/**
708-
* Set route return type.
709-
*
710-
* @param returnType Return type.
711-
* @return This route.
712-
* @deprecated Marked for removal on 4.0
713-
*/
714-
@Deprecated
715-
public @NonNull Route setReturnType(@Nullable Type returnType) {
716-
this.returnType = returnType;
717-
return this;
718-
}
719-
720693
/**
721694
* Response types (format) produces by this route. If set, we expect to find a match in the <code>
722695
* Accept</code> header. If none matches, we send a {@link StatusCode#NOT_ACCEPTABLE} response.
@@ -806,7 +779,8 @@ public boolean isNonBlockingSet() {
806779
* @param <T> Generic type.
807780
* @return value of the specific attribute.
808781
*/
809-
public @Nullable <T> T attribute(@NonNull String name) {
782+
public @Nullable <T> T getAttribute(@NonNull String name) {
783+
//noinspection unchecked
810784
return (T) attributes.get(name);
811785
}
812786

@@ -828,7 +802,7 @@ public boolean isNonBlockingSet() {
828802
* @param value attribute value
829803
* @return This route.
830804
*/
831-
public @NonNull Route attribute(@NonNull String name, @NonNull Object value) {
805+
public @NonNull Route setAttribute(@NonNull String name, @NonNull Object value) {
832806
if (this.attributes == EMPTY_MAP) {
833807
this.attributes = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
834808
}
@@ -1072,7 +1046,7 @@ public boolean isHttpHead() {
10721046
* @return whether this route should be considered as transactional
10731047
*/
10741048
public boolean isTransactional(boolean defaultValue) {
1075-
Object attribute = attribute(Transactional.ATTRIBUTE);
1049+
Object attribute = getAttribute(Transactional.ATTRIBUTE);
10761050

10771051
if (attribute == null) {
10781052
return defaultValue;

jooby/src/main/java/io/jooby/RouteSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public class RouteSet {
121121
* @param value attribute value
122122
* @return This route.
123123
*/
124-
public @NonNull RouteSet attribute(@NonNull String name, @NonNull Object value) {
124+
public @NonNull RouteSet setAttribute(@NonNull String name, @NonNull Object value) {
125125
routes.forEach(it -> it.getAttributes().putIfAbsent(name, value));
126126
return this;
127127
}

jooby/src/main/java/io/jooby/Router.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ default Object execute(@NonNull Context context) {
151151
* @param <T> Attribute type.
152152
* @return Attribute value.
153153
*/
154-
@NonNull default <T> T attribute(@NonNull String key) {
154+
@NonNull default <T> T getAttribute(@NonNull String key) {
155+
@SuppressWarnings("unchecked")
155156
T attribute = (T) getAttributes().get(key);
156157
if (attribute == null) {
157158
throw new MissingValueException(key);
@@ -166,7 +167,7 @@ default Object execute(@NonNull Context context) {
166167
* @param value Attribute value.
167168
* @return This router.
168169
*/
169-
@NonNull default Router attribute(@NonNull String key, Object value) {
170+
@NonNull default Router setAttribute(@NonNull String key, Object value) {
170171
getAttributes().put(key, value);
171172
return this;
172173
}

modules/jooby-apt/src/main/java/io/jooby/apt/JoobyProcessor.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
DEBUG,
3636
INCREMENTAL,
3737
MVC_METHOD,
38-
RETURN_TYPE,
3938
ROUTER_PREFIX,
4039
ROUTER_SUFFIX,
4140
SKIP_ATTRIBUTE_ANNOTATIONS
@@ -48,7 +47,6 @@ public interface Options {
4847
String ROUTER_PREFIX = "jooby.routerPrefix";
4948
String ROUTER_SUFFIX = "jooby.routerSuffix";
5049
String INCREMENTAL = "jooby.incremental";
51-
String RETURN_TYPE = "jooby.returnType";
5250
String MVC_METHOD = "jooby.mvcMethod";
5351
String SKIP_ATTRIBUTE_ANNOTATIONS = "jooby.skipAttributeAnnotations";
5452

modules/jooby-apt/src/main/java/io/jooby/internal/apt/MvcContext.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ private record ResultType(String type, String handler, boolean nonBlocking) {}
3333
private final String routerSuffix;
3434
private final BiConsumer<Diagnostic.Kind, String> output;
3535
private final List<MvcRouter> routers = new ArrayList<>();
36-
private final boolean returnType;
3736
private final boolean mvcMethod;
3837
private final Map<TypeElement, ResultType> handler = new HashMap<>();
3938

@@ -43,7 +42,6 @@ public MvcContext(
4342
this.output = output;
4443
this.debug = Options.boolOpt(processingEnvironment, Options.DEBUG, false);
4544
this.incremental = Options.boolOpt(processingEnvironment, Options.INCREMENTAL, true);
46-
this.returnType = Options.boolOpt(processingEnvironment, Options.RETURN_TYPE, false);
4745
this.mvcMethod = Options.boolOpt(processingEnvironment, Options.MVC_METHOD, false);
4846
this.routerPrefix = Options.string(processingEnvironment, Options.ROUTER_PREFIX, "");
4947
this.routerSuffix = Options.string(processingEnvironment, Options.ROUTER_SUFFIX, "_");
@@ -244,10 +242,6 @@ public boolean generateMvcMethod() {
244242
return mvcMethod;
245243
}
246244

247-
public boolean generateReturnType() {
248-
return returnType;
249-
}
250-
251245
public boolean isIncremental() {
252246
return incremental;
253247
}

modules/jooby-apt/src/main/java/io/jooby/internal/apt/MvcRoute.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,6 @@ public List<String> generateMapping(boolean kt) {
145145
.toSourceCode(kt, this, 2)
146146
.ifPresent(
147147
attributes -> block.add(statement(indent(2), ".setAttributes(", attributes, ")")));
148-
if (context.generateReturnType()) {
149-
/* returnType */
150-
block.add(statement(indent(2), ".setReturnType(", returnType.toSourceCode(kt), ")"));
151-
}
152148
var lineSep = lastLine ? lineSeparator() : lineSeparator() + lineSeparator();
153149
if (context.generateMvcMethod()) {
154150
/* mvcMethod */

modules/jooby-apt/src/test/java/source/Routes.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@
55
*/
66
package source;
77

8-
import static org.junit.jupiter.api.Assertions.assertEquals;
9-
108
import java.util.Arrays;
119
import java.util.List;
1210

1311
import io.jooby.Context;
14-
import io.jooby.Reified;
1512
import io.jooby.annotation.GET;
1613
import io.jooby.annotation.POST;
1714
import io.jooby.annotation.Path;
@@ -21,25 +18,21 @@ public class Routes {
2118

2219
@GET
2320
public String doIt(Context ctx) {
24-
assertEquals(String.class, ctx.getRoute().getReturnType());
2521
return ctx.getRequestPath();
2622
}
2723

2824
@GET("/subpath")
2925
public List<String> subpath(Context ctx) {
30-
assertEquals(Reified.list(String.class).getType(), ctx.getRoute().getReturnType());
3126
return Arrays.asList(ctx.getRequestPath());
3227
}
3328

3429
@GET("/object")
3530
public Object object(Context ctx) {
36-
assertEquals(Object.class, ctx.getRoute().getReturnType());
3731
return ctx;
3832
}
3933

4034
@POST("/post")
4135
public JavaBeanParam post(Context ctx) {
42-
assertEquals(JavaBeanParam.class, ctx.getRoute().getReturnType());
4336
return new JavaBeanParam();
4437
}
4538

modules/jooby-apt/src/test/java/tests/Issue1525.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ public void routeClassAttributes() throws Exception {
2121
app -> {
2222
Route route0 = app.getRoutes().get(0);
2323
assertEquals(1, route0.getAttributes().size(), route0.getAttributes().toString());
24-
assertEquals("Admin", route0.attribute("roleAnnotation"));
24+
assertEquals("Admin", route0.getAttribute("roleAnnotation"));
2525

2626
Route route1 = app.getRoutes().get(1);
2727
assertEquals(1, route1.getAttributes().size(), route1.getAttributes().toString());
28-
assertEquals("User", route1.attribute("roleAnnotation"));
28+
assertEquals("User", route1.getAttribute("roleAnnotation"));
2929
});
3030
}
3131
}

modules/jooby-apt/src/test/java/tests/Issue1527.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,19 @@ public void annotation() throws Exception {
2424
app -> {
2525
Route route0 = app.getRoutes().get(0);
2626
assertEquals(2, route0.getAttributes().size(), route0.getAttributes().toString());
27-
assertEquals(Controller1527.Role.ADMIN, route0.attribute("requireRole"));
28-
assertEquals(Arrays.asList(TopEnum.FOO), route0.attribute("topAnnotation"));
27+
assertEquals(Controller1527.Role.ADMIN, route0.getAttribute("requireRole"));
28+
assertEquals(Arrays.asList(TopEnum.FOO), route0.getAttribute("topAnnotation"));
2929

3030
Route route1 = app.getRoutes().get(1);
3131
assertEquals(1, route1.getAttributes().size(), route1.getAttributes().toString());
3232
assertEquals(
33-
Arrays.asList(TopEnum.BAR, TopEnum.FOO), route1.attribute("topAnnotation"));
33+
Arrays.asList(TopEnum.BAR, TopEnum.FOO), route1.getAttribute("topAnnotation"));
3434

3535
Route route2 = app.getRoutes().get(2);
3636
assertEquals(2, route2.getAttributes().size(), route2.getAttributes().toString());
37-
assertEquals(Arrays.asList(TopEnum.FOO), route2.attribute("topAnnotation"));
38-
assertEquals(Arrays.asList("a", "b", "c"), route2.attribute("stringArrayAnnotation"));
37+
assertEquals(Arrays.asList(TopEnum.FOO), route2.getAttribute("topAnnotation"));
38+
assertEquals(
39+
Arrays.asList("a", "b", "c"), route2.getAttribute("stringArrayAnnotation"));
3940
});
4041
}
4142
}

0 commit comments

Comments
 (0)