Convert org.pkl.core.util POJOs to record classes (#750)

This commit is contained in:
Kushal Pisavadia
2024-11-11 18:00:33 +00:00
committed by GitHub
parent 0d199892b8
commit ff60f61cbb
5 changed files with 8 additions and 33 deletions

View File

@@ -54,7 +54,7 @@ public final class ImportGlobMemberBodyNode extends ExpressionNode {
private VmTyped importModule(VmObjectLike mapping, String path) { private VmTyped importModule(VmObjectLike mapping, String path) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
var globElements = (Map<String, ResolvedGlobElement>) mapping.getExtraStorage(); var globElements = (Map<String, ResolvedGlobElement>) mapping.getExtraStorage();
var importUri = globElements.get(path).getUri(); var importUri = globElements.get(path).uri();
var context = VmContext.get(this); var context = VmContext.get(this);
try { try {
context.getSecurityManager().checkImportModule(currentModule.getUri(), importUri); context.getSecurityManager().checkImportModule(currentModule.getUri(), importUri);

View File

@@ -41,7 +41,7 @@ public class ReadGlobMemberBodyNode extends ExpressionNode {
private Object readResource(VmObjectLike mapping, String path) { private Object readResource(VmObjectLike mapping, String path) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
var globElements = (Map<String, ResolvedGlobElement>) mapping.getExtraStorage(); var globElements = (Map<String, ResolvedGlobElement>) mapping.getExtraStorage();
var resourceUri = VmUtils.getMapValue(globElements, path).getUri(); var resourceUri = VmUtils.getMapValue(globElements, path).uri();
var resource = VmContext.get(this).getResourceManager().read(resourceUri, this).orElse(null); var resource = VmContext.get(this).getResourceManager().read(resourceUri, this).orElse(null);
if (resource == null) { if (resource == null) {
CompilerDirectives.transferToInterpreter(); CompilerDirectives.transferToInterpreter();

View File

@@ -114,7 +114,7 @@ public class VmImportAnalyzer {
entry.stringValue()); entry.stringValue());
var globImports = var globImports =
elements.values().stream() elements.values().stream()
.map(ResolvedGlobElement::getUri) .map(ResolvedGlobElement::uri)
.map(ImportGraph.Import::new) .map(ImportGraph.Import::new)
.toList(); .toList();
result.addAll(globImports); result.addAll(globImports);

View File

@@ -45,29 +45,12 @@ public final class GlobResolver {
} }
} }
public static final class ResolvedGlobElement { public record ResolvedGlobElement(String path, URI uri, boolean isDirectory) {
private final String path;
private final URI uri;
private final boolean isDirectory;
public ResolvedGlobElement(String path, URI uri, boolean isDirectory) { public ResolvedGlobElement(String path, URI uri, boolean isDirectory) {
this.path = path; this.path = path;
this.uri = uri.normalize(); this.uri = uri.normalize();
this.isDirectory = isDirectory; this.isDirectory = isDirectory;
} }
public String getPath() {
return path;
}
public URI getUri() {
return uri;
}
public boolean isDirectory() {
return isDirectory;
}
} }
private static final char NULL = 0; private static final char NULL = 0;
@@ -434,15 +417,15 @@ public final class GlobResolver {
listElementCallCount); listElementCallCount);
for (var element : matchedElements) { for (var element : matchedElements) {
if (isLeaf) { if (isLeaf) {
result.put(element.getPath(), element); result.put(element.path(), element);
} else if (element.isDirectory()) { } else if (element.isDirectory()) {
resolveHierarchicalGlob( resolveHierarchicalGlob(
securityManager, securityManager,
reader, reader,
globPatternParts, globPatternParts,
idx + 1, idx + 1,
element.getUri(), element.uri(),
element.getPath(), element.path(),
hasAbsoluteGlob, hasAbsoluteGlob,
result, result,
listElementCallCount); listElementCallCount);

View File

@@ -48,15 +48,7 @@ public abstract class YamlResolver implements ScalarResolver {
return Tag.STR; return Tag.STR;
} }
private static final class ResolverTuple { private record ResolverTuple(Tag tag, Pattern regexp) {
private final Tag tag;
private final Pattern regexp;
ResolverTuple(Tag tag, Pattern regexp) {
this.tag = tag;
this.regexp = regexp;
}
@Override @Override
public String toString() { public String toString() {
return "Tuple tag=" + tag + " regexp=" + regexp; return "Tuple tag=" + tag + " regexp=" + regexp;