Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions pkl-config-java/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,30 @@ com.github.ajalt.mordant:mordant-markdown-jvm:3.0.1=pklCodegenJava
com.github.ajalt.mordant:mordant-markdown:3.0.1=pklCodegenJava
com.github.ajalt.mordant:mordant:3.0.1=pklCodegenJava
com.github.ben-manes.caffeine:caffeine:2.9.3=swiftExportClasspathResolvable
com.github.ben-manes.caffeine:caffeine:3.0.5=annotationProcessor,testAnnotationProcessor
com.github.kevinstern:software-and-algorithms:1.0=annotationProcessor,testAnnotationProcessor
com.google.auto.service:auto-service-annotations:1.0.1=annotationProcessor,testAnnotationProcessor
com.google.auto.value:auto-value-annotations:1.9=annotationProcessor,testAnnotationProcessor
com.google.auto:auto-common:1.2.2=annotationProcessor,testAnnotationProcessor
com.google.errorprone:error_prone_annotation:2.48.0=annotationProcessor,testAnnotationProcessor
com.google.errorprone:error_prone_annotations:2.28.0=swiftExportClasspathResolvable
com.google.errorprone:error_prone_annotations:2.48.0=annotationProcessor,testAnnotationProcessor
com.google.errorprone:error_prone_check_api:2.48.0=annotationProcessor,testAnnotationProcessor
com.google.errorprone:error_prone_core:2.48.0=annotationProcessor,testAnnotationProcessor
com.google.googlejavaformat:google-java-format:1.34.1=annotationProcessor,testAnnotationProcessor
com.google.guava:failureaccess:1.0.3=annotationProcessor,testAnnotationProcessor
com.google.guava:guava:33.5.0-jre=annotationProcessor,testAnnotationProcessor
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava=annotationProcessor,testAnnotationProcessor
com.google.j2objc:j2objc-annotations:3.1=annotationProcessor,testAnnotationProcessor
com.google.protobuf:protobuf-java:4.33.2=annotationProcessor,testAnnotationProcessor
com.palantir.javapoet:javapoet:0.14.0=pklCodegenJava
io.github.java-diff-utils:java-diff-utils:4.12=kotlinInternalAbiValidation
com.uber.nullaway:nullaway:0.13.1=annotationProcessor,testAnnotationProcessor
io.github.eisop:dataflow-errorprone:3.41.0-eisop1=annotationProcessor,testAnnotationProcessor
io.github.java-diff-utils:java-diff-utils:4.12=annotationProcessor,kotlinInternalAbiValidation,testAnnotationProcessor
io.leangen.geantyref:geantyref:1.3.16=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
io.opentelemetry:opentelemetry-api:1.41.0=swiftExportClasspathResolvable
io.opentelemetry:opentelemetry-context:1.41.0=swiftExportClasspathResolvable
javax.inject:javax.inject:1=testCompileClasspath,testRuntimeClasspath
javax.inject:javax.inject:1=annotationProcessor,testAnnotationProcessor,testCompileClasspath,testRuntimeClasspath
net.bytebuddy:byte-buddy:1.18.3=testCompileClasspath,testRuntimeClasspath
net.java.dev.jna:jna:5.14.0=pklCodegenJava
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath
Expand All @@ -38,6 +55,8 @@ org.bouncycastle:bcpkix-jdk18on:1.80=kotlinBouncyCastleConfiguration
org.bouncycastle:bcprov-jdk18on:1.80=kotlinBouncyCastleConfiguration
org.bouncycastle:bcutil-jdk18on:1.80=kotlinBouncyCastleConfiguration
org.checkerframework:checker-qual:3.43.0=swiftExportClasspathResolvable
org.checkerframework:checker-qual:3.53.0=annotationProcessor,testAnnotationProcessor
org.checkerframework:dataflow-nullaway:3.53.0=annotationProcessor,testAnnotationProcessor
org.graalvm.polyglot:polyglot:25.0.1=pklCodegenJava,runtimeClasspath,testRuntimeClasspath
org.graalvm.sdk:collections:25.0.1=pklCodegenJava,runtimeClasspath,testRuntimeClasspath
org.graalvm.sdk:graal-sdk:25.0.1=pklCodegenJava,runtimeClasspath,testRuntimeClasspath
Expand Down Expand Up @@ -79,7 +98,7 @@ org.jetbrains.kotlinx:kotlinx-serialization-core:1.7.3=swiftExportClasspathResol
org.jetbrains:annotations:13.0=kotlinBuildToolsApiClasspath,kotlinCompilerClasspath,kotlinCompilerPluginClasspathMain,kotlinCompilerPluginClasspathTest,kotlinInternalAbiValidation,kotlinKlibCommonizerClasspath,pklCodegenJava,swiftExportClasspathResolvable,testCompileClasspath,testRuntimeClasspath
org.jetbrains:markdown-jvm:0.7.3=pklCodegenJava
org.jetbrains:markdown:0.7.3=pklCodegenJava
org.jspecify:jspecify:1.0.0=pklCodegenJava,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.jspecify:jspecify:1.0.0=annotationProcessor,compileClasspath,pklCodegenJava,runtimeClasspath,testAnnotationProcessor,testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:6.0.3=testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-engine:6.0.3=testRuntimeClasspath
org.junit.jupiter:junit-jupiter-params:6.0.3=testCompileClasspath,testRuntimeClasspath
Expand All @@ -90,5 +109,6 @@ org.junit:junit-bom:6.0.3=testCompileClasspath,testRuntimeClasspath
org.msgpack:msgpack-core:0.9.11=compileClasspath,pklCodegenJava,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.opentest4j:opentest4j:1.3.0=testCompileClasspath,testRuntimeClasspath
org.organicdesign:Paguro:3.10.3=pklCodegenJava,runtimeClasspath,testRuntimeClasspath
org.pcollections:pcollections:4.0.1=annotationProcessor,testAnnotationProcessor
org.snakeyaml:snakeyaml-engine:2.10=pklCodegenJava,runtimeClasspath,testRuntimeClasspath
empty=annotationProcessor,apiDependenciesMetadata,compileOnlyDependenciesMetadata,fatJar,firstPartySourcesJars,implementationDependenciesMetadata,intransitiveDependenciesMetadata,kotlinCompilerPluginClasspath,kotlinNativeCompilerPluginClasspath,kotlinScriptDefExtensions,shadow,signatures,sourcesJar,testAnnotationProcessor,testApiDependenciesMetadata,testCompileOnlyDependenciesMetadata,testImplementationDependenciesMetadata,testIntransitiveDependenciesMetadata,testKotlinScriptDefExtensions
empty=apiDependenciesMetadata,compileOnlyDependenciesMetadata,fatJar,firstPartySourcesJars,implementationDependenciesMetadata,intransitiveDependenciesMetadata,kotlinCompilerPluginClasspath,kotlinNativeCompilerPluginClasspath,kotlinScriptDefExtensions,shadow,signatures,sourcesJar,testApiDependenciesMetadata,testCompileOnlyDependenciesMetadata,testImplementationDependenciesMetadata,testIntransitiveDependenciesMetadata,testKotlinScriptDefExtensions
1 change: 1 addition & 0 deletions pkl-config-java/pkl-config-java.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ plugins {
id("pklJavaLibrary")
id("pklFatJar")
id("pklPublishLibrary")
id("pklJSpecify")
signing
}

