Naming cleanup.
This commit is contained in:
@@ -3,7 +3,7 @@ package li.cil.oc2.api;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import li.cil.oc2.api.bus.device.object.Callback;
|
||||
import li.cil.oc2.api.bus.device.rpc.RPCMethod;
|
||||
import li.cil.oc2.api.imc.DeviceMethodParameterTypeAdapter;
|
||||
import li.cil.oc2.api.imc.RPCMethodParameterTypeAdapter;
|
||||
import li.cil.oc2.api.provider.DeviceProvider;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
@@ -25,7 +25,7 @@ public final class API {
|
||||
* IMC message for registering Gson type adapters for method parameter serialization and
|
||||
* deserialization.
|
||||
* <p>
|
||||
* Must be called with a supplier that provides an instance of {@link DeviceMethodParameterTypeAdapter}.
|
||||
* Must be called with a supplier that provides an instance of {@link RPCMethodParameterTypeAdapter}.
|
||||
* <p>
|
||||
* It can be necessary to register additional serializers when implementing {@link RPCMethod}s
|
||||
* that use custom parameter types.
|
||||
@@ -34,7 +34,7 @@ public final class API {
|
||||
* @see RPCMethod
|
||||
* @see Callback
|
||||
*/
|
||||
public static final String IMC_ADD_DEVICE_METHOD_PARAMETER_TYPE_ADAPTER = "addDeviceMethodParameterTypeAdapter";
|
||||
public static final String IMC_ADD_RPC_METHOD_PARAMETER_TYPE_ADAPTER = "addRPCMethodParameterTypeAdapter";
|
||||
|
||||
private API() {
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.lang.annotation.Target;
|
||||
* <p>
|
||||
* Method parameters are serialized and deserialized using Gson. When using custom
|
||||
* parameter types it may be necessary to register a custom type adapter for them
|
||||
* via {@link li.cil.oc2.api.API#IMC_ADD_DEVICE_METHOD_PARAMETER_TYPE_ADAPTER}.
|
||||
* via {@link li.cil.oc2.api.API#IMC_ADD_RPC_METHOD_PARAMETER_TYPE_ADAPTER}.
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
||||
@@ -51,7 +51,7 @@ public final class Callbacks {
|
||||
final ArrayList<RPCMethod> methods = new ArrayList<>();
|
||||
for (final Method method : reflectedMethods) {
|
||||
try {
|
||||
methods.add(new ObjectDeviceMethod(methodContainer, method));
|
||||
methods.add(new ObjectRPCMethod(methodContainer, method));
|
||||
} catch (final IllegalAccessException e) {
|
||||
LOGGER.error("Failed accessing method [{}].", method);
|
||||
}
|
||||
@@ -84,12 +84,12 @@ public final class Callbacks {
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
private static final class ObjectDeviceMethod extends AbstractRPCMethod {
|
||||
private static final class ObjectRPCMethod extends AbstractRPCMethod {
|
||||
private final MethodHandle handle;
|
||||
private final String description;
|
||||
private final String returnValueDescription;
|
||||
|
||||
public ObjectDeviceMethod(final Object target, final Method method) throws IllegalAccessException {
|
||||
public ObjectRPCMethod(final Object target, final Method method) throws IllegalAccessException {
|
||||
super(method.getName(),
|
||||
Objects.requireNonNull(method.getAnnotation(Callback.class), "Method without Callback annotation.").synchronize(),
|
||||
method.getReturnType(),
|
||||
@@ -121,7 +121,7 @@ public final class Callbacks {
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
final ObjectDeviceMethod that = (ObjectDeviceMethod) o;
|
||||
final ObjectRPCMethod that = (ObjectRPCMethod) o;
|
||||
return handle.equals(that.handle);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.Optional;
|
||||
* <p>
|
||||
* Method parameters are serialized and deserialized using Gson. When using custom
|
||||
* parameter types it may be necessary to register a custom type adapter for them
|
||||
* via {@link li.cil.oc2.api.API#IMC_ADD_DEVICE_METHOD_PARAMETER_TYPE_ADAPTER}.
|
||||
* via {@link li.cil.oc2.api.API#IMC_ADD_RPC_METHOD_PARAMETER_TYPE_ADAPTER}.
|
||||
*
|
||||
* @see ObjectDevice
|
||||
*/
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package li.cil.oc2.api.imc;
|
||||
|
||||
public final class DeviceMethodParameterTypeAdapter {
|
||||
public final class RPCMethodParameterTypeAdapter {
|
||||
public final Class<?> type;
|
||||
public final Object typeAdapter;
|
||||
|
||||
public DeviceMethodParameterTypeAdapter(final Class<?> type, final Object typeAdapter) {
|
||||
public RPCMethodParameterTypeAdapter(final Class<?> type, final Object typeAdapter) {
|
||||
this.type = type;
|
||||
this.typeAdapter = typeAdapter;
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
package li.cil.oc2.common;
|
||||
|
||||
import li.cil.oc2.common.capabilities.Capabilities;
|
||||
import li.cil.oc2.common.capabilities.DeviceBusElementCapability;
|
||||
import li.cil.oc2.common.device.DeviceMethodParameterTypeAdapters;
|
||||
import li.cil.oc2.common.device.RPCMethodParameterTypeAdapters;
|
||||
import li.cil.oc2.common.device.provider.Providers;
|
||||
import li.cil.oc2.common.network.Network;
|
||||
import li.cil.oc2.common.vm.Allocator;
|
||||
@@ -27,7 +26,7 @@ public final class CommonSetup {
|
||||
MinecraftForge.EVENT_BUS.addListener(CommonSetup::handleServerStoppedEvent);
|
||||
ServerScheduler.register();
|
||||
|
||||
addBuiltinDeviceMethodParameterTypeAdapters();
|
||||
addBuiltinRPCMethodParameterTypeAdapters();
|
||||
}
|
||||
|
||||
public static void handleServerAboutToStart(final FMLServerAboutToStartEvent event) {
|
||||
@@ -39,7 +38,7 @@ public final class CommonSetup {
|
||||
Allocator.resetAndCheckLeaks();
|
||||
}
|
||||
|
||||
private static void addBuiltinDeviceMethodParameterTypeAdapters() {
|
||||
DeviceMethodParameterTypeAdapters.addTypeAdapter(ItemStack.class, new ItemStackJsonSerializer());
|
||||
private static void addBuiltinRPCMethodParameterTypeAdapters() {
|
||||
RPCMethodParameterTypeAdapters.addTypeAdapter(ItemStack.class, new ItemStackJsonSerializer());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package li.cil.oc2.common;
|
||||
|
||||
import li.cil.oc2.api.API;
|
||||
import li.cil.oc2.api.imc.RPCMethodParameterTypeAdapter;
|
||||
import li.cil.oc2.api.provider.DeviceProvider;
|
||||
import li.cil.oc2.api.imc.DeviceMethodParameterTypeAdapter;
|
||||
import li.cil.oc2.common.device.DeviceMethodParameterTypeAdapters;
|
||||
import li.cil.oc2.common.device.RPCMethodParameterTypeAdapters;
|
||||
import li.cil.oc2.common.device.provider.Providers;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraftforge.fml.InterModComms;
|
||||
@@ -22,7 +22,7 @@ public final class IMC {
|
||||
HashMap<String, Consumer<InterModComms.IMCMessage>> map = new HashMap<>();
|
||||
|
||||
map.put(API.IMC_ADD_DEVICE_PROVIDER, IMC::addDeviceProvider);
|
||||
map.put(API.IMC_ADD_DEVICE_METHOD_PARAMETER_TYPE_ADAPTER, IMC::addDeviceMethodParameterTypeAdapter);
|
||||
map.put(API.IMC_ADD_RPC_METHOD_PARAMETER_TYPE_ADAPTER, IMC::addRPCMethodParameterTypeAdapter);
|
||||
|
||||
return map;
|
||||
});
|
||||
@@ -42,10 +42,10 @@ public final class IMC {
|
||||
getMessageParameter(message, DeviceProvider.class).ifPresent(Providers::addProvider);
|
||||
}
|
||||
|
||||
private static void addDeviceMethodParameterTypeAdapter(final InterModComms.IMCMessage message) {
|
||||
getMessageParameter(message, DeviceMethodParameterTypeAdapter.class).ifPresent(value -> {
|
||||
private static void addRPCMethodParameterTypeAdapter(final InterModComms.IMCMessage message) {
|
||||
getMessageParameter(message, RPCMethodParameterTypeAdapter.class).ifPresent(value -> {
|
||||
try {
|
||||
DeviceMethodParameterTypeAdapters.addTypeAdapter(value);
|
||||
RPCMethodParameterTypeAdapters.addTypeAdapter(value);
|
||||
} catch (final IllegalArgumentException e) {
|
||||
LOGGER.error("Received invalid type adapter registration [{}] for type [{}] from mod [{}].", value.typeAdapter, value.type, message.getSenderModId());
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import li.cil.oc2.api.bus.DeviceBusController;
|
||||
import li.cil.oc2.api.bus.device.rpc.RPCDevice;
|
||||
import li.cil.oc2.api.bus.device.rpc.RPCMethod;
|
||||
import li.cil.oc2.api.bus.device.rpc.RPCParameter;
|
||||
import li.cil.oc2.common.device.DeviceMethodParameterTypeAdapters;
|
||||
import li.cil.oc2.common.device.RPCMethodParameterTypeAdapters;
|
||||
import li.cil.oc2.common.device.RPCDeviceList;
|
||||
import li.cil.oc2.serialization.serializers.MessageJsonDeserializer;
|
||||
import li.cil.oc2.serialization.serializers.MethodInvocationJsonDeserializer;
|
||||
@@ -56,7 +56,7 @@ public final class RPCAdapter implements Steppable {
|
||||
this.controller = controller;
|
||||
this.serialDevice = serialDevice;
|
||||
this.transmitBuffer = ByteBuffer.allocate(maxMessageSize);
|
||||
this.gson = DeviceMethodParameterTypeAdapters.beginBuildGson()
|
||||
this.gson = RPCMethodParameterTypeAdapters.beginBuildGson()
|
||||
.registerTypeAdapter(MethodInvocation.class, new MethodInvocationJsonDeserializer())
|
||||
.registerTypeAdapter(Message.class, new MessageJsonDeserializer())
|
||||
.registerTypeAdapter(RPCDeviceWithIdentifier.class, new RPCDeviceWithIdentifierJsonSerializer())
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package li.cil.oc2.common.device;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
import li.cil.oc2.api.imc.DeviceMethodParameterTypeAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public final class DeviceMethodParameterTypeAdapters {
|
||||
private static final ArrayList<DeviceMethodParameterTypeAdapter> TYPE_ADAPTERS = new ArrayList<>();
|
||||
|
||||
public static void addTypeAdapter(final Class<?> type, final Object typeAdapter) {
|
||||
addTypeAdapter(new DeviceMethodParameterTypeAdapter(type, typeAdapter));
|
||||
}
|
||||
|
||||
public static void addTypeAdapter(final DeviceMethodParameterTypeAdapter value) {
|
||||
TYPE_ADAPTERS.add(value);
|
||||
}
|
||||
|
||||
public static GsonBuilder beginBuildGson() {
|
||||
final GsonBuilder builder = new GsonBuilder();
|
||||
|
||||
for (final DeviceMethodParameterTypeAdapter value : TYPE_ADAPTERS) {
|
||||
builder.registerTypeAdapter(value.type, value.typeAdapter);
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package li.cil.oc2.common.device;
|
||||
|
||||
import com.google.gson.GsonBuilder;
|
||||
import li.cil.oc2.api.imc.RPCMethodParameterTypeAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public final class RPCMethodParameterTypeAdapters {
|
||||
private static final ArrayList<RPCMethodParameterTypeAdapter> TYPE_ADAPTERS = new ArrayList<>();
|
||||
|
||||
public static void addTypeAdapter(final Class<?> type, final Object typeAdapter) {
|
||||
addTypeAdapter(new RPCMethodParameterTypeAdapter(type, typeAdapter));
|
||||
}
|
||||
|
||||
public static void addTypeAdapter(final RPCMethodParameterTypeAdapter value) {
|
||||
TYPE_ADAPTERS.add(value);
|
||||
}
|
||||
|
||||
public static GsonBuilder beginBuildGson() {
|
||||
final GsonBuilder builder = new GsonBuilder();
|
||||
|
||||
for (final RPCMethodParameterTypeAdapter value : TYPE_ADAPTERS) {
|
||||
builder.registerTypeAdapter(value.type, value.typeAdapter);
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user