1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-08-30 17:17:55 +00:00

Switch to JSpecify annotations

Now, hear me out, what if instead of having three @Nullable annotations,
we had *four*?

I've been wanting to switch away from javax.annoations for a while. The
library has been deprecated for ever and, unlike other @Nullable
annotations, the annotation is attached to the parameter/function
itself, rather than the type.

We use JSpecify rather than one of the alternatives (JetBrains,
CheckerFramework) mostly because it's what NullAway recommends. We keep
CheckerFramework around for @DefaultQualifier, and JB's for @Contract.

There are some ugly changes here — for instance, `@Nullable byte[]` is
replace by `byte @Nullable`, and `@Nullable ILuaMachine.Factory` is
`ILuaMachine.@Nullable Factory`. Ughr, I understand why, but it does not
spark joy :).
This commit is contained in:
Jonathan Coates
2025-02-16 18:09:15 +00:00
parent 12a44fed6f
commit 0998acaa82
326 changed files with 542 additions and 540 deletions

View File

@@ -4,13 +4,12 @@
package cc.tweaked.web.builder;
import org.jspecify.annotations.Nullable;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import javax.annotation.Nullable;
import static org.objectweb.asm.Opcodes.*;
/**

View File

@@ -4,13 +4,13 @@
package cc.tweaked.web.builder;
import org.jspecify.annotations.Nullable;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.commons.ClassRemapper;
import org.objectweb.asm.commons.Remapper;
import javax.annotation.Nullable;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

View File

@@ -21,13 +21,13 @@ import dan200.computercraft.core.computer.ComputerSide;
import dan200.computercraft.core.filesystem.MemoryMount;
import dan200.computercraft.core.metrics.MetricsObserver;
import dan200.computercraft.core.terminal.Terminal;
import org.jspecify.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.teavm.jso.JSObject;
import org.teavm.jso.core.JSString;
import org.teavm.jso.typedarrays.ArrayBuffer;
import javax.annotation.Nullable;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Objects;

View File

@@ -7,8 +7,8 @@ package cc.tweaked.web;
import cc.tweaked.web.js.Callbacks;
import dan200.computercraft.api.filesystem.Mount;
import dan200.computercraft.core.computer.GlobalEnvironment;
import org.jspecify.annotations.Nullable;
import javax.annotation.Nullable;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
@@ -21,7 +21,7 @@ final class EmulatorEnvironment implements GlobalEnvironment {
private final String version = Callbacks.getModVersion();
private @Nullable ResourceMount romMount;
private @Nullable byte[] bios;
private byte @Nullable [] bios;
private EmulatorEnvironment() {
}

View File

@@ -7,8 +7,8 @@ package cc.tweaked.web;
import cc.tweaked.web.js.Callbacks;
import dan200.computercraft.core.apis.handles.ArrayByteChannel;
import dan200.computercraft.core.filesystem.AbstractInMemoryMount;
import org.jspecify.annotations.Nullable;
import javax.annotation.Nullable;
import java.nio.channels.SeekableByteChannel;
/**
@@ -43,7 +43,7 @@ final class ResourceMount extends AbstractInMemoryMount<ResourceMount.FileEntry>
protected static final class FileEntry extends AbstractInMemoryMount.FileEntry<FileEntry> {
private final String path;
private @Nullable byte[] contents;
private byte @Nullable [] contents;
FileEntry(String path) {
this.path = path;

View File

@@ -4,10 +4,9 @@
package cc.tweaked.web.js;
import org.jspecify.annotations.Nullable;
import org.teavm.jso.JSObject;
import javax.annotation.Nullable;
/**
* The Javascript-side terminal which displays this computer.
*

View File

@@ -4,13 +4,12 @@
package cc.tweaked.web.js;
import org.jspecify.annotations.Nullable;
import org.teavm.jso.JSObject;
import org.teavm.jso.JSProperty;
import org.teavm.jso.core.JSString;
import org.teavm.jso.typedarrays.ArrayBuffer;
import javax.annotation.Nullable;
/**
* A Javascript-facing interface for controlling computers.
*/

View File

