mirror of
https://github.com/apple/pkl.git
synced 2026-06-08 23:02:45 +02:00
Leverage basic Java 17 features (#451)
- Refactor code to use the following basic Java 17 features: - pattern matching for instanceof - @Serial annotation - switch expressions - enhanced switch statements - StringBuilder.isEmpty() - Replace two switch statements with simpler if statements. - Rename a few local variables.
This commit is contained in:
@@ -111,10 +111,10 @@ public class ListSort {
|
|||||||
// append `.length` to avoid rendering the list
|
// append `.length` to avoid rendering the list
|
||||||
new ReplRequest.Eval("sort", "nums.sortWith(cmp).length", false, false))
|
new ReplRequest.Eval("sort", "nums.sortWith(cmp).length", false, false))
|
||||||
.get(0);
|
.get(0);
|
||||||
if (!(response instanceof ReplResponse.EvalSuccess)) {
|
if (!(response instanceof ReplResponse.EvalSuccess success)) {
|
||||||
throw new AssertionError(response);
|
throw new AssertionError(response);
|
||||||
}
|
}
|
||||||
return ((ReplResponse.EvalSuccess) response).getResult();
|
return success.getResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
// note that this is an uneven comparison
|
// note that this is an uneven comparison
|
||||||
|
|||||||
@@ -38,11 +38,11 @@ abstract class AbstractConfig implements Config {
|
|||||||
public Config get(String propertyName) {
|
public Config get(String propertyName) {
|
||||||
var childValue = getRawChildValue(propertyName);
|
var childValue = getRawChildValue(propertyName);
|
||||||
var childName = qualifiedName.isEmpty() ? propertyName : qualifiedName + '.' + propertyName;
|
var childName = qualifiedName.isEmpty() ? propertyName : qualifiedName + '.' + propertyName;
|
||||||
if (childValue instanceof Composite) {
|
if (childValue instanceof Composite composite) {
|
||||||
return new CompositeConfig(childName, mapper, (Composite) childValue);
|
return new CompositeConfig(childName, mapper, composite);
|
||||||
}
|
}
|
||||||
if (childValue instanceof Map) {
|
if (childValue instanceof Map<?, ?> map) {
|
||||||
return new MapConfig(childName, mapper, (Map<?, ?>) childValue);
|
return new MapConfig(childName, mapper, map);
|
||||||
}
|
}
|
||||||
return new LeafConfig(childName, mapper, childValue);
|
return new LeafConfig(childName, mapper, childValue);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,10 +49,10 @@ public class JavaType<T> {
|
|||||||
|
|
||||||
protected JavaType() {
|
protected JavaType() {
|
||||||
var superclass = getClass().getGenericSuperclass();
|
var superclass = getClass().getGenericSuperclass();
|
||||||
if (superclass instanceof Class) {
|
if (!(superclass instanceof ParameterizedType parameterizedType)) {
|
||||||
throw new IllegalStateException("JavaType token must be parameterized.");
|
throw new IllegalStateException("JavaType token must be parameterized.");
|
||||||
}
|
}
|
||||||
type = ((ParameterizedType) superclass).getActualTypeArguments()[0];
|
type = parameterizedType.getActualTypeArguments()[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
private JavaType(Type type) {
|
private JavaType(Type type) {
|
||||||
@@ -161,9 +161,7 @@ public class JavaType<T> {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof JavaType)) return false;
|
if (!(obj instanceof JavaType<?> other)) return false;
|
||||||
|
|
||||||
var other = (JavaType<?>) obj;
|
|
||||||
return type.equals(other.type);
|
return type.equals(other.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ final class PNullToAny implements ConverterFactory {
|
|||||||
@Override
|
@Override
|
||||||
public Optional<Converter<?, ?>> create(PClassInfo<?> sourceType, Type targetType) {
|
public Optional<Converter<?, ?>> create(PClassInfo<?> sourceType, Type targetType) {
|
||||||
if (sourceType != PClassInfo.Null
|
if (sourceType != PClassInfo.Null
|
||||||
|| (targetType instanceof Class && ((Class<?>) targetType).isPrimitive())) {
|
|| (targetType instanceof Class<?> clazz && clazz.isPrimitive())) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,8 +46,7 @@ public final class Reflection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isMissingTypeArguments(Type type) {
|
public static boolean isMissingTypeArguments(Type type) {
|
||||||
if (type instanceof WildcardType) {
|
if (type instanceof WildcardType wildcardType) {
|
||||||
var wildcardType = (WildcardType) type;
|
|
||||||
var baseType =
|
var baseType =
|
||||||
wildcardType.getLowerBounds().length > 0
|
wildcardType.getLowerBounds().length > 0
|
||||||
? wildcardType.getLowerBounds()[0]
|
? wildcardType.getLowerBounds()[0]
|
||||||
@@ -62,11 +61,10 @@ public final class Reflection {
|
|||||||
* instantiable (not an interface or abstract class).
|
* instantiable (not an interface or abstract class).
|
||||||
*/
|
*/
|
||||||
public static Type normalize(Type type) {
|
public static Type normalize(Type type) {
|
||||||
if (type instanceof WildcardType) {
|
if (type instanceof WildcardType wildcardType) {
|
||||||
var wcType = (WildcardType) type;
|
var bounds = wildcardType.getLowerBounds();
|
||||||
var bounds = wcType.getLowerBounds();
|
|
||||||
if (bounds.length > 0) return bounds[0];
|
if (bounds.length > 0) return bounds[0];
|
||||||
bounds = wcType.getUpperBounds();
|
bounds = wildcardType.getUpperBounds();
|
||||||
if (bounds.length > 0) return bounds[0];
|
if (bounds.length > 0) return bounds[0];
|
||||||
}
|
}
|
||||||
return getExactSupertype(type, toRawType(type));
|
return getExactSupertype(type, toRawType(type));
|
||||||
@@ -154,8 +152,8 @@ public final class Reflection {
|
|||||||
* eliminate them.
|
* eliminate them.
|
||||||
*/
|
*/
|
||||||
private static Type uncapture(Type type) {
|
private static Type uncapture(Type type) {
|
||||||
if (type instanceof CaptureType) {
|
if (type instanceof CaptureType captureType) {
|
||||||
return ((CaptureType) type).getWildcardType();
|
return captureType.getWildcardType();
|
||||||
}
|
}
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,10 +35,7 @@ final class Tuple2<S, T> {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof Tuple2)) return false;
|
if (!(obj instanceof Tuple2<?, ?> other)) return false;
|
||||||
|
|
||||||
var other = (Tuple2<?, ?>) obj;
|
|
||||||
|
|
||||||
return first.equals(other.first) && second.equals(other.second);
|
return first.equals(other.first) && second.equals(other.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,9 +59,7 @@ public final class TypeMapping<S, T extends S> {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof TypeMapping)) return false;
|
if (!(obj instanceof TypeMapping<?, ?> other)) return false;
|
||||||
|
|
||||||
var other = (TypeMapping<?, ?>) obj;
|
|
||||||
return requestedType == other.requestedType && implementationType == other.implementationType;
|
return requestedType == other.requestedType && implementationType == other.implementationType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,8 +44,7 @@ public final class Types {
|
|||||||
typeParamsCount, rawType.getTypeName(), typeArguments.length));
|
typeParamsCount, rawType.getTypeName(), typeArguments.length));
|
||||||
}
|
}
|
||||||
for (Type arg : typeArguments) {
|
for (Type arg : typeArguments) {
|
||||||
if (arg instanceof Class) {
|
if (arg instanceof Class<?> clazz) {
|
||||||
var clazz = (Class<?>) arg;
|
|
||||||
if (clazz.isPrimitive()) {
|
if (clazz.isPrimitive()) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
String.format(
|
String.format(
|
||||||
|
|||||||
@@ -64,8 +64,7 @@ public final class ValueMapperBuilder {
|
|||||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
public ValueMapperBuilder addConversion(Conversion<?, ?> conversion) {
|
public ValueMapperBuilder addConversion(Conversion<?, ?> conversion) {
|
||||||
conversions.add(conversion);
|
conversions.add(conversion);
|
||||||
if (conversion.targetType instanceof Class) {
|
if (conversion.targetType instanceof Class<?> clazz) {
|
||||||
var clazz = (Class<?>) conversion.targetType;
|
|
||||||
if (clazz.isPrimitive()) {
|
if (clazz.isPrimitive()) {
|
||||||
conversions.add(
|
conversions.add(
|
||||||
Conversion.of(
|
Conversion.of(
|
||||||
|
|||||||
+3
-9
@@ -91,9 +91,7 @@ public class PObjectToDataObjectJavaxInjectTest {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof Person)) return false;
|
if (!(obj instanceof Person other)) return false;
|
||||||
|
|
||||||
var other = (Person) obj;
|
|
||||||
return name.equals(other.name)
|
return name.equals(other.name)
|
||||||
&& age == other.age
|
&& age == other.age
|
||||||
&& hobbies.equals(other.hobbies)
|
&& hobbies.equals(other.hobbies)
|
||||||
@@ -118,9 +116,7 @@ public class PObjectToDataObjectJavaxInjectTest {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof Address)) return false;
|
if (!(obj instanceof Address other)) return false;
|
||||||
|
|
||||||
var other = (Address) obj;
|
|
||||||
return street.equals(other.street) && zip == other.zip;
|
return street.equals(other.street) && zip == other.zip;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,9 +144,7 @@ public class PObjectToDataObjectJavaxInjectTest {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof Pair)) return false;
|
if (!(obj instanceof Pair<?, ?> other)) return false;
|
||||||
|
|
||||||
var other = (Pair<?, ?>) obj;
|
|
||||||
return first.equals(other.first) && second.equals(other.second);
|
return first.equals(other.first) && second.equals(other.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-12
@@ -136,9 +136,7 @@ public class PObjectToDataObjectTest {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof Person)) return false;
|
if (!(obj instanceof Person other)) return false;
|
||||||
|
|
||||||
var other = (Person) obj;
|
|
||||||
return name.equals(other.name)
|
return name.equals(other.name)
|
||||||
&& age == other.age
|
&& age == other.age
|
||||||
&& hobbies.equals(other.hobbies)
|
&& hobbies.equals(other.hobbies)
|
||||||
@@ -168,9 +166,7 @@ public class PObjectToDataObjectTest {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof PersonConstructoProperties)) return false;
|
if (!(obj instanceof PersonConstructoProperties other)) return false;
|
||||||
|
|
||||||
var other = (PersonConstructoProperties) obj;
|
|
||||||
return name.equals(other.name)
|
return name.equals(other.name)
|
||||||
&& age == other.age
|
&& age == other.age
|
||||||
&& hobbies.equals(other.hobbies)
|
&& hobbies.equals(other.hobbies)
|
||||||
@@ -195,9 +191,7 @@ public class PObjectToDataObjectTest {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof Address)) return false;
|
if (!(obj instanceof Address other)) return false;
|
||||||
|
|
||||||
var other = (Address) obj;
|
|
||||||
return street.equals(other.street) && zip == other.zip;
|
return street.equals(other.street) && zip == other.zip;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,9 +219,7 @@ public class PObjectToDataObjectTest {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof Pair)) return false;
|
if (!(obj instanceof Pair<?, ?> other)) return false;
|
||||||
|
|
||||||
var other = (Pair<?, ?>) obj;
|
|
||||||
return first.equals(other.first) && second.equals(other.second);
|
return first.equals(other.first) && second.equals(other.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,9 +29,7 @@ public class Person {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof Person)) return false;
|
if (!(obj instanceof Person other)) return false;
|
||||||
|
|
||||||
var other = (Person) obj;
|
|
||||||
return name.equals(other.name) && age == other.age;
|
return name.equals(other.name) && age == other.age;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,13 +17,14 @@ package org.pkl.core;
|
|||||||
|
|
||||||
import static org.pkl.core.DataSizeUnit.*;
|
import static org.pkl.core.DataSizeUnit.*;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import org.pkl.core.util.MathUtils;
|
import org.pkl.core.util.MathUtils;
|
||||||
import org.pkl.core.util.Nullable;
|
import org.pkl.core.util.Nullable;
|
||||||
|
|
||||||
/** Java representation of a {@code pkl.base#DataSize} value. */
|
/** Java representation of a {@code pkl.base#DataSize} value. */
|
||||||
public final class DataSize implements Value {
|
public final class DataSize implements Value {
|
||||||
private static final long serialVersionUID = 0L;
|
@Serial private static final long serialVersionUID = 0L;
|
||||||
|
|
||||||
private final double value;
|
private final double value;
|
||||||
private final DataSizeUnit unit;
|
private final DataSizeUnit unit;
|
||||||
@@ -240,9 +241,7 @@ public final class DataSize implements Value {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof DataSize)) return false;
|
if (!(obj instanceof DataSize other)) return false;
|
||||||
|
|
||||||
var other = (DataSize) obj;
|
|
||||||
return convertValueTo(DataSizeUnit.BYTES) == other.convertValueTo(DataSizeUnit.BYTES);
|
return convertValueTo(DataSizeUnit.BYTES) == other.convertValueTo(DataSizeUnit.BYTES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,32 +48,20 @@ public enum DataSizeUnit {
|
|||||||
* exists.
|
* exists.
|
||||||
*/
|
*/
|
||||||
public static @Nullable DataSizeUnit parse(String symbol) {
|
public static @Nullable DataSizeUnit parse(String symbol) {
|
||||||
switch (symbol) {
|
return switch (symbol) {
|
||||||
case "b":
|
case "b" -> BYTES;
|
||||||
return BYTES;
|
case "kb" -> KILOBYTES;
|
||||||
case "kb":
|
case "kib" -> KIBIBYTES;
|
||||||
return KILOBYTES;
|
case "mb" -> MEGABYTES;
|
||||||
case "kib":
|
case "mib" -> MEBIBYTES;
|
||||||
return KIBIBYTES;
|
case "gb" -> GIGABYTES;
|
||||||
case "mb":
|
case "gib" -> GIBIBYTES;
|
||||||
return MEGABYTES;
|
case "tb" -> TERABYTES;
|
||||||
case "mib":
|
case "tib" -> TEBIBYTES;
|
||||||
return MEBIBYTES;
|
case "pb" -> PETABYTES;
|
||||||
case "gb":
|
case "pib" -> PEBIBYTES;
|
||||||
return GIGABYTES;
|
default -> null;
|
||||||
case "gib":
|
};
|
||||||
return GIBIBYTES;
|
|
||||||
case "tb":
|
|
||||||
return TERABYTES;
|
|
||||||
case "tib":
|
|
||||||
return TEBIBYTES;
|
|
||||||
case "pb":
|
|
||||||
return PETABYTES;
|
|
||||||
case "pib":
|
|
||||||
return PEBIBYTES;
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the String symbol of this unit. */
|
/** Returns the String symbol of this unit. */
|
||||||
|
|||||||
@@ -17,13 +17,14 @@ package org.pkl.core;
|
|||||||
|
|
||||||
import static org.pkl.core.DurationUnit.*;
|
import static org.pkl.core.DurationUnit.*;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import org.pkl.core.util.DurationUtils;
|
import org.pkl.core.util.DurationUtils;
|
||||||
import org.pkl.core.util.Nullable;
|
import org.pkl.core.util.Nullable;
|
||||||
|
|
||||||
/** Java representation of a {@code pkl.base#Duration} value. */
|
/** Java representation of a {@code pkl.base#Duration} value. */
|
||||||
public final class Duration implements Value {
|
public final class Duration implements Value {
|
||||||
private static final long serialVersionUID = 0L;
|
@Serial private static final long serialVersionUID = 0L;
|
||||||
|
|
||||||
private final double value;
|
private final double value;
|
||||||
private final DurationUnit unit;
|
private final DurationUnit unit;
|
||||||
@@ -215,9 +216,7 @@ public final class Duration implements Value {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof Duration)) return false;
|
if (!(obj instanceof Duration other)) return false;
|
||||||
|
|
||||||
var other = (Duration) obj;
|
|
||||||
return convertValueTo(DurationUnit.NANOS) == other.convertValueTo(DurationUnit.NANOS);
|
return convertValueTo(DurationUnit.NANOS) == other.convertValueTo(DurationUnit.NANOS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,24 +46,16 @@ public enum DurationUnit {
|
|||||||
* exists.
|
* exists.
|
||||||
*/
|
*/
|
||||||
public static @Nullable DurationUnit parse(String symbol) {
|
public static @Nullable DurationUnit parse(String symbol) {
|
||||||
switch (symbol) {
|
return switch (symbol) {
|
||||||
case "ns":
|
case "ns" -> NANOS;
|
||||||
return NANOS;
|
case "us" -> MICROS;
|
||||||
case "us":
|
case "ms" -> MILLIS;
|
||||||
return MICROS;
|
case "s" -> SECONDS;
|
||||||
case "ms":
|
case "min" -> MINUTES;
|
||||||
return MILLIS;
|
case "h" -> HOURS;
|
||||||
case "s":
|
case "d" -> DAYS;
|
||||||
return SECONDS;
|
default -> null;
|
||||||
case "min":
|
};
|
||||||
return MINUTES;
|
|
||||||
case "h":
|
|
||||||
return HOURS;
|
|
||||||
case "d":
|
|
||||||
return DAYS;
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the string symbol of this unit. */
|
/** Returns the string symbol of this unit. */
|
||||||
@@ -78,24 +70,15 @@ public enum DurationUnit {
|
|||||||
|
|
||||||
/** Converts this unit to a {@link java.time.temporal.ChronoUnit}. */
|
/** Converts this unit to a {@link java.time.temporal.ChronoUnit}. */
|
||||||
public ChronoUnit toChronoUnit() {
|
public ChronoUnit toChronoUnit() {
|
||||||
switch (this) {
|
return switch (this) {
|
||||||
case NANOS:
|
case NANOS -> ChronoUnit.NANOS;
|
||||||
return ChronoUnit.NANOS;
|
case MICROS -> ChronoUnit.MICROS;
|
||||||
case MICROS:
|
case MILLIS -> ChronoUnit.MILLIS;
|
||||||
return ChronoUnit.MICROS;
|
case SECONDS -> ChronoUnit.SECONDS;
|
||||||
case MILLIS:
|
case MINUTES -> ChronoUnit.MINUTES;
|
||||||
return ChronoUnit.MILLIS;
|
case HOURS -> ChronoUnit.HOURS;
|
||||||
case SECONDS:
|
case DAYS -> ChronoUnit.DAYS;
|
||||||
return ChronoUnit.SECONDS;
|
};
|
||||||
case MINUTES:
|
|
||||||
return ChronoUnit.MINUTES;
|
|
||||||
case HOURS:
|
|
||||||
return ChronoUnit.HOURS;
|
|
||||||
case DAYS:
|
|
||||||
return ChronoUnit.DAYS;
|
|
||||||
default:
|
|
||||||
throw new AssertionError("Unknown duration unit: " + this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Converts this unit to a {@link java.util.concurrent.TimeUnit}. */
|
/** Converts this unit to a {@link java.util.concurrent.TimeUnit}. */
|
||||||
|
|||||||
@@ -148,8 +148,7 @@ public class EvaluatorImpl implements Evaluator {
|
|||||||
(module) -> {
|
(module) -> {
|
||||||
var output = (VmTyped) VmUtils.readMember(module, Identifier.OUTPUT);
|
var output = (VmTyped) VmUtils.readMember(module, Identifier.OUTPUT);
|
||||||
var value = VmUtils.readMember(output, Identifier.VALUE);
|
var value = VmUtils.readMember(output, Identifier.VALUE);
|
||||||
if (value instanceof VmValue) {
|
if (value instanceof VmValue vmValue) {
|
||||||
var vmValue = (VmValue) value;
|
|
||||||
vmValue.force(false);
|
vmValue.force(false);
|
||||||
return vmValue.export();
|
return vmValue.export();
|
||||||
}
|
}
|
||||||
@@ -194,8 +193,7 @@ public class EvaluatorImpl implements Evaluator {
|
|||||||
(module) -> {
|
(module) -> {
|
||||||
var expressionResult =
|
var expressionResult =
|
||||||
VmUtils.evaluateExpression(module, expression, securityManager, moduleResolver);
|
VmUtils.evaluateExpression(module, expression, securityManager, moduleResolver);
|
||||||
if (expressionResult instanceof VmValue) {
|
if (expressionResult instanceof VmValue value) {
|
||||||
var value = (VmValue) expressionResult;
|
|
||||||
value.force(false);
|
value.force(false);
|
||||||
return value.export();
|
return value.export();
|
||||||
}
|
}
|
||||||
@@ -248,8 +246,7 @@ public class EvaluatorImpl implements Evaluator {
|
|||||||
var value = VmUtils.readMember(output, Identifier.VALUE);
|
var value = VmUtils.readMember(output, Identifier.VALUE);
|
||||||
var valueClassInfo = VmUtils.getClass(value).getPClassInfo();
|
var valueClassInfo = VmUtils.getClass(value).getPClassInfo();
|
||||||
if (valueClassInfo.equals(classInfo)) {
|
if (valueClassInfo.equals(classInfo)) {
|
||||||
if (value instanceof VmValue) {
|
if (value instanceof VmValue vmValue) {
|
||||||
var vmValue = (VmValue) value;
|
|
||||||
vmValue.force(false);
|
vmValue.force(false);
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
return (T) vmValue.export();
|
return (T) vmValue.export();
|
||||||
@@ -317,10 +314,10 @@ public class EvaluatorImpl implements Evaluator {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new PklBugException(e);
|
throw new PklBugException(e);
|
||||||
} catch (ExceptionInInitializerError e) {
|
} catch (ExceptionInInitializerError e) {
|
||||||
if (!(e.getCause() instanceof VmException)) {
|
if (!(e.getCause() instanceof VmException vmException)) {
|
||||||
throw new PklBugException(e);
|
throw new PklBugException(e);
|
||||||
}
|
}
|
||||||
var pklException = ((VmException) e.getCause()).toPklException(frameTransformer);
|
var pklException = vmException.toPklException(frameTransformer);
|
||||||
var error = new ExceptionInInitializerError(pklException);
|
var error = new ExceptionInInitializerError(pklException);
|
||||||
error.setStackTrace(e.getStackTrace());
|
error.setStackTrace(e.getStackTrace());
|
||||||
throw new PklBugException(error);
|
throw new PklBugException(error);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.pkl.core;
|
package org.pkl.core;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -23,8 +24,7 @@ import org.pkl.core.util.Nullable;
|
|||||||
|
|
||||||
/** Common base class for TypeAlias, PClass, PClass.Property, and PClass.Method. */
|
/** Common base class for TypeAlias, PClass, PClass.Property, and PClass.Method. */
|
||||||
public abstract class Member implements Serializable {
|
public abstract class Member implements Serializable {
|
||||||
|
@Serial private static final long serialVersionUID = 0L;
|
||||||
private static final long serialVersionUID = 0L;
|
|
||||||
|
|
||||||
private final @Nullable String docComment;
|
private final @Nullable String docComment;
|
||||||
private final SourceLocation sourceLocation;
|
private final SourceLocation sourceLocation;
|
||||||
@@ -99,8 +99,7 @@ public abstract class Member implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class SourceLocation implements Serializable {
|
public static class SourceLocation implements Serializable {
|
||||||
|
@Serial private static final long serialVersionUID = 0L;
|
||||||
private static final long serialVersionUID = 0L;
|
|
||||||
|
|
||||||
private final int startLine;
|
private final int startLine;
|
||||||
private final int endLine;
|
private final int endLine;
|
||||||
|
|||||||
@@ -15,12 +15,13 @@
|
|||||||
*/
|
*/
|
||||||
package org.pkl.core;
|
package org.pkl.core;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import org.pkl.core.util.Nullable;
|
import org.pkl.core.util.Nullable;
|
||||||
|
|
||||||
/** Java representation of a {@code pkl.base#Class} value. */
|
/** Java representation of a {@code pkl.base#Class} value. */
|
||||||
public final class PClass extends Member implements Value {
|
public final class PClass extends Member implements Value {
|
||||||
private static final long serialVersionUID = 0L;
|
@Serial private static final long serialVersionUID = 0L;
|
||||||
|
|
||||||
private final PClassInfo<?> classInfo;
|
private final PClassInfo<?> classInfo;
|
||||||
private final List<TypeParameter> typeParameters;
|
private final List<TypeParameter> typeParameters;
|
||||||
@@ -138,8 +139,7 @@ public final class PClass extends Member implements Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public abstract static class ClassMember extends Member {
|
public abstract static class ClassMember extends Member {
|
||||||
|
@Serial private static final long serialVersionUID = 0L;
|
||||||
private static final long serialVersionUID = 0L;
|
|
||||||
|
|
||||||
private final PClass owner;
|
private final PClass owner;
|
||||||
|
|
||||||
@@ -176,8 +176,7 @@ public final class PClass extends Member implements Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final class Property extends ClassMember {
|
public static final class Property extends ClassMember {
|
||||||
|
@Serial private static final long serialVersionUID = 0L;
|
||||||
private static final long serialVersionUID = 0L;
|
|
||||||
|
|
||||||
private final PType type;
|
private final PType type;
|
||||||
|
|
||||||
@@ -213,8 +212,7 @@ public final class PClass extends Member implements Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final class Method extends ClassMember {
|
public static final class Method extends ClassMember {
|
||||||
|
@Serial private static final long serialVersionUID = 0L;
|
||||||
private static final long serialVersionUID = 0L;
|
|
||||||
|
|
||||||
private final List<TypeParameter> typeParameters;
|
private final List<TypeParameter> typeParameters;
|
||||||
private final Map<String, PType> parameters;
|
private final Map<String, PType> parameters;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ package org.pkl.core;
|
|||||||
|
|
||||||
import static java.util.Map.*;
|
import static java.util.Map.*;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -26,8 +27,7 @@ import org.pkl.core.util.Nullable;
|
|||||||
/** Information about a Pkl class and its Java representation. */
|
/** Information about a Pkl class and its Java representation. */
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public final class PClassInfo<T> implements Serializable {
|
public final class PClassInfo<T> implements Serializable {
|
||||||
|
@Serial private static final long serialVersionUID = 0L;
|
||||||
private static final long serialVersionUID = 0L;
|
|
||||||
|
|
||||||
// Simple name of a module's class.
|
// Simple name of a module's class.
|
||||||
// User-facing via `module.getClass()` and error messages.
|
// User-facing via `module.getClass()` and error messages.
|
||||||
@@ -100,7 +100,7 @@ public final class PClassInfo<T> implements Serializable {
|
|||||||
/** Returns the class info for the given value's class. */
|
/** Returns the class info for the given value's class. */
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T> PClassInfo<T> forValue(T value) {
|
public static <T> PClassInfo<T> forValue(T value) {
|
||||||
if (value instanceof Value) return (PClassInfo<T>) ((Value) value).getClassInfo();
|
if (value instanceof Value v) return (PClassInfo<T>) v.getClassInfo();
|
||||||
|
|
||||||
if (value instanceof String) return (PClassInfo<T>) String;
|
if (value instanceof String) return (PClassInfo<T>) String;
|
||||||
if (value instanceof Boolean) return (PClassInfo<T>) Boolean;
|
if (value instanceof Boolean) return (PClassInfo<T>) Boolean;
|
||||||
@@ -179,9 +179,7 @@ public final class PClassInfo<T> implements Serializable {
|
|||||||
|
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof PClassInfo)) return false;
|
if (!(obj instanceof PClassInfo<?> other)) return false;
|
||||||
|
|
||||||
var other = (PClassInfo<?>) obj;
|
|
||||||
return qualifiedName.equals(other.qualifiedName);
|
return qualifiedName.equals(other.qualifiedName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.pkl.core;
|
package org.pkl.core;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -22,7 +23,7 @@ import org.pkl.core.util.Nullable;
|
|||||||
|
|
||||||
/** Java representation of a Pkl module. */
|
/** Java representation of a Pkl module. */
|
||||||
public final class PModule extends PObject {
|
public final class PModule extends PObject {
|
||||||
private static final long serialVersionUID = 0L;
|
@Serial private static final long serialVersionUID = 0L;
|
||||||
|
|
||||||
private final URI moduleUri;
|
private final URI moduleUri;
|
||||||
private final String moduleName;
|
private final String moduleName;
|
||||||
@@ -62,10 +63,7 @@ public final class PModule extends PObject {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof PModule)) return false;
|
if (!(obj instanceof PModule other)) return false;
|
||||||
|
|
||||||
var other = (PModule) obj;
|
|
||||||
|
|
||||||
return moduleUri.equals(other.moduleUri)
|
return moduleUri.equals(other.moduleUri)
|
||||||
&& moduleName.equals(other.moduleName)
|
&& moduleName.equals(other.moduleName)
|
||||||
&& classInfo.equals(other.classInfo)
|
&& classInfo.equals(other.classInfo)
|
||||||
|
|||||||
@@ -15,9 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.pkl.core;
|
package org.pkl.core;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
|
||||||
/** Java representation of a {@code pkl.base#Null} value. */
|
/** Java representation of a {@code pkl.base#Null} value. */
|
||||||
public final class PNull implements Value {
|
public final class PNull implements Value {
|
||||||
private static final long serialVersionUID = 0L;
|
@Serial private static final long serialVersionUID = 0L;
|
||||||
private static final PNull INSTANCE = new PNull();
|
private static final PNull INSTANCE = new PNull();
|
||||||
|
|
||||||
/** Returns the sole instance of this class. */
|
/** Returns the sole instance of this class. */
|
||||||
|
|||||||
@@ -15,13 +15,14 @@
|
|||||||
*/
|
*/
|
||||||
package org.pkl.core;
|
package org.pkl.core;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import org.pkl.core.util.Nullable;
|
import org.pkl.core.util.Nullable;
|
||||||
|
|
||||||
/** Java representation of a Pkl object. */
|
/** Java representation of a Pkl object. */
|
||||||
public class PObject implements Composite {
|
public class PObject implements Composite {
|
||||||
private static final long serialVersionUID = 0L;
|
@Serial private static final long serialVersionUID = 0L;
|
||||||
|
|
||||||
protected final PClassInfo<?> classInfo;
|
protected final PClassInfo<?> classInfo;
|
||||||
protected final Map<String, Object> properties;
|
protected final Map<String, Object> properties;
|
||||||
|
|||||||
@@ -15,30 +15,30 @@
|
|||||||
*/
|
*/
|
||||||
package org.pkl.core;
|
package org.pkl.core;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/** A Pkl type as used in type annotations. */
|
/** A Pkl type as used in type annotations. */
|
||||||
public abstract class PType implements Serializable {
|
public abstract class PType implements Serializable {
|
||||||
|
@Serial private static final long serialVersionUID = 0L;
|
||||||
private static final long serialVersionUID = 0L;
|
|
||||||
|
|
||||||
/** The `unknown` type. Omitting a type annotation is equivalent to stating this type. */
|
/** The `unknown` type. Omitting a type annotation is equivalent to stating this type. */
|
||||||
public static final PType UNKNOWN =
|
public static final PType UNKNOWN =
|
||||||
new PType() {
|
new PType() {
|
||||||
private static final long serialVersionUID = 0L;
|
@Serial private static final long serialVersionUID = 0L;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** The bottom type. */
|
/** The bottom type. */
|
||||||
public static final PType NOTHING =
|
public static final PType NOTHING =
|
||||||
new PType() {
|
new PType() {
|
||||||
private static final long serialVersionUID = 0L;
|
@Serial private static final long serialVersionUID = 0L;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** The type of the enclosing module. */
|
/** The type of the enclosing module. */
|
||||||
public static final PType MODULE =
|
public static final PType MODULE =
|
||||||
new PType() {
|
new PType() {
|
||||||
private static final long serialVersionUID = 0L;
|
@Serial private static final long serialVersionUID = 0L;
|
||||||
};
|
};
|
||||||
|
|
||||||
private PType() {}
|
private PType() {}
|
||||||
@@ -48,8 +48,7 @@ public abstract class PType implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final class StringLiteral extends PType {
|
public static final class StringLiteral extends PType {
|
||||||
|
@Serial private static final long serialVersionUID = 0L;
|
||||||
private static final long serialVersionUID = 0L;
|
|
||||||
|
|
||||||
private final String literal;
|
private final String literal;
|
||||||
|
|
||||||
@@ -63,8 +62,7 @@ public abstract class PType implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final class Class extends PType {
|
public static final class Class extends PType {
|
||||||
|
@Serial private static final long serialVersionUID = 0L;
|
||||||
private static final long serialVersionUID = 0L;
|
|
||||||
|
|
||||||
private final PClass pClass;
|
private final PClass pClass;
|
||||||
private final List<PType> typeArguments;
|
private final List<PType> typeArguments;
|
||||||
@@ -97,8 +95,7 @@ public abstract class PType implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final class Nullable extends PType {
|
public static final class Nullable extends PType {
|
||||||
|
@Serial private static final long serialVersionUID = 0L;
|
||||||
private static final long serialVersionUID = 0L;
|
|
||||||
|
|
||||||
private final PType baseType;
|
private final PType baseType;
|
||||||
|
|
||||||
@@ -133,8 +130,7 @@ public abstract class PType implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final class Alias extends PType {
|
public static final class Alias extends PType {
|
||||||
|
@Serial private static final long serialVersionUID = 0L;
|
||||||
private static final long serialVersionUID = 0L;
|
|
||||||
|
|
||||||
private final TypeAlias typeAlias;
|
private final TypeAlias typeAlias;
|
||||||
private final List<PType> typeArguments;
|
private final List<PType> typeArguments;
|
||||||
@@ -169,8 +165,7 @@ public abstract class PType implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final class Function extends PType {
|
public static final class Function extends PType {
|
||||||
|
@Serial private static final long serialVersionUID = 0L;
|
||||||
private static final long serialVersionUID = 0L;
|
|
||||||
|
|
||||||
private final List<PType> parameterTypes;
|
private final List<PType> parameterTypes;
|
||||||
private final PType returnType;
|
private final PType returnType;
|
||||||
@@ -190,8 +185,7 @@ public abstract class PType implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final class Union extends PType {
|
public static final class Union extends PType {
|
||||||
|
@Serial private static final long serialVersionUID = 0L;
|
||||||
private static final long serialVersionUID = 0L;
|
|
||||||
|
|
||||||
private final List<PType> elementTypes;
|
private final List<PType> elementTypes;
|
||||||
|
|
||||||
@@ -205,8 +199,7 @@ public abstract class PType implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final class TypeVariable extends PType {
|
public static final class TypeVariable extends PType {
|
||||||
|
@Serial private static final long serialVersionUID = 0L;
|
||||||
private static final long serialVersionUID = 0L;
|
|
||||||
|
|
||||||
private final TypeParameter typeParameter;
|
private final TypeParameter typeParameter;
|
||||||
|
|
||||||
|
|||||||
@@ -15,13 +15,14 @@
|
|||||||
*/
|
*/
|
||||||
package org.pkl.core;
|
package org.pkl.core;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import org.pkl.core.util.Nullable;
|
import org.pkl.core.util.Nullable;
|
||||||
|
|
||||||
/** Java representation of a {@code pkl.base#Pair} value. */
|
/** Java representation of a {@code pkl.base#Pair} value. */
|
||||||
public final class Pair<F, S> implements Value, Iterable<Object> {
|
public final class Pair<F, S> implements Value, Iterable<Object> {
|
||||||
private static final long serialVersionUID = 0L;
|
@Serial private static final long serialVersionUID = 0L;
|
||||||
|
|
||||||
private final F first;
|
private final F first;
|
||||||
private final S second;
|
private final S second;
|
||||||
@@ -54,14 +55,11 @@ public final class Pair<F, S> implements Value, Iterable<Object> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object next() {
|
public Object next() {
|
||||||
switch (pos++) {
|
return switch (pos++) {
|
||||||
case 0:
|
case 0 -> first;
|
||||||
return first;
|
case 1 -> second;
|
||||||
case 1:
|
default -> throw new NoSuchElementException("Pair only has two elements.");
|
||||||
return second;
|
};
|
||||||
default:
|
|
||||||
throw new NoSuchElementException("Pair only has two elements.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -84,9 +82,7 @@ public final class Pair<F, S> implements Value, Iterable<Object> {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof Pair)) return false;
|
if (!(obj instanceof Pair<?, ?> other)) return false;
|
||||||
|
|
||||||
var other = (Pair<?, ?>) obj;
|
|
||||||
return first.equals(other.first) && second.equals(other.second);
|
return first.equals(other.first) && second.equals(other.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,14 +42,14 @@ final class PcfRenderer implements ValueRenderer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderDocument(Object value) {
|
public void renderDocument(Object value) {
|
||||||
if (!(value instanceof Composite)) {
|
if (!(value instanceof Composite composite)) {
|
||||||
throw new RendererException(
|
throw new RendererException(
|
||||||
String.format(
|
String.format(
|
||||||
"The top-level value of a Pcf document must have type `Composite`, but got type `%s`.",
|
"The top-level value of a Pcf document must have type `Composite`, but got type `%s`.",
|
||||||
value.getClass().getTypeName()));
|
value.getClass().getTypeName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
new Visitor().doVisitProperties(((Composite) value).getProperties());
|
new Visitor().doVisitProperties(composite.getProperties());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -101,9 +101,7 @@ public final class Platform {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof Platform)) return false;
|
if (!(obj instanceof Platform other)) return false;
|
||||||
|
|
||||||
var other = (Platform) obj;
|
|
||||||
return language.equals(other.language)
|
return language.equals(other.language)
|
||||||
&& runtime.equals(other.runtime)
|
&& runtime.equals(other.runtime)
|
||||||
&& virtualMachine.equals(other.virtualMachine)
|
&& virtualMachine.equals(other.virtualMachine)
|
||||||
@@ -133,9 +131,7 @@ public final class Platform {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof Language)) return false;
|
if (!(obj instanceof Language other)) return false;
|
||||||
|
|
||||||
var other = (Language) obj;
|
|
||||||
return version.equals(other.version);
|
return version.equals(other.version);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,9 +165,7 @@ public final class Platform {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof Runtime)) return false;
|
if (!(obj instanceof Runtime other)) return false;
|
||||||
|
|
||||||
var other = (Runtime) obj;
|
|
||||||
return name.equals(other.name) && version.equals(other.version);
|
return name.equals(other.name) && version.equals(other.version);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,9 +199,7 @@ public final class Platform {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof VirtualMachine)) return false;
|
if (!(obj instanceof VirtualMachine other)) return false;
|
||||||
|
|
||||||
var other = (VirtualMachine) obj;
|
|
||||||
return name.equals(other.name) && version.equals(other.version);
|
return name.equals(other.name) && version.equals(other.version);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,9 +233,7 @@ public final class Platform {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof OperatingSystem)) return false;
|
if (!(obj instanceof OperatingSystem other)) return false;
|
||||||
|
|
||||||
var other = (OperatingSystem) obj;
|
|
||||||
return name.equals(other.name) && version.equals(other.version);
|
return name.equals(other.name) && version.equals(other.version);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,9 +260,7 @@ public final class Platform {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof Processor)) return false;
|
if (!(obj instanceof Processor other)) return false;
|
||||||
|
|
||||||
var other = (Processor) obj;
|
|
||||||
return architecture.equals(other.architecture);
|
return architecture.equals(other.architecture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,12 +49,11 @@ final class PropertiesRenderer implements ValueRenderer {
|
|||||||
private class Visitor implements ValueConverter<String> {
|
private class Visitor implements ValueConverter<String> {
|
||||||
|
|
||||||
public void renderDocument(Object value) {
|
public void renderDocument(Object value) {
|
||||||
if (value instanceof Composite) {
|
if (value instanceof Composite composite) {
|
||||||
doVisitMap(null, ((Composite) value).getProperties());
|
doVisitMap(null, composite.getProperties());
|
||||||
} else if (value instanceof Map) {
|
} else if (value instanceof Map<?, ?> map) {
|
||||||
doVisitMap(null, (Map<?, ?>) value);
|
doVisitMap(null, map);
|
||||||
} else if (value instanceof Pair) {
|
} else if (value instanceof Pair<?, ?> pair) {
|
||||||
Pair<?, ?> pair = (Pair<?, ?>) value;
|
|
||||||
doVisitKeyAndValue(null, pair.getFirst(), pair.getSecond());
|
doVisitKeyAndValue(null, pair.getFirst(), pair.getSecond());
|
||||||
} else {
|
} else {
|
||||||
throw new RendererException(
|
throw new RendererException(
|
||||||
@@ -181,10 +180,10 @@ final class PropertiesRenderer implements ValueRenderer {
|
|||||||
|
|
||||||
var keyString = keyPrefix == null ? convert(key) : keyPrefix + "." + convert(key);
|
var keyString = keyPrefix == null ? convert(key) : keyPrefix + "." + convert(key);
|
||||||
|
|
||||||
if (value instanceof Composite) {
|
if (value instanceof Composite composite) {
|
||||||
doVisitMap(keyString, ((Composite) value).getProperties());
|
doVisitMap(keyString, composite.getProperties());
|
||||||
} else if (value instanceof Map) {
|
} else if (value instanceof Map<?, ?> map) {
|
||||||
doVisitMap(keyString, (Map<?, ?>) value);
|
doVisitMap(keyString, map);
|
||||||
} else {
|
} else {
|
||||||
write(keyString, true, restrictCharset);
|
write(keyString, true, restrictCharset);
|
||||||
writeSeparator();
|
writeSeparator();
|
||||||
|
|||||||
@@ -148,9 +148,7 @@ public class Release {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof Release)) return false;
|
if (!(obj instanceof Release other)) return false;
|
||||||
|
|
||||||
var other = (Release) obj;
|
|
||||||
return version.equals(other.version)
|
return version.equals(other.version)
|
||||||
&& versionInfo.equals(other.versionInfo)
|
&& versionInfo.equals(other.versionInfo)
|
||||||
&& commitId.equals(other.commitId)
|
&& commitId.equals(other.commitId)
|
||||||
@@ -200,9 +198,7 @@ public class Release {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof SourceCode)) return false;
|
if (!(obj instanceof SourceCode other)) return false;
|
||||||
|
|
||||||
var other = (SourceCode) obj;
|
|
||||||
return homepage.equals(other.homepage) && version.equals(other.version);
|
return homepage.equals(other.homepage) && version.equals(other.version);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,9 +225,7 @@ public class Release {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof Documentation)) return false;
|
if (!(obj instanceof Documentation other)) return false;
|
||||||
|
|
||||||
var other = (Documentation) obj;
|
|
||||||
return homepage.equals(other.homepage);
|
return homepage.equals(other.homepage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,9 +256,7 @@ public class Release {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof StandardLibrary)) return false;
|
if (!(obj instanceof StandardLibrary other)) return false;
|
||||||
|
|
||||||
var other = (StandardLibrary) obj;
|
|
||||||
return modules.equals(other.modules);
|
return modules.equals(other.modules);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,21 +75,16 @@ public final class SecurityManagers {
|
|||||||
SecurityManagers::getDefaultTrustLevel;
|
SecurityManagers::getDefaultTrustLevel;
|
||||||
|
|
||||||
private static int getDefaultTrustLevel(URI uri) {
|
private static int getDefaultTrustLevel(URI uri) {
|
||||||
switch (uri.getScheme()) {
|
return switch (uri.getScheme()) {
|
||||||
case "repl":
|
case "repl" -> 40;
|
||||||
return 40;
|
case "file" -> uri.getHost() == null ? 30 : 10;
|
||||||
case "file":
|
case "jar" ->
|
||||||
return uri.getHost() == null ? 30 : 10;
|
// use trust level of embedded URL
|
||||||
case "jar":
|
getDefaultTrustLevel(URI.create(uri.toString().substring(4)));
|
||||||
// use trust level of embedded URL
|
case "modulepath" -> 20;
|
||||||
return getDefaultTrustLevel(URI.create(uri.toString().substring(4)));
|
case "pkl" -> 0;
|
||||||
case "modulepath":
|
default -> 10;
|
||||||
return 20;
|
};
|
||||||
case "pkl":
|
|
||||||
return 0;
|
|
||||||
default:
|
|
||||||
return 10;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -105,10 +105,7 @@ public final class StackFrame {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof StackFrame)) return false;
|
if (!(obj instanceof StackFrame other)) return false;
|
||||||
|
|
||||||
var other = (StackFrame) obj;
|
|
||||||
|
|
||||||
if (startLine != other.startLine) return false;
|
if (startLine != other.startLine) return false;
|
||||||
if (startColumn != other.startColumn) return false;
|
if (startColumn != other.startColumn) return false;
|
||||||
if (endLine != other.endLine) return false;
|
if (endLine != other.endLine) return false;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.pkl.core;
|
package org.pkl.core;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.pkl.core.util.LateInit;
|
import org.pkl.core.util.LateInit;
|
||||||
@@ -22,7 +23,7 @@ import org.pkl.core.util.Nullable;
|
|||||||
|
|
||||||
/** Java representation of a {@code pkl.base#TypeAlias} value. */
|
/** Java representation of a {@code pkl.base#TypeAlias} value. */
|
||||||
public final class TypeAlias extends Member implements Value {
|
public final class TypeAlias extends Member implements Value {
|
||||||
private static final long serialVersionUID = 0L;
|
@Serial private static final long serialVersionUID = 0L;
|
||||||
|
|
||||||
private final String moduleName;
|
private final String moduleName;
|
||||||
private final String qualifiedName;
|
private final String qualifiedName;
|
||||||
|
|||||||
@@ -15,13 +15,13 @@
|
|||||||
*/
|
*/
|
||||||
package org.pkl.core;
|
package org.pkl.core;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import org.pkl.core.util.LateInit;
|
import org.pkl.core.util.LateInit;
|
||||||
|
|
||||||
/** A type parameter of a generic class, type alias, or method. */
|
/** A type parameter of a generic class, type alias, or method. */
|
||||||
public final class TypeParameter implements Serializable {
|
public final class TypeParameter implements Serializable {
|
||||||
|
@Serial private static final long serialVersionUID = 0L;
|
||||||
private static final long serialVersionUID = 0L;
|
|
||||||
|
|
||||||
private final Variance variance;
|
private final Variance variance;
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|||||||
@@ -56,24 +56,24 @@ public interface ValueConverter<T> {
|
|||||||
T convertRegex(Pattern value);
|
T convertRegex(Pattern value);
|
||||||
|
|
||||||
default T convert(Object value) {
|
default T convert(Object value) {
|
||||||
if (value instanceof Value) {
|
if (value instanceof Value v) {
|
||||||
return ((Value) value).accept(this);
|
return (v.accept(this));
|
||||||
} else if (value instanceof String) {
|
} else if (value instanceof String string) {
|
||||||
return convertString((String) value);
|
return convertString(string);
|
||||||
} else if (value instanceof Boolean) {
|
} else if (value instanceof Boolean b) {
|
||||||
return convertBoolean((Boolean) value);
|
return convertBoolean(b);
|
||||||
} else if (value instanceof Long) {
|
} else if (value instanceof Long l) {
|
||||||
return convertInt((Long) value);
|
return convertInt(l);
|
||||||
} else if (value instanceof Double) {
|
} else if (value instanceof Double d) {
|
||||||
return convertFloat((Double) value);
|
return convertFloat(d);
|
||||||
} else if (value instanceof List) {
|
} else if (value instanceof List<?> list) {
|
||||||
return convertList((List<?>) value);
|
return convertList(list);
|
||||||
} else if (value instanceof Set) {
|
} else if (value instanceof Set<?> set) {
|
||||||
return convertSet((Set<?>) value);
|
return convertSet(set);
|
||||||
} else if (value instanceof Map) {
|
} else if (value instanceof Map<?, ?> map) {
|
||||||
return convertMap((Map<?, ?>) value);
|
return convertMap(map);
|
||||||
} else if (value instanceof Pattern) {
|
} else if (value instanceof Pattern pattern) {
|
||||||
return convertRegex((Pattern) value);
|
return convertRegex(pattern);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Cannot convert value with unexpected type: " + value);
|
throw new IllegalArgumentException("Cannot convert value with unexpected type: " + value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,31 +135,24 @@ public final class ValueFormatter {
|
|||||||
for (; i < value.length(); i++) {
|
for (; i < value.length(); i++) {
|
||||||
var ch = value.charAt(i);
|
var ch = value.charAt(i);
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case '\n':
|
case '\n' -> appendable.append(escapeSequence).append('n');
|
||||||
appendable.append(escapeSequence).append('n');
|
case '\r' -> appendable.append(escapeSequence).append('r');
|
||||||
break;
|
case '\t' -> appendable.append(escapeSequence).append('t');
|
||||||
case '\r':
|
case '\\' -> {
|
||||||
appendable.append(escapeSequence).append('r');
|
|
||||||
break;
|
|
||||||
case '\t':
|
|
||||||
appendable.append(escapeSequence).append('t');
|
|
||||||
break;
|
|
||||||
case '\\':
|
|
||||||
if (useCustomStringDelimiters) {
|
if (useCustomStringDelimiters) {
|
||||||
appendable.append(ch);
|
appendable.append(ch);
|
||||||
} else {
|
} else {
|
||||||
appendable.append("\\\\");
|
appendable.append("\\\\");
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case '"':
|
case '"' -> {
|
||||||
if (useCustomStringDelimiters) {
|
if (useCustomStringDelimiters) {
|
||||||
appendable.append(ch);
|
appendable.append(ch);
|
||||||
} else {
|
} else {
|
||||||
appendable.append("\\\"");
|
appendable.append("\\\"");
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
default:
|
default -> appendable.append(ch);
|
||||||
appendable.append(ch);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,27 +170,27 @@ public final class ValueFormatter {
|
|||||||
for (var i = 0; i < value.length(); i++) {
|
for (var i = 0; i < value.length(); i++) {
|
||||||
var ch = value.charAt(i);
|
var ch = value.charAt(i);
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case '\n':
|
case '\n' -> {
|
||||||
appendable.append('\n').append(lineIndent);
|
appendable.append('\n').append(lineIndent);
|
||||||
consecutiveQuotes = 0;
|
consecutiveQuotes = 0;
|
||||||
break;
|
}
|
||||||
case '\r':
|
case '\r' -> {
|
||||||
appendable.append(escapeSequence).append('r');
|
appendable.append(escapeSequence).append('r');
|
||||||
consecutiveQuotes = 0;
|
consecutiveQuotes = 0;
|
||||||
break;
|
}
|
||||||
case '\t':
|
case '\t' -> {
|
||||||
appendable.append(escapeSequence).append('t');
|
appendable.append(escapeSequence).append('t');
|
||||||
consecutiveQuotes = 0;
|
consecutiveQuotes = 0;
|
||||||
break;
|
}
|
||||||
case '\\':
|
case '\\' -> {
|
||||||
if (useCustomStringDelimiters) {
|
if (useCustomStringDelimiters) {
|
||||||
appendable.append(ch);
|
appendable.append(ch);
|
||||||
} else {
|
} else {
|
||||||
appendable.append("\\\\");
|
appendable.append("\\\\");
|
||||||
}
|
}
|
||||||
consecutiveQuotes = 0;
|
consecutiveQuotes = 0;
|
||||||
break;
|
}
|
||||||
case '"':
|
case '"' -> {
|
||||||
if (consecutiveQuotes == 2 && !useCustomStringDelimiters) {
|
if (consecutiveQuotes == 2 && !useCustomStringDelimiters) {
|
||||||
appendable.append("\\\"");
|
appendable.append("\\\"");
|
||||||
consecutiveQuotes = 0;
|
consecutiveQuotes = 0;
|
||||||
@@ -205,10 +198,11 @@ public final class ValueFormatter {
|
|||||||
appendable.append('"');
|
appendable.append('"');
|
||||||
consecutiveQuotes += 1;
|
consecutiveQuotes += 1;
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
default:
|
default -> {
|
||||||
appendable.append(ch);
|
appendable.append(ch);
|
||||||
consecutiveQuotes = 0;
|
consecutiveQuotes = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,12 +266,12 @@ public final class ValueFormatter {
|
|||||||
for (var i = 0; i < value.length(); i++) {
|
for (var i = 0; i < value.length(); i++) {
|
||||||
var ch = value.charAt(i);
|
var ch = value.charAt(i);
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case '\\':
|
case '\\' -> {
|
||||||
currentPoundContext = PoundContext.BACKSLASH;
|
currentPoundContext = PoundContext.BACKSLASH;
|
||||||
currentPoundCountBackslash = 1;
|
currentPoundCountBackslash = 1;
|
||||||
poundCountBackslash = Math.max(poundCountBackslash, currentPoundCountBackslash);
|
poundCountBackslash = Math.max(poundCountBackslash, currentPoundCountBackslash);
|
||||||
break;
|
}
|
||||||
case '"':
|
case '"' -> {
|
||||||
consecutiveQuoteCount += 1;
|
consecutiveQuoteCount += 1;
|
||||||
if (consecutiveQuoteCount < 3) {
|
if (consecutiveQuoteCount < 3) {
|
||||||
currentPoundContext = PoundContext.SINGLELINE_QUOTE;
|
currentPoundContext = PoundContext.SINGLELINE_QUOTE;
|
||||||
@@ -289,34 +283,36 @@ public final class ValueFormatter {
|
|||||||
poundCountMultilineQuote =
|
poundCountMultilineQuote =
|
||||||
Math.max(poundCountMultilineQuote, currentPoundCountMultilineQuote);
|
Math.max(poundCountMultilineQuote, currentPoundCountMultilineQuote);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case '#':
|
case '#' -> {
|
||||||
consecutiveQuoteCount = 0;
|
consecutiveQuoteCount = 0;
|
||||||
switch (currentPoundContext) {
|
switch (currentPoundContext) {
|
||||||
case SINGLELINE_QUOTE:
|
case SINGLELINE_QUOTE -> {
|
||||||
currentPoundCountSingleQuote += 1;
|
currentPoundCountSingleQuote += 1;
|
||||||
poundCountSingleQuote =
|
poundCountSingleQuote =
|
||||||
Math.max(poundCountSingleQuote, currentPoundCountSingleQuote);
|
Math.max(poundCountSingleQuote, currentPoundCountSingleQuote);
|
||||||
break;
|
}
|
||||||
case MULTILINE_QUOTE:
|
case MULTILINE_QUOTE -> {
|
||||||
currentPoundCountMultilineQuote += 1;
|
currentPoundCountMultilineQuote += 1;
|
||||||
poundCountMultilineQuote =
|
poundCountMultilineQuote =
|
||||||
Math.max(poundCountMultilineQuote, currentPoundCountMultilineQuote);
|
Math.max(poundCountMultilineQuote, currentPoundCountMultilineQuote);
|
||||||
break;
|
}
|
||||||
case BACKSLASH:
|
case BACKSLASH -> {
|
||||||
currentPoundCountBackslash += 1;
|
currentPoundCountBackslash += 1;
|
||||||
poundCountBackslash = Math.max(poundCountBackslash, currentPoundCountBackslash);
|
poundCountBackslash = Math.max(poundCountBackslash, currentPoundCountBackslash);
|
||||||
break;
|
}
|
||||||
default:
|
default -> {}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case '\n':
|
case '\n' -> {
|
||||||
isMultiline = true;
|
isMultiline = true;
|
||||||
default:
|
|
||||||
consecutiveQuoteCount = 0;
|
consecutiveQuoteCount = 0;
|
||||||
currentPoundContext = PoundContext.OTHER;
|
currentPoundContext = PoundContext.OTHER;
|
||||||
break;
|
}
|
||||||
|
default -> {
|
||||||
|
consecutiveQuoteCount = 0;
|
||||||
|
currentPoundContext = PoundContext.OTHER;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new StringFacts(
|
return new StringFacts(
|
||||||
|
|||||||
@@ -90,24 +90,24 @@ public interface ValueVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
default void visit(Object value) {
|
default void visit(Object value) {
|
||||||
if (value instanceof Value) {
|
if (value instanceof Value v) {
|
||||||
((Value) value).accept(this);
|
v.accept(this);
|
||||||
} else if (value instanceof String) {
|
} else if (value instanceof String string) {
|
||||||
visitString((String) value);
|
visitString(string);
|
||||||
} else if (value instanceof Boolean) {
|
} else if (value instanceof Boolean b) {
|
||||||
visitBoolean((Boolean) value);
|
visitBoolean(b);
|
||||||
} else if (value instanceof Long) {
|
} else if (value instanceof Long l) {
|
||||||
visitInt((Long) value);
|
visitInt(l);
|
||||||
} else if (value instanceof Double) {
|
} else if (value instanceof Double d) {
|
||||||
visitFloat((Double) value);
|
visitFloat(d);
|
||||||
} else if (value instanceof List) {
|
} else if (value instanceof List<?> list) {
|
||||||
visitList((List<?>) value);
|
visitList(list);
|
||||||
} else if (value instanceof Set) {
|
} else if (value instanceof Set<?> set) {
|
||||||
visitSet((Set<?>) value);
|
visitSet(set);
|
||||||
} else if (value instanceof Map) {
|
} else if (value instanceof Map<?, ?> map) {
|
||||||
visitMap((Map<?, ?>) value);
|
visitMap(map);
|
||||||
} else if (value instanceof Pattern) {
|
} else if (value instanceof Pattern pattern) {
|
||||||
visitRegex((Pattern) value);
|
visitRegex(pattern);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Cannot visit value with unexpected type: " + value);
|
throw new IllegalArgumentException("Cannot visit value with unexpected type: " + value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -194,9 +194,7 @@ public final class Version implements Comparable<Version> {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof Version)) return false;
|
if (!(obj instanceof Version other)) return false;
|
||||||
|
|
||||||
var other = (Version) obj;
|
|
||||||
return major == other.major
|
return major == other.major
|
||||||
&& minor == other.minor
|
&& minor == other.minor
|
||||||
&& patch == other.patch
|
&& patch == other.patch
|
||||||
@@ -210,8 +208,7 @@ public final class Version implements Comparable<Version> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return ""
|
return major
|
||||||
+ major
|
|
||||||
+ "."
|
+ "."
|
||||||
+ minor
|
+ minor
|
||||||
+ "."
|
+ "."
|
||||||
|
|||||||
@@ -75,13 +75,12 @@ final class YamlRenderer implements ValueRenderer {
|
|||||||
@Override
|
@Override
|
||||||
public void renderDocument(Object value) {
|
public void renderDocument(Object value) {
|
||||||
if (isStream) {
|
if (isStream) {
|
||||||
if (!(value instanceof Iterable)) {
|
if (!(value instanceof Iterable<?> iterable)) {
|
||||||
throw new RendererException(
|
throw new RendererException(
|
||||||
String.format(
|
String.format(
|
||||||
"The top-level value of a YAML stream must have type `Collection`, but got type `%s`.",
|
"The top-level value of a YAML stream must have type `Collection`, but got type `%s`.",
|
||||||
value.getClass().getTypeName()));
|
value.getClass().getTypeName()));
|
||||||
}
|
}
|
||||||
var iterable = (Iterable<?>) value;
|
|
||||||
emitter.emit(new StreamStartEvent());
|
emitter.emit(new StreamStartEvent());
|
||||||
for (var elem : iterable) {
|
for (var elem : iterable) {
|
||||||
emitter.emit(new DocumentStartEvent(false, Optional.empty(), Map.of()));
|
emitter.emit(new DocumentStartEvent(false, Optional.empty(), Map.of()));
|
||||||
|
|||||||
@@ -89,7 +89,6 @@ public abstract class MemberNode extends PklRootNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUndefined() {
|
public boolean isUndefined() {
|
||||||
return bodyNode instanceof DefaultPropertyBodyNode
|
return bodyNode instanceof DefaultPropertyBodyNode propBodyNode && propBodyNode.isUndefined();
|
||||||
&& ((DefaultPropertyBodyNode) bodyNode).isUndefined();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,26 +161,19 @@ public final class VmModifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String toString(int modifier) {
|
public static String toString(int modifier) {
|
||||||
switch (modifier) {
|
return switch (modifier) {
|
||||||
case ABSTRACT:
|
case ABSTRACT -> "abstract";
|
||||||
return "abstract";
|
case OPEN -> "open";
|
||||||
case OPEN:
|
case LOCAL -> "local";
|
||||||
return "open";
|
case HIDDEN -> "hidden";
|
||||||
case LOCAL:
|
case EXTERNAL -> "external";
|
||||||
return "local";
|
case FIXED -> "fixed";
|
||||||
case HIDDEN:
|
case CONST -> "const";
|
||||||
return "hidden";
|
default ->
|
||||||
case EXTERNAL:
|
throw new VmExceptionBuilder()
|
||||||
return "external";
|
.bug("Cannot convert internal modifier `%s` to a string.", toString(modifier))
|
||||||
case FIXED:
|
.build();
|
||||||
return "fixed";
|
};
|
||||||
case CONST:
|
|
||||||
return "const";
|
|
||||||
default:
|
|
||||||
throw new VmExceptionBuilder()
|
|
||||||
.bug("Cannot convert internal modifier `%s` to a string.", toString(modifier))
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static VmSet getMirrors(int modifiers, boolean isClass) {
|
public static VmSet getMirrors(int modifiers, boolean isClass) {
|
||||||
|
|||||||
@@ -43,17 +43,10 @@ public abstract class AbstractAstBuilder<T> extends PklParserBaseVisitor<T> {
|
|||||||
var builder = new StringBuilder();
|
var builder = new StringBuilder();
|
||||||
for (var token : ts) {
|
for (var token : ts) {
|
||||||
switch (token.getType()) {
|
switch (token.getType()) {
|
||||||
case PklLexer.SLCharacters:
|
case PklLexer.SLCharacters -> builder.append(token.getText());
|
||||||
builder.append(token.getText());
|
case PklLexer.SLCharacterEscape -> builder.append(parseCharacterEscapeSequence(token));
|
||||||
break;
|
case PklLexer.SLUnicodeEscape -> builder.appendCodePoint(parseUnicodeEscapeSequence(token));
|
||||||
case PklLexer.SLCharacterEscape:
|
default -> throw exceptionBuilder().unreachableCode().build();
|
||||||
builder.append(parseCharacterEscapeSequence(token));
|
|
||||||
break;
|
|
||||||
case PklLexer.SLUnicodeEscape:
|
|
||||||
builder.appendCodePoint(parseUnicodeEscapeSequence(token));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw exceptionBuilder().unreachableCode().build();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,23 +81,19 @@ public abstract class AbstractAstBuilder<T> extends PklParserBaseVisitor<T> {
|
|||||||
var text = token.getText();
|
var text = token.getText();
|
||||||
var lastChar = text.charAt(text.length() - 1);
|
var lastChar = text.charAt(text.length() - 1);
|
||||||
|
|
||||||
switch (lastChar) {
|
return switch (lastChar) {
|
||||||
case 'n':
|
case 'n' -> "\n";
|
||||||
return "\n";
|
case 'r' -> "\r";
|
||||||
case 'r':
|
case 't' -> "\t";
|
||||||
return "\r";
|
case '"' -> "\"";
|
||||||
case 't':
|
case '\\' -> "\\";
|
||||||
return "\t";
|
default ->
|
||||||
case '"':
|
throw exceptionBuilder()
|
||||||
return "\"";
|
.evalError(
|
||||||
case '\\':
|
"invalidCharacterEscapeSequence", text, text.substring(0, text.length() - 1))
|
||||||
return "\\";
|
.withSourceSection(createSourceSection(token))
|
||||||
default:
|
.build();
|
||||||
throw exceptionBuilder()
|
};
|
||||||
.evalError("invalidCharacterEscapeSequence", text, text.substring(0, text.length() - 1))
|
|
||||||
.withSourceSection(createSourceSection(token))
|
|
||||||
.build();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final SourceSection createSourceSection(ParserRuleContext ctx) {
|
protected final SourceSection createSourceSection(ParserRuleContext ctx) {
|
||||||
|
|||||||
@@ -461,7 +461,7 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
|
|
||||||
while (parent instanceof IfExprContext
|
while (parent instanceof IfExprContext
|
||||||
|| parent instanceof TraceExprContext
|
|| parent instanceof TraceExprContext
|
||||||
|| parent instanceof LetExprContext && ((LetExprContext) parent).r == child) {
|
|| parent instanceof LetExprContext letExpr && letExpr.r == child) {
|
||||||
|
|
||||||
if (parent instanceof LetExprContext) {
|
if (parent instanceof LetExprContext) {
|
||||||
assert scope != null;
|
assert scope != null;
|
||||||
@@ -481,7 +481,7 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
scope.getName(),
|
scope.getName(),
|
||||||
levelsUp == 0 ? new GetOwnerNode() : new GetEnclosingOwnerNode(levelsUp));
|
levelsUp == 0 ? new GetOwnerNode() : new GetEnclosingOwnerNode(levelsUp));
|
||||||
} else if (parent instanceof ObjectElementContext
|
} else if (parent instanceof ObjectElementContext
|
||||||
|| parent instanceof ObjectEntryContext && ((ObjectEntryContext) parent).v == child) {
|
|| parent instanceof ObjectEntryContext objectEntry && objectEntry.v == child) {
|
||||||
inferredParentNode =
|
inferredParentNode =
|
||||||
ApplyVmFunction1NodeGen.create(
|
ApplyVmFunction1NodeGen.create(
|
||||||
ReadPropertyNodeGen.create(
|
ReadPropertyNodeGen.create(
|
||||||
@@ -506,7 +506,7 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
language,
|
language,
|
||||||
scopeName,
|
scopeName,
|
||||||
levelsUp == 0 ? new GetOwnerNode() : new GetEnclosingOwnerNode(levelsUp));
|
levelsUp == 0 ? new GetOwnerNode() : new GetEnclosingOwnerNode(levelsUp));
|
||||||
} else if (parent instanceof LetExprContext && ((LetExprContext) parent).l == child) {
|
} else if (parent instanceof LetExprContext letExpr && letExpr.l == child) {
|
||||||
// TODO (unclear how to infer type now that let-expression is implemented as lambda
|
// TODO (unclear how to infer type now that let-expression is implemented as lambda
|
||||||
// invocation)
|
// invocation)
|
||||||
throw exceptionBuilder()
|
throw exceptionBuilder()
|
||||||
@@ -604,8 +604,8 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
if (VmModifier.isExternal(modifiers)) {
|
if (VmModifier.isExternal(modifiers)) {
|
||||||
bodyNode =
|
bodyNode =
|
||||||
externalMemberRegistry.getPropertyBody(scope.getQualifiedName(), headerSection);
|
externalMemberRegistry.getPropertyBody(scope.getQualifiedName(), headerSection);
|
||||||
if (bodyNode instanceof LanguageAwareNode) {
|
if (bodyNode instanceof LanguageAwareNode languageAwareNode) {
|
||||||
((LanguageAwareNode) bodyNode).initLanguage(language);
|
languageAwareNode.initLanguage(language);
|
||||||
}
|
}
|
||||||
} else if (VmModifier.isAbstract(modifiers)) {
|
} else if (VmModifier.isAbstract(modifiers)) {
|
||||||
bodyNode =
|
bodyNode =
|
||||||
@@ -1046,15 +1046,12 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
|
|
||||||
checkSpaceSeparatedObjectMembers(ctx);
|
checkSpaceSeparatedObjectMembers(ctx);
|
||||||
for (var memberCtx : objectMemberCtx) {
|
for (var memberCtx : objectMemberCtx) {
|
||||||
if (memberCtx instanceof ObjectPropertyContext) {
|
if (memberCtx instanceof ObjectPropertyContext propertyCtx) {
|
||||||
var propertyCtx = (ObjectPropertyContext) memberCtx;
|
|
||||||
addProperty(members, doVisitObjectProperty(propertyCtx));
|
addProperty(members, doVisitObjectProperty(propertyCtx));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memberCtx instanceof ObjectEntryContext) {
|
if (memberCtx instanceof ObjectEntryContext entryCtx) {
|
||||||
var entryCtx = (ObjectEntryContext) memberCtx;
|
|
||||||
|
|
||||||
var keyAndValue = doVisitObjectEntry(entryCtx);
|
var keyAndValue = doVisitObjectEntry(entryCtx);
|
||||||
var key = keyAndValue.first;
|
var key = keyAndValue.first;
|
||||||
keyNodes.add(key);
|
keyNodes.add(key);
|
||||||
@@ -1063,15 +1060,13 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memberCtx instanceof ObjectElementContext) {
|
if (memberCtx instanceof ObjectElementContext elementCtx) {
|
||||||
var elementCtx = (ObjectElementContext) memberCtx;
|
|
||||||
var element = doVisitObjectElement(elementCtx);
|
var element = doVisitObjectElement(elementCtx);
|
||||||
elements.add(element);
|
elements.add(element);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memberCtx instanceof ObjectMethodContext) {
|
if (memberCtx instanceof ObjectMethodContext methodCtx) {
|
||||||
var methodCtx = (ObjectMethodContext) memberCtx;
|
|
||||||
addProperty(members, doVisitObjectMethod(methodCtx));
|
addProperty(members, doVisitObjectMethod(methodCtx));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -1191,8 +1186,8 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
null,
|
null,
|
||||||
scope.getQualifiedName());
|
scope.getQualifiedName());
|
||||||
|
|
||||||
if (elementNode instanceof ConstantNode) {
|
if (elementNode instanceof ConstantNode constantNode) {
|
||||||
member.initConstantValue((ConstantNode) elementNode);
|
member.initConstantValue(constantNode);
|
||||||
} else {
|
} else {
|
||||||
member.initMemberNode(
|
member.initMemberNode(
|
||||||
new UntypedObjectMemberNode(
|
new UntypedObjectMemberNode(
|
||||||
@@ -1248,8 +1243,8 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
|
|
||||||
if (valueCtx != null) { // ["key"] = value
|
if (valueCtx != null) { // ["key"] = value
|
||||||
var valueNode = visitExpr(valueCtx);
|
var valueNode = visitExpr(valueCtx);
|
||||||
if (valueNode instanceof ConstantNode) {
|
if (valueNode instanceof ConstantNode constantNode) {
|
||||||
member.initConstantValue((ConstantNode) valueNode);
|
member.initConstantValue(constantNode);
|
||||||
} else {
|
} else {
|
||||||
member.initMemberNode(
|
member.initMemberNode(
|
||||||
new UntypedObjectMemberNode(
|
new UntypedObjectMemberNode(
|
||||||
@@ -1297,24 +1292,16 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer visitModifier(ModifierContext ctx) {
|
public Integer visitModifier(ModifierContext ctx) {
|
||||||
switch (ctx.t.getType()) {
|
return switch (ctx.t.getType()) {
|
||||||
case PklLexer.EXTERNAL:
|
case PklLexer.EXTERNAL -> VmModifier.EXTERNAL;
|
||||||
return VmModifier.EXTERNAL;
|
case PklLexer.ABSTRACT -> VmModifier.ABSTRACT;
|
||||||
case PklLexer.ABSTRACT:
|
case PklLexer.OPEN -> VmModifier.OPEN;
|
||||||
return VmModifier.ABSTRACT;
|
case PklLexer.LOCAL -> VmModifier.LOCAL;
|
||||||
case PklLexer.OPEN:
|
case PklLexer.HIDDEN_ -> VmModifier.HIDDEN;
|
||||||
return VmModifier.OPEN;
|
case PklLexer.FIXED -> VmModifier.FIXED;
|
||||||
case PklLexer.LOCAL:
|
case PklLexer.CONST -> VmModifier.CONST;
|
||||||
return VmModifier.LOCAL;
|
default -> throw createUnexpectedTokenError(ctx.t);
|
||||||
case PklLexer.HIDDEN_:
|
};
|
||||||
return VmModifier.HIDDEN;
|
|
||||||
case PklLexer.FIXED:
|
|
||||||
return VmModifier.FIXED;
|
|
||||||
case PklLexer.CONST:
|
|
||||||
return VmModifier.CONST;
|
|
||||||
default:
|
|
||||||
throw createUnexpectedTokenError(ctx.t);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private int doVisitModifiers(
|
private int doVisitModifiers(
|
||||||
@@ -1410,8 +1397,8 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
bodyNode =
|
bodyNode =
|
||||||
externalMemberRegistry.getFunctionBody(
|
externalMemberRegistry.getFunctionBody(
|
||||||
scope.getQualifiedName(), headerSection, paramCount);
|
scope.getQualifiedName(), headerSection, paramCount);
|
||||||
if (bodyNode instanceof LanguageAwareNode) {
|
if (bodyNode instanceof LanguageAwareNode languageAwareNode) {
|
||||||
((LanguageAwareNode) bodyNode).initLanguage(language);
|
languageAwareNode.initLanguage(language);
|
||||||
}
|
}
|
||||||
} else if (VmModifier.isAbstract(modifiers)) {
|
} else if (VmModifier.isAbstract(modifiers)) {
|
||||||
bodyNode =
|
bodyNode =
|
||||||
@@ -1730,33 +1717,30 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visitComparisonExpr(ComparisonExprContext ctx) {
|
public Object visitComparisonExpr(ComparisonExprContext ctx) {
|
||||||
switch (ctx.t.getType()) {
|
return switch (ctx.t.getType()) {
|
||||||
case PklLexer.LT:
|
case PklLexer.LT ->
|
||||||
return LessThanNodeGen.create(createSourceSection(ctx), visitExpr(ctx.l), visitExpr(ctx.r));
|
LessThanNodeGen.create(createSourceSection(ctx), visitExpr(ctx.l), visitExpr(ctx.r));
|
||||||
case PklLexer.GT:
|
case PklLexer.GT ->
|
||||||
return GreaterThanNodeGen.create(
|
GreaterThanNodeGen.create(createSourceSection(ctx), visitExpr(ctx.l), visitExpr(ctx.r));
|
||||||
createSourceSection(ctx), visitExpr(ctx.l), visitExpr(ctx.r));
|
case PklLexer.LTE ->
|
||||||
case PklLexer.LTE:
|
LessThanOrEqualNodeGen.create(
|
||||||
return LessThanOrEqualNodeGen.create(
|
createSourceSection(ctx), visitExpr(ctx.l), visitExpr(ctx.r));
|
||||||
createSourceSection(ctx), visitExpr(ctx.l), visitExpr(ctx.r));
|
case PklLexer.GTE ->
|
||||||
case PklLexer.GTE:
|
GreaterThanOrEqualNodeGen.create(
|
||||||
return GreaterThanOrEqualNodeGen.create(
|
createSourceSection(ctx), visitExpr(ctx.l), visitExpr(ctx.r));
|
||||||
createSourceSection(ctx), visitExpr(ctx.l), visitExpr(ctx.r));
|
default -> throw createUnexpectedTokenError(ctx.t);
|
||||||
default:
|
};
|
||||||
throw createUnexpectedTokenError(ctx.t);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object visitEqualityExpr(EqualityExprContext ctx) {
|
public Object visitEqualityExpr(EqualityExprContext ctx) {
|
||||||
switch (ctx.t.getType()) {
|
return switch (ctx.t.getType()) {
|
||||||
case PklLexer.EQUAL:
|
case PklLexer.EQUAL ->
|
||||||
return EqualNodeGen.create(createSourceSection(ctx), visitExpr(ctx.l), visitExpr(ctx.r));
|
EqualNodeGen.create(createSourceSection(ctx), visitExpr(ctx.l), visitExpr(ctx.r));
|
||||||
case PklLexer.NOT_EQUAL:
|
case PklLexer.NOT_EQUAL ->
|
||||||
return NotEqualNodeGen.create(createSourceSection(ctx), visitExpr(ctx.l), visitExpr(ctx.r));
|
NotEqualNodeGen.create(createSourceSection(ctx), visitExpr(ctx.l), visitExpr(ctx.r));
|
||||||
default:
|
default -> throw createUnexpectedTokenError(ctx.t);
|
||||||
throw createUnexpectedTokenError(ctx.t);
|
};
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1879,34 +1863,30 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ExpressionNode visitAdditiveExpr(AdditiveExprContext ctx) {
|
public ExpressionNode visitAdditiveExpr(AdditiveExprContext ctx) {
|
||||||
switch (ctx.t.getType()) {
|
return switch (ctx.t.getType()) {
|
||||||
case PklLexer.PLUS:
|
case PklLexer.PLUS ->
|
||||||
return AdditionNodeGen.create(createSourceSection(ctx), visitExpr(ctx.l), visitExpr(ctx.r));
|
AdditionNodeGen.create(createSourceSection(ctx), visitExpr(ctx.l), visitExpr(ctx.r));
|
||||||
case PklLexer.MINUS:
|
case PklLexer.MINUS ->
|
||||||
return SubtractionNodeGen.create(
|
SubtractionNodeGen.create(createSourceSection(ctx), visitExpr(ctx.l), visitExpr(ctx.r));
|
||||||
createSourceSection(ctx), visitExpr(ctx.l), visitExpr(ctx.r));
|
default -> throw createUnexpectedTokenError(ctx.t);
|
||||||
default:
|
};
|
||||||
throw createUnexpectedTokenError(ctx.t);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ExpressionNode visitMultiplicativeExpr(MultiplicativeExprContext ctx) {
|
public ExpressionNode visitMultiplicativeExpr(MultiplicativeExprContext ctx) {
|
||||||
switch (ctx.t.getType()) {
|
return switch (ctx.t.getType()) {
|
||||||
case PklLexer.STAR:
|
case PklLexer.STAR ->
|
||||||
return MultiplicationNodeGen.create(
|
MultiplicationNodeGen.create(
|
||||||
createSourceSection(ctx), visitExpr(ctx.l), visitExpr(ctx.r));
|
createSourceSection(ctx), visitExpr(ctx.l), visitExpr(ctx.r));
|
||||||
case PklLexer.DIV:
|
case PklLexer.DIV ->
|
||||||
return DivisionNodeGen.create(createSourceSection(ctx), visitExpr(ctx.l), visitExpr(ctx.r));
|
DivisionNodeGen.create(createSourceSection(ctx), visitExpr(ctx.l), visitExpr(ctx.r));
|
||||||
case PklLexer.INT_DIV:
|
case PklLexer.INT_DIV ->
|
||||||
return TruncatingDivisionNodeGen.create(
|
TruncatingDivisionNodeGen.create(
|
||||||
createSourceSection(ctx), visitExpr(ctx.l), visitExpr(ctx.r));
|
createSourceSection(ctx), visitExpr(ctx.l), visitExpr(ctx.r));
|
||||||
case PklLexer.MOD:
|
case PklLexer.MOD ->
|
||||||
return RemainderNodeGen.create(
|
RemainderNodeGen.create(createSourceSection(ctx), visitExpr(ctx.l), visitExpr(ctx.r));
|
||||||
createSourceSection(ctx), visitExpr(ctx.l), visitExpr(ctx.r));
|
default -> throw createUnexpectedTokenError(ctx.t);
|
||||||
default:
|
};
|
||||||
throw createUnexpectedTokenError(ctx.t);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1951,14 +1931,12 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
if (receiver instanceof OuterNode) {
|
if (receiver instanceof OuterNode) {
|
||||||
var outerScope = getParentLexicalScope();
|
var outerScope = getParentLexicalScope();
|
||||||
if (outerScope != null) {
|
if (outerScope != null) {
|
||||||
switch (constLevel) {
|
needsConst =
|
||||||
case MODULE:
|
switch (constLevel) {
|
||||||
needsConst = outerScope.isModuleScope();
|
case MODULE -> outerScope.isModuleScope();
|
||||||
break;
|
case ALL -> outerScope.getConstLevel() != ConstLevel.ALL;
|
||||||
case ALL:
|
case NONE -> false;
|
||||||
needsConst = outerScope.getConstLevel() != ConstLevel.ALL;
|
};
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (receiver instanceof GetModuleNode) {
|
} else if (receiver instanceof GetModuleNode) {
|
||||||
needsConst = constLevel != ConstLevel.NONE;
|
needsConst = constLevel != ConstLevel.NONE;
|
||||||
@@ -1998,13 +1976,12 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
var propertyName = toIdentifier(ctx.Identifier());
|
var propertyName = toIdentifier(ctx.Identifier());
|
||||||
var receiver = visitExpr(ctx.expr());
|
var receiver = visitExpr(ctx.expr());
|
||||||
|
|
||||||
if (receiver instanceof IntLiteralNode) {
|
if (receiver instanceof IntLiteralNode intLiteralNode) {
|
||||||
var durationUnit = VmDuration.toUnit(propertyName);
|
var durationUnit = VmDuration.toUnit(propertyName);
|
||||||
if (durationUnit != null) {
|
if (durationUnit != null) {
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
return new ConstantValueNode(
|
return new ConstantValueNode(
|
||||||
sourceSection,
|
sourceSection, new VmDuration(intLiteralNode.executeInt(null), durationUnit));
|
||||||
new VmDuration(((IntLiteralNode) receiver).executeInt(null), durationUnit));
|
|
||||||
}
|
}
|
||||||
var dataSizeUnit = VmDataSize.toUnit(propertyName);
|
var dataSizeUnit = VmDataSize.toUnit(propertyName);
|
||||||
if (dataSizeUnit != null) {
|
if (dataSizeUnit != null) {
|
||||||
@@ -2015,13 +1992,12 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (receiver instanceof FloatLiteralNode) {
|
if (receiver instanceof FloatLiteralNode floatLiteralNode) {
|
||||||
var durationUnit = VmDuration.toUnit(propertyName);
|
var durationUnit = VmDuration.toUnit(propertyName);
|
||||||
if (durationUnit != null) {
|
if (durationUnit != null) {
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
return new ConstantValueNode(
|
return new ConstantValueNode(
|
||||||
sourceSection,
|
sourceSection, new VmDuration(floatLiteralNode.executeFloat(null), durationUnit));
|
||||||
new VmDuration(((FloatLiteralNode) receiver).executeFloat(null), durationUnit));
|
|
||||||
}
|
}
|
||||||
var dataSizeUnit = VmDataSize.toUnit(propertyName);
|
var dataSizeUnit = VmDataSize.toUnit(propertyName);
|
||||||
if (dataSizeUnit != null) {
|
if (dataSizeUnit != null) {
|
||||||
@@ -2037,14 +2013,12 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
if (receiver instanceof OuterNode) {
|
if (receiver instanceof OuterNode) {
|
||||||
var outerScope = getParentLexicalScope();
|
var outerScope = getParentLexicalScope();
|
||||||
if (outerScope != null) {
|
if (outerScope != null) {
|
||||||
switch (constLevel) {
|
needsConst =
|
||||||
case MODULE:
|
switch (constLevel) {
|
||||||
needsConst = outerScope.isModuleScope();
|
case MODULE -> outerScope.isModuleScope();
|
||||||
break;
|
case ALL -> outerScope.getConstLevel() != ConstLevel.ALL;
|
||||||
case ALL:
|
case NONE -> false;
|
||||||
needsConst = outerScope.getConstLevel() != ConstLevel.ALL;
|
};
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (receiver instanceof GetModuleNode) {
|
} else if (receiver instanceof GetModuleNode) {
|
||||||
needsConst = constLevel != ConstLevel.NONE;
|
needsConst = constLevel != ConstLevel.NONE;
|
||||||
@@ -2482,13 +2456,12 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
|
|
||||||
while (!list.isEmpty()) {
|
while (!list.isEmpty()) {
|
||||||
var current = list.removeFirst();
|
var current = list.removeFirst();
|
||||||
if (current instanceof UnionTypeContext) {
|
if (current instanceof UnionTypeContext unionType) {
|
||||||
var union = (UnionTypeContext) current;
|
list.addFirst(unionType.r);
|
||||||
list.addFirst(union.r);
|
list.addFirst(unionType.l);
|
||||||
list.addFirst(union.l);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (current instanceof DefaultUnionTypeContext) {
|
if (current instanceof DefaultUnionTypeContext defaultUnionType) {
|
||||||
if (defaultIndex == -1) {
|
if (defaultIndex == -1) {
|
||||||
defaultIndex = index;
|
defaultIndex = index;
|
||||||
} else {
|
} else {
|
||||||
@@ -2497,10 +2470,9 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
.withSourceSection(createSourceSection(ctx))
|
.withSourceSection(createSourceSection(ctx))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
var def = (DefaultUnionTypeContext) current;
|
|
||||||
isUnionOfStringLiterals =
|
isUnionOfStringLiterals =
|
||||||
isUnionOfStringLiterals && def.type() instanceof StringLiteralTypeContext;
|
isUnionOfStringLiterals && defaultUnionType.type() instanceof StringLiteralTypeContext;
|
||||||
collector.add(def.type());
|
collector.add(defaultUnionType.type());
|
||||||
} else {
|
} else {
|
||||||
isUnionOfStringLiterals =
|
isUnionOfStringLiterals =
|
||||||
isUnionOfStringLiterals && current instanceof StringLiteralTypeContext;
|
isUnionOfStringLiterals && current instanceof StringLiteralTypeContext;
|
||||||
@@ -2735,7 +2707,7 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var tokens = lastPart.ts;
|
var tokens = lastPart.ts;
|
||||||
assert tokens.size() >= 1;
|
assert !tokens.isEmpty();
|
||||||
var lastToken = tokens.get(tokens.size() - 1);
|
var lastToken = tokens.get(tokens.size() - 1);
|
||||||
|
|
||||||
if (lastToken.getType() == PklLexer.MLNewline) {
|
if (lastToken.getType() == PklLexer.MLNewline) {
|
||||||
@@ -2759,13 +2731,8 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
var text = token.getText();
|
var text = token.getText();
|
||||||
|
|
||||||
for (var i = 0; i < text.length(); i++) {
|
for (var i = 0; i < text.length(); i++) {
|
||||||
switch (text.charAt(i)) {
|
var ch = text.charAt(i);
|
||||||
case ' ':
|
if (ch != ' ' && ch != '\t') return false;
|
||||||
case '\t':
|
|
||||||
continue;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -2775,12 +2742,9 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
var text = token.getText();
|
var text = token.getText();
|
||||||
|
|
||||||
for (var i = 0; i < text.length(); i++) {
|
for (var i = 0; i < text.length(); i++) {
|
||||||
switch (text.charAt(i)) {
|
var ch = text.charAt(i);
|
||||||
case ' ':
|
if (ch != ' ' && ch != '\t') {
|
||||||
case '\t':
|
return text.substring(0, i);
|
||||||
continue;
|
|
||||||
default:
|
|
||||||
return text.substring(0, i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2829,11 +2793,11 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
Token token = tokens.get(i);
|
Token token = tokens.get(i);
|
||||||
|
|
||||||
switch (token.getType()) {
|
switch (token.getType()) {
|
||||||
case PklLexer.MLNewline:
|
case PklLexer.MLNewline -> {
|
||||||
builder.append('\n');
|
builder.append('\n');
|
||||||
isLineStart = true;
|
isLineStart = true;
|
||||||
break;
|
}
|
||||||
case PklLexer.MLCharacters:
|
case PklLexer.MLCharacters -> {
|
||||||
var text = token.getText();
|
var text = token.getText();
|
||||||
if (isLineStart) {
|
if (isLineStart) {
|
||||||
if (text.startsWith(commonIndent)) {
|
if (text.startsWith(commonIndent)) {
|
||||||
@@ -2852,8 +2816,8 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
builder.append(text);
|
builder.append(text);
|
||||||
}
|
}
|
||||||
isLineStart = false;
|
isLineStart = false;
|
||||||
break;
|
}
|
||||||
case PklLexer.MLCharacterEscape:
|
case PklLexer.MLCharacterEscape -> {
|
||||||
if (isLineStart && !commonIndent.isEmpty()) {
|
if (isLineStart && !commonIndent.isEmpty()) {
|
||||||
throw exceptionBuilder()
|
throw exceptionBuilder()
|
||||||
.evalError("stringIndentationMustMatchLastLine")
|
.evalError("stringIndentationMustMatchLastLine")
|
||||||
@@ -2862,8 +2826,8 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
}
|
}
|
||||||
builder.append(parseCharacterEscapeSequence(token));
|
builder.append(parseCharacterEscapeSequence(token));
|
||||||
isLineStart = false;
|
isLineStart = false;
|
||||||
break;
|
}
|
||||||
case PklLexer.MLUnicodeEscape:
|
case PklLexer.MLUnicodeEscape -> {
|
||||||
if (isLineStart && !commonIndent.isEmpty()) {
|
if (isLineStart && !commonIndent.isEmpty()) {
|
||||||
throw exceptionBuilder()
|
throw exceptionBuilder()
|
||||||
.evalError("stringIndentationMustMatchLastLine")
|
.evalError("stringIndentationMustMatchLastLine")
|
||||||
@@ -2872,9 +2836,8 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
}
|
}
|
||||||
builder.appendCodePoint(parseUnicodeEscapeSequence(token));
|
builder.appendCodePoint(parseUnicodeEscapeSequence(token));
|
||||||
isLineStart = false;
|
isLineStart = false;
|
||||||
break;
|
}
|
||||||
default:
|
default -> throw exceptionBuilder().unreachableCode().build();
|
||||||
throw exceptionBuilder().unreachableCode().build();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2883,26 +2846,28 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
|
|
||||||
private ResolveDeclaredTypeNode doVisitTypeName(QualifiedIdentifierContext ctx) {
|
private ResolveDeclaredTypeNode doVisitTypeName(QualifiedIdentifierContext ctx) {
|
||||||
var tokens = ctx.ts;
|
var tokens = ctx.ts;
|
||||||
switch (tokens.size()) {
|
return switch (tokens.size()) {
|
||||||
case 1:
|
case 1 -> {
|
||||||
var token = tokens.get(0);
|
var token = tokens.get(0);
|
||||||
return new ResolveSimpleDeclaredTypeNode(
|
yield new ResolveSimpleDeclaredTypeNode(
|
||||||
createSourceSection(token), Identifier.get(token.getText()), isBaseModule);
|
createSourceSection(token), Identifier.get(token.getText()), isBaseModule);
|
||||||
case 2:
|
}
|
||||||
|
case 2 -> {
|
||||||
var token1 = tokens.get(0);
|
var token1 = tokens.get(0);
|
||||||
var token2 = tokens.get(1);
|
var token2 = tokens.get(1);
|
||||||
return new ResolveQualifiedDeclaredTypeNode(
|
yield new ResolveQualifiedDeclaredTypeNode(
|
||||||
createSourceSection(ctx),
|
createSourceSection(ctx),
|
||||||
createSourceSection(token1),
|
createSourceSection(token1),
|
||||||
createSourceSection(token2),
|
createSourceSection(token2),
|
||||||
Identifier.localProperty(token1.getText()),
|
Identifier.localProperty(token1.getText()),
|
||||||
Identifier.get(token2.getText()));
|
Identifier.get(token2.getText()));
|
||||||
default:
|
}
|
||||||
throw exceptionBuilder()
|
default ->
|
||||||
.evalError("invalidTypeName", ctx.getText())
|
throw exceptionBuilder()
|
||||||
.withSourceSection(createSourceSection(ctx))
|
.evalError("invalidTypeName", ctx.getText())
|
||||||
.build();
|
.withSourceSection(createSourceSection(ctx))
|
||||||
}
|
.build();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkCommaSeparatedElements(
|
private void checkCommaSeparatedElements(
|
||||||
@@ -2918,11 +2883,11 @@ public final class AstBuilder extends AbstractAstBuilder<Object> {
|
|||||||
var index = elements.indexOf(child);
|
var index = elements.indexOf(child);
|
||||||
if (index > 0) { // 0 rather than -1 because no separator is expected before first element
|
if (index > 0) { // 0 rather than -1 because no separator is expected before first element
|
||||||
assert prevChild != null;
|
assert prevChild != null;
|
||||||
if (!(prevChild instanceof TerminalNode)
|
if (!(prevChild instanceof TerminalNode terminalNode)
|
||||||
|| !separators.contains(((TerminalNode) prevChild).getSymbol())) {
|
|| !separators.contains(terminalNode.getSymbol())) {
|
||||||
var prevToken =
|
var prevToken =
|
||||||
prevChild instanceof TerminalNode
|
prevChild instanceof TerminalNode terminalNode
|
||||||
? ((TerminalNode) prevChild).getSymbol()
|
? terminalNode.getSymbol()
|
||||||
: ((ParserRuleContext) prevChild).getStop();
|
: ((ParserRuleContext) prevChild).getStop();
|
||||||
throw exceptionBuilder()
|
throw exceptionBuilder()
|
||||||
.evalError("missingCommaSeparator")
|
.evalError("missingCommaSeparator")
|
||||||
|
|||||||
@@ -93,11 +93,10 @@ public class ImportsAndReadsParser
|
|||||||
@Override
|
@Override
|
||||||
public List<Pair<String, SourceSection>> visitReadExpr(ReadExprContext ctx) {
|
public List<Pair<String, SourceSection>> visitReadExpr(ReadExprContext ctx) {
|
||||||
var expr = ctx.expr();
|
var expr = ctx.expr();
|
||||||
if (!(expr instanceof SingleLineStringLiteralContext)) {
|
if (!(expr instanceof SingleLineStringLiteralContext slCtx)) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
// best-effort approach; only collect read expressions that are string constants.
|
// best-effort approach; only collect read expressions that are string constants.
|
||||||
var slCtx = (SingleLineStringLiteralContext) expr;
|
|
||||||
var singleParts = slCtx.singleLineStringPart();
|
var singleParts = slCtx.singleLineStringPart();
|
||||||
String importString;
|
String importString;
|
||||||
if (singleParts.isEmpty()) {
|
if (singleParts.isEmpty()) {
|
||||||
|
|||||||
@@ -284,8 +284,8 @@ public final class SymbolTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getNextEntryName(@Nullable ExpressionNode keyNode) {
|
private String getNextEntryName(@Nullable ExpressionNode keyNode) {
|
||||||
if (keyNode instanceof ConstantNode) {
|
if (keyNode instanceof ConstantNode constantNode) {
|
||||||
var value = ((ConstantNode) keyNode).getValue();
|
var value = constantNode.getValue();
|
||||||
if (value instanceof String) {
|
if (value instanceof String) {
|
||||||
return "[\"" + value + "\"]";
|
return "[\"" + value + "\"]";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ public abstract class EqualNode extends ExpressionNode {
|
|||||||
|
|
||||||
protected static @Nullable Class<? extends VmValue> getVmValueJavaClassOrNull(Object value) {
|
protected static @Nullable Class<? extends VmValue> getVmValueJavaClassOrNull(Object value) {
|
||||||
// OK to perform slow cast here (not a guard)
|
// OK to perform slow cast here (not a guard)
|
||||||
return value instanceof VmValue ? ((VmValue) value).getClass() : null;
|
return value instanceof VmValue vmValue ? vmValue.getClass() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// covers all remaining cases (else it's a bug)
|
// covers all remaining cases (else it's a bug)
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ public abstract class NotEqualNode extends ExpressionNode {
|
|||||||
|
|
||||||
protected static @Nullable Class<? extends VmValue> getVmValueJavaClassOrNull(Object value) {
|
protected static @Nullable Class<? extends VmValue> getVmValueJavaClassOrNull(Object value) {
|
||||||
// OK to perform slow cast here (not a guard)
|
// OK to perform slow cast here (not a guard)
|
||||||
return value instanceof VmValue ? ((VmValue) value).getClass() : null;
|
return value instanceof VmValue vmValue ? vmValue.getClass() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// covers all remaining cases (else it's a bug)
|
// covers all remaining cases (else it's a bug)
|
||||||
|
|||||||
+1
-1
@@ -161,7 +161,7 @@ public abstract class GeneratorObjectLiteralNode extends ObjectLiteralNode {
|
|||||||
@TruffleBoundary
|
@TruffleBoundary
|
||||||
protected void fallback(Object parent) {
|
protected void fallback(Object parent) {
|
||||||
VmUtils.checkIsInstantiable(
|
VmUtils.checkIsInstantiable(
|
||||||
parent instanceof VmClass ? (VmClass) parent : VmUtils.getClass(parent), getParentNode());
|
parent instanceof VmClass vmClass ? vmClass : VmUtils.getClass(parent), getParentNode());
|
||||||
|
|
||||||
throw exceptionBuilder().unreachableCode().build();
|
throw exceptionBuilder().unreachableCode().build();
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -167,7 +167,7 @@ public abstract class GeneratorSpreadNode extends GeneratorMemberNode {
|
|||||||
.evalError("cannotIterateOverThisValue", VmUtils.getClass(iterable))
|
.evalError("cannotIterateOverThisValue", VmUtils.getClass(iterable))
|
||||||
.withLocation(iterableNode)
|
.withLocation(iterableNode)
|
||||||
.withProgramValue("Value", iterable);
|
.withProgramValue("Value", iterable);
|
||||||
if (iterable instanceof VmObject && ((VmObject) iterable).isTyped()) {
|
if (iterable instanceof VmObject vmObject && vmObject.isTyped()) {
|
||||||
builder.withHint(
|
builder.withHint(
|
||||||
"`Typed` values are not iterable. If you mean to spread its members, convert it to `Dynamic` using `toDynamic()`.");
|
"`Typed` values are not iterable. If you mean to spread its members, convert it to `Dynamic` using `toDynamic()`.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ public final class AmendFunctionNode extends PklNode {
|
|||||||
System.arraycopy(frameArguments, 2, arguments, 2, frameArguments.length - 2);
|
System.arraycopy(frameArguments, 2, arguments, 2, frameArguments.length - 2);
|
||||||
|
|
||||||
var valueToAmend = callNode.call(functionToAmend.getCallTarget(), arguments);
|
var valueToAmend = callNode.call(functionToAmend.getCallTarget(), arguments);
|
||||||
if (!(valueToAmend instanceof VmFunction)) {
|
if (!(valueToAmend instanceof VmFunction newFunctionToAmend)) {
|
||||||
var materializedFrame = context.frame;
|
var materializedFrame = context.frame;
|
||||||
if (materializedFrame != null) {
|
if (materializedFrame != null) {
|
||||||
for (var slot : parameterSlots) {
|
for (var slot : parameterSlots) {
|
||||||
@@ -199,7 +199,6 @@ public final class AmendFunctionNode extends PklNode {
|
|||||||
return amendObjectNode.executeGeneric(frame);
|
return amendObjectNode.executeGeneric(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
var newFunctionToAmend = (VmFunction) valueToAmend;
|
|
||||||
return currentFunction.copy(
|
return currentFunction.copy(
|
||||||
newFunctionToAmend.getParameterCount(),
|
newFunctionToAmend.getParameterCount(),
|
||||||
nextFunctionRootNode,
|
nextFunctionRootNode,
|
||||||
|
|||||||
+1
-1
@@ -70,7 +70,7 @@ public abstract class SpecializedObjectLiteralNode extends ObjectLiteralNode {
|
|||||||
@TruffleBoundary
|
@TruffleBoundary
|
||||||
@Idempotent
|
@Idempotent
|
||||||
protected boolean checkIsValidTypedAmendment(Object parent) {
|
protected boolean checkIsValidTypedAmendment(Object parent) {
|
||||||
var parentClass = parent instanceof VmClass ? (VmClass) parent : VmUtils.getClass(parent);
|
var parentClass = parent instanceof VmClass vmClass ? vmClass : VmUtils.getClass(parent);
|
||||||
VmUtils.checkIsInstantiable(parentClass, getParentNode());
|
VmUtils.checkIsInstantiable(parentClass, getParentNode());
|
||||||
|
|
||||||
for (var member : EconomicMaps.getValues(members)) {
|
for (var member : EconomicMaps.getValues(members)) {
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ public abstract class ReadPropertyNode extends ExpressionNode {
|
|||||||
|
|
||||||
protected static @Nullable Class<? extends VmObjectLike> getVmObjectSubclassOrNull(Object value) {
|
protected static @Nullable Class<? extends VmObjectLike> getVmObjectSubclassOrNull(Object value) {
|
||||||
// OK to perform slow cast here (not a guard)
|
// OK to perform slow cast here (not a guard)
|
||||||
return value instanceof VmObjectLike ? ((VmObjectLike) value).getClass() : null;
|
return value instanceof VmObjectLike objectLike ? objectLike.getClass() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ClassProperty resolveProperty(Object value) {
|
protected ClassProperty resolveProperty(Object value) {
|
||||||
|
|||||||
@@ -168,15 +168,12 @@ public final class ResolveMethodNode extends ExpressionNode {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var memberIsOutsideConstScope = levelsUp > constDepth;
|
var memberIsOutsideConstScope = levelsUp > constDepth;
|
||||||
var invalid = false;
|
var invalid =
|
||||||
switch (constLevel) {
|
switch (constLevel) {
|
||||||
case ALL:
|
case ALL -> memberIsOutsideConstScope && !method.isConst();
|
||||||
invalid = memberIsOutsideConstScope && !method.isConst();
|
case MODULE -> currOwner.isModuleObject() && !method.isConst();
|
||||||
break;
|
default -> false;
|
||||||
case MODULE:
|
};
|
||||||
invalid = currOwner.isModuleObject() && !method.isConst();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (invalid) {
|
if (invalid) {
|
||||||
throw exceptionBuilder().evalError("methodMustBeConst", methodName.toString()).build();
|
throw exceptionBuilder().evalError("methodMustBeConst", methodName.toString()).build();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -226,15 +226,12 @@ public final class ResolveVariableNode extends ExpressionNode {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var memberIsOutsideConstScope = levelsUp > constDepth;
|
var memberIsOutsideConstScope = levelsUp > constDepth;
|
||||||
var invalid = false;
|
var invalid =
|
||||||
switch (constLevel) {
|
switch (constLevel) {
|
||||||
case ALL:
|
case ALL -> memberIsOutsideConstScope && !member.isConst();
|
||||||
invalid = memberIsOutsideConstScope && !member.isConst();
|
case MODULE -> currOwner.isModuleObject() && !member.isConst();
|
||||||
break;
|
default -> false;
|
||||||
case MODULE:
|
};
|
||||||
invalid = currOwner.isModuleObject() && !member.isConst();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (invalid) {
|
if (invalid) {
|
||||||
throw exceptionBuilder().evalError("propertyMustBeConst", variableName.toString()).build();
|
throw exceptionBuilder().evalError("propertyMustBeConst", variableName.toString()).build();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,9 +40,9 @@ public final class TraceNode extends ExpressionNode {
|
|||||||
|
|
||||||
@TruffleBoundary
|
@TruffleBoundary
|
||||||
private void doTrace(Object value, VmContext context) {
|
private void doTrace(Object value, VmContext context) {
|
||||||
if (value instanceof VmObjectLike) {
|
if (value instanceof VmObjectLike objectLike) {
|
||||||
try {
|
try {
|
||||||
((VmObjectLike) value).force(true, true);
|
objectLike.force(true, true);
|
||||||
} catch (VmException ignored) {
|
} catch (VmException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public abstract class ApplyVmFunction1Node extends ExpressionNode {
|
|||||||
|
|
||||||
public final boolean executeBoolean(VmFunction function, Object arg1) {
|
public final boolean executeBoolean(VmFunction function, Object arg1) {
|
||||||
var result = execute(function, arg1);
|
var result = execute(function, arg1);
|
||||||
if (result instanceof Boolean) return (Boolean) result;
|
if (result instanceof Boolean b) return b;
|
||||||
|
|
||||||
CompilerDirectives.transferToInterpreter();
|
CompilerDirectives.transferToInterpreter();
|
||||||
throw exceptionBuilder().typeMismatch(result, BaseModule.getBooleanClass()).build();
|
throw exceptionBuilder().typeMismatch(result, BaseModule.getBooleanClass()).build();
|
||||||
@@ -47,7 +47,7 @@ public abstract class ApplyVmFunction1Node extends ExpressionNode {
|
|||||||
|
|
||||||
public final String executeString(VmFunction function, Object arg1) {
|
public final String executeString(VmFunction function, Object arg1) {
|
||||||
var result = execute(function, arg1);
|
var result = execute(function, arg1);
|
||||||
if (result instanceof String) return (String) result;
|
if (result instanceof String string) return string;
|
||||||
|
|
||||||
CompilerDirectives.transferToInterpreter();
|
CompilerDirectives.transferToInterpreter();
|
||||||
throw exceptionBuilder().typeMismatch(result, BaseModule.getStringClass()).build();
|
throw exceptionBuilder().typeMismatch(result, BaseModule.getStringClass()).build();
|
||||||
@@ -55,7 +55,7 @@ public abstract class ApplyVmFunction1Node extends ExpressionNode {
|
|||||||
|
|
||||||
public final Long executeInt(VmFunction function, Object arg1) {
|
public final Long executeInt(VmFunction function, Object arg1) {
|
||||||
var result = execute(function, arg1);
|
var result = execute(function, arg1);
|
||||||
if (result instanceof Long) return (Long) result;
|
if (result instanceof Long l) return l;
|
||||||
|
|
||||||
CompilerDirectives.transferToInterpreter();
|
CompilerDirectives.transferToInterpreter();
|
||||||
throw exceptionBuilder().typeMismatch(result, BaseModule.getIntClass()).build();
|
throw exceptionBuilder().typeMismatch(result, BaseModule.getIntClass()).build();
|
||||||
@@ -63,7 +63,7 @@ public abstract class ApplyVmFunction1Node extends ExpressionNode {
|
|||||||
|
|
||||||
public final VmCollection executeCollection(VmFunction function, Object arg1) {
|
public final VmCollection executeCollection(VmFunction function, Object arg1) {
|
||||||
var result = execute(function, arg1);
|
var result = execute(function, arg1);
|
||||||
if (result instanceof VmCollection) return (VmCollection) result;
|
if (result instanceof VmCollection collection) return collection;
|
||||||
|
|
||||||
CompilerDirectives.transferToInterpreter();
|
CompilerDirectives.transferToInterpreter();
|
||||||
throw exceptionBuilder().typeMismatch(result, BaseModule.getCollectionClass()).build();
|
throw exceptionBuilder().typeMismatch(result, BaseModule.getCollectionClass()).build();
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public abstract class ApplyVmFunction2Node extends PklNode {
|
|||||||
|
|
||||||
public final boolean executeBoolean(VmFunction function, Object arg1, Object arg2) {
|
public final boolean executeBoolean(VmFunction function, Object arg1, Object arg2) {
|
||||||
var result = execute(function, arg1, arg2);
|
var result = execute(function, arg1, arg2);
|
||||||
if (result instanceof Boolean) return (Boolean) result;
|
if (result instanceof Boolean b) return b;
|
||||||
|
|
||||||
CompilerDirectives.transferToInterpreter();
|
CompilerDirectives.transferToInterpreter();
|
||||||
throw exceptionBuilder().typeMismatch(result, BaseModule.getBooleanClass()).build();
|
throw exceptionBuilder().typeMismatch(result, BaseModule.getBooleanClass()).build();
|
||||||
@@ -37,7 +37,7 @@ public abstract class ApplyVmFunction2Node extends PklNode {
|
|||||||
|
|
||||||
public final VmCollection executeCollection(VmFunction function, Object arg1, Object arg2) {
|
public final VmCollection executeCollection(VmFunction function, Object arg1, Object arg2) {
|
||||||
var result = execute(function, arg1, arg2);
|
var result = execute(function, arg1, arg2);
|
||||||
if (result instanceof VmCollection) return (VmCollection) result;
|
if (result instanceof VmCollection collection) return collection;
|
||||||
|
|
||||||
CompilerDirectives.transferToInterpreter();
|
CompilerDirectives.transferToInterpreter();
|
||||||
throw exceptionBuilder().typeMismatch(result, BaseModule.getCollectionClass()).build();
|
throw exceptionBuilder().typeMismatch(result, BaseModule.getCollectionClass()).build();
|
||||||
@@ -45,7 +45,7 @@ public abstract class ApplyVmFunction2Node extends PklNode {
|
|||||||
|
|
||||||
public final VmMap executeMap(VmFunction function, Object arg1, Object arg2) {
|
public final VmMap executeMap(VmFunction function, Object arg1, Object arg2) {
|
||||||
var result = execute(function, arg1, arg2);
|
var result = execute(function, arg1, arg2);
|
||||||
if (result instanceof VmMap) return (VmMap) result;
|
if (result instanceof VmMap map) return map;
|
||||||
|
|
||||||
CompilerDirectives.transferToInterpreter();
|
CompilerDirectives.transferToInterpreter();
|
||||||
throw exceptionBuilder().typeMismatch(result, BaseModule.getMapClass()).build();
|
throw exceptionBuilder().typeMismatch(result, BaseModule.getMapClass()).build();
|
||||||
@@ -53,7 +53,7 @@ public abstract class ApplyVmFunction2Node extends PklNode {
|
|||||||
|
|
||||||
public final Long executeInt(VmFunction function, Object arg1, Object arg2) {
|
public final Long executeInt(VmFunction function, Object arg1, Object arg2) {
|
||||||
var result = execute(function, arg1, arg2);
|
var result = execute(function, arg1, arg2);
|
||||||
if (result instanceof Long) return (Long) result;
|
if (result instanceof Long l) return l;
|
||||||
|
|
||||||
CompilerDirectives.transferToInterpreter();
|
CompilerDirectives.transferToInterpreter();
|
||||||
throw exceptionBuilder().typeMismatch(result, BaseModule.getIntClass()).build();
|
throw exceptionBuilder().typeMismatch(result, BaseModule.getIntClass()).build();
|
||||||
@@ -61,9 +61,7 @@ public abstract class ApplyVmFunction2Node extends PklNode {
|
|||||||
|
|
||||||
public final VmPair executePair(VmFunction function, Object arg1, Object arg2) {
|
public final VmPair executePair(VmFunction function, Object arg1, Object arg2) {
|
||||||
var result = execute(function, arg1, arg2);
|
var result = execute(function, arg1, arg2);
|
||||||
if (result instanceof VmPair) {
|
if (result instanceof VmPair pair) return pair;
|
||||||
return (VmPair) result;
|
|
||||||
}
|
|
||||||
|
|
||||||
CompilerDirectives.transferToInterpreter();
|
CompilerDirectives.transferToInterpreter();
|
||||||
throw exceptionBuilder().typeMismatch(result, BaseModule.getPairClass()).build();
|
throw exceptionBuilder().typeMismatch(result, BaseModule.getPairClass()).build();
|
||||||
|
|||||||
@@ -54,8 +54,8 @@ public final class ModuleNode extends PklRootNode {
|
|||||||
@Override
|
@Override
|
||||||
public Object execute(VirtualFrame frame) {
|
public Object execute(VirtualFrame frame) {
|
||||||
var module = executeBody(frame, moduleNode);
|
var module = executeBody(frame, moduleNode);
|
||||||
if (module instanceof VmClass) {
|
if (module instanceof VmClass vmClass) {
|
||||||
return ((VmClass) module).getPrototype();
|
return vmClass.getPrototype();
|
||||||
}
|
}
|
||||||
|
|
||||||
assert module instanceof VmTyped;
|
assert module instanceof VmTyped;
|
||||||
|
|||||||
@@ -106,8 +106,8 @@ public final class ObjectMember extends Member {
|
|||||||
|
|
||||||
public @Nullable Object getLocalPropertyDefaultValue() {
|
public @Nullable Object getLocalPropertyDefaultValue() {
|
||||||
assert isProp() && isLocal();
|
assert isProp() && isLocal();
|
||||||
return getMemberNode() instanceof LocalTypedPropertyNode
|
return getMemberNode() instanceof LocalTypedPropertyNode propertyNode
|
||||||
? ((LocalTypedPropertyNode) getMemberNode()).getDefaultValue()
|
? propertyNode.getDefaultValue()
|
||||||
: VmDynamic.empty();
|
: VmDynamic.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ public final class UnresolvedMethodNode extends UnresolvedClassMemberNode {
|
|||||||
for (var annotation : annotations) {
|
for (var annotation : annotations) {
|
||||||
if (annotation.getVmClass() == BaseModule.getDeprecatedClass()) {
|
if (annotation.getVmClass() == BaseModule.getDeprecatedClass()) {
|
||||||
var messageObj = VmUtils.readMemberOrNull(annotation, Identifier.MESSAGE);
|
var messageObj = VmUtils.readMemberOrNull(annotation, Identifier.MESSAGE);
|
||||||
deprecation = messageObj instanceof String ? (String) messageObj : "";
|
deprecation = messageObj instanceof String string ? string : "";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -310,7 +310,7 @@ public abstract class TypeNode extends PklNode {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(VirtualFrame frame, Object value) {
|
public void execute(VirtualFrame frame, Object value) {
|
||||||
if (value instanceof VmTyped && ((VmTyped) value).getVmClass() == moduleClass) return;
|
if (value instanceof VmTyped typed && typed.getVmClass() == moduleClass) return;
|
||||||
|
|
||||||
throw typeMismatch(value, moduleClass);
|
throw typeMismatch(value, moduleClass);
|
||||||
}
|
}
|
||||||
@@ -346,8 +346,8 @@ public abstract class TypeNode extends PklNode {
|
|||||||
public void execute(VirtualFrame frame, Object value) {
|
public void execute(VirtualFrame frame, Object value) {
|
||||||
var moduleClass = ((VmTyped) getModuleNode.executeGeneric(frame)).getVmClass();
|
var moduleClass = ((VmTyped) getModuleNode.executeGeneric(frame)).getVmClass();
|
||||||
|
|
||||||
if (value instanceof VmTyped) {
|
if (value instanceof VmTyped typed) {
|
||||||
var valueClass = ((VmTyped) value).getVmClass();
|
var valueClass = typed.getVmClass();
|
||||||
if (moduleClass.isSuperclassOf(valueClass)) return;
|
if (moduleClass.isSuperclassOf(valueClass)) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -465,7 +465,7 @@ public abstract class TypeNode extends PklNode {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(VirtualFrame frame, Object value) {
|
public void execute(VirtualFrame frame, Object value) {
|
||||||
if (value instanceof VmValue && clazz == ((VmValue) value).getVmClass()) return;
|
if (value instanceof VmValue vmValue && clazz == vmValue.getVmClass()) return;
|
||||||
|
|
||||||
throw typeMismatch(value, clazz);
|
throw typeMismatch(value, clazz);
|
||||||
}
|
}
|
||||||
@@ -1431,9 +1431,8 @@ public abstract class TypeNode extends PklNode {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(VirtualFrame frame, Object value) {
|
public void execute(VirtualFrame frame, Object value) {
|
||||||
if (value instanceof Long) {
|
if (value instanceof Long l) {
|
||||||
var v = (long) value;
|
if ((l & mask) == l) return;
|
||||||
if ((v & mask) == v) return;
|
|
||||||
|
|
||||||
throw new VmTypeMismatchException.Constraint(typeAlias.getConstraintSection(), value);
|
throw new VmTypeMismatchException.Constraint(typeAlias.getConstraintSection(), value);
|
||||||
}
|
}
|
||||||
@@ -1465,9 +1464,8 @@ public abstract class TypeNode extends PklNode {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(VirtualFrame frame, Object value) {
|
public void execute(VirtualFrame frame, Object value) {
|
||||||
if (value instanceof Long) {
|
if (value instanceof Long l) {
|
||||||
var v = (long) value;
|
if (l == l.byteValue()) return;
|
||||||
if (v == (byte) v) return;
|
|
||||||
|
|
||||||
throw new VmTypeMismatchException.Constraint(
|
throw new VmTypeMismatchException.Constraint(
|
||||||
BaseModule.getInt8TypeAlias().getConstraintSection(), value);
|
BaseModule.getInt8TypeAlias().getConstraintSection(), value);
|
||||||
@@ -1500,9 +1498,8 @@ public abstract class TypeNode extends PklNode {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(VirtualFrame frame, Object value) {
|
public void execute(VirtualFrame frame, Object value) {
|
||||||
if (value instanceof Long) {
|
if (value instanceof Long l) {
|
||||||
var v = (long) value;
|
if (l == l.shortValue()) return;
|
||||||
if (v == (short) v) return;
|
|
||||||
|
|
||||||
throw new VmTypeMismatchException.Constraint(
|
throw new VmTypeMismatchException.Constraint(
|
||||||
BaseModule.getInt16TypeAlias().getConstraintSection(), value);
|
BaseModule.getInt16TypeAlias().getConstraintSection(), value);
|
||||||
@@ -1535,9 +1532,8 @@ public abstract class TypeNode extends PklNode {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(VirtualFrame frame, Object value) {
|
public void execute(VirtualFrame frame, Object value) {
|
||||||
if (value instanceof Long) {
|
if (value instanceof Long l) {
|
||||||
var v = (long) value;
|
if (l == l.intValue()) return;
|
||||||
if (v == (int) v) return;
|
|
||||||
|
|
||||||
throw new VmTypeMismatchException.Constraint(
|
throw new VmTypeMismatchException.Constraint(
|
||||||
BaseModule.getInt32TypeAlias().getConstraintSection(), value);
|
BaseModule.getInt32TypeAlias().getConstraintSection(), value);
|
||||||
@@ -1836,21 +1832,21 @@ public abstract class TypeNode extends PklNode {
|
|||||||
@Override
|
@Override
|
||||||
public void executeAndSet(VirtualFrame frame, Object value) {
|
public void executeAndSet(VirtualFrame frame, Object value) {
|
||||||
var kind = frame.getFrameDescriptor().getSlotKind(slot);
|
var kind = frame.getFrameDescriptor().getSlotKind(slot);
|
||||||
if (value instanceof Long) {
|
if (value instanceof Long l) {
|
||||||
if (kind == FrameSlotKind.Double || kind == FrameSlotKind.Object) {
|
if (kind == FrameSlotKind.Double || kind == FrameSlotKind.Object) {
|
||||||
frame.getFrameDescriptor().setSlotKind(slot, FrameSlotKind.Object);
|
frame.getFrameDescriptor().setSlotKind(slot, FrameSlotKind.Object);
|
||||||
frame.setObject(slot, value);
|
frame.setObject(slot, l);
|
||||||
} else {
|
} else {
|
||||||
frame.getFrameDescriptor().setSlotKind(slot, FrameSlotKind.Long);
|
frame.getFrameDescriptor().setSlotKind(slot, FrameSlotKind.Long);
|
||||||
frame.setLong(slot, (long) value);
|
frame.setLong(slot, l);
|
||||||
}
|
}
|
||||||
} else if (value instanceof Double) {
|
} else if (value instanceof Double d) {
|
||||||
if (kind == FrameSlotKind.Long || kind == FrameSlotKind.Object) {
|
if (kind == FrameSlotKind.Long || kind == FrameSlotKind.Object) {
|
||||||
frame.getFrameDescriptor().setSlotKind(slot, FrameSlotKind.Object);
|
frame.getFrameDescriptor().setSlotKind(slot, FrameSlotKind.Object);
|
||||||
frame.setObject(slot, value);
|
frame.setObject(slot, d);
|
||||||
} else {
|
} else {
|
||||||
frame.getFrameDescriptor().setSlotKind(slot, FrameSlotKind.Double);
|
frame.getFrameDescriptor().setSlotKind(slot, FrameSlotKind.Double);
|
||||||
frame.setDouble(slot, (double) value);
|
frame.setDouble(slot, d);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw typeMismatch(value, BaseModule.getNumberClass());
|
throw typeMismatch(value, BaseModule.getNumberClass());
|
||||||
|
|||||||
@@ -133,9 +133,7 @@ public abstract class UnresolvedTypeNode extends PklNode {
|
|||||||
|
|
||||||
var type = resolveTypeNode.executeGeneric(frame);
|
var type = resolveTypeNode.executeGeneric(frame);
|
||||||
|
|
||||||
if (type instanceof VmClass) {
|
if (type instanceof VmClass clazz) {
|
||||||
VmClass clazz = (VmClass) type;
|
|
||||||
|
|
||||||
// Note: FinalClassTypeNode and NonFinalClassTypeNode assume that
|
// Note: FinalClassTypeNode and NonFinalClassTypeNode assume that
|
||||||
// String/Boolean/Int/Float and their supertypes are handled separately.
|
// String/Boolean/Int/Float and their supertypes are handled separately.
|
||||||
|
|
||||||
@@ -163,9 +161,7 @@ public abstract class UnresolvedTypeNode extends PklNode {
|
|||||||
return TypeNode.forClass(sourceSection, clazz);
|
return TypeNode.forClass(sourceSection, clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type instanceof VmTypeAlias) {
|
if (type instanceof VmTypeAlias alias) {
|
||||||
var alias = (VmTypeAlias) type;
|
|
||||||
|
|
||||||
if (alias.getModuleName().equals("pkl.base")) {
|
if (alias.getModuleName().equals("pkl.base")) {
|
||||||
switch (alias.getSimpleName()) {
|
switch (alias.getSimpleName()) {
|
||||||
case "NonNull":
|
case "NonNull":
|
||||||
@@ -219,8 +215,7 @@ public abstract class UnresolvedTypeNode extends PklNode {
|
|||||||
|
|
||||||
var baseType = resolveTypeNode.executeGeneric(frame);
|
var baseType = resolveTypeNode.executeGeneric(frame);
|
||||||
|
|
||||||
if (baseType instanceof VmClass) {
|
if (baseType instanceof VmClass clazz) {
|
||||||
var clazz = (VmClass) baseType;
|
|
||||||
checkNumberOfTypeArguments(clazz);
|
checkNumberOfTypeArguments(clazz);
|
||||||
|
|
||||||
if (clazz.isCollectionClass()) {
|
if (clazz.isCollectionClass()) {
|
||||||
@@ -289,8 +284,7 @@ public abstract class UnresolvedTypeNode extends PklNode {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (baseType instanceof VmTypeAlias) {
|
if (baseType instanceof VmTypeAlias typeAlias) {
|
||||||
var typeAlias = (VmTypeAlias) baseType;
|
|
||||||
var argLength = typeArgumentNodes.length;
|
var argLength = typeArgumentNodes.length;
|
||||||
var resolvedTypeArgumentNodes = new TypeNode[argLength];
|
var resolvedTypeArgumentNodes = new TypeNode[argLength];
|
||||||
for (var i = 0; i < argLength; i++) {
|
for (var i = 0; i < argLength; i++) {
|
||||||
|
|||||||
@@ -66,9 +66,9 @@ public abstract class VmTypeMismatchException extends ControlFlowException {
|
|||||||
public void describe(StringBuilder builder, String indent) {
|
public void describe(StringBuilder builder, String indent) {
|
||||||
String renderedType;
|
String renderedType;
|
||||||
var valueFormatter = ValueFormatter.basic();
|
var valueFormatter = ValueFormatter.basic();
|
||||||
if (expectedType instanceof String) {
|
if (expectedType instanceof String string) {
|
||||||
// string literal type
|
// string literal type
|
||||||
renderedType = valueFormatter.formatStringValue((String) expectedType, "");
|
renderedType = valueFormatter.formatStringValue(string, "");
|
||||||
} else if (expectedType instanceof Set) {
|
} else if (expectedType instanceof Set) {
|
||||||
// union of string literal types
|
// union of string literal types
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@@ -90,10 +90,9 @@ public abstract class VmTypeMismatchException extends ControlFlowException {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// give better error than "expected foo.Bar, but got foo.Bar" in case of naming conflict
|
// give better error than "expected foo.Bar, but got foo.Bar" in case of naming conflict
|
||||||
if (actualValue instanceof VmTyped && expectedType instanceof VmClass) {
|
if (actualValue instanceof VmTyped actualObj
|
||||||
var actualObj = (VmTyped) actualValue;
|
&& expectedType instanceof VmClass expectedClass) {
|
||||||
var actualClass = actualObj.getVmClass();
|
var actualClass = actualObj.getVmClass();
|
||||||
var expectedClass = (VmClass) expectedType;
|
|
||||||
if (actualClass.getQualifiedName().equals(expectedClass.getQualifiedName())) {
|
if (actualClass.getQualifiedName().equals(expectedClass.getQualifiedName())) {
|
||||||
var actualModuleUri = actualClass.getModule().getModuleInfo().getModuleKey().getUri();
|
var actualModuleUri = actualClass.getModule().getModuleInfo().getModuleKey().getUri();
|
||||||
var expectedModuleUri = expectedClass.getModule().getModuleInfo().getModuleKey().getUri();
|
var expectedModuleUri = expectedClass.getModule().getModuleInfo().getModuleKey().getUri();
|
||||||
|
|||||||
@@ -90,14 +90,9 @@ final class RequestRewritingClient implements HttpClient {
|
|||||||
publisher -> builder.method(method, publisher),
|
publisher -> builder.method(method, publisher),
|
||||||
() -> {
|
() -> {
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case "GET":
|
case "GET" -> builder.GET();
|
||||||
builder.GET();
|
case "DELETE" -> builder.DELETE();
|
||||||
break;
|
default -> builder.method(method, HttpRequest.BodyPublishers.noBody());
|
||||||
case "DELETE":
|
|
||||||
builder.DELETE();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
builder.method(method, HttpRequest.BodyPublishers.noBody());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -673,11 +673,11 @@ public final class ModuleKeys {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private @Nullable Path getLocalPath(Dependency dependency) {
|
private @Nullable Path getLocalPath(Dependency dependency) {
|
||||||
if (!(dependency instanceof LocalDependency)) {
|
if (!(dependency instanceof LocalDependency localDependency)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return ((LocalDependency) dependency)
|
return localDependency.resolveAssetPath(
|
||||||
.resolveAssetPath(getProjectDepsResolver().getProjectDir(), packageAssetUri);
|
getProjectDepsResolver().getProjectDir(), packageAssetUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -64,15 +64,10 @@ public class PathElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object obj) {
|
||||||
if (this == o) {
|
if (this == obj) return true;
|
||||||
return true;
|
if (!(obj instanceof PathElement other)) return false;
|
||||||
}
|
return isDirectory == other.isDirectory && name.equals(other.name);
|
||||||
if (!(o instanceof PathElement)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
PathElement that = (PathElement) o;
|
|
||||||
return isDirectory == that.isDirectory && name.equals(that.name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -107,20 +107,18 @@ public class DependencyMetadata {
|
|||||||
|
|
||||||
private static Map<String, RemoteDependency> parseDependencies(Object deps)
|
private static Map<String, RemoteDependency> parseDependencies(Object deps)
|
||||||
throws JsonParseException {
|
throws JsonParseException {
|
||||||
if (!(deps instanceof JsObject)) {
|
if (!(deps instanceof JsObject dependencies)) {
|
||||||
throw new FormatException("object", deps.getClass());
|
throw new FormatException("object", deps.getClass());
|
||||||
}
|
}
|
||||||
var dependencies = (JsObject) deps;
|
|
||||||
var ret = new HashMap<String, RemoteDependency>(dependencies.size());
|
var ret = new HashMap<String, RemoteDependency>(dependencies.size());
|
||||||
for (var key : dependencies.keySet()) {
|
for (var key : dependencies.keySet()) {
|
||||||
var remoteDependency =
|
var remoteDependency =
|
||||||
dependencies.get(
|
dependencies.get(
|
||||||
key,
|
key,
|
||||||
(dep) -> {
|
(dep) -> {
|
||||||
if (!(dep instanceof JsObject)) {
|
if (!(dep instanceof JsObject obj)) {
|
||||||
throw new FormatException("object", dep.getClass());
|
throw new FormatException("object", dep.getClass());
|
||||||
}
|
}
|
||||||
var obj = (JsObject) dep;
|
|
||||||
var checksums = obj.get("checksums", DependencyMetadata::parseChecksums);
|
var checksums = obj.get("checksums", DependencyMetadata::parseChecksums);
|
||||||
var packageUri = obj.get("uri", PackageUtils::parsePackageUriWithoutChecksums);
|
var packageUri = obj.get("uri", PackageUtils::parsePackageUriWithoutChecksums);
|
||||||
return new RemoteDependency(packageUri, checksums);
|
return new RemoteDependency(packageUri, checksums);
|
||||||
@@ -131,25 +129,23 @@ public class DependencyMetadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Checksums parseChecksums(Object obj) throws JsonParseException {
|
public static Checksums parseChecksums(Object obj) throws JsonParseException {
|
||||||
if (!(obj instanceof JsObject)) {
|
if (!(obj instanceof JsObject jsObj)) {
|
||||||
throw new FormatException("object", obj.getClass());
|
throw new FormatException("object", obj.getClass());
|
||||||
}
|
}
|
||||||
var jsObj = (JsObject) obj;
|
|
||||||
var sha256 = jsObj.getString("sha256");
|
var sha256 = jsObj.getString("sha256");
|
||||||
return new Checksums(sha256);
|
return new Checksums(sha256);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> parseAuthors(Object obj) throws JsonParseException {
|
public static List<String> parseAuthors(Object obj) throws JsonParseException {
|
||||||
if (!(obj instanceof JsArray)) {
|
if (!(obj instanceof JsArray arr)) {
|
||||||
throw new FormatException("array", obj.getClass());
|
throw new FormatException("array", obj.getClass());
|
||||||
}
|
}
|
||||||
var arr = (JsArray) obj;
|
|
||||||
var ret = new ArrayList<String>(arr.size());
|
var ret = new ArrayList<String>(arr.size());
|
||||||
for (var elem : arr) {
|
for (var elem : arr) {
|
||||||
if (!(elem instanceof String)) {
|
if (!(elem instanceof String string)) {
|
||||||
throw new FormatException("string", elem.getClass());
|
throw new FormatException("string", elem.getClass());
|
||||||
}
|
}
|
||||||
ret.add((String) elem);
|
ret.add(string);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ import org.pkl.core.util.json.Json.JsonParseException;
|
|||||||
public class PackageUtils {
|
public class PackageUtils {
|
||||||
public static PackageUri parsePackageUriWithoutChecksums(Object obj)
|
public static PackageUri parsePackageUriWithoutChecksums(Object obj)
|
||||||
throws JsonParseException, URISyntaxException {
|
throws JsonParseException, URISyntaxException {
|
||||||
if (!(obj instanceof String)) {
|
if (!(obj instanceof String string)) {
|
||||||
throw new FormatException("string", obj.getClass());
|
throw new FormatException("string", obj.getClass());
|
||||||
}
|
}
|
||||||
var packageUri = new PackageUri((String) obj);
|
var packageUri = new PackageUri(string);
|
||||||
checkHasNoChecksumComponent(packageUri);
|
checkHasNoChecksumComponent(packageUri);
|
||||||
return packageUri;
|
return packageUri;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,48 +125,48 @@ public class Parser {
|
|||||||
|
|
||||||
var curr = ctx.getChild(ctx.getChildCount() - 2); // last child before EOF
|
var curr = ctx.getChild(ctx.getChildCount() - 2); // last child before EOF
|
||||||
while (curr.getChildCount() > 0) {
|
while (curr.getChildCount() > 0) {
|
||||||
if (curr instanceof ClassBodyContext) {
|
if (curr instanceof ClassBodyContext classBody) {
|
||||||
if (((ClassBodyContext) curr).err == null) throw incompleteInput(curr, "}");
|
if (classBody.err == null) throw incompleteInput(curr, "}");
|
||||||
else return;
|
else return;
|
||||||
}
|
}
|
||||||
if (curr instanceof ParameterListContext) {
|
if (curr instanceof ParameterListContext parameterList) {
|
||||||
if (((ParameterListContext) curr).err == null) throw incompleteInput(curr, ")");
|
if (parameterList.err == null) throw incompleteInput(curr, ")");
|
||||||
else return;
|
else return;
|
||||||
}
|
}
|
||||||
if (curr instanceof ArgumentListContext) {
|
if (curr instanceof ArgumentListContext argumentList) {
|
||||||
if (((ArgumentListContext) curr).err == null) throw incompleteInput(curr, ")");
|
if (argumentList.err == null) throw incompleteInput(curr, ")");
|
||||||
else return;
|
else return;
|
||||||
}
|
}
|
||||||
if (curr instanceof TypeParameterListContext) {
|
if (curr instanceof TypeParameterListContext typeParameterList) {
|
||||||
if (((TypeParameterListContext) curr).err == null) throw incompleteInput(curr, ">");
|
if (typeParameterList.err == null) throw incompleteInput(curr, ">");
|
||||||
else return;
|
else return;
|
||||||
}
|
}
|
||||||
if (curr instanceof TypeArgumentListContext) {
|
if (curr instanceof TypeArgumentListContext typeArgumentList) {
|
||||||
if (((TypeArgumentListContext) curr).err == null) throw incompleteInput(curr, ">");
|
if (typeArgumentList.err == null) throw incompleteInput(curr, ">");
|
||||||
else return;
|
else return;
|
||||||
}
|
}
|
||||||
if (curr instanceof ParenthesizedTypeContext) {
|
if (curr instanceof ParenthesizedTypeContext parenthesizedType) {
|
||||||
if (((ParenthesizedTypeContext) curr).err == null) throw incompleteInput(curr, ")");
|
if (parenthesizedType.err == null) throw incompleteInput(curr, ")");
|
||||||
else return;
|
else return;
|
||||||
}
|
}
|
||||||
if (curr instanceof ConstrainedTypeContext) {
|
if (curr instanceof ConstrainedTypeContext constrainedType) {
|
||||||
if (((ConstrainedTypeContext) curr).err == null) throw incompleteInput(curr, ")");
|
if (constrainedType.err == null) throw incompleteInput(curr, ")");
|
||||||
else return;
|
else return;
|
||||||
}
|
}
|
||||||
if (curr instanceof ParenthesizedExprContext) {
|
if (curr instanceof ParenthesizedExprContext parenthesizedExpr) {
|
||||||
if (((ParenthesizedExprContext) curr).err == null) throw incompleteInput(curr, ")");
|
if (parenthesizedExpr.err == null) throw incompleteInput(curr, ")");
|
||||||
else return;
|
else return;
|
||||||
}
|
}
|
||||||
if (curr instanceof SuperSubscriptExprContext) {
|
if (curr instanceof SuperSubscriptExprContext superSubscriptExpr) {
|
||||||
if (((SuperSubscriptExprContext) curr).err == null) throw incompleteInput(curr, "]");
|
if (superSubscriptExpr.err == null) throw incompleteInput(curr, "]");
|
||||||
else return;
|
else return;
|
||||||
}
|
}
|
||||||
if (curr instanceof SubscriptExprContext) {
|
if (curr instanceof SubscriptExprContext subscriptExpr) {
|
||||||
if (((SubscriptExprContext) curr).err == null) throw incompleteInput(curr, "]");
|
if (subscriptExpr.err == null) throw incompleteInput(curr, "]");
|
||||||
else return;
|
else return;
|
||||||
}
|
}
|
||||||
if (curr instanceof ObjectBodyContext) {
|
if (curr instanceof ObjectBodyContext objectBody) {
|
||||||
if (((ObjectBodyContext) curr).err == null) throw incompleteInput(curr, "}");
|
if (objectBody.err == null) throw incompleteInput(curr, "}");
|
||||||
else return;
|
else return;
|
||||||
}
|
}
|
||||||
curr = curr.getChild(curr.getChildCount() - 1);
|
curr = curr.getChild(curr.getChildCount() - 1);
|
||||||
|
|||||||
@@ -131,8 +131,8 @@ public final class Project {
|
|||||||
PackageUtils.checkHasNoChecksumComponent(packageUri);
|
PackageUtils.checkHasNoChecksumComponent(packageUri);
|
||||||
var objChecksum = object.getProperty("checksums");
|
var objChecksum = object.getProperty("checksums");
|
||||||
Checksums checksums = null;
|
Checksums checksums = null;
|
||||||
if (objChecksum instanceof PObject) {
|
if (objChecksum instanceof PObject pObject) {
|
||||||
var sha256 = (String) ((PObject) objChecksum).get("sha256");
|
var sha256 = (String) pObject.get("sha256");
|
||||||
assert sha256 != null;
|
assert sha256 != null;
|
||||||
checksums = new Checksums(sha256);
|
checksums = new Checksums(sha256);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,10 +99,9 @@ public class ProjectDeps {
|
|||||||
|
|
||||||
private static EconomicMap<CanonicalPackageUri, Dependency> parseResolvedDependencies(
|
private static EconomicMap<CanonicalPackageUri, Dependency> parseResolvedDependencies(
|
||||||
Object object) throws JsonParseException, URISyntaxException {
|
Object object) throws JsonParseException, URISyntaxException {
|
||||||
if (!(object instanceof JsObject)) {
|
if (!(object instanceof JsObject jsObj)) {
|
||||||
throw new FormatException("resolvedDependencies", "object", object.getClass());
|
throw new FormatException("resolvedDependencies", "object", object.getClass());
|
||||||
}
|
}
|
||||||
var jsObj = (JsObject) object;
|
|
||||||
var ret = EconomicMaps.<CanonicalPackageUri, Dependency>create(jsObj.size());
|
var ret = EconomicMaps.<CanonicalPackageUri, Dependency>create(jsObj.size());
|
||||||
for (var entry : jsObj.entrySet()) {
|
for (var entry : jsObj.entrySet()) {
|
||||||
Dependency resolvedDependency = parseResolvedDependency(entry);
|
Dependency resolvedDependency = parseResolvedDependency(entry);
|
||||||
@@ -115,10 +114,9 @@ public class ProjectDeps {
|
|||||||
private static Dependency parseResolvedDependency(Entry<String, Object> entry)
|
private static Dependency parseResolvedDependency(Entry<String, Object> entry)
|
||||||
throws JsonParseException {
|
throws JsonParseException {
|
||||||
var input = entry.getValue();
|
var input = entry.getValue();
|
||||||
if (!(input instanceof JsObject)) {
|
if (!(input instanceof JsObject obj)) {
|
||||||
throw new VmExceptionBuilder().evalError("invalid object").build();
|
throw new VmExceptionBuilder().evalError("invalid object").build();
|
||||||
}
|
}
|
||||||
var obj = (JsObject) input;
|
|
||||||
var type = obj.getString("type");
|
var type = obj.getString("type");
|
||||||
var uri = obj.get("uri", PackageUtils::parsePackageUriWithoutChecksums);
|
var uri = obj.get("uri", PackageUtils::parsePackageUriWithoutChecksums);
|
||||||
if (type.equals("remote")) {
|
if (type.equals("remote")) {
|
||||||
@@ -211,8 +209,8 @@ public class ProjectDeps {
|
|||||||
while (cursor.advance()) {
|
while (cursor.advance()) {
|
||||||
jsonWriter.name(cursor.getKey().toString());
|
jsonWriter.name(cursor.getKey().toString());
|
||||||
var dependency = cursor.getValue();
|
var dependency = cursor.getValue();
|
||||||
if (dependency instanceof LocalDependency) {
|
if (dependency instanceof LocalDependency localDependency) {
|
||||||
writeLocalDependency((LocalDependency) dependency);
|
writeLocalDependency(localDependency);
|
||||||
} else {
|
} else {
|
||||||
writeRemoteDependency((RemoteDependency) dependency);
|
writeRemoteDependency((RemoteDependency) dependency);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,16 +116,16 @@ public class ReplServer implements AutoCloseable {
|
|||||||
public List<ReplResponse> handleRequest(ReplRequest request) {
|
public List<ReplResponse> handleRequest(ReplRequest request) {
|
||||||
polyglotContext.enter();
|
polyglotContext.enter();
|
||||||
try {
|
try {
|
||||||
if (request instanceof Eval) {
|
if (request instanceof Eval eval) {
|
||||||
return handleEval((Eval) request);
|
return handleEval(eval);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request instanceof Load) {
|
if (request instanceof Load load) {
|
||||||
return handleLoad((Load) request);
|
return handleLoad(load);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request instanceof ReplRequest.Completion) {
|
if (request instanceof ReplRequest.Completion completion) {
|
||||||
return handleCompletion((ReplRequest.Completion) request);
|
return handleCompletion(completion);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request instanceof Reset) {
|
if (request instanceof Reset) {
|
||||||
@@ -157,8 +157,8 @@ public class ReplServer implements AutoCloseable {
|
|||||||
return results.stream()
|
return results.stream()
|
||||||
.map(
|
.map(
|
||||||
result ->
|
result ->
|
||||||
result instanceof ReplResponse
|
result instanceof ReplResponse response
|
||||||
? (ReplResponse) result
|
? response
|
||||||
: new EvalSuccess(render(result)))
|
: new EvalSuccess(render(result)))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
@@ -210,20 +210,20 @@ public class ReplServer implements AutoCloseable {
|
|||||||
if (tree instanceof ExprContext) {
|
if (tree instanceof ExprContext) {
|
||||||
var exprNode = (ExpressionNode) tree.accept(builder);
|
var exprNode = (ExpressionNode) tree.accept(builder);
|
||||||
evaluateExpr(replState, exprNode, forceResults, results);
|
evaluateExpr(replState, exprNode, forceResults, results);
|
||||||
} else if (tree instanceof ImportClauseContext) {
|
} else if (tree instanceof ImportClauseContext importClause) {
|
||||||
addStaticModuleProperty(builder.visitImportClause((ImportClauseContext) tree));
|
addStaticModuleProperty(builder.visitImportClause(importClause));
|
||||||
} else if (tree instanceof ClassPropertyContext) {
|
} else if (tree instanceof ClassPropertyContext classProperty) {
|
||||||
var propertyNode = builder.visitClassProperty((ClassPropertyContext) tree);
|
var propertyNode = builder.visitClassProperty(classProperty);
|
||||||
var property = addModuleProperty(propertyNode);
|
var property = addModuleProperty(propertyNode);
|
||||||
if (evalDefinitions) {
|
if (evalDefinitions) {
|
||||||
evaluateMemberDef(replState, property, forceResults, results);
|
evaluateMemberDef(replState, property, forceResults, results);
|
||||||
}
|
}
|
||||||
} else if (tree instanceof ClazzContext) {
|
} else if (tree instanceof ClazzContext clazz) {
|
||||||
addStaticModuleProperty(builder.visitClazz((ClazzContext) tree));
|
addStaticModuleProperty(builder.visitClazz(clazz));
|
||||||
} else if (tree instanceof TypeAliasContext) {
|
} else if (tree instanceof TypeAliasContext typeAlias) {
|
||||||
addStaticModuleProperty(builder.visitTypeAlias((TypeAliasContext) tree));
|
addStaticModuleProperty(builder.visitTypeAlias(typeAlias));
|
||||||
} else if (tree instanceof ClassMethodContext) {
|
} else if (tree instanceof ClassMethodContext classMethod) {
|
||||||
addModuleMethodDef(builder.visitClassMethod((ClassMethodContext) tree));
|
addModuleMethodDef(builder.visitClassMethod(classMethod));
|
||||||
} else if (tree instanceof ModuleDeclContext) {
|
} else if (tree instanceof ModuleDeclContext) {
|
||||||
// do nothing for now
|
// do nothing for now
|
||||||
} else if (tree instanceof TerminalNode && tree.toString().equals(",")) {
|
} else if (tree instanceof TerminalNode && tree.toString().equals(",")) {
|
||||||
@@ -360,8 +360,8 @@ public class ReplServer implements AutoCloseable {
|
|||||||
assert !(lastResult instanceof ReplResponse);
|
assert !(lastResult instanceof ReplResponse);
|
||||||
|
|
||||||
VmObjectLike composite;
|
VmObjectLike composite;
|
||||||
if (lastResult instanceof VmObjectLike) {
|
if (lastResult instanceof VmObjectLike objectLike) {
|
||||||
composite = (VmObjectLike) lastResult;
|
composite = objectLike;
|
||||||
} else {
|
} else {
|
||||||
composite = VmUtils.getClass(lastResult).getPrototype();
|
composite = VmUtils.getClass(lastResult).getPrototype();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -556,11 +556,11 @@ public final class ResourceReaders {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private @Nullable Path getLocalPath(Dependency dependency, PackageAssetUri packageAssetUri) {
|
private @Nullable Path getLocalPath(Dependency dependency, PackageAssetUri packageAssetUri) {
|
||||||
if (!(dependency instanceof LocalDependency)) {
|
if (!(dependency instanceof LocalDependency localDependency)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return ((LocalDependency) dependency)
|
return localDependency.resolveAssetPath(
|
||||||
.resolveAssetPath(getProjectDepsResolver().getProjectDir(), packageAssetUri);
|
getProjectDepsResolver().getProjectDir(), packageAssetUri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -136,24 +136,19 @@ public final class BaseModule extends StdLibModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static VmClass getFunctionNClass(int paramCount) {
|
public static VmClass getFunctionNClass(int paramCount) {
|
||||||
switch (paramCount) {
|
return switch (paramCount) {
|
||||||
case 0:
|
case 0 -> getFunction0Class();
|
||||||
return getFunction0Class();
|
case 1 -> getFunction1Class();
|
||||||
case 1:
|
case 2 -> getFunction2Class();
|
||||||
return getFunction1Class();
|
case 3 -> getFunction3Class();
|
||||||
case 2:
|
case 4 -> getFunction4Class();
|
||||||
return getFunction2Class();
|
case 5 -> getFunction5Class();
|
||||||
case 3:
|
default -> {
|
||||||
return getFunction3Class();
|
|
||||||
case 4:
|
|
||||||
return getFunction4Class();
|
|
||||||
case 5:
|
|
||||||
return getFunction5Class();
|
|
||||||
default:
|
|
||||||
CompilerDirectives.transferToInterpreter();
|
CompilerDirectives.transferToInterpreter();
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
String.format("Class `Function%d` does not exist.", paramCount));
|
String.format("Class `Function%d` does not exist.", paramCount));
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static VmClass getFunction0Class() {
|
public static VmClass getFunction0Class() {
|
||||||
|
|||||||
@@ -33,8 +33,7 @@ public class KeyLookupSuggestions {
|
|||||||
|
|
||||||
map.forEach(
|
map.forEach(
|
||||||
entry -> {
|
entry -> {
|
||||||
if (!(entry.getKey() instanceof String)) return;
|
if (!(entry.getKey() instanceof String entryKey)) return;
|
||||||
var entryKey = (String) entry.getKey();
|
|
||||||
var similarity = STRING_SIMILARITY.similarity(entryKey, key);
|
var similarity = STRING_SIMILARITY.similarity(entryKey, key);
|
||||||
if (similarity >= SIMILARITY_THRESHOLD) {
|
if (similarity >= SIMILARITY_THRESHOLD) {
|
||||||
candidates.add(new Candidate(entryKey, similarity));
|
candidates.add(new Candidate(entryKey, similarity));
|
||||||
@@ -50,8 +49,7 @@ public class KeyLookupSuggestions {
|
|||||||
|
|
||||||
object.iterateMemberValues(
|
object.iterateMemberValues(
|
||||||
(memberKey, member, value) -> {
|
(memberKey, member, value) -> {
|
||||||
if (!(memberKey instanceof String)) return true;
|
if (!(memberKey instanceof String stringKey)) return true;
|
||||||
var stringKey = (String) memberKey;
|
|
||||||
var similarity = STRING_SIMILARITY.similarity(stringKey, key);
|
var similarity = STRING_SIMILARITY.similarity(stringKey, key);
|
||||||
if (similarity >= SIMILARITY_THRESHOLD) {
|
if (similarity >= SIMILARITY_THRESHOLD) {
|
||||||
candidates.add(new Candidate(stringKey, similarity));
|
candidates.add(new Candidate(stringKey, similarity));
|
||||||
@@ -80,7 +78,7 @@ public class KeyLookupSuggestions {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
return (obj instanceof Candidate && ((Candidate) obj).key.equals(key));
|
return (obj instanceof Candidate candidate && candidate.key.equals(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -144,9 +144,7 @@ public class MemberLookupSuggestions {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof Candidate)) return false;
|
if (!(obj instanceof Candidate other)) return false;
|
||||||
|
|
||||||
var other = (Candidate) obj;
|
|
||||||
// member lookup is name rather than signature based (but distinguishes kind)
|
// member lookup is name rather than signature based (but distinguishes kind)
|
||||||
return kind == other.kind && name.equals(other.name);
|
return kind == other.kind && name.equals(other.name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,9 +45,9 @@ final class MinPklVersionChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void check(String moduleName, @Nullable ParserRuleContext ctx, @Nullable Node importNode) {
|
static void check(String moduleName, @Nullable ParserRuleContext ctx, @Nullable Node importNode) {
|
||||||
if (!(ctx instanceof ModuleContext)) return;
|
if (!(ctx instanceof ModuleContext moduleCtx)) return;
|
||||||
|
|
||||||
var moduleDeclCtx = ((ModuleContext) ctx).moduleDecl();
|
var moduleDeclCtx = moduleCtx.moduleDecl();
|
||||||
if (moduleDeclCtx == null) return;
|
if (moduleDeclCtx == null) return;
|
||||||
|
|
||||||
for (var annCtx : moduleDeclCtx.annotation()) {
|
for (var annCtx : moduleDeclCtx.annotation()) {
|
||||||
@@ -57,9 +57,8 @@ final class MinPklVersionChecker {
|
|||||||
if (objectBodyCtx == null) continue;
|
if (objectBodyCtx == null) continue;
|
||||||
|
|
||||||
for (var memberCtx : objectBodyCtx.objectMember()) {
|
for (var memberCtx : objectBodyCtx.objectMember()) {
|
||||||
if (!(memberCtx instanceof ObjectPropertyContext)) continue;
|
if (!(memberCtx instanceof ObjectPropertyContext propertyCtx)) continue;
|
||||||
|
|
||||||
var propertyCtx = (ObjectPropertyContext) memberCtx;
|
|
||||||
if (!Identifier.MIN_PKL_VERSION.toString().equals(getText(propertyCtx.Identifier())))
|
if (!Identifier.MIN_PKL_VERSION.toString().equals(getText(propertyCtx.Identifier())))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -84,8 +83,7 @@ final class MinPklVersionChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static @Nullable String getLastIdText(@Nullable TypeContext typeCtx) {
|
private static @Nullable String getLastIdText(@Nullable TypeContext typeCtx) {
|
||||||
if (!(typeCtx instanceof DeclaredTypeContext)) return null;
|
if (!(typeCtx instanceof DeclaredTypeContext declCtx)) return null;
|
||||||
var declCtx = (DeclaredTypeContext) typeCtx;
|
|
||||||
var token = declCtx.qualifiedIdentifier().Identifier;
|
var token = declCtx.qualifiedIdentifier().Identifier;
|
||||||
return token == null ? null : token.getText();
|
return token == null ? null : token.getText();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -203,16 +203,12 @@ public final class MirrorFactories {
|
|||||||
.addStringProperty("name", TypeParameter::getName)
|
.addStringProperty("name", TypeParameter::getName)
|
||||||
.addProperty(
|
.addProperty(
|
||||||
"variance",
|
"variance",
|
||||||
typeParameter -> {
|
typeParameter ->
|
||||||
switch (typeParameter.getVariance()) {
|
switch (typeParameter.getVariance()) {
|
||||||
case COVARIANT:
|
case COVARIANT -> "out";
|
||||||
return "out";
|
case CONTRAVARIANT -> "in";
|
||||||
case CONTRAVARIANT:
|
default -> VmNull.withoutDefault();
|
||||||
return "in";
|
});
|
||||||
default:
|
|
||||||
return VmNull.withoutDefault();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
classTypeFactory
|
classTypeFactory
|
||||||
.addTypedProperty(
|
.addTypedProperty(
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ public final class ModuleCache {
|
|||||||
|
|
||||||
var module1 = modulesByOriginalUri.get(moduleKey.getUri());
|
var module1 = modulesByOriginalUri.get(moduleKey.getUri());
|
||||||
if (module1 != null) {
|
if (module1 != null) {
|
||||||
if (module1 instanceof VmTyped) return (VmTyped) module1;
|
if (module1 instanceof VmTyped typed) return typed;
|
||||||
|
|
||||||
assert module1 instanceof RuntimeException;
|
assert module1 instanceof RuntimeException;
|
||||||
// would be more accurate/safe to throw a clone with adapted Pkl stack trace
|
// would be more accurate/safe to throw a clone with adapted Pkl stack trace
|
||||||
@@ -145,7 +145,7 @@ public final class ModuleCache {
|
|||||||
var resolvedKey = resolve(moduleKey, securityManager, importNode);
|
var resolvedKey = resolve(moduleKey, securityManager, importNode);
|
||||||
var module2 = modulesByResolvedUri.get(resolvedKey.getUri());
|
var module2 = modulesByResolvedUri.get(resolvedKey.getUri());
|
||||||
if (module2 != null) {
|
if (module2 != null) {
|
||||||
if (module2 instanceof VmTyped) return (VmTyped) module2;
|
if (module2 instanceof VmTyped typed) return typed;
|
||||||
|
|
||||||
assert module2 instanceof RuntimeException;
|
assert module2 instanceof RuntimeException;
|
||||||
// would be more accurate/safe to throw a clone with adapted Pkl stack trace
|
// would be more accurate/safe to throw a clone with adapted Pkl stack trace
|
||||||
|
|||||||
@@ -160,8 +160,8 @@ public final class ResourceManager {
|
|||||||
var res = resource.get();
|
var res = resource.get();
|
||||||
if (res instanceof String) return resource;
|
if (res instanceof String) return resource;
|
||||||
|
|
||||||
if (res instanceof Resource) {
|
if (res instanceof Resource r) {
|
||||||
return Optional.of(resourceFactory.create((Resource) res));
|
return Optional.of(resourceFactory.create(r));
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new VmExceptionBuilder()
|
throw new VmExceptionBuilder()
|
||||||
|
|||||||
@@ -66,12 +66,12 @@ class StackTraceGenerator {
|
|||||||
|
|
||||||
for (Node current = callNode; current != null; current = current.getParent()) {
|
for (Node current = callNode; current != null; current = current.getParent()) {
|
||||||
if (current.getSourceSection() != null) {
|
if (current.getSourceSection() != null) {
|
||||||
return current instanceof MemberNode
|
return current instanceof MemberNode memberNode
|
||||||
// Always display the member body's source section instead of the member
|
// Always display the member body's source section instead of the member
|
||||||
// (root) node's source section (which includes doc comment etc.), even
|
// (root) node's source section (which includes doc comment etc.), even
|
||||||
// if `callNode` is a child of root node rather than body node.
|
// if `callNode` is a child of root node rather than body node.
|
||||||
// This improves stack trace output for failed property type checks.
|
// This improves stack trace output for failed property type checks.
|
||||||
? ((MemberNode) current).getBodySection()
|
? memberNode.getBodySection()
|
||||||
: current.getSourceSection();
|
: current.getSourceSection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,8 +41,7 @@ public class StackTraceRenderer {
|
|||||||
String leftMargin,
|
String leftMargin,
|
||||||
boolean isFirstElement) {
|
boolean isFirstElement) {
|
||||||
for (var frame : frames) {
|
for (var frame : frames) {
|
||||||
if (frame instanceof StackFrameLoop) {
|
if (frame instanceof StackFrameLoop loop) {
|
||||||
var loop = (StackFrameLoop) frame;
|
|
||||||
// ensure a cycle of length 1 doesn't get rendered as a loop
|
// ensure a cycle of length 1 doesn't get rendered as a loop
|
||||||
if (loop.count == 1) {
|
if (loop.count == 1) {
|
||||||
doRender(loop.frames, null, builder, leftMargin, isFirstElement);
|
doRender(loop.frames, null, builder, leftMargin, isFirstElement);
|
||||||
|
|||||||
@@ -129,10 +129,9 @@ public abstract class VmCollection extends VmValue implements Iterable<Object> {
|
|||||||
public final VmCollection flatten() {
|
public final VmCollection flatten() {
|
||||||
var builder = builder();
|
var builder = builder();
|
||||||
for (var elem : this) {
|
for (var elem : this) {
|
||||||
if (elem instanceof Iterable) {
|
if (elem instanceof Iterable<?> iterable) {
|
||||||
builder.addAll((Iterable<?>) elem);
|
builder.addAll(iterable);
|
||||||
} else if (elem instanceof VmListing) {
|
} else if (elem instanceof VmListing listing) {
|
||||||
var listing = (VmListing) elem;
|
|
||||||
listing.forceAndIterateMemberValues(
|
listing.forceAndIterateMemberValues(
|
||||||
(key, member, value) -> {
|
(key, member, value) -> {
|
||||||
builder.add(value);
|
builder.add(value);
|
||||||
|
|||||||
@@ -144,9 +144,7 @@ public final class VmDataSize extends VmValue implements Comparable<VmDataSize>
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof VmDataSize)) return false;
|
if (!(obj instanceof VmDataSize other)) return false;
|
||||||
|
|
||||||
var other = (VmDataSize) obj;
|
|
||||||
// converting to a fixed unit guarantees that equals() is commutative and consistent with
|
// converting to a fixed unit guarantees that equals() is commutative and consistent with
|
||||||
// hashCode()
|
// hashCode()
|
||||||
return convertValueTo(DataSizeUnit.BYTES) == other.convertValueTo(DataSizeUnit.BYTES);
|
return convertValueTo(DataSizeUnit.BYTES) == other.convertValueTo(DataSizeUnit.BYTES);
|
||||||
|
|||||||
@@ -140,9 +140,7 @@ public final class VmDuration extends VmValue implements Comparable<VmDuration>
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof VmDuration)) return false;
|
if (!(obj instanceof VmDuration other)) return false;
|
||||||
|
|
||||||
var other = (VmDuration) obj;
|
|
||||||
// converting to a fixed unit guarantees that equals() is commutative and consistent with
|
// converting to a fixed unit guarantees that equals() is commutative and consistent with
|
||||||
// hashCode()
|
// hashCode()
|
||||||
return getValue(DurationUnit.NANOS) == other.getValue(DurationUnit.NANOS);
|
return getValue(DurationUnit.NANOS) == other.getValue(DurationUnit.NANOS);
|
||||||
|
|||||||
@@ -101,9 +101,8 @@ public final class VmDynamic extends VmObject {
|
|||||||
@TruffleBoundary
|
@TruffleBoundary
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof VmDynamic)) return false;
|
if (!(obj instanceof VmDynamic other)) return false;
|
||||||
|
|
||||||
var other = (VmDynamic) obj;
|
|
||||||
// could use shallow force, but deep force is cached
|
// could use shallow force, but deep force is cached
|
||||||
force(false);
|
force(false);
|
||||||
other.force(false);
|
other.force(false);
|
||||||
|
|||||||
@@ -127,11 +127,11 @@ public class VmExceptionBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public VmExceptionBuilder cannotFindMember(VmObjectLike receiver, Object memberKey) {
|
public VmExceptionBuilder cannotFindMember(VmObjectLike receiver, Object memberKey) {
|
||||||
if (memberKey instanceof Identifier) {
|
if (memberKey instanceof Identifier identifier) {
|
||||||
return cannotFindProperty(receiver, (Identifier) memberKey, true, false);
|
return cannotFindProperty(receiver, identifier, true, false);
|
||||||
}
|
}
|
||||||
if (memberKey instanceof String) {
|
if (memberKey instanceof String string) {
|
||||||
var candidates = KeyLookupSuggestions.forObject(receiver, (String) memberKey);
|
var candidates = KeyLookupSuggestions.forObject(receiver, string);
|
||||||
if (!candidates.isEmpty()) {
|
if (!candidates.isEmpty()) {
|
||||||
return evalError(
|
return evalError(
|
||||||
"cannotFindKeyListCandidates",
|
"cannotFindKeyListCandidates",
|
||||||
@@ -245,8 +245,8 @@ public class VmExceptionBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public VmExceptionBuilder cannotFindKey(VmMap map, Object key) {
|
public VmExceptionBuilder cannotFindKey(VmMap map, Object key) {
|
||||||
if (key instanceof String) {
|
if (key instanceof String string) {
|
||||||
var candidates = KeyLookupSuggestions.forMap(map, (String) key);
|
var candidates = KeyLookupSuggestions.forMap(map, string);
|
||||||
if (!candidates.isEmpty()) {
|
if (!candidates.isEmpty()) {
|
||||||
return evalError(
|
return evalError(
|
||||||
"cannotFindKeyListCandidates",
|
"cannotFindKeyListCandidates",
|
||||||
@@ -334,44 +334,42 @@ public class VmExceptionBuilder {
|
|||||||
throw new IllegalStateException("No message set.");
|
throw new IllegalStateException("No message set.");
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (kind) {
|
return switch (kind) {
|
||||||
case EVAL_ERROR:
|
case EVAL_ERROR ->
|
||||||
return new VmEvalException(
|
new VmEvalException(
|
||||||
message,
|
message,
|
||||||
cause,
|
cause,
|
||||||
isExternalMessage,
|
isExternalMessage,
|
||||||
messageArguments,
|
messageArguments,
|
||||||
programValues,
|
programValues,
|
||||||
location,
|
location,
|
||||||
sourceSection,
|
sourceSection,
|
||||||
memberName,
|
memberName,
|
||||||
hint);
|
hint);
|
||||||
case UNDEFINED_VALUE:
|
case UNDEFINED_VALUE ->
|
||||||
return new VmUndefinedValueException(
|
new VmUndefinedValueException(
|
||||||
message,
|
message,
|
||||||
cause,
|
cause,
|
||||||
isExternalMessage,
|
isExternalMessage,
|
||||||
messageArguments,
|
messageArguments,
|
||||||
programValues,
|
programValues,
|
||||||
location,
|
location,
|
||||||
sourceSection,
|
sourceSection,
|
||||||
memberName,
|
memberName,
|
||||||
hint,
|
hint,
|
||||||
receiver);
|
receiver);
|
||||||
case BUG:
|
case BUG ->
|
||||||
return new VmBugException(
|
new VmBugException(
|
||||||
message,
|
message,
|
||||||
cause,
|
cause,
|
||||||
isExternalMessage,
|
isExternalMessage,
|
||||||
messageArguments,
|
messageArguments,
|
||||||
programValues,
|
programValues,
|
||||||
location,
|
location,
|
||||||
sourceSection,
|
sourceSection,
|
||||||
memberName,
|
memberName,
|
||||||
hint);
|
hint);
|
||||||
default:
|
};
|
||||||
throw unreachableCode().build();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Identifier> collectPropertyNames(VmObjectLike object, boolean isRead) {
|
private List<Identifier> collectPropertyNames(VmObjectLike object, boolean isRead) {
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ public class VmExceptionRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void render(VmException exception, StringBuilder builder) {
|
private void render(VmException exception, StringBuilder builder) {
|
||||||
if (exception instanceof VmBugException) {
|
if (exception instanceof VmBugException bugException) {
|
||||||
renderBugException((VmBugException) exception, builder);
|
renderBugException(bugException, builder);
|
||||||
} else {
|
} else {
|
||||||
renderException(exception, builder);
|
renderException(exception, builder);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public final class VmFunction extends VmObjectLike {
|
|||||||
|
|
||||||
public String applyString(Object arg1) {
|
public String applyString(Object arg1) {
|
||||||
var result = apply(arg1);
|
var result = apply(arg1);
|
||||||
if (result instanceof String) return (String) result;
|
if (result instanceof String string) return string;
|
||||||
|
|
||||||
CompilerDirectives.transferToInterpreter();
|
CompilerDirectives.transferToInterpreter();
|
||||||
throw new VmExceptionBuilder().typeMismatch(result, BaseModule.getStringClass()).build();
|
throw new VmExceptionBuilder().typeMismatch(result, BaseModule.getStringClass()).build();
|
||||||
|
|||||||
@@ -107,9 +107,7 @@ public final class VmIntSeq extends VmValue implements Iterable<Long> {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof VmIntSeq)) return false;
|
if (!(obj instanceof VmIntSeq other)) return false;
|
||||||
|
|
||||||
var other = (VmIntSeq) obj;
|
|
||||||
return isEmpty()
|
return isEmpty()
|
||||||
? other.isEmpty()
|
? other.isEmpty()
|
||||||
: start == other.start && last == other.last && step == other.step;
|
: start == other.start && last == other.last && step == other.step;
|
||||||
|
|||||||
@@ -424,8 +424,8 @@ public final class VmList extends VmCollection {
|
|||||||
public boolean equals(@Nullable Object other) {
|
public boolean equals(@Nullable Object other) {
|
||||||
if (this == other) return true;
|
if (this == other) return true;
|
||||||
//noinspection SimplifiableIfStatement
|
//noinspection SimplifiableIfStatement
|
||||||
if (!(other instanceof VmList)) return false;
|
if (!(other instanceof VmList list)) return false;
|
||||||
return rrbt.equals(((VmList) other).rrbt);
|
return rrbt.equals(list.rrbt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -104,9 +104,8 @@ public final class VmListing extends VmObject {
|
|||||||
@TruffleBoundary
|
@TruffleBoundary
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof VmListing)) return false;
|
if (!(obj instanceof VmListing other)) return false;
|
||||||
|
|
||||||
var other = (VmListing) obj;
|
|
||||||
if (length != other.length) return false;
|
if (length != other.length) return false;
|
||||||
// could use shallow force, but deep force is cached
|
// could use shallow force, but deep force is cached
|
||||||
force(false);
|
force(false);
|
||||||
|
|||||||
@@ -245,8 +245,8 @@ public final class VmMap extends VmValue implements Iterable<Map.Entry<Object, O
|
|||||||
public boolean equals(@Nullable Object other) {
|
public boolean equals(@Nullable Object other) {
|
||||||
if (this == other) return true;
|
if (this == other) return true;
|
||||||
//noinspection SimplifiableIfStatement
|
//noinspection SimplifiableIfStatement
|
||||||
if (!(other instanceof VmMap)) return false;
|
if (!(other instanceof VmMap vmMap)) return false;
|
||||||
return map.equals(((VmMap) other).map);
|
return map.equals(vmMap.map);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -68,8 +68,7 @@ public final class VmMapping extends VmObject {
|
|||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (__allKeys == null) {
|
if (__allKeys == null) {
|
||||||
// building upon parent's `getAllKeys()` should improve at least worst case efficiency
|
// building upon parent's `getAllKeys()` should improve at least worst case efficiency
|
||||||
var parentKeys =
|
var parentKeys = parent instanceof VmMapping mapping ? mapping.getAllKeys() : VmSet.EMPTY;
|
||||||
parent instanceof VmMapping ? ((VmMapping) parent).getAllKeys() : VmSet.EMPTY;
|
|
||||||
var builder = VmSet.builder(parentKeys);
|
var builder = VmSet.builder(parentKeys);
|
||||||
for (var cursor = members.getEntries(); cursor.advance(); ) {
|
for (var cursor = members.getEntries(); cursor.advance(); ) {
|
||||||
var member = cursor.getValue();
|
var member = cursor.getValue();
|
||||||
@@ -127,9 +126,8 @@ public final class VmMapping extends VmObject {
|
|||||||
@TruffleBoundary
|
@TruffleBoundary
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof VmMapping)) return false;
|
if (!(obj instanceof VmMapping other)) return false;
|
||||||
|
|
||||||
var other = (VmMapping) obj;
|
|
||||||
// could use shallow force, but deep force is cached
|
// could use shallow force, but deep force is cached
|
||||||
force(false);
|
force(false);
|
||||||
other.force(false);
|
other.force(false);
|
||||||
|
|||||||
@@ -54,14 +54,11 @@ public final class VmPair extends VmValue implements Iterable<Object> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object next() {
|
public Object next() {
|
||||||
switch (pos++) {
|
return switch (pos++) {
|
||||||
case 0:
|
case 0 -> first;
|
||||||
return first;
|
case 1 -> second;
|
||||||
case 1:
|
default -> throw new NoSuchElementException("VmPair only has two elements.");
|
||||||
return second;
|
};
|
||||||
default:
|
|
||||||
throw new NoSuchElementException("VmPair only has two elements.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -105,9 +102,7 @@ public final class VmPair extends VmValue implements Iterable<Object> {
|
|||||||
@TruffleBoundary
|
@TruffleBoundary
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof VmPair)) return false;
|
if (!(obj instanceof VmPair other)) return false;
|
||||||
|
|
||||||
var other = (VmPair) obj;
|
|
||||||
return first.equals(other.first) && second.equals(other.second);
|
return first.equals(other.first) && second.equals(other.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,9 +67,7 @@ public final class VmRegex extends VmValue {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof VmRegex)) return false;
|
if (!(obj instanceof VmRegex other)) return false;
|
||||||
|
|
||||||
var other = (VmRegex) obj;
|
|
||||||
return pattern.pattern().equals(other.pattern.pattern());
|
return pattern.pattern().equals(other.pattern.pattern());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -324,8 +324,8 @@ public final class VmSet extends VmCollection {
|
|||||||
public boolean equals(@Nullable Object other) {
|
public boolean equals(@Nullable Object other) {
|
||||||
if (this == other) return true;
|
if (this == other) return true;
|
||||||
//noinspection SimplifiableIfStatement
|
//noinspection SimplifiableIfStatement
|
||||||
if (!(other instanceof VmSet)) return false;
|
if (!(other instanceof VmSet vmSet)) return false;
|
||||||
return set.equals(((VmSet) other).set);
|
return set.equals(vmSet.set);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -98,8 +98,8 @@ public final class VmTypeAlias extends VmValue {
|
|||||||
*/
|
*/
|
||||||
@TruffleBoundary
|
@TruffleBoundary
|
||||||
public SourceSection getBaseTypeSection() {
|
public SourceSection getBaseTypeSection() {
|
||||||
if (typeNode instanceof ConstrainedTypeNode) {
|
if (typeNode instanceof ConstrainedTypeNode constrainedTypeNode) {
|
||||||
return ((ConstrainedTypeNode) typeNode).getBaseTypeSection();
|
return constrainedTypeNode.getBaseTypeSection();
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new VmExceptionBuilder()
|
throw new VmExceptionBuilder()
|
||||||
@@ -176,8 +176,7 @@ public final class VmTypeAlias extends VmValue {
|
|||||||
|
|
||||||
clone.accept(
|
clone.accept(
|
||||||
node -> {
|
node -> {
|
||||||
if (node instanceof TypeVariableNode) {
|
if (node instanceof TypeVariableNode typeVarNode) {
|
||||||
var typeVarNode = (TypeVariableNode) node;
|
|
||||||
int index = typeVarNode.getTypeParameterIndex();
|
int index = typeVarNode.getTypeParameterIndex();
|
||||||
// should not need to clone type argument node because it is not used by its original
|
// should not need to clone type argument node because it is not used by its original
|
||||||
// root node
|
// root node
|
||||||
|
|||||||
@@ -177,9 +177,8 @@ public final class VmTyped extends VmObject {
|
|||||||
@TruffleBoundary
|
@TruffleBoundary
|
||||||
public boolean equals(@Nullable Object obj) {
|
public boolean equals(@Nullable Object obj) {
|
||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (!(obj instanceof VmTyped)) return false;
|
if (!(obj instanceof VmTyped other)) return false;
|
||||||
|
|
||||||
var other = (VmTyped) obj;
|
|
||||||
if (clazz != other.clazz) return false;
|
if (clazz != other.clazz) return false;
|
||||||
// could use shallow force, but deep force is cached
|
// could use shallow force, but deep force is cached
|
||||||
force(false);
|
force(false);
|
||||||
|
|||||||
@@ -60,11 +60,10 @@ public final class VmUndefinedValueException extends VmEvalException {
|
|||||||
renderPath(builder, path);
|
renderPath(builder, path);
|
||||||
builder.append('`');
|
builder.append('`');
|
||||||
path.pop();
|
path.pop();
|
||||||
if (topLevelValue instanceof VmTyped && ((VmTyped) topLevelValue).isModuleObject()) {
|
if (topLevelValue instanceof VmTyped typed && typed.isModuleObject()) {
|
||||||
var modl = (VmTyped) topLevelValue;
|
|
||||||
builder
|
builder
|
||||||
.append(" of module `")
|
.append(" of module `")
|
||||||
.append(modl.getModuleInfo().getModuleSchema(modl).getModuleUri())
|
.append(typed.getModuleInfo().getModuleSchema(typed).getModuleUri())
|
||||||
.append('`');
|
.append('`');
|
||||||
}
|
}
|
||||||
builder.append('.');
|
builder.append('.');
|
||||||
|
|||||||
@@ -233,7 +233,7 @@ public final class VmUtils {
|
|||||||
@TruffleBoundary
|
@TruffleBoundary
|
||||||
public static @Nullable Object readMemberOrNull(
|
public static @Nullable Object readMemberOrNull(
|
||||||
VmObjectLike receiver, Object memberKey, boolean checkType, IndirectCallNode callNode) {
|
VmObjectLike receiver, Object memberKey, boolean checkType, IndirectCallNode callNode) {
|
||||||
assert (!(memberKey instanceof Identifier) || !((Identifier) memberKey).isLocalProp())
|
assert (!(memberKey instanceof Identifier identifier) || !identifier.isLocalProp())
|
||||||
: "Must use ReadLocalPropertyNode for local properties.";
|
: "Must use ReadLocalPropertyNode for local properties.";
|
||||||
|
|
||||||
final var cachedValue = receiver.getCachedValue(memberKey);
|
final var cachedValue = receiver.getCachedValue(memberKey);
|
||||||
@@ -329,12 +329,12 @@ public final class VmUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isRenderDirective(Object value) {
|
public static boolean isRenderDirective(Object value) {
|
||||||
return value instanceof VmTyped && isRenderDirective((VmTyped) value);
|
return value instanceof VmTyped typed && isRenderDirective(typed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isPcfRenderDirective(Object value) {
|
public static boolean isPcfRenderDirective(Object value) {
|
||||||
return value instanceof VmTyped
|
return value instanceof VmTyped typed
|
||||||
&& ((VmTyped) value).getVmClass().getPClassInfo() == PClassInfo.PcfRenderDirective;
|
&& typed.getVmClass().getPClassInfo() == PClassInfo.PcfRenderDirective;
|
||||||
}
|
}
|
||||||
|
|
||||||
@TruffleBoundary
|
@TruffleBoundary
|
||||||
@@ -348,8 +348,8 @@ public final class VmUtils {
|
|||||||
|
|
||||||
// implements same behavior as AnyNodes#getClass
|
// implements same behavior as AnyNodes#getClass
|
||||||
public static VmClass getClass(Object value) {
|
public static VmClass getClass(Object value) {
|
||||||
if (value instanceof VmValue) {
|
if (value instanceof VmValue vmValue) {
|
||||||
return ((VmValue) value).getVmClass();
|
return vmValue.getVmClass();
|
||||||
}
|
}
|
||||||
if (value instanceof String) {
|
if (value instanceof String) {
|
||||||
return BaseModule.getStringClass();
|
return BaseModule.getStringClass();
|
||||||
@@ -627,8 +627,8 @@ public final class VmUtils {
|
|||||||
// because constant type check wouldn't find the property (type)
|
// because constant type check wouldn't find the property (type)
|
||||||
var isLocalTyped = property.isLocal() && typeNode != null;
|
var isLocalTyped = property.isLocal() && typeNode != null;
|
||||||
|
|
||||||
if (bodyNode instanceof ConstantNode && !isLocalTyped) {
|
if (bodyNode instanceof ConstantNode constantNode && !isLocalTyped) {
|
||||||
property.initConstantValue((ConstantNode) bodyNode);
|
property.initConstantValue(constantNode);
|
||||||
return property;
|
return property;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -661,8 +661,8 @@ public final class VmUtils {
|
|||||||
// because constant type check wouldn't find the property (type)
|
// because constant type check wouldn't find the property (type)
|
||||||
var isLocalTyped = property.isLocal() && typeNode != null;
|
var isLocalTyped = property.isLocal() && typeNode != null;
|
||||||
|
|
||||||
if (bodyNode instanceof ConstantNode && !isLocalTyped) {
|
if (bodyNode instanceof ConstantNode constantNode && !isLocalTyped) {
|
||||||
property.initConstantValue((ConstantNode) bodyNode);
|
property.initConstantValue(constantNode);
|
||||||
return property;
|
return property;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user