import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.DataInput;
import java.io.DataOutput;
-import java.io.Externalizable;
import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
import java.nio.charset.StandardCharsets;
import java.util.regex.Pattern;
import org.eclipse.jdt.annotation.NonNull;
* discerned.
*/
public final class FrontendType implements Comparable<FrontendType>, WritableIdentifier {
- interface SerialForm extends Externalizable {
- @NonNull FrontendType type();
-
- void setType(@NonNull FrontendType type);
-
- @java.io.Serial
- Object readResolve();
-
- @Override
- default void writeExternal(final ObjectOutput out) throws IOException {
- final var serialized = type().getSerialized();
- out.writeInt(serialized.length);
- out.write(serialized);
- }
-
- @Override
- default void readExternal(final ObjectInput in) throws IOException {
- final var serialized = new byte[in.readInt()];
- in.readFully(serialized);
- // TODO: consider caching instances here
- setType(new FrontendType(new String(serialized, StandardCharsets.UTF_8), serialized));
- }
- }
-
- @Deprecated(since = "7.0.0", forRemoval = true)
- private static final class Proxy implements SerialForm {
- @java.io.Serial
- private static final long serialVersionUID = 1L;
-
- private FrontendType type;
-
- // checkstyle flags the public modifier as redundant however it is explicitly needed for Java serialization to
- // be able to create instances via reflection.
- @SuppressWarnings("checkstyle:RedundantModifier")
- public Proxy() {
- // For Externalizable
- }
-
- Proxy(final FrontendType type) {
- this.type = requireNonNull(type);
- }
-
- @Override
- public FrontendType type() {
- return verifyNotNull(type);
- }
-
- @Override
- public void setType(final FrontendType type) {
- this.type = requireNonNull(type);
- }
-
- @Override
- public Object readResolve() {
- return type();
- }
- }
-
@java.io.Serial
private static final long serialVersionUID = 1L;
private static final String SIMPLE_STRING_REGEX = "^[a-zA-Z0-9-_.*+:=,!~';]+$";
@java.io.Serial
private Object writeReplace() {
- return new FT(this);
+ return new FT(getSerialized());
}
}