Expand Down
9 changes: 5 additions & 4 deletions pkl-config-java/src/main/java/org/pkl/config/java/Config.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,6 +18,7 @@
import java.io.InputStream;
import java.lang.reflect.Type;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.pkl.config.java.mapper.ConversionException;
import org.pkl.config.java.mapper.ValueMapper;
import org.pkl.core.Composite;
Expand Down Expand Up @@ -55,7 +56,7 @@ public interface Config {
*
* @throws ConversionException if the value cannot be converted to the given type
*/
<T> T as(Class<T> type);
<T extends @Nullable Object> T as(Class<T> type);

/**
* Converts this node's value to the given {@link Type}.
Expand All @@ -64,14 +65,14 @@ public interface Config {
*
* @throws ConversionException if the value cannot be converted to the given type
*/
<T> T as(Type type);
<T extends @Nullable Object> T as(Type type);

/**
* Converts this node's value to the given {@link JavaType}.
*
* @throws ConversionException if the value cannot be converted to the given type
*/
<T> T as(JavaType<T> type);
<T extends @Nullable Object> T as(JavaType<T> type);

/**
* Decode a config from the supplied byte array.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,14 +21,14 @@
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import org.jspecify.annotations.Nullable;
import org.pkl.config.java.mapper.ValueMapperBuilder;
import org.pkl.core.EvaluatorBuilder;
import org.pkl.core.SecurityManager;
import org.pkl.core.StackFrameTransformer;
import org.pkl.core.http.HttpClient;
import org.pkl.core.project.DeclaredDependencies;
import org.pkl.core.project.Project;
import org.pkl.core.util.Nullable;

/** A builder for {@link ConfigEvaluator}s. */
@SuppressWarnings({"UnusedReturnValue", "unused"})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,9 +18,9 @@
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.*;
import org.jspecify.annotations.Nullable;
import org.pkl.config.java.mapper.Types;
import org.pkl.core.Pair;
import org.pkl.core.util.Nullable;

/**
* Runtime representation of a possibly parameterized Java type. Factory methods are provided to
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,10 +20,10 @@
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.pkl.config.java.InvalidMappingException;
import org.pkl.core.PClassInfo;
import org.pkl.core.util.IoUtils;
import org.pkl.core.util.Nullable;

/**
* Describes mappings of Pkl class names to their corresponding Java classes.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,13 +15,15 @@
*/
package org.pkl.config.java.mapper;

import org.jspecify.annotations.Nullable;

/** Thrown when a {@link ValueMapper} conversion fails. */
public class ConversionException extends RuntimeException {
public ConversionException(String message) {
super(message);
}

public ConversionException(String message, Throwable cause) {
public ConversionException(String message, @Nullable Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,14 +15,16 @@
*/
package org.pkl.config.java.mapper;

import org.jspecify.annotations.Nullable;

/**
* Converter for a particular source and target type.
*
* @param <S> the converter's source type
* @param <T> the converter's target type
*/
@FunctionalInterface
public interface Converter<S, T> {
public interface Converter<S, T extends @Nullable Object> {
/**
* Converts the given value. The given {@link ValueMapper} can be used to convert nested values of
* composite values (objects, collections, etc.).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,8 +19,8 @@
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Optional;
import org.jspecify.annotations.Nullable;
import org.pkl.core.PClassInfo;
import org.pkl.core.util.Nullable;

final class PCollectionToArray implements ConverterFactory {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,8 +23,8 @@
import java.util.Collection;
import java.util.Optional;
import java.util.function.Function;
import org.jspecify.annotations.Nullable;
import org.pkl.core.PClassInfo;
import org.pkl.core.util.Nullable;

class PCollectionToCollection implements ConverterFactory {
private static final Lookup lookup = MethodHandles.lookup();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,8 +24,8 @@
import java.util.Optional;
import java.util.Properties;
import java.util.function.Function;
import org.jspecify.annotations.Nullable;
import org.pkl.core.PClassInfo;
import org.pkl.core.util.Nullable;

class PMapToMap implements ConverterFactory {
private static final Lookup lookup = MethodHandles.lookup();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,10 +22,10 @@
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.reflect.*;
import java.util.*;
import org.jspecify.annotations.Nullable;
import org.pkl.core.Composite;
import org.pkl.core.PClassInfo;
import org.pkl.core.PObject;
import org.pkl.core.util.Nullable;

public class PObjectToDataObject implements ConverterFactory {
private static final Lookup lookup = MethodHandles.lookup();
Expand Down Expand Up @@ -156,7 +156,7 @@ private static class ConverterImpl<T> implements Converter<Composite, T> {
private final MethodHandle constructorHandle;
private final Collection<Tuple2<String, Type>> parameters;
private final PClassInfo<Object>[] cachedPropertyTypes;
private final Converter<Object, T>[] cachedConverters;
private final @Nullable Converter<Object, T>[] cachedConverters;

ConverterImpl(
Type targetType,
Expand All @@ -172,7 +172,7 @@ private static class ConverterImpl<T> implements Converter<Composite, T> {
Arrays.fill(cachedPropertyTypes, PClassInfo.Unavailable);

@SuppressWarnings("unchecked")
Converter<Object, T>[] cachedConverters = new Converter[parameters.size()];
@Nullable Converter<Object, T>[] cachedConverters = new Converter[parameters.size()];
Comment thread
HT154 marked this conversation as resolved.
this.cachedConverters = cachedConverters;
}

Expand Down Expand Up @@ -203,8 +203,9 @@ public T convert(Composite value, ValueMapper valueMapper) {
cachedPropertyTypes[i] = cachedPropertyType;
cachedConverters[i] = valueMapper.getConverter(cachedPropertyType, param.second);
}
assert cachedConverters[i] != null;
args[i] = cachedConverters[i].convert(property, valueMapper);
var cachedConverter = cachedConverters[i];
assert cachedConverter != null;
args[i] = cachedConverter.convert(property, valueMapper);
i += 1;
} catch (ConversionException e) {
throw new ConversionException(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,9 +18,9 @@
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Optional;
import org.jspecify.annotations.Nullable;
import org.pkl.core.PClassInfo;
import org.pkl.core.Pair;
import org.pkl.core.util.Nullable;

final class PPairToPair implements ConverterFactory {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -46,12 +46,16 @@ private ConverterImpl(Class<?> enumType) {
if (enumType == DataSizeUnit.class) {
for (var value : values) {
var unit = (DataSizeUnit) value;
enumValuesByName.put(CodeGeneratorUtils.toEnumConstantName(unit.getSymbol()), value);
var name = CodeGeneratorUtils.toEnumConstantName(unit.getSymbol());
assert name != null;
enumValuesByName.put(name, value);
}
} else if (enumType == DurationUnit.class) {
for (var value : values) {
var unit = (DurationUnit) value;
enumValuesByName.put(CodeGeneratorUtils.toEnumConstantName(unit.getSymbol()), value);
var name = CodeGeneratorUtils.toEnumConstantName(unit.getSymbol());
assert name != null;
enumValuesByName.put(name, value);
}
} else {
for (Enum<?> value : values) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,7 +20,7 @@
import io.leangen.geantyref.CaptureType;
import io.leangen.geantyref.GenericTypeReflector;
import java.lang.reflect.*;
import org.pkl.core.util.Nullable;
import org.jspecify.annotations.Nullable;

/**
* Reflection utilities for implementing {@link ConverterFactory}s. Mostly covers introspection of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2026 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,7 +16,7 @@
package org.pkl.config.java.mapper;

import java.util.Objects;
import org.pkl.core.util.Nullable;
import org.jspecify.annotations.Nullable;

// avoid name clash with org.pkl.core.Pair
final class Tuple2<S, T> {
Expand Down
Loading