mirror of
https://github.com/apple/pkl.git
synced 2026-07-07 13:35:36 +02:00
Convert org.pkl.core POJOs to record classes (#808)
This commit is contained in:
@@ -98,21 +98,21 @@ public abstract class Member implements Serializable {
|
||||
return simpleName;
|
||||
}
|
||||
|
||||
public static class SourceLocation implements Serializable {
|
||||
public record SourceLocation(int startLine, int endLine) implements Serializable {
|
||||
@Serial private static final long serialVersionUID = 0L;
|
||||
|
||||
private final int startLine;
|
||||
private final int endLine;
|
||||
|
||||
public SourceLocation(int startLine, int endLine) {
|
||||
this.startLine = startLine;
|
||||
this.endLine = endLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of 0.28.0, replaced by {@link #startLine()}.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public int getStartLine() {
|
||||
return startLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of 0.28.0, replaced by {@link #endLine()}.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public int getEndLine() {
|
||||
return endLine;
|
||||
}
|
||||
|
||||
@@ -41,20 +41,12 @@ public final class PklInfo {
|
||||
return packageIndex;
|
||||
}
|
||||
|
||||
/** A Pkl package index. */
|
||||
public static final class PackageIndex {
|
||||
private final String homepage;
|
||||
|
||||
/** Constructs a {@link PackageIndex}. */
|
||||
public PackageIndex(String homepage) {
|
||||
this.homepage = homepage;
|
||||
}
|
||||
|
||||
/** The homepage of this package index. */
|
||||
public String homepage() {
|
||||
return homepage;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Pkl package index.
|
||||
*
|
||||
* @param homepage The homepage of this package index.
|
||||
*/
|
||||
public record PackageIndex(String homepage) {
|
||||
/** Returns the homepage of the given package. */
|
||||
public String getPackagePage(String packageName, String packageVersion) {
|
||||
return homepage + packageName + "/" + packageVersion + "/";
|
||||
|
||||
@@ -17,14 +17,18 @@ package org.pkl.core;
|
||||
|
||||
import com.oracle.truffle.api.Truffle;
|
||||
import com.oracle.truffle.api.TruffleOptions;
|
||||
import java.util.Objects;
|
||||
import org.graalvm.home.Version;
|
||||
|
||||
/**
|
||||
* Information about the Pkl release that the current program runs on. This class is the Java
|
||||
* equivalent of standard library module {@code pkl.platform}.
|
||||
*/
|
||||
public final class Platform {
|
||||
public record Platform(
|
||||
Language language,
|
||||
Runtime runtime,
|
||||
VirtualMachine virtualMachine,
|
||||
OperatingSystem operatingSystem,
|
||||
Processor processor) {
|
||||
private static final Platform CURRENT;
|
||||
|
||||
static {
|
||||
@@ -49,225 +53,46 @@ public final class Platform {
|
||||
new Processor(architecture));
|
||||
}
|
||||
|
||||
private final Language language;
|
||||
private final Runtime runtime;
|
||||
private final VirtualMachine virtualMachine;
|
||||
private final OperatingSystem operatingSystem;
|
||||
private final Processor processor;
|
||||
|
||||
/** Constructs a platform. */
|
||||
public Platform(
|
||||
Language language,
|
||||
Runtime runtime,
|
||||
VirtualMachine virtualMachine,
|
||||
OperatingSystem operatingSystem,
|
||||
Processor processor) {
|
||||
this.language = language;
|
||||
this.runtime = runtime;
|
||||
this.virtualMachine = virtualMachine;
|
||||
this.operatingSystem = operatingSystem;
|
||||
this.processor = processor;
|
||||
}
|
||||
|
||||
/** The Pkl release that the current program runs on. */
|
||||
public static Platform current() {
|
||||
return CURRENT;
|
||||
}
|
||||
|
||||
/** The language implementation of this platform. */
|
||||
public Language language() {
|
||||
return language;
|
||||
}
|
||||
/**
|
||||
* The language implementation of a platform.
|
||||
*
|
||||
* @param version the version of this language implementation
|
||||
*/
|
||||
public record Language(String version) {}
|
||||
|
||||
/** The language runtime of this platform. */
|
||||
public Runtime runtime() {
|
||||
return runtime;
|
||||
}
|
||||
/**
|
||||
* The language runtime of a platform.
|
||||
*
|
||||
* @param name the name of this language runtime.
|
||||
* @param version the version of this language runtime.
|
||||
*/
|
||||
public record Runtime(String name, String version) {}
|
||||
|
||||
/** The virtual machine of this platform. */
|
||||
public VirtualMachine virtualMachine() {
|
||||
return virtualMachine;
|
||||
}
|
||||
/**
|
||||
* The virtual machine of a platform.
|
||||
*
|
||||
* @param name the name of this virtual machine.
|
||||
* @param version the version of this virtual machine.
|
||||
*/
|
||||
public record VirtualMachine(String name, String version) {}
|
||||
|
||||
/** The operating system of this platform. */
|
||||
public OperatingSystem operatingSystem() {
|
||||
return operatingSystem;
|
||||
}
|
||||
/**
|
||||
* The operating system of a platform.
|
||||
*
|
||||
* @param name the name of this operating system.
|
||||
* @param version the version of this operating system.
|
||||
*/
|
||||
public record OperatingSystem(String name, String version) {}
|
||||
|
||||
/** The processor of this platform. */
|
||||
public Processor processor() {
|
||||
return processor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof Platform other)) return false;
|
||||
return language.equals(other.language)
|
||||
&& runtime.equals(other.runtime)
|
||||
&& virtualMachine.equals(other.virtualMachine)
|
||||
&& operatingSystem.equals(other.operatingSystem)
|
||||
&& processor.equals(other.processor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(language, runtime, virtualMachine, operatingSystem, processor);
|
||||
}
|
||||
|
||||
/** The language implementation of a platform. */
|
||||
public static final class Language {
|
||||
private final String version;
|
||||
|
||||
/** Constructs a {@link Language}. */
|
||||
public Language(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
/** The version of this language implementation. */
|
||||
public String version() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof Language other)) return false;
|
||||
return version.equals(other.version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return version.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
/** The language runtime of a platform. */
|
||||
public static final class Runtime {
|
||||
private final String name;
|
||||
private final String version;
|
||||
|
||||
/** Constructs a {@link Runtime}. */
|
||||
public Runtime(String name, String version) {
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
/** The name of this language runtime. */
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/** The version of this language runtime. */
|
||||
public String version() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof Runtime other)) return false;
|
||||
return name.equals(other.name) && version.equals(other.version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, version);
|
||||
}
|
||||
}
|
||||
|
||||
/** The virtual machine of a platform. */
|
||||
public static final class VirtualMachine {
|
||||
private final String name;
|
||||
private final String version;
|
||||
|
||||
/** Constructs a {@link VirtualMachine}. */
|
||||
public VirtualMachine(String name, String version) {
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
/** The name of this virtual machine. */
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/** The version of this virtual machine. */
|
||||
public String version() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof VirtualMachine other)) return false;
|
||||
return name.equals(other.name) && version.equals(other.version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, version);
|
||||
}
|
||||
}
|
||||
|
||||
/** The operating system of a platform. */
|
||||
public static final class OperatingSystem {
|
||||
private final String name;
|
||||
private final String version;
|
||||
|
||||
/** Constructs an {@link OperatingSystem}. */
|
||||
public OperatingSystem(String name, String version) {
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
/** The name of this operating system. */
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/** The version of this operating system. */
|
||||
public String version() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof OperatingSystem other)) return false;
|
||||
return name.equals(other.name) && version.equals(other.version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, version);
|
||||
}
|
||||
}
|
||||
|
||||
/** The processor of a platform. */
|
||||
public static final class Processor {
|
||||
private final String architecture;
|
||||
|
||||
/** Constructs a {@link Processor}. */
|
||||
public Processor(String architecture) {
|
||||
this.architecture = architecture;
|
||||
}
|
||||
|
||||
/** The instruction set architecture of this processor. */
|
||||
public String architecture() {
|
||||
return architecture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof Processor other)) return false;
|
||||
return architecture.equals(other.architecture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return architecture.hashCode();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The processor of a platform.
|
||||
*
|
||||
* @param architecture the instruction set architecture of this processor.
|
||||
*/
|
||||
public record Processor(String architecture) {}
|
||||
}
|
||||
|
||||
@@ -164,25 +164,15 @@ public final class Release {
|
||||
}
|
||||
|
||||
/** The source code of a Pkl release. */
|
||||
public static final class SourceCode {
|
||||
private final String homepage;
|
||||
private final String version;
|
||||
|
||||
/** Constructs a {@link SourceCode}. */
|
||||
public SourceCode(String homepage, String version) {
|
||||
this.homepage = homepage;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public record SourceCode(String homepage, String version) {
|
||||
/**
|
||||
* @deprecated As of 0.28.0, replaced by {@link #version()}.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
/** The homepage of this source code. */
|
||||
public String homepage() {
|
||||
return homepage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the source code page of the file with the given path. <b>Note:</b> Files may be moved
|
||||
* or deleted anytime.
|
||||
@@ -195,75 +185,20 @@ public final class Release {
|
||||
public String getSourceCodeUrlScheme() {
|
||||
return homepage + "blob/" + version + "/stdlib%{path}#L%{line}-L%{endLine}";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof SourceCode other)) return false;
|
||||
return homepage.equals(other.homepage) && version.equals(other.version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(homepage, version);
|
||||
}
|
||||
}
|
||||
|
||||
/** The documentation of a Pkl release. */
|
||||
public static final class Documentation {
|
||||
private final String homepage;
|
||||
|
||||
/** Constructs a {@link Documentation}. */
|
||||
public Documentation(String homepage) {
|
||||
this.homepage = homepage;
|
||||
}
|
||||
|
||||
/** The homepage of this documentation. */
|
||||
public String homepage() {
|
||||
return homepage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof Documentation other)) return false;
|
||||
return homepage.equals(other.homepage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return homepage.hashCode();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The documentation of a Pkl release.
|
||||
*
|
||||
* @param homepage the homepage of this documentation.
|
||||
*/
|
||||
public record Documentation(String homepage) {}
|
||||
|
||||
/**
|
||||
* The standard library of a Pkl release.
|
||||
*
|
||||
* @since 0.21.0
|
||||
* @param modules the modules of this standard library.
|
||||
*/
|
||||
public static final class StandardLibrary {
|
||||
private final Set<String> modules;
|
||||
|
||||
/** Constructs a {@link StandardLibrary}. */
|
||||
public StandardLibrary(Set<String> modules) {
|
||||
this.modules = modules;
|
||||
}
|
||||
|
||||
/** The modules of this standard library. */
|
||||
public Set<String> modules() {
|
||||
return modules;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof StandardLibrary other)) return false;
|
||||
return modules.equals(other.modules);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return modules.hashCode();
|
||||
}
|
||||
}
|
||||
public record StandardLibrary(Set<String> modules) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user