@@ -5,6 +5,7 @@
package cc.tweaked.web.js;
import org.jetbrains.annotations.Contract;
import org.jspecify.annotations.Nullable;
import org.teavm.jso.JSBody;
import org.teavm.jso.JSByRef;
import org.teavm.jso.JSObject;
@@ -15,7 +16,6 @@ import org.teavm.jso.core.JSString;
import org.teavm.jso.typedarrays.ArrayBuffer;
import org.teavm.jso.typedarrays.Int8Array;
import javax.annotation.Nullable;
import java.nio.ByteBuffer;
/**
@@ -29,7 +29,7 @@ public class JavascriptConv {
* @return The converted value.
*/
@Contract("null -> null; !null -> !null")
public static @Nullable Object[] toJava(@Nullable JSObject[] value) {
public static @Nullable Object @Nullable [] toJava(@Nullable JSObject @Nullable [] value) {
if (value == null) return null;
var out = new Object[value.length];
for (var i = 0; i < value.length; i++) out[i] = toJava(value[i]);

View File

@@ -6,10 +6,10 @@ package cc.tweaked.web.peripheral;
import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.api.lua.LuaTable;
import org.jspecify.annotations.Nullable;
import org.teavm.jso.webaudio.AudioBuffer;
import org.teavm.jso.webaudio.AudioContext;
import javax.annotation.Nullable;
import java.util.Optional;
import static cc.tweaked.web.peripheral.SpeakerPeripheral.SAMPLE_RATE;

View File

@@ -10,9 +10,9 @@ import dan200.computercraft.api.lua.LuaTable;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IPeripheral;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.jspecify.annotations.Nullable;
import org.teavm.jso.webaudio.AudioContext;
import javax.annotation.Nullable;
import java.util.Optional;
import static dan200.computercraft.api.lua.LuaValues.checkFinite;

View File

@@ -16,12 +16,12 @@ import dan200.computercraft.core.apis.http.ResourceGroup;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpMethod;
import org.jspecify.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.teavm.jso.ajax.XMLHttpRequest;
import org.teavm.jso.typedarrays.ArrayBuffer;
import javax.annotation.Nullable;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.ByteBuffer;

View File

@@ -13,10 +13,10 @@ import dan200.computercraft.core.apis.http.ResourceGroup;
import dan200.computercraft.core.apis.http.options.Action;
import dan200.computercraft.core.apis.http.options.Options;
import io.netty.handler.codec.http.HttpHeaders;
import org.jspecify.annotations.Nullable;
import org.teavm.jso.typedarrays.Int8Array;
import org.teavm.jso.websocket.WebSocket;
import javax.annotation.Nullable;
import java.net.URI;
import java.nio.ByteBuffer;

View File

@@ -13,9 +13,9 @@ import dan200.computercraft.api.lua.MethodResult;
import dan200.computercraft.api.peripheral.PeripheralType;
import dan200.computercraft.core.methods.LuaMethod;
import dan200.computercraft.core.methods.NamedMethod;
import org.jspecify.annotations.Nullable;
import org.teavm.metaprogramming.*;
import javax.annotation.Nullable;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;

View File

@@ -11,12 +11,12 @@ import com.google.common.primitives.Primitives;
import com.google.common.reflect.TypeToken;
import dan200.computercraft.api.lua.*;
import dan200.computercraft.core.methods.LuaMethod;
import org.jspecify.annotations.Nullable;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Type;
import org.teavm.metaprogramming.ReflectClass;
import javax.annotation.Nullable;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.nio.ByteBuffer;
@@ -124,8 +124,7 @@ public final class StaticGenerator<T> {
}
}
@Nullable
private byte[] generate(String className, Class<?> target, Method targetMethod, boolean unsafe) {
private byte @Nullable [] generate(String className, Class<?> target, Method targetMethod, boolean unsafe) {
var internalName = className.replace(".", "/");
// Construct a public final class which extends Object and implements MethodInstance.Delegate
@@ -207,8 +206,7 @@ public final class StaticGenerator<T> {
return cw.toByteArray();
}
@Nullable
private Boolean loadArg(MethodVisitor mw, Class<?> target, Method method, boolean unsafe, java.lang.reflect.Type genericArg, int argIndex) {
private @Nullable Boolean loadArg(MethodVisitor mw, Class<?> target, Method method, boolean unsafe, java.lang.reflect.Type genericArg, int argIndex) {
if (genericArg == target) {
mw.visitVarInsn(ALOAD, 1);
mw.visitTypeInsn(CHECKCAST, Type.getInternalName(target));