Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ private void printError(String message, @Nullable Object... args) {
*/
private int execute() throws IOException {
// collect available meta-models
EPackage.Registry registry = new PackageModelCollector(metaModelPath).collect();
var collectionResult = new PackageModelCollector(metaModelPath).collect();
List<PackageModelCollector.Issue> issues = collectionResult.left();
EPackage.Registry registry = collectionResult.right();

issues.forEach(System.err::println);

// parse query
var setup = new NeoJoinStandaloneSetup(registry);
Expand Down
27 changes: 20 additions & 7 deletions lang/frontend/ide/src/main/java/tools/vitruv/neojoin/ide/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.io.PrintStream;
import java.io.PrintWriter;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;

@NullUnmarked
Expand Down Expand Up @@ -54,12 +56,18 @@ static class Logging {
public void run() {
var ioConfig = redirectIo();

String errorMessage = null;
List<String> errorMessages = new ArrayList<>();
try {
NeoJoinIdeSetup.Registry = new PackageModelCollector(metaModelPath).collect();
var collectionResult = new PackageModelCollector(metaModelPath).collect();
NeoJoinIdeSetup.Registry = collectionResult.right();

collectionResult.left().forEach(issue ->
errorMessages.add(issue.toString())
);
} catch (Exception ex) {
NeoJoinIdeSetup.Registry = new EPackageRegistryImpl();
errorMessage = "Invalid meta-model path: " + ex.getMessage();
var errorMessage = "Invalid meta-model path: " + ex.getMessage();
errorMessages.add(errorMessage);
System.err.printf("[ERROR] %s%n > full meta-model path: %s%n", errorMessage, metaModelPath);
}

Expand All @@ -71,9 +79,9 @@ public void run() {
ioConfig.in(), ioConfig.out(),
true, ioConfig.trace()
);
if (errorMessage != null) {
launcher.getRemoteProxy().showMessage(new MessageParams(MessageType.Error, errorMessage));
}

showErrorMessages(launcher, errorMessages);

languageServer.connect(launcher.getRemoteProxy());
var future = launcher.startListening();

Expand All @@ -86,6 +94,12 @@ public void run() {
}
}

private void showErrorMessages(Launcher<LanguageClient> launcher, Iterable<String> errorMessages) {
for (var errorMessage : errorMessages) {
launcher.getRemoteProxy().showMessage(new MessageParams(MessageType.Error, errorMessage));
}
}

private record LanguageServerIoConfig(
InputStream in,
OutputStream out,
Expand Down Expand Up @@ -142,5 +156,4 @@ private boolean isTraceLoggingEnabled() {
public static void main(String[] args) {
System.exit(new CommandLine(new Main()).execute(args));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
import tools.vitruv.neojoin.utils.EMFUtils;
import tools.vitruv.neojoin.utils.Pair;

import java.util.ArrayList;
import java.util.List;

/**
* Searches for meta-model files with the {@code .ecore} extension and collects them into a package registry.
Expand All @@ -25,23 +29,36 @@ public PackageModelCollector(String searchPathString) {
super(searchPathString);
}

public EPackage.Registry collect() {
public Pair<List<Issue>, EPackage.Registry> collect() {
if (!Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey(FileExtension)) {
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
FileExtension, new EcoreResourceFactoryImpl());
}

var registry = new EPackageRegistryImpl();
List<Issue> issues = new ArrayList<>();

collectResourcesAsStream(new ResourceSetImpl()).forEach(res ->
EMFUtils.getAllEPackages(res).forEach(pack -> {
var previousValue = registry.put(pack.getNsURI(), pack);
if (previousValue != null) {
throw new IllegalArgumentException("Found multiple packages with URI '%s'.".formatted(pack.getNsURI()));
}
}));
if (registry.containsKey(pack.getNsURI())) {
issues.add(new Issue.PackageURIDuplication(pack.getNsURI()));
} else {
registry.put(pack.getNsURI(), pack);
}
})
);

return registry;
return new Pair<>(issues, registry);
}

public sealed interface Issue {

record PackageURIDuplication(String packageUri) implements Issue {

@Override
public String toString() {
return "Found multiple packages with URI '%s'.".formatted(packageUri);
}
}
}
}
Loading