Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » NoSuchElement exception when programmatically executing transformation
NoSuchElement exception when programmatically executing transformation [message #1807631] Wed, 05 June 2019 11:24 Go to next message
G LG is currently offline G LGFriend
Messages: 4
Registered: March 2019
Junior Member
Hi,

I am trying to programmatically execute a transformation on an EObject returned by an XText resource. The ATL transformation works when run from Eclipse on an xmi file corresponding to the same EObject returned by the same XText resource (similar piece of code except for the saving to XMI part).

When run programmatically, I get a NoSuchElementException when a registered operation ("first") tries to access its first local variable [return ((LinkedHashSet<?>)localVars[0]).iterator().next();] in ExecEnv$100.exec (called in ASMOperation.exec(...) line 391) while it does not have any local variables (localVars[0] exists but is an empty LinkedHashSet).

I am probably doing something wrong but I do not know what. Here is the code I use :

// XTEXT PART
Injector xtextInjector = new StarBNFStandaloneSetup().createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet = xtextInjector.getInstance(XtextResourceSet.class);
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
URI uri = URI.createPlatformResourceURI(srcFile.getFullPath().toString(), true);
Resource resource = resourceSet.getResource(uri, true);
bnf_parsing.starBNF.Grammar grammarInSBNF = (bnf_parsing.starBNF.Grammar) resource.getContents().get(0);

// ATL PART
// Initialization
ILauncher transformationLauncher = new EMFVMLauncher();
ModelFactory modelFactory = new EMFModelFactory();
IInjector atlInjector = new EMFInjector();
IExtractor extractor = new EMFExtractor();
// Retrieving *BNF ECore files
Bundle sbnfBundle = Platform.getBundle("bnf_parsing");
URL sbnfEcoreEntryURL = sbnfBundle.getEntry("model/generated/StarBNF.ecore");
java.net.URI sbnfMetamodelURI = null;
try { sbnfMetamodelURI = FileLocator.toFileURL(sbnfEcoreEntryURL).toURI(); }
catch (...) { ... }
// Retrieving CFG ECore files
Bundle cfgBundle = Platform.getBundle("Context-Free-Grammar");
URL cfgEcoreEntryURL = cfgBundle.getEntry("model/contextFreeGrammar.ecore");
java.net.URI cfgMetamodelURI = null;
try { cfgMetamodelURI = FileLocator.toFileURL(cfgEcoreEntryURL).toURI(); }
catch (...) { ... }
// Loading metamodels
IReferenceModel sbnfMetamodel = null;
IReferenceModel cfgMetamodel = null;
try {
sbnfMetamodel = modelFactory.newReferenceModel();
atlInjector.inject(sbnfMetamodel, sbnfMetamodelURI.toString());
cfgMetamodel = modelFactory.newReferenceModel();
atlInjector.inject(cfgMetamodel, cfgMetamodelURI.toString());
} catch (ATLCoreException e) { ... }
// Loading models
IModel sbnfModel = null;
IModel cfgModel = null;
try {
sbnfModel = modelFactory.newModel(sbnfMetamodel);
cfgModel = modelFactory.newModel(cfgMetamodel);
} catch (ATLCoreException e) { ... }
// Initializing IN model
transformationLauncher.initialize(new HashMap<String,Object>());
transformationLauncher.addInModel(sbnfModel, "IN", "StarBNF");
transformationLauncher.addOutModel(cfgModel, "OUT", "CFG");
// Loading transformation file
Bundle atlBundle = Platform.getBundle("ATL-Transformations-for-StarBNF-and-CFG");
URL asmEntryURL = atlBundle.getEntry("StarBNF2CFG.asm");
URL asmFileURL = null;
java.net.URI asmFileURI = null;
try {
asmFileURL = FileLocator.toFileURL(asmEntryURL);
asmFileURI = asmFileURL.toURI();
}
catch (IOException e) { ... }
FileInputStream asmIS = null;
try {
asmIS = new FileInputStream(asmFileURL.getPath());
// asmIS = new FileInputStream(asmFileURI.toString());
} catch (FileNotFoundException e) { ... }
Object asmModule = transformationLauncher. loadModule(asmIS);
// Running transformation
// >>>>> The following line raises the exception <<<<<
Object transformationResult = transformationLauncher.launch(
ILauncher.RUN_MODE,
new NullProgressMonitor(),
new HashMap<String,Object>(),
asmModule);

try { extractor.extract(cfgModel, dstPath.toString()); }
catch (ATLCoreException e) { ... }
// Unloading all models and metamodels (EMF-specific)
EMFModelFactory emfModelFactory = (EMFModelFactory) modelFactory;
emfModelFactory.unload((EMFModel) sbnfModel);
emfModelFactory.unload((EMFModel) cfgModel);
emfModelFactory.unload((EMFReferenceModel) sbnfMetamodel);
emfModelFactory.unload((EMFReferenceModel) cfgMetamodel);

Can someone provide me feedback on what I am doing wrong ?

Thanks,

Re: NoSuchElement exception when programmatically executing transformation [message #1808723 is a reply to message #1807631] Sun, 30 June 2019 10:33 Go to previous message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 589
Registered: September 2012
Location: Belgium
Senior Member

I can't figure this out without the ATL code.

B.t.w. Is there any reason you cannot use the latest EMFTVM runtime?


Cheers,
Dennis
Previous Topic:Invalid Context error in ATL
Next Topic:transformation problem (root class)
Goto Forum:
  


Current Time: Fri Mar 29 07:37:41 GMT 2024

Powered by FUDForum. Page generated in 0.02615 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top