Remove Config.makeConfig (#1531)

This doesn't really make sense as part of the `Config` API.

We can maybe make class `ConfigUtils` public, but, I don't know how useful it
is anyways; it's more of an implementation detail.
This commit is contained in:
Daniel Chao
2026-04-17 11:19:02 -07:00
committed by GitHub
parent 1571d72111
commit b1a5d8c915
4 changed files with 48 additions and 15 deletions
@@ -31,6 +31,12 @@ XXX
Things to watch out for when upgrading. Things to watch out for when upgrading.
=== Removed Java APIs
The following APIs have been removed without replacement.
* `org.pkl.config.java.Config#makeConfig` (pr:https://github.com/apple/pkl/pull/1531[])
.XXX .XXX
[%collapsible] [%collapsible]
==== ====
@@ -15,13 +15,13 @@
*/ */
package org.pkl.config.java; package org.pkl.config.java;
import static org.pkl.config.java.ConfigUtils.makeConfig;
import java.io.InputStream; import java.io.InputStream;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.Map;
import org.jspecify.annotations.Nullable; import org.jspecify.annotations.Nullable;
import org.pkl.config.java.mapper.ConversionException; import org.pkl.config.java.mapper.ConversionException;
import org.pkl.config.java.mapper.ValueMapper; import org.pkl.config.java.mapper.ValueMapper;
import org.pkl.core.Composite;
import org.pkl.core.Evaluator; import org.pkl.core.Evaluator;
import org.pkl.core.PklBinaryDecoder; import org.pkl.core.PklBinaryDecoder;
@@ -30,6 +30,7 @@ import org.pkl.core.PklBinaryDecoder;
* using {@link #get(String)}. To consume the node's composite or scalar value, convert the value to * using {@link #get(String)}. To consume the node's composite or scalar value, convert the value to
* the desired Java type, using one of the provided {@link #as} methods. * the desired Java type, using one of the provided {@link #as} methods.
*/ */
@SuppressWarnings("unused")
public interface Config { public interface Config {
/** /**
* The dot-separated name of this node. For example, the node reached using {@code * The dot-separated name of this node. For example, the node reached using {@code
@@ -110,14 +111,4 @@ public interface Config {
static Config fromPklBinary(InputStream inputStream) { static Config fromPklBinary(InputStream inputStream) {
return fromPklBinary(inputStream, ValueMapper.preconfigured()); return fromPklBinary(inputStream, ValueMapper.preconfigured());
} }
static Config makeConfig(Object decoded, ValueMapper mapper) {
if (decoded instanceof Composite composite) {
return new CompositeConfig("", mapper, composite);
}
if (decoded instanceof Map<?, ?> map) {
return new MapConfig("", mapper, map);
}
return new LeafConfig("", mapper, decoded);
}
} }
@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
*/ */
package org.pkl.config.java; package org.pkl.config.java;
import static org.pkl.config.java.ConfigUtils.makeConfig;
import org.pkl.config.java.mapper.ValueMapper; import org.pkl.config.java.mapper.ValueMapper;
import org.pkl.core.Evaluator; import org.pkl.core.Evaluator;
import org.pkl.core.ModuleSource; import org.pkl.core.ModuleSource;
@@ -37,13 +39,13 @@ final class ConfigEvaluatorImpl implements ConfigEvaluator {
@Override @Override
public Config evaluateOutputValue(ModuleSource moduleSource) { public Config evaluateOutputValue(ModuleSource moduleSource) {
var value = evaluator.evaluateOutputValue(moduleSource); var value = evaluator.evaluateOutputValue(moduleSource);
return Config.makeConfig(value, mapper); return makeConfig(value, mapper);
} }
@Override @Override
public Config evaluateExpression(ModuleSource moduleSource, String expression) { public Config evaluateExpression(ModuleSource moduleSource, String expression) {
var value = evaluator.evaluateExpression(moduleSource, expression); var value = evaluator.evaluateExpression(moduleSource, expression);
return Config.makeConfig(value, mapper); return makeConfig(value, mapper);
} }
@Override @Override
@@ -0,0 +1,34 @@
/*
* Copyright © 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pkl.config.java;
import java.util.Map;
import org.pkl.config.java.mapper.ValueMapper;
import org.pkl.core.Composite;
class ConfigUtils {
private ConfigUtils() {}
static Config makeConfig(Object decoded, ValueMapper mapper) {
if (decoded instanceof Composite composite) {
return new CompositeConfig("", mapper, composite);
}
if (decoded instanceof Map<?, ?> map) {
return new MapConfig("", mapper, map);
}
return new LeafConfig("", mapper, decoded);
}
}