Skip to content

Commit

Permalink
Fix issue eclipse-gemoc#13
Browse files Browse the repository at this point in the history
Signed-off-by: fcoulon <fabien.coulon@obeo.fr>
  • Loading branch information
fcoulon committed Jun 12, 2019
1 parent 9aae275 commit de59f75
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,18 @@ public void initializeFrom(ILaunchConfiguration configuration) {
_entryPointModelElementLabel.setText("");
_entryPointMethodText.setText(runConfiguration.getExecutionEntryPoint());
updateMainElementName();

org.eclipse.gemoc.dsl.Dsl language = DslHelper.load(_languageCombo.getText());
if(language != null) {
List<String> errors = Helper.validate(language);
for(String error : errors) {
setErrorMessage(error);
}
}
else {
setErrorMessage("Can't find the language: '" + _languageCombo.getText() + "'");
}

} catch (CoreException e) {
Activator.error(e.getMessage(), e);
}
Expand Down Expand Up @@ -490,17 +502,23 @@ protected String getModelInitializationMethodName(){

Dsl environment = Helper.gemocDslToAleDsl(language);
ALEInterpreter interpreter = new ALEInterpreter();
List<ParseResult<ModelUnit>> parsedSemantics = (new DslBuilder(interpreter.getQueryEnvironment())).parse(environment);
Optional<Method> initOperation =
parsedSemantics
.stream()
.filter(sem -> sem.getRoot() != null)
.map(sem -> sem.getRoot())
.flatMap(unit -> unit.getClassExtensions().stream())
.filter(xtdCls -> xtdCls.getBaseClass().getName().equals(tagetClassName))
.flatMap(xtdCls -> xtdCls.getMethods().stream())
.filter(op -> op.getTags().contains("init"))
.findFirst();
Optional<Method> initOperation = Optional.empty();
try {
List<ParseResult<ModelUnit>> parsedSemantics = (new DslBuilder(interpreter.getQueryEnvironment())).parse(environment);
initOperation =
parsedSemantics
.stream()
.filter(sem -> sem.getRoot() != null)
.map(sem -> sem.getRoot())
.flatMap(unit -> unit.getClassExtensions().stream())
.filter(xtdCls -> xtdCls.getBaseClass().getName().equals(tagetClassName))
.flatMap(xtdCls -> xtdCls.getMethods().stream())
.filter(op -> op.getTags().contains("init"))
.findFirst();
}
catch(Exception e) {
e.printStackTrace();
}

if(initOperation.isPresent()){
return (new MethodLabelProvider()).getText(initOperation.get());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.eclipse.gemoc.ale.interpreted.engine;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
Expand All @@ -21,7 +24,50 @@ public static org.eclipse.emf.ecoretools.ale.core.parser.Dsl gemocDslToAleDsl(or
.map(elem -> URI.createFileURI(WorkbenchDsl.convertToFile(elem)).toString())
.collect(Collectors.toList());

return new WorkbenchDsl(ecoreFileUris,aleUris);
WorkbenchDsl res = new WorkbenchDsl(new ArrayList<String>(),new ArrayList<String>());
try {
res = new WorkbenchDsl(ecoreFileUris,aleUris);
}
catch(Exception e) {
e.printStackTrace();
}
return res;
}

/**
* Check language's Ecore & ALE URIs
*/
public static List<String> validate(org.eclipse.gemoc.dsl.Dsl language) {
List<String> errors = new ArrayList<>();

List<String> ecoreUris = getEcoreUris(language);
List<String> aleUris = getAleUris(language);

for(String uri : ecoreUris) {
boolean isPresent = false;
try {
isPresent = Files.exists(Paths.get(URI.createFileURI(WorkbenchDsl.convertToFile(uri)).toString()));
}
catch(Exception e) {}

if(!isPresent) {
errors.add("Can't find: " + uri + " (declared in the language '" + language.getName() + "'");
}
}

for(String uri : aleUris) {
boolean isPresent = false;
try {
isPresent = Files.exists(Paths.get(URI.createFileURI(WorkbenchDsl.convertToFile(uri)).toString()));
}
catch(Exception e) {}

if(!isPresent) {
errors.add("Can't find: " + uri + " (declared in the language '" + language.getName() + "'");
}
}

return errors;
}

public static List<String> getEcoreUris(org.eclipse.gemoc.dsl.Dsl language) {
Expand Down

0 comments on commit de59f75

Please sign in to comment.