Add TabCompletionCache #9
@ -111,7 +111,7 @@ public abstract class AbstractSWCommand<T> {
|
||||
for (Method method : methods) {
|
||||
Cached cached = method.getAnnotation(Cached.class);
|
||||
addMapper(Mapper.class, method, i -> i == 0, false, AbstractTypeMapper.class, (anno, typeMapper) -> {
|
||||
addToCache(cached, typeMapper);
|
||||
TabCompletionCache.add(typeMapper, cached);
|
||||
if (anno.local()) {
|
||||
localTypeMapper.putIfAbsent(anno.value(), (AbstractTypeMapper<T, ?>) typeMapper);
|
||||
} else {
|
||||
@ -119,7 +119,7 @@ public abstract class AbstractSWCommand<T> {
|
||||
}
|
||||
});
|
||||
addMapper(ClassMapper.class, method, i -> i == 0, false, AbstractTypeMapper.class, (anno, typeMapper) -> {
|
||||
addToCache(cached, typeMapper);
|
||||
TabCompletionCache.add(typeMapper, cached);
|
||||
if (anno.local()) {
|
||||
localTypeMapper.putIfAbsent(anno.value().getTypeName(), (AbstractTypeMapper<T, ?>) typeMapper);
|
||||
} else {
|
||||
@ -213,14 +213,6 @@ public abstract class AbstractSWCommand<T> {
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
private void addToCache(Cached cached, AbstractTypeMapper<?, ?> typeMapper) {
|
||||
if (cached != null) {
|
||||
TabCompletionCache.cached.add(typeMapper);
|
||||
if (cached.global()) TabCompletionCache.global.add(typeMapper);
|
||||
TabCompletionCache.cacheDuration.put(typeMapper, cached.timeUnit().toMillis(cached.cacheDuration()));
|
||||
}
|
||||
}
|
||||
|
||||
private <T extends Annotation> void add(Class<T> annotation, Method method, IntPredicate parameterTester, boolean firstParameter, Class<?> returnType, BiConsumer<T, Parameter[]> consumer) {
|
||||
T[] anno = SWCommandUtils.getAnnotation(method, annotation);
|
||||
if (anno == null || anno.length == 0) return;
|
||||
|
@ -15,6 +15,14 @@ public class TabCompletionCache {
|
||||
Set<AbstractTypeMapper<?, ?>> global = new HashSet<>();
|
||||
Map<AbstractTypeMapper<?, ?>, Long> cacheDuration = new HashMap<>();
|
||||
|
||||
void add(AbstractTypeMapper<?, ?> typeMapper, AbstractSWCommand.Cached cached) {
|
||||
if (cached != null) {
|
||||
TabCompletionCache.cached.add(typeMapper);
|
||||
if (cached.global()) TabCompletionCache.global.add(typeMapper);
|
||||
TabCompletionCache.cacheDuration.put(typeMapper, cached.timeUnit().toMillis(cached.cacheDuration()));
|
||||
}
|
||||
}
|
||||
|
||||
@EqualsAndHashCode
|
||||
@AllArgsConstructor
|
||||
private static class Key {
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren