Skip to content

Commit 796dc37

Browse files
committed
apt: delete dead code
1 parent be73ae9 commit 796dc37

13 files changed

Lines changed: 2 additions & 1600 deletions

File tree

jooby/src/main/java/io/jooby/internal/RouterImpl.java

Lines changed: 2 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,17 @@
2222
import io.jooby.ServiceRegistry;
2323
import io.jooby.SessionOptions;
2424
import io.jooby.StatusCode;
25-
import io.jooby.SneakyThrows;
2625
import io.jooby.TemplateEngine;
27-
import io.jooby.annotations.Dispatch;
2826
import io.jooby.internal.asm.ClassSource;
29-
import io.jooby.internal.mvc.MvcAnnotationParser;
30-
import io.jooby.internal.mvc.MvcCompiler;
31-
import io.jooby.internal.mvc.MvcMetadata;
32-
import io.jooby.internal.mvc.MvcMethod;
33-
import io.jooby.internal.mvc.MvcAnnotation;
3427
import org.slf4j.Logger;
3528
import org.slf4j.LoggerFactory;
3629

3730
import javax.annotation.Nonnull;
3831
import javax.inject.Provider;
3932
import java.io.FileNotFoundException;
40-
import java.lang.reflect.Method;
41-
import java.lang.reflect.Modifier;
4233
import java.nio.file.Path;
4334
import java.nio.file.Paths;
4435
import java.util.ArrayList;
45-
import java.util.Collections;
46-
import java.util.Comparator;
4736
import java.util.HashMap;
4837
import java.util.LinkedList;
4938
import java.util.List;
@@ -141,8 +130,6 @@ public Stack executor(Executor executor) {
141130

142131
private ServiceRegistry services = new ServiceRegistryImpl();
143132

144-
private MvcAnnotationParser annotationParser;
145-
146133
private ClassSource source;
147134

148135
private SessionOptions sessionOptions = new SessionOptions();
@@ -227,9 +214,7 @@ public Router use(@Nonnull Router router) {
227214
}
228215

229216
@Nonnull @Override public Router mvc(@Nonnull Object router) {
230-
checkMvcAnnotations();
231-
mvc(null, router.getClass(), () -> router);
232-
return this;
217+
throw new UnsupportedOperationException();
233218
}
234219

235220
@Nonnull @Override public Router mvc(@Nonnull Class router) {
@@ -238,9 +223,7 @@ public Router use(@Nonnull Router router) {
238223

239224
@Nonnull @Override
240225
public <T> Router mvc(@Nonnull Class<T> router, @Nonnull Provider<T> provider) {
241-
checkMvcAnnotations();
242-
mvc(null, router, provider);
243-
return this;
226+
throw new UnsupportedOperationException();
244227
}
245228

246229
@Nonnull @Override public Router encoder(@Nonnull MessageEncoder encoder) {
@@ -588,104 +571,6 @@ private Router newStack(@Nonnull Stack stack, @Nonnull Runnable action,
588571
return this;
589572
}
590573

591-
private void mvc(String prefix, Class type, Provider provider) {
592-
find(prefix, type, method -> {
593-
594-
Route.Handler instance = MvcCompiler
595-
.newHandler(source.getLoader(), method, provider);
596-
597-
Route route = route(method.getHttpMethod(), method.getPattern(), instance)
598-
.setReturnType(method.getReturnType(source.getLoader()));
599-
600-
MvcAnnotation model = method.getModel();
601-
List<MediaType> produces = model.getProduces();
602-
if (produces.size() > 0) {
603-
route.setProduces(produces);
604-
}
605-
606-
List<MediaType> consumes = model.getConsumes();
607-
if (consumes.size() > 0) {
608-
route.setConsumes(consumes);
609-
}
610-
611-
Map<String, Object> attributes = model.getAttributes();
612-
if (attributes.size() > 0) {
613-
route.setAttributes(attributes);
614-
}
615-
});
616-
}
617-
618-
private void find(String prefix, Class type, SneakyThrows.Consumer<MvcMethod> consumer) {
619-
MvcMetadata mvcMetadata = new MvcMetadata(source);
620-
mvcMetadata.parse(type);
621-
List<MvcMethod> routes = new ArrayList<>();
622-
Stream.of(type.getDeclaredMethods()).forEach(method -> {
623-
if (Modifier.isPublic(method.getModifiers())) {
624-
annotationParser.parse(method).forEach(model -> {
625-
String[] paths = pathPrefix(prefix, model.getPath());
626-
for (String path : paths) {
627-
MvcMethod mvc = mvcMetadata.create(method);
628-
mvc.setPattern(path);
629-
mvc.setModel(model);
630-
mvc.setMethod(method);
631-
routes.add(mvc);
632-
}
633-
});
634-
}
635-
});
636-
Collections.sort(routes, Comparator.comparingInt(MvcMethod::getLine));
637-
routes.forEach(mvc -> {
638-
String executorKey = dispatchTo(mvc.getMethod());
639-
if (executorKey != null) {
640-
if (executorKey.length() == 0) {
641-
dispatch(() -> consumer.accept(mvc));
642-
} else {
643-
Executor executor = services.getOrNull(ServiceKey.key(Executor.class, executorKey));
644-
if (executor == null) {
645-
// TODO: replace with usage exception
646-
throw new IllegalArgumentException(
647-
"Missing executor: " + executorKey + ", required by: " + mvc.getMethod()
648-
.getDeclaringClass().getName() + "." + mvc.getMethod()
649-
.getName() + ", at line: " + mvc.getLine());
650-
}
651-
dispatch(executor, () -> consumer.accept(mvc));
652-
}
653-
} else {
654-
consumer.accept(mvc);
655-
}
656-
});
657-
mvcMetadata.destroy();
658-
}
659-
660-
private String dispatchTo(Method method) {
661-
Dispatch dispatch = method.getAnnotation(Dispatch.class);
662-
if (dispatch != null) {
663-
return dispatch.value();
664-
}
665-
Dispatch parent = method.getDeclaringClass().getAnnotation(Dispatch.class);
666-
if (parent != null) {
667-
return parent.value();
668-
}
669-
return null;
670-
}
671-
672-
private String[] pathPrefix(String prefix, String[] path) {
673-
if (prefix == null) {
674-
return path;
675-
}
676-
String[] result = new String[path.length];
677-
for (int i = 0; i < path.length; i++) {
678-
result[i] = prefix + "/" + path[i];
679-
}
680-
return result;
681-
}
682-
683-
private void checkMvcAnnotations() {
684-
if (annotationParser == null) {
685-
annotationParser = MvcAnnotationParser.create(source.getLoader());
686-
}
687-
}
688-
689574
private void copy(Route src, Route it) {
690575
Route.Before before = Optional.ofNullable(it.getBefore())
691576
.map(filter -> Optional.ofNullable(src.getBefore()).map(filter::then).orElse(filter))

jooby/src/main/java/io/jooby/internal/mvc/CompositeAnnotationParser.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

jooby/src/main/java/io/jooby/internal/mvc/JaxrsAnnotationParser.java

Lines changed: 0 additions & 74 deletions
This file was deleted.

jooby/src/main/java/io/jooby/internal/mvc/JoobyAnnotationParser.java

Lines changed: 0 additions & 108 deletions
This file was deleted.

0 commit comments

Comments
 (0)