Skip to content

Commit

Permalink
Use lambda instead of inner class to define parent ResourceVisitor.Su…
Browse files Browse the repository at this point in the history
…pplier
  • Loading branch information
ibaca committed Nov 24, 2023
1 parent 1ba144c commit 1e2858f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static java.util.Arrays.asList;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;

import org.junit.Test;

Expand All @@ -12,7 +12,7 @@ public class ResourceVisitorTest {
// check root path is accepted (this is a bit obscure, currently anything starting with ".*?//" is a root path)
MyCollectorResourceVisitor rb0 = new MyCollectorResourceVisitor("http://base/");
assertThat(rb0.uri(), equalTo("http://base"));
// basic path an param check
// basic path a param check
MyCollectorResourceVisitor rb1 = (MyCollectorResourceVisitor) new MyCollectorResourceVisitor("http://base")
.path("path").param("p1", "v1");
assertThat(rb1.uri(), equalTo("http://base/path?p1=v1"));
Expand All @@ -27,7 +27,7 @@ public class ResourceVisitorTest {
}

private static class MyCollectorResourceVisitor extends CollectorResourceVisitor {
private MyCollectorResourceVisitor(String base) {super(base);}
private MyCollectorResourceVisitor(String base) { super(base); }
@Override protected String encodeComponent(String str) { return str.replaceAll(":", "%3A"); }
@Override public <T> T as(Class<? super T> container, Class<?> type) { return null; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ private void processRestService(TypeElement restService) throws Exception {
.addAnnotation(Inject.class)
.addModifiers(PUBLIC)
.addParameter(TypeName.get(ResourceVisitor.Supplier.class), "parent", FINAL)
.addStatement("super(new $T() { public $T get() { return $L.get().path($S); } })",
ResourceVisitor.Supplier.class, ResourceVisitor.class, "parent", rsPath)
.addStatement("super(() -> $L.get().path($S))", "parent", rsPath)
.build());

List<ExecutableElement> methods = restService.getEnclosedElements().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public interface TestService {
@QueryParam("qS") String qS, @QueryParam("qI") int qI, @QueryParam("qIs") List<Integer> qIs,
@HeaderParam("hS") String hS, @HeaderParam("hI") int hI);

@GwtIncompatible Response gwtIncompatible();
@SuppressWarnings("UnusedReturnValue") @GwtIncompatible Response gwtIncompatible();
}

@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD)
public @interface GwtIncompatible {}
public @interface GwtIncompatible { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ public class AutoRestGwtProcessorTest {
+ "public class Rest_RestServiceModel extends RestServiceModel implements Rest {\n"
+ " @Inject\n"
+ " public Rest_RestServiceModel(final ResourceVisitor.Supplier parent) {\n"
+ " super(new ResourceVisitor.Supplier() {\n"
+ " public ResourceVisitor get() { return parent.get().path(\"a\"); }\n"
+ " });\n"
+ " super(() -> parent.get().path(\"a\"));\n"
+ " }\n"
+ "\n"
+ " @Override"
Expand Down

0 comments on commit 1e2858f

Please sign in to comment.