Skip to content

Commit

Permalink
core: Cleanup and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
TheElectronWill committed May 12, 2024
1 parent 081ba32 commit a2fcf42
Show file tree
Hide file tree
Showing 20 changed files with 72 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.electronwill.nightconfig.core.conversion;

/**
* Thrown when a value that is associated to a field, or that should become associated to a
* field, doesn't conform to the @Spec(something) annotation of that field.
* Thrown when a value that is associated to a field, or that should become
* associated to a field, doesn't conform to the {@code @Spec(something)}
* annotation of that field.
*
* @deprecated Use the new package
* {@link com.electronwill.nightconfig.core.serde} with
* {@code serde.annotations}.
* @author TheElectronWill
*/
@Deprecated
public final class InvalidValueException extends RuntimeException {
public InvalidValueException(String message) {
super(message);
Expand All @@ -25,4 +30,4 @@ public InvalidValueException(String message, Throwable cause) {
public InvalidValueException(String messageFormat, Object... args) {
super(String.format(messageFormat, args));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
/**
* Thrown when an important reflective operation fails.
*
* @deprecated Use the new package
* {@link com.electronwill.nightconfig.core.serde} with
* {@code serde.annotations}.
* @author TheElectronWill
*/
@Deprecated
public class ReflectionException extends RuntimeException {
public ReflectionException(String message) {
super(message);
Expand All @@ -13,4 +17,4 @@ public ReflectionException(String message) {
public ReflectionException(String message, Throwable cause) {
super(message, cause);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Provides tools for converting configurations to/from Java objects, and converting config values on the fly.
* <b>(deprecated)</b> Provides tools for converting configurations to/from Java objects, and converting config values on the fly.
* <p>
* The most useful class in this package is {@link com.electronwill.nightconfig.core.conversion.ObjectConverter},
* which performs object-to-config deserialization and config-to-object serialization.
*
* @see ObjectConverter
* <p>
* <b>Note: as of NightConfig 3.7.0, this package is replaced by {@link com.electronwill.nightconfig.core.serde}.</b>
*/
package com.electronwill.nightconfig.core.conversion;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import com.electronwill.nightconfig.core.UnmodifiableConfig;
import com.electronwill.nightconfig.core.serde.annotations.*;

/**
* Holds deserialization settings and provides some base deserialization logic.
*/
public final class DeserializerContext {
final AbstractObjectDeserializer settings;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.electronwill.nightconfig.core.UnmodifiableConfig;

/**
* Implements Config to Object deserialization.
* Builder for {@link ObjectDeserializer}.
*/
public final class ObjectDeserializerBuilder {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.function.Supplier;

import com.electronwill.nightconfig.core.Config;
import com.electronwill.nightconfig.core.UnmodifiableConfig;
import com.electronwill.nightconfig.core.ConfigFormat;
import com.electronwill.nightconfig.core.file.FileConfig;
import com.electronwill.nightconfig.core.serde.annotations.SerdeDefault;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.electronwill.nightconfig.core.UnmodifiableConfig;

/**
* Implements Object to Config serialization.
* Builder for {@link ObjectSerializer}.
*/
public final class ObjectSerializerBuilder {
final IdentityHashMap<Class<?>, ValueSerializer<?, ?>> classBasedSerializers = new IdentityHashMap<>(7);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.electronwill.nightconfig.core.serde;

/**
* Thrown when an assertion, specified on a field by an annotation of type
* {@link com.electronwill.nightconfig.core.serde.annotations.SerdeAssert},
* is not verified during (de)serialization.
*/
public final class SerdeAssertException extends SerdeException {
SerdeAssertException(String message) {
super(message);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.electronwill.nightconfig.core.serde;

/**
* Thrown when an error occurs during the serialization
* or deserialization process.
*/
public class SerdeException extends RuntimeException {
SerdeException(String message) {
super(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import com.electronwill.nightconfig.core.ConfigFormat;
import com.electronwill.nightconfig.core.serde.annotations.*;

/**
* Holds serialization settings and provides some base serialization logic.
*/
public final class SerializerContext {
final ObjectSerializer settings;
final Supplier<? extends ConfigFormat<?>> formatSupplier;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.electronwill.nightconfig.core.serde.annotations;

import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.*;

/**
* Throw an exception if the annotated field does not match the given condition.
Expand Down Expand Up @@ -33,6 +31,7 @@
*/
@Repeatable(SerdeAssertsContainer.class)
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface SerdeAssert {
/**
* One or multiple assertions to check.
Expand Down Expand Up @@ -94,6 +93,11 @@ String customCheck()
*/
SerdePhase phase() default SerdePhase.BOTH;

/**
* An condition that the field's value must verify during (de)serialization.
* <p>
* An exception is thrown if the field does not satisfy the condition.
*/
public static enum AssertThat {
/**
* Throw an exception if the field is null.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.electronwill.nightconfig.core.serde.annotations;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.*;

/**
* A container for multiple {@link SerdeAssert} annotations, because
Expand All @@ -11,6 +10,7 @@
* you should simply repeat the {@code @SerdeAssert} annotation multiple times.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface SerdeAssertsContainer {
SerdeAssert[] value();
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.electronwill.nightconfig.core.serde.annotations;

import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.*;

import com.electronwill.nightconfig.core.CommentedConfig;
import com.electronwill.nightconfig.core.io.ConfigWriter;
Expand Down Expand Up @@ -34,6 +32,7 @@
*/
@Repeatable(SerdeCommentsContainer.class)
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface SerdeComment {
String value();
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.electronwill.nightconfig.core.serde.annotations;

import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.*;

/**
* A container for multiple {@link SerdeComment} annotations, because
Expand All @@ -12,6 +10,7 @@
* you should simply repeat the {@code @SerdeComment} annotation multiple times.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface SerdeCommentsContainer {
SerdeComment[] value();
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.electronwill.nightconfig.core.serde.annotations;

import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.*;

import com.electronwill.nightconfig.core.Config;

Expand Down Expand Up @@ -84,6 +82,7 @@
*/
@Repeatable(SerdeDefaultsContainer.class)
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface SerdeDefault {
/**
* The class that defines the method that provides the default value.
Expand Down Expand Up @@ -136,6 +135,11 @@
*/
WhenValue[] whenValue() default { WhenValue.IS_MISSING };

/**
* A condition that defines when to use the default value during (de)serialization.
* <p>
* The default value is used if the condition is true.
*/
public static enum WhenValue {
/**
* When deserializing a field, call the default value provider if the value is
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.electronwill.nightconfig.core.serde.annotations;

import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.*;

/**
* A container for multiple {@link SerdeDefault} annotations, because
Expand All @@ -12,6 +10,7 @@
* you should simply repeat the {@code @SerdeDefault} annotation multiple times.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface SerdeDefaultsContainer {
SerdeDefault[] value();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.electronwill.nightconfig.core.serde.annotations;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.*;

/**
* Sets the key to use when serializing/deserializing an element, instead of its
Expand Down Expand Up @@ -32,6 +31,7 @@
* </pre>
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface SerdeKey {
String value();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.electronwill.nightconfig.core.serde.annotations;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.*;

import com.electronwill.nightconfig.core.UnmodifiableConfig;

Expand Down Expand Up @@ -78,6 +77,7 @@
* </code></pre>
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface SerdeSkipDeserializingIf {
/**
* The type of skip predicate: either a predefined condition, or {@code CUSTOM}.
Expand Down Expand Up @@ -120,6 +120,11 @@
*/
String customCheck() default "";

/**
* A condition that defines when to skip the field during deserialization.
* <p>
* The field is skipped if the condition is true.
*/
public static enum SkipDeIf {
/**
* Skip the field if the corresponding config entry is missing.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.electronwill.nightconfig.core.serde.annotations;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.*;

/**
* Don't serialize the annotated field if some condition is true.
Expand Down Expand Up @@ -61,6 +60,7 @@
* </code></pre>
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface SerdeSkipSerializingIf {
/**
* The type of skip predicate: either a predefined condition, or {@code CUSTOM}.
Expand Down Expand Up @@ -105,6 +105,11 @@
*/
String customCheck() default "";

/**
* A condition that defines when to skip the field during serialization.
* <p>
* The field is skipped if the condition is true.
*/
public static enum SkipSerIf {
/**
* Skip the field if it's null.
Expand Down

0 comments on commit a2fcf42

Please sign in to comment.