Skip to content

Commit

Permalink
Add serialisation adapters for Temporal and TemporalAmount types.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Boerman committed Mar 21, 2024
1 parent 391b71c commit 51202da
Show file tree
Hide file tree
Showing 6 changed files with 932 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

/**
* Indicates that methods annotated with this annotation can be called by ScalaPlugins as a result of bytecode transformation.
* Indicates that interfaces annotated with this annotation are implemented by classes which are generated at runtime.
*
* @see RuntimeConversions#serialize(Object, ParameterType, ClassLoader)
* @see RuntimeConversions#deserialize(Object, ParameterType, ClassLoader)
Expand All @@ -25,6 +26,7 @@
* @see ParameterType#from(Type)
* @see ArrayParameterType#from(ParameterType, boolean)
* @see ParameterizedParameterType#from(Class, ParameterType...)
* @see Adapter
*/
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE})
@Retention(RetentionPolicy.CLASS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*
* @param <T> the type of the wrapped value
*/
@Called // there exist implementations of this interface which are generated at runtime through bytecode generation.
public interface Adapter<T> extends ConfigurationSerializable {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.bukkit.configuration.serialization.ConfigurationSerializable;
import xyz.janboerman.scalaloader.bytecode.Called;
import xyz.janboerman.scalaloader.compat.IScalaPluginLoader;
import xyz.janboerman.scalaloader.configurationserializable.runtime.types.*;
import xyz.janboerman.scalaloader.configurationserializable.transform.ConfigurationSerializableError;
import xyz.janboerman.scalaloader.compat.IScalaPluginClassLoader;
Expand All @@ -11,6 +10,20 @@
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.Period;
import java.time.Year;
import java.time.YearMonth;
import java.time.ZonedDateTime;
import java.time.chrono.HijrahDate;
import java.time.chrono.JapaneseDate;
import java.time.chrono.MinguoDate;
import java.time.chrono.ThaiBuddhistDate;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.Function;
Expand Down Expand Up @@ -216,7 +229,38 @@ else if (Tuple.isTuple(live)) {
return new xyz.janboerman.scalaloader.configurationserializable.runtime.types.BigDecimal((BigDecimal) live);
} else if (live instanceof Enum) {
return xyz.janboerman.scalaloader.configurationserializable.runtime.types.Enum.forEnum((Enum) live, pluginClassLoader);
} else if (live instanceof Instant) {
return new DateTime.Instant((Instant) live);
} else if (live instanceof ZonedDateTime) {
return new DateTime.ZonedDateTime((ZonedDateTime) live);
} else if (live instanceof LocalDateTime) {
return new DateTime.LocalDateTime((LocalDateTime) live);
} else if (live instanceof LocalTime) {
return new DateTime.LocalTime((LocalTime) live);
} else if (live instanceof LocalDate) {
return new DateTime.LocalDate((LocalDate) live);
} else if (live instanceof Year) {
return new DateTime.Year((Year) live);
} else if (live instanceof YearMonth) {
return new DateTime.YearMonth((YearMonth) live);
} else if (live instanceof OffsetDateTime) {
return new DateTime.OffsetDateTime((OffsetDateTime) live);
} else if (live instanceof MinguoDate) {
return new DateTime.MinguoDate((MinguoDate) live);
} else if (live instanceof JapaneseDate) {
return new DateTime.JapaneseDate((JapaneseDate) live);
} else if (live instanceof HijrahDate) {
return new DateTime.HijrahDate((HijrahDate) live);
} else if (live instanceof ThaiBuddhistDate) {
return new DateTime.ThaiBuddhistDate((ThaiBuddhistDate) live);
} else if (live instanceof Duration) {
return new DateTime.Duration((Duration) live);
} else if (live instanceof Period) {
return new DateTime.Period((Period) live);
} else if (live instanceof Date) {
return new DateTime.Date((Date) live);
}
// TODO adapter for types which implement Serializable ?

//if the type is not ConfigurationSerializable, warn the plugin author
if (!(live instanceof ConfigurationSerializable) && pluginClassLoader.getPluginLoader().debugSettings().logMissingCodecs()) {
Expand Down
Loading

0 comments on commit 51202da

Please sign in to comment.