Skip to content

Commit 3d30779

Browse files
committed
Add @NotNull annotations
1 parent ac22b1f commit 3d30779

20 files changed

+176
-205
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- has conditional bean registration mechanism
1212
- detects slow bean creation
1313
- provides [event bus](https://github.com/coditory/quark-eventbus) integration
14+
- public API annotated with `@NotNull` and `@Nullable` for better [kotlin integration](https://kotlinlang.org/docs/java-to-kotlin-nullability-guide.html#platform-types)
1415

1516
## Installation
1617

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ description = 'Coditory Quark Context Library'
1414
dependencies {
1515
api 'org.slf4j:slf4j-api:2.0.3'
1616
api 'org.jetbrains:annotations:23.0.0'
17-
api 'com.coditory.quark:quark-eventbus:0.0.4'
17+
api 'com.coditory.quark:quark-eventbus:0.0.5'
1818
testImplementation 'ch.qos.logback:logback-classic:1.4.4'
1919
testImplementation 'org.spockframework:spock-core:2.3-groovy-4.0'
2020
testImplementation 'org.skyscreamer:jsonassert:1.5.1'
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package com.coditory.quark.context;
22

3+
import org.jetbrains.annotations.NotNull;
4+
35
@FunctionalInterface
46
public interface BeanCreator<T> {
5-
T create(ResolutionContext context);
7+
@NotNull
8+
T create(@NotNull ResolutionContext context);
69

7-
default boolean isActive(ConditionContext context) {
10+
default boolean isActive(@NotNull ConditionContext context) {
811
return true;
912
}
1013
}
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
package com.coditory.quark.context;
22

3+
import org.jetbrains.annotations.NotNull;
4+
35
import static java.util.Objects.requireNonNull;
46

57
public record BeanDescriptor<T>(Class<T> type, String name) {
6-
public static <T> BeanDescriptor<T> descriptor(Class<T> type) {
8+
@NotNull
9+
public static <T> BeanDescriptor<T> descriptor(@NotNull Class<T> type) {
710
return new BeanDescriptor<>(type, null);
811
}
912

10-
public static <T> BeanDescriptor<T> descriptor(Class<T> type, String name) {
13+
@NotNull
14+
public static <T> BeanDescriptor<T> descriptor(@NotNull Class<T> type, String name) {
1115
return new BeanDescriptor<>(type, name);
1216
}
1317

14-
public BeanDescriptor(Class<T> type, String name) {
18+
public BeanDescriptor(@NotNull Class<T> type, String name) {
1519
this.type = requireNonNull(type);
1620
this.name = name == null || name.isBlank() ? null : name;
1721
}
1822

19-
public <R> BeanDescriptor<R> withType(Class<R> type) {
23+
@NotNull
24+
public <R> BeanDescriptor<R> withType(@NotNull Class<R> type) {
2025
return new BeanDescriptor<>(type, name);
2126
}
2227

2328
public boolean hasName() {
2429
return name != null;
2530
}
2631

32+
@NotNull
2733
public String toShortString() {
2834
return name != null
2935
? type.getSimpleName() + ":" + name
@@ -32,8 +38,6 @@ public String toShortString() {
3238

3339
@Override
3440
public String toString() {
35-
return name != null
36-
? type.getSimpleName() + ":" + name
37-
: type.getSimpleName();
41+
return "BeanDescriptor{" + toShortString() + "}";
3842
}
3943
}
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
package com.coditory.quark.context;
22

3-
public class BeanFinalizationException extends RuntimeException {
4-
public BeanFinalizationException(String message) {
5-
super(message);
6-
}
7-
8-
public BeanFinalizationException(String message, Throwable cause) {
3+
public final class BeanFinalizationException extends RuntimeException {
4+
BeanFinalizationException(String message, Throwable cause) {
95
super(message, cause);
106
}
117
}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
package com.coditory.quark.context;
22

33
public class BeanInitializationException extends RuntimeException {
4-
public BeanInitializationException(String message) {
5-
super(message);
6-
}
7-
8-
public BeanInitializationException(String message, Throwable cause) {
4+
BeanInitializationException(String message, Throwable cause) {
95
super(message, cause);
106
}
117
}

src/main/java/com/coditory/quark/context/BeanTimer.java

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

src/main/java/com/coditory/quark/context/ConditionContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import static java.util.Objects.requireNonNull;
1111
import static java.util.stream.Collectors.toSet;
1212

13-
class ConditionContext {
13+
final class ConditionContext {
1414
static ConditionContext from(Set<BeanHolder<?>> holders, Map<String, Object> properties) {
1515
Set<BeanDescriptor<?>> descriptors = holders.stream()
1616
.map(BeanHolder::getDescriptor)

src/main/java/com/coditory/quark/context/ConditionsResolver.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ private ConditionsResolver() {
1717
throw new UnsupportedOperationException("Do not instantiate utility class");
1818
}
1919

20-
public static boolean isActive(ConditionContext context, Method method) {
20+
static boolean isActive(ConditionContext context, Method method) {
2121
return isActive(context, method.getAnnotations());
2222
}
2323

24-
public static boolean isActive(ConditionContext context, Class<?> type) {
24+
static boolean isActive(ConditionContext context, Class<?> type) {
2525
return isActive(context, type.getAnnotations());
2626
}
2727

28-
private static boolean isActive(ConditionContext context, Annotation[] annotations) {
28+
static boolean isActive(ConditionContext context, Annotation[] annotations) {
2929
return Arrays.stream(annotations)
3030
.allMatch(annotation -> isActive(context, annotation));
3131
}

src/main/java/com/coditory/quark/context/ConstructorBasedBeanCreator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.coditory.quark.context;
22

33
import com.coditory.quark.context.annotations.Inject;
4+
import org.jetbrains.annotations.NotNull;
45

56
import java.lang.reflect.Constructor;
67
import java.util.Arrays;
@@ -44,8 +45,9 @@ static <T> ConstructorBasedBeanCreator<T> fromConstructor(Class<T> type) {
4445
this.constructor = requireNonNull(constructor);
4546
}
4647

48+
@NotNull
4749
@Override
48-
public T create(ResolutionContext context) {
50+
public T create(@NotNull ResolutionContext context) {
4951
Object[] args = resolveArguments(constructor, context);
5052
try {
5153
return constructor.newInstance(args);
@@ -55,7 +57,7 @@ public T create(ResolutionContext context) {
5557
}
5658

5759
@Override
58-
public boolean isActive(ConditionContext context) {
60+
public boolean isActive(@NotNull ConditionContext context) {
5961
return ConditionsResolver.isActive(context, type);
6062
}
6163
}

0 commit comments

Comments
 (0)