Skip to content

Commit a2c8b66

Browse files
committed
APT: refactor test code
1 parent 8ba33c1 commit a2c8b66

7 files changed

Lines changed: 152 additions & 147 deletions

File tree

modules/jooby-apt/src/main/java/io/jooby/compiler/MvcHandlerCompiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public TypeDefinition getController() {
285285
}
286286

287287
public String getKey() {
288-
return getController().getName() + "." + executable.getSimpleName() + methodDescriptor();
288+
return httpMethod.toUpperCase() + pattern;
289289
}
290290

291291
private String methodDescriptor() {

modules/jooby-apt/src/main/java/io/jooby/compiler/MvcProcessor.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ private List<String> path(TypeElement method, ExecutableElement exec) {
145145
}
146146
return prefix.stream()
147147
.flatMap(root -> methodPath.stream().map(p -> root + p))
148+
.distinct()
148149
.collect(Collectors.toList());
149150
}
150151

@@ -158,14 +159,15 @@ private List<String> path(String method, List<? extends AnnotationMirror> annota
158159
.flatMap(mirror -> {
159160
String type = mirror.getAnnotationType().toString();
160161
if (type.equals(Annotations.PATH) || type.equals(method)) {
161-
return Annotations.attribute(mirror, "value").stream();
162+
return Stream.concat(Annotations.attribute(mirror, "path").stream(),
163+
Annotations.attribute(mirror, "value").stream());
162164
}
163165
return Stream.empty();
164166
})
167+
.distinct()
165168
.collect(Collectors.toList());
166169
}
167170

168-
169171
@Override
170172
public Iterable<? extends Completion> getCompletions(Element element, AnnotationMirror annotation,
171173
ExecutableElement member, String userText) {

modules/jooby-apt/src/test/java/io/jooby/compiler/MvcHandlerCompilerRunner.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,33 +35,31 @@ public MvcHandlerCompilerRunner(Object instance) throws Exception {
3535
.compilesWithoutError();
3636
}
3737

38-
public MvcHandlerCompilerRunner compile(String executableName, Class[] args,
38+
public MvcHandlerCompilerRunner compile(String path,
3939
SneakyThrows.Consumer<Route.Handler> consumer) throws Exception {
40-
return compile("GET", executableName, args, false, consumer);
40+
return compile(path, false, consumer);
4141
}
4242

43-
public MvcHandlerCompilerRunner compile(String httpMethod, String executableName, Class[] args,
43+
public MvcHandlerCompilerRunner compile(String path, boolean debug,
4444
SneakyThrows.Consumer<Route.Handler> consumer) throws Exception {
45-
return compile(httpMethod, executableName, args, false, consumer);
45+
return compile("GET", path, debug, consumer);
4646
}
4747

48-
public MvcHandlerCompilerRunner compile(String executableName, Class[] args, boolean debug,
48+
public MvcHandlerCompilerRunner compile(String method, String path,
4949
SneakyThrows.Consumer<Route.Handler> consumer) throws Exception {
50-
return compile("GET", executableName, args, debug, consumer);
50+
return compile(method, path, false, consumer);
5151
}
5252

53-
public MvcHandlerCompilerRunner compile(String httpMethod, String executableName, Class[] args, boolean debug,
53+
public MvcHandlerCompilerRunner compile(String method, String path, boolean debug,
5454
SneakyThrows.Consumer<Route.Handler> consumer) throws Exception {
55-
Class clazz = instance.getClass();
56-
Method method = clazz.getMethod(executableName, args);
57-
String key = clazz.getName() + "." + executableName + Type.getMethodDescriptor(method);
58-
// key = key.replace("[B", "Lbyte[];");
55+
String key = method.toUpperCase() + path;
56+
// key = key.replace("[B", "Lbyte[];");
5957
MvcHandlerCompiler compiler = processor.compilerFor(key);
60-
assertNotNull("Compiler not found for: " + method, compiler);
58+
assertNotNull("Compiler not found for: " + key, compiler);
6159
if (debug) {
6260
System.out.println(compiler);
6361
}
64-
String handlerName = clazz.getName() + "$" + httpMethod + "$" + executableName;
62+
String handlerName = compiler.getGeneratedClass();
6563
Class<? extends Route.Handler> handleClass = compileClass(handlerName, compiler.compile());
6664
Constructor<? extends Route.Handler> constructor = handleClass
6765
.getDeclaredConstructor(Provider.class);

0 commit comments

Comments
 (0)