organize and clean up
This commit is contained in:
+44
@@ -0,0 +1,44 @@
|
||||
package p.studio.compiler.dtos;
|
||||
|
||||
import com.fasterxml.jackson.annotation.*;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record PrometeuManifestDTO(
|
||||
String name,
|
||||
String version,
|
||||
String language,
|
||||
List<DependencyDeclaration> dependencies) {
|
||||
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)
|
||||
@JsonSubTypes({
|
||||
@JsonSubTypes.Type(value = DependencyDeclaration.Local.class),
|
||||
@JsonSubTypes.Type(value = DependencyDeclaration.Git.class)
|
||||
})
|
||||
public interface DependencyDeclaration {
|
||||
@Getter
|
||||
class Local implements DependencyDeclaration {
|
||||
private final String path;
|
||||
|
||||
@JsonCreator
|
||||
public Local(@JsonProperty("path") final String path) {
|
||||
this.path = path;
|
||||
}
|
||||
}
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@Getter
|
||||
class Git implements DependencyDeclaration {
|
||||
private final String url;
|
||||
private final String rev;
|
||||
|
||||
@JsonCreator
|
||||
public Git(@JsonProperty("url") final String url, @JsonProperty("rev") final String rev) {
|
||||
this.url = url;
|
||||
this.rev = rev;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
@@ -10,4 +10,5 @@ public class FrontendSpec {
|
||||
private final String languageId;
|
||||
private final ReadOnlySet<String> allowedExtensions;
|
||||
private final ReadOnlySet<String> sourceRoots;
|
||||
private final boolean caseSensitive;
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
package p.studio.compiler.source.identifiers;
|
||||
|
||||
public class FileId extends AbstractSourceIdentifier {
|
||||
public static final FileId NONE = new FileId(-1L);
|
||||
public class FileId extends SourceIdentifier {
|
||||
public static final FileId NONE = new FileId(-1);
|
||||
|
||||
public FileId(long id) {
|
||||
public FileId(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
package p.studio.compiler.source.identifiers;
|
||||
|
||||
public class ModuleId extends AbstractSourceIdentifier {
|
||||
public ModuleId(long id) {
|
||||
public class ModuleId extends SourceIdentifier {
|
||||
public ModuleId(int id) {
|
||||
super(id);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
package p.studio.compiler.source.identifiers;
|
||||
|
||||
public class NameId extends AbstractSourceIdentifier {
|
||||
public NameId(long id) {
|
||||
public class NameId extends SourceIdentifier {
|
||||
public NameId(int id) {
|
||||
super(id);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
package p.studio.compiler.source.identifiers;
|
||||
|
||||
public class NodeId extends AbstractSourceIdentifier {
|
||||
public NodeId(long id) {
|
||||
public class NodeId extends SourceIdentifier {
|
||||
public NodeId(int id) {
|
||||
super(id);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-5
@@ -1,11 +1,7 @@
|
||||
package p.studio.compiler.source.identifiers;
|
||||
|
||||
public class ProjectId extends AbstractSourceIdentifier {
|
||||
public class ProjectId extends SourceIdentifier {
|
||||
public ProjectId(int id) {
|
||||
super(Integer.toUnsignedLong(id));
|
||||
}
|
||||
|
||||
public ProjectId(long id) {
|
||||
super(id);
|
||||
}
|
||||
}
|
||||
|
||||
+10
-4
@@ -3,18 +3,24 @@ package p.studio.compiler.source.identifiers;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Getter
|
||||
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
||||
abstract class AbstractSourceIdentifier {
|
||||
public abstract class SourceIdentifier {
|
||||
@EqualsAndHashCode.Include
|
||||
private final long id;
|
||||
private final int id;
|
||||
|
||||
AbstractSourceIdentifier(long id) {
|
||||
public SourceIdentifier(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return (int) id;
|
||||
if (id < 0) {
|
||||
throw new IllegalArgumentException("index should be valid (positive)");
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package p.studio.compiler.source.identifiers;
|
||||
|
||||
public class SymbolId extends AbstractSourceIdentifier {
|
||||
public class SymbolId extends SourceIdentifier {
|
||||
public SymbolId(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
package p.studio.compiler.source.identifiers;
|
||||
|
||||
public class TypeId extends AbstractSourceIdentifier {
|
||||
public TypeId(long id) {
|
||||
public class TypeId extends SourceIdentifier {
|
||||
public TypeId(int id) {
|
||||
super(id);
|
||||
}
|
||||
}
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package p.studio.compiler.source.tables;
|
||||
|
||||
import p.studio.compiler.source.identifiers.SourceIdentifier;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
|
||||
public abstract class DenseTable<IDENTIFIER extends SourceIdentifier, VALUE> {
|
||||
private final List<VALUE> values = new ArrayList<>();
|
||||
private final Function<Integer, IDENTIFIER> identifierGenerator;
|
||||
|
||||
protected DenseTable(final Function<Integer, IDENTIFIER> identifierGenerator) {
|
||||
this.identifierGenerator = Objects.requireNonNull(identifierGenerator);
|
||||
}
|
||||
|
||||
public final int size() { return values.size(); }
|
||||
|
||||
public final VALUE get(IDENTIFIER id) {
|
||||
return values.get(id.getIndex());
|
||||
}
|
||||
|
||||
public IDENTIFIER register(VALUE value) {
|
||||
final int idx = values.size();
|
||||
values.add(value);
|
||||
return identifierGenerator.apply(idx);
|
||||
}
|
||||
|
||||
protected void clear() {
|
||||
values.clear();
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package p.studio.compiler.source.tables;
|
||||
|
||||
import p.studio.compiler.source.identifiers.FileId;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class FileTable extends InternTable<FileId, Path> {
|
||||
public FileTable() {
|
||||
super(FileId::new);
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package p.studio.compiler.source.tables;
|
||||
|
||||
import p.studio.compiler.source.identifiers.SourceIdentifier;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
public abstract class InternTable<IDENTIFIER extends SourceIdentifier, VALUE>
|
||||
extends DenseTable<IDENTIFIER, VALUE> {
|
||||
|
||||
private final Map<VALUE, IDENTIFIER> identifierByValue = new HashMap<>();
|
||||
|
||||
public InternTable(Function<Integer, IDENTIFIER> identifierGenerator) {
|
||||
super(identifierGenerator);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDENTIFIER register(final VALUE value) {
|
||||
return identifierByValue.computeIfAbsent(value, super::register);
|
||||
}
|
||||
|
||||
public IDENTIFIER get(final VALUE value) {
|
||||
return identifierByValue.get(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
super.clear();
|
||||
identifierByValue.clear();
|
||||
}
|
||||
|
||||
public boolean containsKey(VALUE value) {
|
||||
return identifierByValue.containsKey(value);
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package p.studio.compiler.source.tables;
|
||||
|
||||
import p.studio.compiler.source.identifiers.ProjectId;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class ProjectTable extends InternTable<ProjectId, Path> {
|
||||
public ProjectTable() {
|
||||
super(ProjectId::new);
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package p.studio.compiler.utilities;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import p.studio.compiler.dtos.PrometeuManifestDTO;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public final class PrometeuManifestMapper {
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
public static PrometeuManifestDTO read(Path manifestPath) {
|
||||
try {
|
||||
return mapper.readValue(manifestPath.toFile(), PrometeuManifestDTO.class);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("failed to read manifest " + manifestPath, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user