[*] Migrate to jspecify annotations
This commit is contained in:
@@ -5,7 +5,7 @@ import de.siphalor.tweed5.core.api.entry.CompoundConfigEntry;
|
||||
import de.siphalor.tweed5.core.api.entry.ConfigEntry;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Value;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.util.function.Supplier;
|
||||
@@ -28,9 +28,9 @@ public interface WeavableCompoundConfigEntry<T> extends CompoundConfigEntry<T> {
|
||||
@Value
|
||||
@RequiredArgsConstructor
|
||||
class SubEntry {
|
||||
@NotNull String name;
|
||||
@NotNull ConfigEntry<?> configEntry;
|
||||
@NotNull MethodHandle getter;
|
||||
@NotNull MethodHandle setter;
|
||||
String name;
|
||||
ConfigEntry<?> configEntry;
|
||||
@Nullable MethodHandle getter;
|
||||
@Nullable MethodHandle setter;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
@NullMarked
|
||||
package de.siphalor.tweed5.weaver.pojo.api.entry;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
@@ -9,8 +9,7 @@ import de.siphalor.tweed5.weaver.pojo.impl.entry.CollectionConfigEntryImpl;
|
||||
import de.siphalor.tweed5.weaver.pojo.impl.weaving.PojoWeavingException;
|
||||
import de.siphalor.tweed5.weaver.pojo.impl.weaving.collection.CollectionWeavingConfig;
|
||||
import de.siphalor.tweed5.weaver.pojo.impl.weaving.collection.CollectionWeavingConfigImpl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
@@ -33,7 +32,7 @@ public class CollectionPojoWeaver implements TweedPojoWeaver {
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
@Override
|
||||
public @Nullable <T> ConfigEntry<T> weaveEntry(ActualType<T> valueType, WeavingContext context) {
|
||||
public <T> @Nullable ConfigEntry<T> weaveEntry(ActualType<T> valueType, WeavingContext context) {
|
||||
List<ActualType<?>> collectionTypeParams = valueType.getTypesOfSuperArguments(Collection.class);
|
||||
if (collectionTypeParams == null) {
|
||||
return null;
|
||||
@@ -82,7 +81,7 @@ public class CollectionPojoWeaver implements TweedPojoWeaver {
|
||||
return CollectionWeavingConfigImpl.withOverrides(parent, local);
|
||||
}
|
||||
|
||||
private CollectionWeavingConfig createWeavingConfigFromAnnotations(@NotNull AnnotatedElement annotations) {
|
||||
private @Nullable CollectionWeavingConfig createWeavingConfigFromAnnotations(AnnotatedElement annotations) {
|
||||
CollectionWeaving annotation = annotations.getAnnotation(CollectionWeaving.class);
|
||||
if (annotation == null) {
|
||||
return null;
|
||||
|
||||
@@ -15,8 +15,7 @@ import de.siphalor.tweed5.weaver.pojo.impl.weaving.PojoClassIntrospector;
|
||||
import de.siphalor.tweed5.weaver.pojo.impl.weaving.PojoWeavingException;
|
||||
import de.siphalor.tweed5.weaver.pojo.impl.weaving.compound.CompoundWeavingConfig;
|
||||
import de.siphalor.tweed5.weaver.pojo.impl.weaving.compound.CompoundWeavingConfigImpl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
@@ -44,7 +43,7 @@ public class CompoundPojoWeaver implements TweedPojoWeaver {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable <T> ConfigEntry<T> weaveEntry(ActualType<T> valueType, WeavingContext context) {
|
||||
public <T> @Nullable ConfigEntry<T> weaveEntry(ActualType<T> valueType, WeavingContext context) {
|
||||
if (context.annotations().getAnnotation(CompoundWeaving.class) == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -88,8 +87,7 @@ public class CompoundPojoWeaver implements TweedPojoWeaver {
|
||||
return CompoundWeavingConfigImpl.withOverrides(parent, local);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private CompoundWeavingConfig createWeavingConfigFromAnnotations(@NotNull AnnotatedElement annotations) {
|
||||
private @Nullable CompoundWeavingConfig createWeavingConfigFromAnnotations(AnnotatedElement annotations) {
|
||||
CompoundWeaving annotation = annotations.getAnnotation(CompoundWeaving.class);
|
||||
if (annotation == null) {
|
||||
return null;
|
||||
@@ -127,7 +125,6 @@ public class CompoundPojoWeaver implements TweedPojoWeaver {
|
||||
|
||||
//noinspection rawtypes
|
||||
Class<? extends WeavableCompoundConfigEntry> annotationEntryClass = weavingConfig.compoundEntryClass();
|
||||
@NotNull
|
||||
Class<WeavableCompoundConfigEntry<C>> weavableEntryClass = (Class<WeavableCompoundConfigEntry<C>>) (
|
||||
annotationEntryClass != null
|
||||
? annotationEntryClass
|
||||
@@ -143,7 +140,7 @@ public class CompoundPojoWeaver implements TweedPojoWeaver {
|
||||
return property.getter() != null && (property.setter() != null || property.isFinal());
|
||||
}
|
||||
|
||||
private @NotNull WeavableCompoundConfigEntry.SubEntry weaveCompoundSubEntry(
|
||||
private WeavableCompoundConfigEntry.SubEntry weaveCompoundSubEntry(
|
||||
PojoClassIntrospector.Property property,
|
||||
WeavingContext.ExtensionsData newExtensionsData,
|
||||
WeavingContext parentContext
|
||||
@@ -167,7 +164,9 @@ public class CompoundPojoWeaver implements TweedPojoWeaver {
|
||||
);
|
||||
}
|
||||
|
||||
private @NotNull String convertName(String name, CompoundWeavingConfig weavingConfig) {
|
||||
private String convertName(String name, CompoundWeavingConfig weavingConfig) {
|
||||
// Always non-null at this point, since null values were already defaulted
|
||||
//noinspection DataFlowIssue
|
||||
return NamingFormat.convert(
|
||||
name,
|
||||
weavingConfig.compoundSourceNamingFormat(),
|
||||
@@ -175,7 +174,7 @@ public class CompoundPojoWeaver implements TweedPojoWeaver {
|
||||
);
|
||||
}
|
||||
|
||||
private @NotNull NamingFormat getNamingFormatById(String id) {
|
||||
private NamingFormat getNamingFormatById(String id) {
|
||||
NamingFormat namingFormat = namingFormatCollector.namingFormats().get(id);
|
||||
if (namingFormat == null) {
|
||||
throw new PojoWeavingException(
|
||||
|
||||
@@ -3,7 +3,6 @@ package de.siphalor.tweed5.weaver.pojo.api.weaving;
|
||||
import de.siphalor.tweed5.core.api.entry.ConfigEntry;
|
||||
import de.siphalor.tweed5.core.impl.entry.SimpleConfigEntryImpl;
|
||||
import de.siphalor.tweed5.typeutils.api.type.ActualType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class TrivialPojoWeaver implements TweedPojoWeaver {
|
||||
@Override
|
||||
@@ -12,7 +11,7 @@ public class TrivialPojoWeaver implements TweedPojoWeaver {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable <T> ConfigEntry<T> weaveEntry(ActualType<T> valueType, WeavingContext context) {
|
||||
public <T> ConfigEntry<T> weaveEntry(ActualType<T> valueType, WeavingContext context) {
|
||||
SimpleConfigEntryImpl<T> entry = new SimpleConfigEntryImpl<>(valueType.declaredType());
|
||||
entry.seal(context.configContainer());
|
||||
return entry;
|
||||
|
||||
@@ -2,8 +2,7 @@ package de.siphalor.tweed5.weaver.pojo.api.weaving;
|
||||
|
||||
import de.siphalor.tweed5.core.api.entry.ConfigEntry;
|
||||
import de.siphalor.tweed5.typeutils.api.type.ActualType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface TweedPojoWeavingFunction {
|
||||
@@ -12,8 +11,7 @@ public interface TweedPojoWeavingFunction {
|
||||
* The returned config entry must be sealed.
|
||||
* @return The resulting, sealed config entry or {@code null}, if the weaving function is not applicable to the given parameters.
|
||||
*/
|
||||
@Nullable
|
||||
<T> ConfigEntry<T> weaveEntry(ActualType<T> valueType, WeavingContext context);
|
||||
<T> @Nullable ConfigEntry<T> weaveEntry(ActualType<T> valueType, WeavingContext context);
|
||||
|
||||
@FunctionalInterface
|
||||
interface NonNull extends TweedPojoWeavingFunction {
|
||||
@@ -25,6 +23,6 @@ public interface TweedPojoWeavingFunction {
|
||||
* @throws RuntimeException when a valid config entry could not be resolved.
|
||||
*/
|
||||
@Override
|
||||
@NotNull <T> ConfigEntry<T> weaveEntry(ActualType<T> valueType, WeavingContext context);
|
||||
<T> @org.jspecify.annotations.NonNull ConfigEntry<T> weaveEntry(ActualType<T> valueType, WeavingContext context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,26 +6,19 @@ import de.siphalor.tweed5.patchwork.api.Patchwork;
|
||||
import de.siphalor.tweed5.typeutils.api.type.ActualType;
|
||||
import lombok.*;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
import java.util.Arrays;
|
||||
|
||||
@Value
|
||||
public class WeavingContext implements TweedPojoWeavingFunction.NonNull {
|
||||
@Nullable
|
||||
WeavingContext parent;
|
||||
@Nullable WeavingContext parent;
|
||||
@Getter(AccessLevel.NONE)
|
||||
@NotNull
|
||||
TweedPojoWeavingFunction.NonNull weavingFunction;
|
||||
@NotNull
|
||||
ConfigContainer<?> configContainer;
|
||||
@NotNull
|
||||
String[] path;
|
||||
@NotNull
|
||||
ExtensionsData extensionsData;
|
||||
@NotNull
|
||||
AnnotatedElement annotations;
|
||||
|
||||
public static Builder builder(TweedPojoWeavingFunction.NonNull weavingFunction, ConfigContainer<?> configContainer) {
|
||||
@@ -36,14 +29,14 @@ public class WeavingContext implements TweedPojoWeavingFunction.NonNull {
|
||||
return new Builder(null, weavingFunction, configContainer, new String[]{ baseName });
|
||||
}
|
||||
|
||||
public Builder subContextBuilder(@NotNull String subPathName) {
|
||||
public Builder subContextBuilder(String subPathName) {
|
||||
String[] newPath = Arrays.copyOf(path, path.length + 1);
|
||||
newPath[path.length] = subPathName;
|
||||
return new Builder(this, weavingFunction, configContainer, newPath).extensionsData(extensionsData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull <T> ConfigEntry<T> weaveEntry(ActualType<T> valueType, WeavingContext context) {
|
||||
public <T> ConfigEntry<T> weaveEntry(ActualType<T> valueType, WeavingContext context) {
|
||||
return weavingFunction.weaveEntry(valueType, context);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
@NullMarked
|
||||
package de.siphalor.tweed5.weaver.pojo.api.weaving;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
@@ -0,0 +1,4 @@
|
||||
@NullMarked
|
||||
package de.siphalor.tweed5.weaver.pojo.api.weaving.postprocess;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
@@ -9,6 +9,7 @@ import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.function.IntFunction;
|
||||
@@ -18,7 +19,7 @@ import java.util.function.IntFunction;
|
||||
@ToString(callSuper = true)
|
||||
public class CollectionConfigEntryImpl<E, T extends Collection<E>> extends BaseConfigEntry<T> implements WeavableCollectionConfigEntry<E, T> {
|
||||
private final IntFunction<T> constructor;
|
||||
private ConfigEntry<E> elementEntry;
|
||||
private @Nullable ConfigEntry<E> elementEntry;
|
||||
|
||||
public CollectionConfigEntryImpl(@NotNull Class<T> valueClass, IntFunction<T> constructor) {
|
||||
super(valueClass);
|
||||
|
||||
@@ -5,7 +5,6 @@ import de.siphalor.tweed5.core.api.entry.ConfigEntry;
|
||||
import de.siphalor.tweed5.core.api.entry.ConfigEntryValueVisitor;
|
||||
import de.siphalor.tweed5.core.api.entry.ConfigEntryVisitor;
|
||||
import de.siphalor.tweed5.weaver.pojo.api.entry.WeavableCompoundConfigEntry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -17,7 +16,7 @@ public class StaticPojoCompoundConfigEntry<T> extends BaseConfigEntry<T> impleme
|
||||
private final Map<String, SubEntry> subEntries = new LinkedHashMap<>();
|
||||
private final Map<String, ConfigEntry<?>> subConfigEntries = new LinkedHashMap<>();
|
||||
|
||||
public StaticPojoCompoundConfigEntry(@NotNull Class<T> valueClass, @NotNull Supplier<T> noArgsConstructor) {
|
||||
public StaticPojoCompoundConfigEntry(Class<T> valueClass, Supplier<T> noArgsConstructor) {
|
||||
super(valueClass);
|
||||
this.noArgsConstructor = noArgsConstructor;
|
||||
}
|
||||
@@ -91,7 +90,7 @@ public class StaticPojoCompoundConfigEntry<T> extends BaseConfigEntry<T> impleme
|
||||
subEntries.forEach((key, entry) -> {
|
||||
if (visitor.enterCompoundSubEntry(key)) {
|
||||
try {
|
||||
Object subValue = entry.getter().invokeExact(value);
|
||||
Object subValue = entry.getter().invoke(value);
|
||||
//noinspection unchecked
|
||||
visitor.visitEntry((ConfigEntry<Object>) entry.configEntry(), subValue);
|
||||
} catch (Throwable e) {
|
||||
@@ -103,11 +102,11 @@ public class StaticPojoCompoundConfigEntry<T> extends BaseConfigEntry<T> impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull T deepCopy(@NotNull T value) {
|
||||
public T deepCopy(T value) {
|
||||
T copy = instantiateCompoundValue();
|
||||
for (SubEntry subEntry : subEntries.values()) {
|
||||
try {
|
||||
Object subValue = subEntry.getter().invokeExact(value);
|
||||
Object subValue = subEntry.getter().invoke(value);
|
||||
subEntry.setter().invoke(copy, subValue);
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Failed to copy value of sub entry \"" + subEntry.name() + "\"", e);
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
@NullMarked
|
||||
package de.siphalor.tweed5.weaver.pojo.impl.entry;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
@@ -5,7 +5,7 @@ import lombok.Builder;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Value;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
@@ -23,7 +23,7 @@ public class PojoClassIntrospector {
|
||||
private final Class<?> clazz;
|
||||
private final MethodHandles.Lookup lookup = MethodHandles.publicLookup();
|
||||
|
||||
private Map<String, Property> properties;
|
||||
private @Nullable Map<String, Property> properties;
|
||||
|
||||
public static PojoClassIntrospector forClass(Class<?> clazz) {
|
||||
if ((clazz.getModifiers() & Modifier.PUBLIC) == 0) {
|
||||
|
||||
@@ -15,7 +15,7 @@ import de.siphalor.tweed5.weaver.pojo.api.weaving.WeavingContext;
|
||||
import de.siphalor.tweed5.weaver.pojo.api.weaving.postprocess.TweedPojoWeavingPostProcessor;
|
||||
import lombok.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package de.siphalor.tweed5.weaver.pojo.impl.weaving.collection;
|
||||
|
||||
import de.siphalor.tweed5.weaver.pojo.api.entry.WeavableCollectionConfigEntry;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
public interface CollectionWeavingConfig {
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Nullable
|
||||
Class<? extends WeavableCollectionConfigEntry> collectionEntryClass();
|
||||
@Nullable Class<? extends WeavableCollectionConfigEntry> collectionEntryClass();
|
||||
}
|
||||
|
||||
@@ -3,15 +3,14 @@ package de.siphalor.tweed5.weaver.pojo.impl.weaving.collection;
|
||||
import de.siphalor.tweed5.weaver.pojo.api.entry.WeavableCollectionConfigEntry;
|
||||
import lombok.Builder;
|
||||
import lombok.Value;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
@Builder
|
||||
@Value
|
||||
public class CollectionWeavingConfigImpl implements CollectionWeavingConfig {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Nullable
|
||||
Class<? extends WeavableCollectionConfigEntry> collectionEntryClass;
|
||||
@Nullable Class<? extends WeavableCollectionConfigEntry> collectionEntryClass;
|
||||
|
||||
public static CollectionWeavingConfigImpl withOverrides(CollectionWeavingConfig self, CollectionWeavingConfig overrides) {
|
||||
return CollectionWeavingConfigImpl.builder()
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
@NullMarked
|
||||
package de.siphalor.tweed5.weaver.pojo.impl.weaving.collection;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
@@ -2,14 +2,13 @@ package de.siphalor.tweed5.weaver.pojo.impl.weaving.compound;
|
||||
|
||||
import de.siphalor.tweed5.namingformat.api.NamingFormat;
|
||||
import de.siphalor.tweed5.weaver.pojo.api.entry.WeavableCompoundConfigEntry;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
public interface CompoundWeavingConfig {
|
||||
NamingFormat compoundSourceNamingFormat();
|
||||
@Nullable NamingFormat compoundSourceNamingFormat();
|
||||
|
||||
NamingFormat compoundTargetNamingFormat();
|
||||
@Nullable NamingFormat compoundTargetNamingFormat();
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Nullable
|
||||
Class<? extends WeavableCompoundConfigEntry> compoundEntryClass();
|
||||
@Nullable Class<? extends WeavableCompoundConfigEntry> compoundEntryClass();
|
||||
}
|
||||
|
||||
@@ -4,17 +4,16 @@ import de.siphalor.tweed5.namingformat.api.NamingFormat;
|
||||
import de.siphalor.tweed5.weaver.pojo.api.entry.WeavableCompoundConfigEntry;
|
||||
import lombok.Builder;
|
||||
import lombok.Value;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
@Builder
|
||||
@Value
|
||||
public class CompoundWeavingConfigImpl implements CompoundWeavingConfig {
|
||||
|
||||
NamingFormat compoundSourceNamingFormat;
|
||||
NamingFormat compoundTargetNamingFormat;
|
||||
@Nullable NamingFormat compoundSourceNamingFormat;
|
||||
@Nullable NamingFormat compoundTargetNamingFormat;
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Nullable
|
||||
Class<? extends WeavableCompoundConfigEntry> compoundEntryClass;
|
||||
@Nullable Class<? extends WeavableCompoundConfigEntry> compoundEntryClass;
|
||||
|
||||
public static CompoundWeavingConfigImpl withOverrides(CompoundWeavingConfig self, CompoundWeavingConfig overrides) {
|
||||
return CompoundWeavingConfigImpl.builder()
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
@NullMarked
|
||||
package de.siphalor.tweed5.weaver.pojo.impl.weaving.compound;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
@@ -0,0 +1,4 @@
|
||||
@NullMarked
|
||||
package de.siphalor.tweed5.weaver.pojo.impl.weaving;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
Reference in New Issue
Block a user