code improvements, add pipeline stages
This commit is contained in:
+20
-5
@@ -9,14 +9,19 @@ import p.studio.compiler.utilities.SourceProviderFactory;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
|
||||
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
||||
public class SourceHandle {
|
||||
@Getter
|
||||
private final ProjectId projectId;
|
||||
@Getter
|
||||
private final Path relativePath;
|
||||
@EqualsAndHashCode.Include
|
||||
@Getter
|
||||
private final Path path; // canon path to file
|
||||
private final Path canonPath;
|
||||
@Getter
|
||||
private final String filename;
|
||||
@Getter
|
||||
@@ -27,16 +32,18 @@ public class SourceHandle {
|
||||
|
||||
public SourceHandle(
|
||||
final ProjectId projectId,
|
||||
final Path path,
|
||||
final Path relativePath,
|
||||
final Path canonPath,
|
||||
final long size,
|
||||
final long lastModified,
|
||||
final SourceProviderFactory factory) {
|
||||
this.projectId = projectId;
|
||||
this.path = path;
|
||||
this.filename = path.getFileName().toString();
|
||||
this.relativePath = relativePath;
|
||||
this.canonPath = canonPath;
|
||||
this.filename = canonPath.getFileName().toString();
|
||||
this.size = size;
|
||||
this.lastModified = lastModified;
|
||||
this.provider = factory.create(path);
|
||||
this.provider = factory.create(canonPath);
|
||||
}
|
||||
|
||||
public byte[] readBytes() throws IOException {
|
||||
@@ -46,4 +53,12 @@ public class SourceHandle {
|
||||
public String readUtf8() throws IOException {
|
||||
return new String(readBytes(), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SourceHandle{ %s, %s, %sKb, mod: %s }".formatted(projectId,
|
||||
relativePath,
|
||||
size / 1024,
|
||||
LocalDateTime.ofInstant(Instant.ofEpochMilli(lastModified), ZoneId.systemDefault()));
|
||||
}
|
||||
}
|
||||
+15
-7
@@ -6,29 +6,37 @@ import p.studio.compiler.source.identifiers.FileId;
|
||||
import p.studio.compiler.source.identifiers.ProjectId;
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class FileTable extends InternTable<FileId, SourceHandle> implements FileTableReader {
|
||||
|
||||
private final Map<ProjectId, Set<FileId>> projectFiles = new HashMap<>();
|
||||
private final FileIds[] projectFiles;
|
||||
|
||||
public FileTable() {
|
||||
public FileTable(int projectCapacity) {
|
||||
super(FileId::new);
|
||||
projectFiles = new FileIds[projectCapacity];
|
||||
Arrays.setAll(projectFiles, ignored -> new FileIds());
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileId register(final SourceHandle value) {
|
||||
final var fileId = super.register(value);
|
||||
projectFiles.computeIfAbsent(value.getProjectId(), ignored -> new HashSet<>()).add(fileId);
|
||||
projectFiles[value.getProjectId().getIndex()].set.add(fileId);
|
||||
return fileId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReadOnlyList<FileId> getFiles(final ProjectId projectId) {
|
||||
final var fileIds = projectFiles.get(projectId);
|
||||
if (CollectionUtils.isEmpty(fileIds)) {
|
||||
final var fileIds = projectFiles[projectId.getIndex()];
|
||||
if (CollectionUtils.isEmpty(fileIds.set)) {
|
||||
return ReadOnlyList.empty();
|
||||
}
|
||||
return ReadOnlyList.wrap(fileIds);
|
||||
return ReadOnlyList.wrap(fileIds.set);
|
||||
}
|
||||
|
||||
private static class FileIds {
|
||||
public final Set<FileId> set = new HashSet<>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user