mirror of
https://github.com/apple/pkl.git
synced 2026-07-08 05:55:13 +02:00
Convert org.pkl.core.resource POJOs to record classes (#748)
This commit is contained in:
@@ -20,22 +20,19 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
|
||||||
/** An external (file, HTTP, etc.) resource. */
|
/** An external (file, HTTP, etc.) resource. */
|
||||||
public final class Resource {
|
public record Resource(URI uri, byte[] bytes) {
|
||||||
private final URI uri;
|
/**
|
||||||
|
* @deprecated As of 0.28.0, replaced by {@link #uri()}
|
||||||
private final byte[] bytes;
|
*/
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
/** Constructs a resource. */
|
|
||||||
public Resource(URI uri, byte[] bytes) {
|
|
||||||
this.uri = uri;
|
|
||||||
this.bytes = bytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns the URI of this resource. */
|
|
||||||
public URI getUri() {
|
public URI getUri() {
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated As of 0.28.0, replaced by {@link #bytes()}
|
||||||
|
*/
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
public byte[] getBytes() {
|
public byte[] getBytes() {
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public final class ResourceManager {
|
|||||||
|
|
||||||
resourceFactory =
|
resourceFactory =
|
||||||
new VmObjectFactory<Resource>(BaseModule::getResourceClass)
|
new VmObjectFactory<Resource>(BaseModule::getResourceClass)
|
||||||
.addProperty("uri", resource -> resource.getUri().toString())
|
.addProperty("uri", resource -> resource.uri().toString())
|
||||||
.addProperty("text", Resource::getText)
|
.addProperty("text", Resource::getText)
|
||||||
.addProperty("base64", Resource::getBase64);
|
.addProperty("base64", Resource::getBase64);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public final class ResourceNodes {
|
|||||||
@Specialization(guards = "self.hasExtraStorage()")
|
@Specialization(guards = "self.hasExtraStorage()")
|
||||||
protected String evalWithExtraStorage(VmTyped self) {
|
protected String evalWithExtraStorage(VmTyped self) {
|
||||||
var resource = (Resource) self.getExtraStorage();
|
var resource = (Resource) self.getExtraStorage();
|
||||||
return ByteArrayUtils.md5(resource.getBytes());
|
return ByteArrayUtils.md5(resource.bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
@TruffleBoundary
|
@TruffleBoundary
|
||||||
@@ -54,7 +54,7 @@ public final class ResourceNodes {
|
|||||||
@Specialization(guards = "self.hasExtraStorage()")
|
@Specialization(guards = "self.hasExtraStorage()")
|
||||||
protected String evalWithExtraStorage(VmTyped self) {
|
protected String evalWithExtraStorage(VmTyped self) {
|
||||||
var resource = (Resource) self.getExtraStorage();
|
var resource = (Resource) self.getExtraStorage();
|
||||||
return ByteArrayUtils.sha1(resource.getBytes());
|
return ByteArrayUtils.sha1(resource.bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
@TruffleBoundary
|
@TruffleBoundary
|
||||||
@@ -71,7 +71,7 @@ public final class ResourceNodes {
|
|||||||
@Specialization(guards = "self.hasExtraStorage()")
|
@Specialization(guards = "self.hasExtraStorage()")
|
||||||
protected String evalWithExtraStorage(VmTyped self) {
|
protected String evalWithExtraStorage(VmTyped self) {
|
||||||
var resource = (Resource) self.getExtraStorage();
|
var resource = (Resource) self.getExtraStorage();
|
||||||
return ByteArrayUtils.sha256(resource.getBytes());
|
return ByteArrayUtils.sha256(resource.bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
@TruffleBoundary
|
@TruffleBoundary
|
||||||
@@ -88,7 +88,7 @@ public final class ResourceNodes {
|
|||||||
@Specialization(guards = "self.hasExtraStorage()")
|
@Specialization(guards = "self.hasExtraStorage()")
|
||||||
protected long evalWithExtraStorage(VmTyped self) {
|
protected long evalWithExtraStorage(VmTyped self) {
|
||||||
var resource = (Resource) self.getExtraStorage();
|
var resource = (Resource) self.getExtraStorage();
|
||||||
return ByteArrayUtils.sha256Int(resource.getBytes());
|
return ByteArrayUtils.sha256Int(resource.bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
@TruffleBoundary
|
@TruffleBoundary
|
||||||
|
|||||||
Reference in New Issue
Block a user