Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Jspecify Annotations #650

Merged
merged 16 commits into from
Jul 24, 2024
2 changes: 1 addition & 1 deletion inject-events/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<dependency>
<groupId>io.avaje</groupId>
<artifactId>avaje-inject</artifactId>
<version>10.0-RC6</version>
<version>10.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static boolean externallyProvided(String type) {

static void addOptionalType(String paramType, String name) {
if (!CTX.get().providedTypes.contains(paramType)) {
CTX.get().optionalTypes.add(Util.addQualifierSuffixTrim(name, paramType));
CTX.get().optionalTypes.add(ProcessorUtils.trimAnnotations(Util.addQualifierSuffixTrim(name, paramType)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,14 @@ static String getNamed(Element p) {
return null;
}

/**
* Return true if the element has a Nullable annotation.
*/
/** Return true if the element has a Nullable annotation. */
static boolean isNullable(Element p) {
for (final AnnotationMirror mirror : p.getAnnotationMirrors()) {

if (ProcessorUtils.hasAnnotationWithName(p, NULLABLE)) {
return true;
}

for (final AnnotationMirror mirror : UType.parse(p.asType()).annotations()) {
if (NULLABLE.equals(shortName(mirror.getAnnotationType().toString()))) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

import org.jspecify.annotations.Nullable;

import io.avaje.inject.External;
import io.avaje.lang.Nullable;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;

@Singleton
public class ExternalDeps {
@Inject @Nullable AtomicLong longy;

public ExternalDeps(@External AtomicBoolean bool, @Nullable AtomicInteger inty) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import io.avaje.inject.BeanScope;
import io.avaje.inject.spi.AvajeModule;
import io.avaje.lang.Nullable;
import org.jspecify.annotations.Nullable;

import java.io.IOException;
import java.io.InputStream;
Expand Down
12 changes: 7 additions & 5 deletions inject-test/src/main/java/io/avaje/inject/test/PluginMgr.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package io.avaje.inject.test;

import io.avaje.inject.BeanScope;
import io.avaje.lang.Nullable;

import java.util.ServiceLoader;

import org.jspecify.annotations.Nullable;

import io.avaje.inject.BeanScope;
import io.avaje.inject.test.Plugin.Scope;

final class PluginMgr {

private PluginMgr() {}
Expand All @@ -23,8 +25,8 @@ static Plugin plugin() {
/**
* Return a new plugin scope (if there is a plugin).
*/
@Nullable
static Plugin.Scope scope(BeanScope beanScope) {
@Nullable
static Scope scope(BeanScope beanScope) {
return plugin == null ? null : plugin.createScope(beanScope);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package io.avaje.inject.test;

import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

import io.avaje.inject.BeanScope;
import io.avaje.inject.BeanScopeBuilder;
import io.avaje.lang.NonNullApi;
import io.avaje.lang.Nullable;

/**
* Provides access to the global "test scope" and helper methods to use it.
*
*/
@NonNullApi
@NullMarked
public abstract class TestBeanScope {

/**
Expand Down
12 changes: 6 additions & 6 deletions inject/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
<description>avaje-inject dependency injection library using source code generation</description>
<dependencies>

<dependency>
<groupId>org.jspecify</groupId>
<artifactId>jspecify</artifactId>
<version>1.0.0</version>
</dependency>

<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
Expand All @@ -24,12 +30,6 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>io.avaje</groupId>
<artifactId>avaje-lang</artifactId>
<version>1.1</version>
</dependency>

<dependency>
<groupId>io.avaje</groupId>
<artifactId>avaje-applog</artifactId>
Expand Down
3 changes: 0 additions & 3 deletions inject/src/main/java/io/avaje/inject/BeanEntry.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package io.avaje.inject;

import io.avaje.lang.NonNullApi;

import java.util.Set;

/**
* A bean entry with priority and optional name.
*
* @see BeanScope#all()
*/
@NonNullApi
public interface BeanEntry {

/**
Expand Down
4 changes: 1 addition & 3 deletions inject/src/main/java/io/avaje/inject/BeanScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import java.util.Map;
import java.util.Optional;

import io.avaje.lang.NonNullApi;
import io.avaje.lang.Nullable;
import org.jspecify.annotations.Nullable;

/**
* Holds beans created by dependency injection.
Expand Down Expand Up @@ -67,7 +66,6 @@
*
* }</pre>
*/
@NonNullApi
public interface BeanScope extends AutoCloseable {

/**
Expand Down
13 changes: 6 additions & 7 deletions inject/src/main/java/io/avaje/inject/BeanScopeBuilder.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package io.avaje.inject;

import io.avaje.inject.spi.AvajeModule;
import io.avaje.inject.spi.ConfigPropertyPlugin;
import io.avaje.inject.spi.PropertyRequiresPlugin;
import io.avaje.lang.NonNullApi;
import io.avaje.lang.Nullable;

import java.lang.reflect.Type;
import java.util.function.Consumer;
import java.util.function.Supplier;

import org.jspecify.annotations.Nullable;

import io.avaje.inject.spi.AvajeModule;
import io.avaje.inject.spi.ConfigPropertyPlugin;
import io.avaje.inject.spi.PropertyRequiresPlugin;

/**
* Build a bean scope with options for shutdown hook and supplying external dependencies.
* <p>
Expand All @@ -30,7 +30,6 @@
*
* }</pre>
*/
@NonNullApi
public interface BeanScopeBuilder {

/**
Expand Down
15 changes: 11 additions & 4 deletions inject/src/main/java/io/avaje/inject/DBeanScopeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static java.lang.System.Logger.Level.DEBUG;
import static java.lang.System.Logger.Level.INFO;
import static java.util.Collections.emptySet;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -14,14 +15,20 @@
import java.util.function.Consumer;
import java.util.function.Supplier;

import org.jspecify.annotations.Nullable;

import io.avaje.applog.AppLog;
import io.avaje.inject.spi.*;
import io.avaje.lang.NonNullApi;
import io.avaje.lang.Nullable;
import io.avaje.inject.spi.AvajeModule;
import io.avaje.inject.spi.Builder;
import io.avaje.inject.spi.ClosePair;
import io.avaje.inject.spi.ConfigPropertyPlugin;
import io.avaje.inject.spi.EnrichBean;
import io.avaje.inject.spi.ModuleOrdering;
import io.avaje.inject.spi.PropertyRequiresPlugin;
import io.avaje.inject.spi.SuppliedBean;
import jakarta.inject.Provider;

/** Build a bean scope with options for shutdown hook and supplying test doubles. */
@NonNullApi
final class DBeanScopeBuilder implements BeanScopeBuilder.ForTesting {

private static final System.Logger log = AppLog.getLogger("io.avaje.inject");
Expand Down
1 change: 1 addition & 0 deletions inject/src/main/java/io/avaje/inject/package-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
*
* }</pre>
*/
@org.jspecify.annotations.NullMarked
package io.avaje.inject;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.Optional;

import io.avaje.lang.NonNullApi;
import org.jspecify.annotations.NullMarked;

/**
* Plugin interface which contains the application properties used for wiring. Used with
Expand All @@ -11,28 +11,33 @@
* <p>The plugin is loaded via ServiceLoader and defaults to an implementation that uses {@link
* System#getProperty(String)} and {@link System#getenv(String)}.
*/
@NonNullApi
@NullMarked
public interface ConfigPropertyPlugin extends InjectExtension, PropertyRequiresPlugin {

/**
* Return a configuration value that might not exist.
*/
@Override
Optional<String> get(String property);

/**
* Return true if the property is defined.
*/
@Override
boolean contains(String property);

/** Return true if the property is not defined. */
@Override
default boolean missing(String property) {
return !contains(property);
}

/** Return true if the property is equal to the given value. */
@Override
boolean equalTo(String property, String value);

/** Return true if the property is not defined or not equal to the given value. */
@Override
default boolean notEqualTo(String property, String value) {
return !equalTo(property, value);
}
Expand Down
34 changes: 21 additions & 13 deletions inject/src/main/java/io/avaje/inject/spi/DBeanScope.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
package io.avaje.inject.spi;

import io.avaje.applog.AppLog;
import io.avaje.inject.BeanEntry;
import io.avaje.inject.BeanScope;
import io.avaje.inject.Priority;
import io.avaje.lang.NonNullApi;
import io.avaje.lang.Nullable;
import static java.lang.System.Logger.Level.INFO;
import static java.lang.System.Logger.Level.TRACE;

import java.lang.System.Logger.Level;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import static java.lang.System.Logger.Level.INFO;
import static java.lang.System.Logger.Level.TRACE;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;

@NonNullApi
import io.avaje.applog.AppLog;
import io.avaje.inject.BeanEntry;
import io.avaje.inject.BeanScope;
import io.avaje.inject.Priority;

@NullMarked
final class DBeanScope implements BeanScope {

private static final System.Logger log = AppLog.getLogger("io.avaje.inject");
Expand Down Expand Up @@ -175,10 +182,11 @@ private <T> List<T> listOf(Type type) {
static <T> List<T> combine(List<T> values, List<T> parentValues) {
if (values.isEmpty()) {
return parentValues;
} else if (parentValues.isEmpty()) {
return values;
} else {
values.addAll(parentValues);
if (parentValues.isEmpty()) {
SentryMan marked this conversation as resolved.
Show resolved Hide resolved
} else {
values.addAll(parentValues);
}
return values;
}
}
Expand Down
9 changes: 5 additions & 4 deletions inject/src/main/java/io/avaje/inject/spi/DEntry.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package io.avaje.inject.spi;

import io.avaje.inject.BeanEntry;
import io.avaje.lang.NonNullApi;

import java.util.LinkedHashSet;
import java.util.Set;

@NonNullApi
import org.jspecify.annotations.NullMarked;

import io.avaje.inject.BeanEntry;

@NullMarked
final class DEntry implements BeanEntry {

private final String qualifierName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.Optional;

import io.avaje.lang.NonNullApi;
import org.jspecify.annotations.NullMarked;

/**
* Plugin interface which contains the application properties used for wiring. Used with {@link
Expand All @@ -13,7 +13,7 @@
*
* @deprecated use ConfigPropertyPlugin Instead
*/
@NonNullApi
@NullMarked
@Deprecated(forRemoval = true)
public interface PropertyRequiresPlugin extends InjectExtension {

Expand Down
5 changes: 3 additions & 2 deletions inject/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
exports io.avaje.inject;
exports io.avaje.inject.spi;

requires transitive io.avaje.lang;
requires transitive io.avaje.applog;
requires transitive jakarta.inject;
requires static io.avaje.config;
requires static org.mockito;
requires static io.avaje.spi;

requires static transitive jakarta.inject;
requires static transitive org.jspecify;

uses io.avaje.inject.spi.InjectExtension;
uses io.avaje.inject.spi.Module;
uses io.avaje.inject.spi.Plugin;
Expand Down
Loading