implements PLN-0006
This commit is contained in:
+17
@@ -0,0 +1,17 @@
|
||||
package p.studio.compiler.messages;
|
||||
|
||||
public record Addressable(
|
||||
String address,
|
||||
int assetId) {
|
||||
|
||||
public Addressable {
|
||||
address = normalize(address);
|
||||
}
|
||||
|
||||
private static String normalize(final String address) {
|
||||
if (address == null) {
|
||||
return "";
|
||||
}
|
||||
return address.trim();
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package p.studio.compiler.messages;
|
||||
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public record FESurfaceContext(
|
||||
ReadOnlyList<Addressable> assets) {
|
||||
|
||||
public FESurfaceContext {
|
||||
assets = normalizeAssets(assets);
|
||||
}
|
||||
|
||||
public static FESurfaceContext empty() {
|
||||
return new FESurfaceContext(ReadOnlyList.empty());
|
||||
}
|
||||
|
||||
private static ReadOnlyList<Addressable> normalizeAssets(final ReadOnlyList<Addressable> assets) {
|
||||
if (assets == null || assets.isEmpty()) {
|
||||
return ReadOnlyList.empty();
|
||||
}
|
||||
final var dedup = new LinkedHashMap<String, Addressable>();
|
||||
for (final var asset : assets) {
|
||||
if (asset == null || asset.address().isBlank()) {
|
||||
continue;
|
||||
}
|
||||
dedup.put(asset.address(), asset);
|
||||
}
|
||||
return ReadOnlyList.wrap(new ArrayList<>(dedup.values()));
|
||||
}
|
||||
}
|
||||
+20
-2
@@ -14,12 +14,13 @@ public class FrontendPhaseContext {
|
||||
private final NameTable nameTable;
|
||||
private final int stdlibVersion;
|
||||
private final HostAdmissionContext hostAdmissionContext;
|
||||
private final FESurfaceContext feSurfaceContext;
|
||||
|
||||
public FrontendPhaseContext(
|
||||
final ProjectTableReader projectTable,
|
||||
final FileTableReader fileTable,
|
||||
final BuildStack stack) {
|
||||
this(projectTable, fileTable, stack, 1, HostAdmissionContext.permissiveDefault());
|
||||
this(projectTable, fileTable, stack, 1, HostAdmissionContext.permissiveDefault(), FESurfaceContext.empty());
|
||||
}
|
||||
|
||||
public FrontendPhaseContext(
|
||||
@@ -27,7 +28,7 @@ public class FrontendPhaseContext {
|
||||
final FileTableReader fileTable,
|
||||
final BuildStack stack,
|
||||
final int stdlibVersion) {
|
||||
this(projectTable, fileTable, stack, stdlibVersion, HostAdmissionContext.permissiveDefault());
|
||||
this(projectTable, fileTable, stack, stdlibVersion, HostAdmissionContext.permissiveDefault(), FESurfaceContext.empty());
|
||||
}
|
||||
|
||||
public FrontendPhaseContext(
|
||||
@@ -36,6 +37,16 @@ public class FrontendPhaseContext {
|
||||
final BuildStack stack,
|
||||
final int stdlibVersion,
|
||||
final HostAdmissionContext hostAdmissionContext) {
|
||||
this(projectTable, fileTable, stack, stdlibVersion, hostAdmissionContext, FESurfaceContext.empty());
|
||||
}
|
||||
|
||||
public FrontendPhaseContext(
|
||||
final ProjectTableReader projectTable,
|
||||
final FileTableReader fileTable,
|
||||
final BuildStack stack,
|
||||
final int stdlibVersion,
|
||||
final HostAdmissionContext hostAdmissionContext,
|
||||
final FESurfaceContext feSurfaceContext) {
|
||||
this.projectTable = projectTable;
|
||||
this.fileTable = fileTable;
|
||||
this.stack = stack;
|
||||
@@ -44,6 +55,9 @@ public class FrontendPhaseContext {
|
||||
this.hostAdmissionContext = hostAdmissionContext == null
|
||||
? HostAdmissionContext.permissiveDefault()
|
||||
: hostAdmissionContext;
|
||||
this.feSurfaceContext = feSurfaceContext == null
|
||||
? FESurfaceContext.empty()
|
||||
: feSurfaceContext;
|
||||
}
|
||||
|
||||
public SourceKind sourceKind(final ProjectId projectId) {
|
||||
@@ -61,4 +75,8 @@ public class FrontendPhaseContext {
|
||||
public NameTable nameTable() {
|
||||
return nameTable;
|
||||
}
|
||||
|
||||
public FESurfaceContext feSurfaceContext() {
|
||||
return feSurfaceContext;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user