Compare commits
No commits in common. "b2e8e0c5b999cd62cb7ef62bb4898c6c75c64ebf" and "b64126a01b91e765730ff493a2ed2cdc545a0dd9" have entirely different histories.
b2e8e0c5b9
...
b64126a01b
@ -4,7 +4,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = 'com.jessebrault.di'
|
||||
version = '0.2.0-SNAPSHOT'
|
||||
version = '0.1.0'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.0-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
9
gradlew
vendored
9
gradlew
vendored
@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015 the original authors.
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@ -114,6 +114,7 @@ case "$( uname )" in #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
@ -171,6 +172,7 @@ fi
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
@ -203,14 +205,15 @@ fi
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
|
||||
3
gradlew.bat
vendored
3
gradlew.bat
vendored
@ -70,10 +70,11 @@ goto fail
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
|
||||
@ -1,15 +1,14 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.jessebrault.di.ObjectFactoryUtil.toTypes;
|
||||
import static groowt.util.di.ObjectFactoryUtil.toTypes;
|
||||
|
||||
// TODO: maybe inject fields
|
||||
public abstract class AbstractInjectingObjectFactory implements ObjectFactory {
|
||||
@ -105,15 +104,20 @@ public abstract class AbstractInjectingObjectFactory implements ObjectFactory {
|
||||
|
||||
}
|
||||
|
||||
private final Map<Class<?>, Constructor<?>[]> cachedAllConstructors = new ConcurrentHashMap<>();
|
||||
private final Map<Class<?>, Constructor<?>> cachedInjectConstructors = new ConcurrentHashMap<>();
|
||||
private final Map<Class<?>, Map<Class<?>[], Constructor<?>>> cachedNonInjectConstructors = new ConcurrentHashMap<>();
|
||||
private final Map<Class<?>, Collection<Method>> cachedSetters = new ConcurrentHashMap<>();
|
||||
private final Map<Method, Parameter> cachedSetterParameters = new ConcurrentHashMap<>();
|
||||
private final Map<Class<?>, Constructor<?>[]> cachedAllConstructors = new HashMap<>();
|
||||
private final Collection<CachedInjectConstructor<?>> cachedInjectConstructors = new ArrayList<>();
|
||||
private final Collection<CachedNonInjectConstructor<?>> cachedNonInjectConstructors = new ArrayList<>();
|
||||
private final Map<Class<?>, Collection<Method>> cachedSetters = new HashMap<>();
|
||||
private final Map<Method, Parameter> cachedSetterParameters = new HashMap<>();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> @Nullable Constructor<T> findCachedInjectConstructor(Class<T> clazz) {
|
||||
return (Constructor<T>) this.cachedInjectConstructors.get(clazz);
|
||||
for (final CachedInjectConstructor<?> cachedConstructor : this.cachedInjectConstructors) {
|
||||
if (clazz.equals(cachedConstructor.clazz())) {
|
||||
return (Constructor<T>) cachedConstructor.constructor();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -149,14 +153,15 @@ public abstract class AbstractInjectingObjectFactory implements ObjectFactory {
|
||||
}
|
||||
|
||||
protected final void putCachedInjectConstructor(CachedInjectConstructor<?> cached) {
|
||||
this.cachedInjectConstructors.put(cached.clazz(), cached.constructor());
|
||||
this.cachedInjectConstructors.add(cached);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> @Nullable Constructor<T> findCachedNonInjectConstructor(Class<T> clazz, Class<?>[] paramTypes) {
|
||||
final Map<Class<?>[], Constructor<?>> constructors = this.cachedNonInjectConstructors.get(clazz);
|
||||
if (constructors != null) {
|
||||
return (Constructor<T>) constructors.get(paramTypes);
|
||||
for (final CachedNonInjectConstructor<?> cachedConstructor : this.cachedNonInjectConstructors) {
|
||||
if (clazz.equals(cachedConstructor.clazz()) && Arrays.equals(cachedConstructor.paramTypes(), paramTypes)) {
|
||||
return (Constructor<T>) cachedConstructor.constructor();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -204,10 +209,7 @@ public abstract class AbstractInjectingObjectFactory implements ObjectFactory {
|
||||
}
|
||||
|
||||
protected final void putCachedNonInjectConstructor(CachedNonInjectConstructor<?> cached) {
|
||||
final Map<Class<?>[], Constructor<?>> constructors = this.cachedNonInjectConstructors.computeIfAbsent(
|
||||
cached.clazz(), clazz -> new HashMap<>()
|
||||
);
|
||||
constructors.put(cached.paramTypes(), cached.constructor());
|
||||
this.cachedNonInjectConstructors.add(cached);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1,7 +1,7 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
import com.jessebrault.di.filters.FilterHandler;
|
||||
import com.jessebrault.di.filters.IterableFilterHandler;
|
||||
import groowt.util.di.filters.FilterHandler;
|
||||
import groowt.util.di.filters.IterableFilterHandler;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
@ -12,7 +12,7 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static com.jessebrault.di.RegistryObjectFactoryUtil.orElseSupply;
|
||||
import static groowt.util.di.RegistryObjectFactoryUtil.orElseSupply;
|
||||
|
||||
public abstract class AbstractRegistryObjectFactory extends AbstractInjectingObjectFactory
|
||||
implements RegistryObjectFactory {
|
||||
@ -1,3 +1,3 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
sealed public interface Binding<T> permits ClassBinding, ProviderBinding, SingletonBinding, LazySingletonBinding {}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
import jakarta.inject.Provider;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
import jakarta.inject.Provider;
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
public record ClassBinding<T>(Class<T> from, Class<? extends T> to) implements Binding<T> {}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
import jakarta.inject.Named;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
import com.jessebrault.di.filters.FilterHandler;
|
||||
import com.jessebrault.di.filters.IterableFilterHandler;
|
||||
import groowt.util.di.filters.FilterHandler;
|
||||
import groowt.util.di.filters.IterableFilterHandler;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
@ -14,7 +14,7 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import static com.jessebrault.di.RegistryObjectFactoryUtil.*;
|
||||
import static groowt.util.di.RegistryObjectFactoryUtil.*;
|
||||
|
||||
public class DefaultRegistryObjectFactory extends AbstractRegistryObjectFactory {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.BiPredicate;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
public interface KeyHolder<B extends KeyBinder<K>, K, T> {
|
||||
Class<B> binderType();
|
||||
@ -1,4 +1,4 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
public interface NamedRegistryExtension extends RegistryExtension, KeyBinder<String>, QualifierHandlerContainer {}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
import jakarta.inject.Provider;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
import jakarta.inject.Qualifier;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
public interface RegistryExtension {}
|
||||
@ -1,9 +1,9 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
import groovy.lang.Closure;
|
||||
import groovy.lang.DelegatesTo;
|
||||
import com.jessebrault.di.filters.FilterHandler;
|
||||
import com.jessebrault.di.filters.IterableFilterHandler;
|
||||
import groowt.util.di.filters.FilterHandler;
|
||||
import groowt.util.di.filters.IterableFilterHandler;
|
||||
import jakarta.inject.Provider;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
import com.jessebrault.di.filters.Filter;
|
||||
import com.jessebrault.di.filters.IterableFilter;
|
||||
import groowt.util.di.filters.Filter;
|
||||
import groowt.util.di.filters.IterableFilter;
|
||||
import jakarta.inject.Qualifier;
|
||||
import jakarta.inject.Scope;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
import jakarta.inject.Scope;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
import jakarta.inject.Provider;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
public record SimpleKeyHolder<B extends KeyBinder<K>, K, T>(Class<B> binderType, Class<T> type, K key)
|
||||
implements KeyHolder<B, K, T> {}
|
||||
@ -1,3 +1,3 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
public record SingletonBinding<T>(T to) implements Binding<T> {}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
import jakarta.inject.Singleton;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -1,9 +1,9 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
import jakarta.inject.Provider;
|
||||
import jakarta.inject.Singleton;
|
||||
|
||||
import static com.jessebrault.di.BindingUtil.toLazySingleton;
|
||||
import static groowt.util.di.BindingUtil.toLazySingleton;
|
||||
|
||||
public final class SingletonScopeHandler implements ScopeHandler<Singleton> {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.jessebrault.di.annotation;
|
||||
package groowt.util.di.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.jessebrault.di.filters;
|
||||
package groowt.util.di.filters;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.jessebrault.di.filters;
|
||||
package groowt.util.di.filters;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Objects;
|
||||
@ -1,9 +1,9 @@
|
||||
package com.jessebrault.di.filters;
|
||||
package groowt.util.di.filters;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
import static com.jessebrault.di.filters.FilterUtil.isAssignableToAnyOf;
|
||||
import static groowt.util.di.filters.FilterUtil.isAssignableToAnyOf;
|
||||
|
||||
public final class FilterHandlers {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.jessebrault.di.filters;
|
||||
package groowt.util.di.filters;
|
||||
|
||||
public final class FilterUtil {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.jessebrault.di.filters;
|
||||
package groowt.util.di.filters;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.jessebrault.di.filters;
|
||||
package groowt.util.di.filters;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
package com.jessebrault.di.filters;
|
||||
package groowt.util.di.filters;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import java.util.function.BiPredicate;
|
||||
|
||||
import static com.jessebrault.di.filters.FilterUtil.isAssignableToAnyOf;
|
||||
import static groowt.util.di.filters.FilterUtil.isAssignableToAnyOf;
|
||||
|
||||
public final class IterableFilterHandlers {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package com.jessebrault.di.filters;
|
||||
package groowt.util.di.filters;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.function.BiPredicate;
|
||||
@ -1,4 +1,4 @@
|
||||
package com.jessebrault.di.filters;
|
||||
package groowt.util.di.filters;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Objects;
|
||||
@ -1,11 +1,11 @@
|
||||
package com.jessebrault.di;
|
||||
package groowt.util.di;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Named;
|
||||
import jakarta.inject.Singleton;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static com.jessebrault.di.BindingUtil.*;
|
||||
import static groowt.util.di.BindingUtil.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class DefaultRegistryObjectFactoryTests {
|
||||
Loading…
Reference in New Issue
Block a user