use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.
the class EMFGeneratorFragment2 method generate.
@Override
public void generate() {
boolean _isEmpty = IterableExtensions.isEmpty(Iterables.<GeneratedMetamodel>filter(this.getGrammar().getMetamodelDeclarations(), GeneratedMetamodel.class));
if (_isEmpty) {
return;
}
try {
final Grammar clonedGrammar = this.cloneGrammarIntoNewResourceSet(this.getGrammar());
final ResourceSet workingResourceSet = clonedGrammar.eResource().getResourceSet();
final Function1<GeneratedMetamodel, EPackage> _function = (GeneratedMetamodel it) -> {
return it.getEPackage();
};
final List<EPackage> generatedPackages = IterableExtensions.<EPackage>toList(IterableExtensions.<GeneratedMetamodel, EPackage>map(Iterables.<GeneratedMetamodel>filter(clonedGrammar.getMetamodelDeclarations(), GeneratedMetamodel.class), _function));
if ((this.genModel != null)) {
this.registerUsedGenModel(workingResourceSet.getURIConverter(), clonedGrammar);
}
boolean _isEmpty_1 = generatedPackages.isEmpty();
boolean _not = (!_isEmpty_1);
if (_not) {
final Map<String, EPackage> usedEPackages = this.findAllUsedEPackages(generatedPackages);
final Map<String, EPackage> loadedEPackages = this.findEPackagesInGenPackages(usedEPackages.keySet(), workingResourceSet);
final Map<EObject, EObject> eNamedElementMapping = this.createENamedElementMapping(usedEPackages, loadedEPackages);
this.replaceReferencesInGeneratedPackages(generatedPackages, eNamedElementMapping);
final Resource ePackageResource = this.createResourceForEPackages(clonedGrammar, generatedPackages, workingResourceSet);
if ((!this.skipGenerate)) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("Generating EMF model");
{
if (this.generateEdit) {
{
if (this.generateEditor) {
_builder.append(", edit");
} else {
_builder.append(" and edit");
}
}
}
}
{
if (this.generateEditor) {
_builder.append(" and editor");
}
}
_builder.append(" code");
EMFGeneratorFragment2.LOG.info(_builder);
final GenModel genModel = this.getSaveAndReconcileGenModel(clonedGrammar, generatedPackages, workingResourceSet);
genModel.reconcile();
this.doGenerate(genModel);
this.addProjectContributions(clonedGrammar, generatedPackages, workingResourceSet);
if (this.bindEPackageAndEFactory) {
for (final EPackage pkg : generatedPackages) {
{
final GenPackage genPkg = GenModelUtil2.getGenPackage(pkg, genModel.eResource().getResourceSet());
GuiceModuleAccess.BindingFactory _bindingFactory = new GuiceModuleAccess.BindingFactory();
TypeReference _typeRef = TypeReference.typeRef(genPkg.getQualifiedPackageInterfaceName());
StringConcatenationClient _client = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
String _packageInterfaceName = genPkg.getPackageInterfaceName();
_builder.append(_packageInterfaceName);
_builder.append(".eINSTANCE");
}
};
GuiceModuleAccess.BindingFactory _addTypeToInstance = _bindingFactory.addTypeToInstance(_typeRef, _client);
TypeReference _typeRef_1 = TypeReference.typeRef(genPkg.getQualifiedFactoryInterfaceName());
StringConcatenationClient _client_1 = new StringConcatenationClient() {
@Override
protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
String _factoryInterfaceName = genPkg.getFactoryInterfaceName();
_builder.append(_factoryInterfaceName);
_builder.append(".eINSTANCE");
}
};
_addTypeToInstance.addTypeToInstance(_typeRef_1, _client_1).contributeTo(this.getLanguage().getRuntimeGenModule());
}
}
}
}
this.saveResource(ePackageResource);
}
this.updateBuildProperties();
} catch (final Throwable _t) {
if (_t instanceof Exception) {
final Exception e = (Exception) _t;
EMFGeneratorFragment2.LOG.error("Failed to execute EMF generator", e);
} else {
throw Exceptions.sneakyThrow(_t);
}
}
}
use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.
the class GrammarAccessFragment2 method addAllGrammarsToResource.
protected void addAllGrammarsToResource(final Resource resource, final Grammar grammar, final Set<Grammar> visitedGrammars) {
boolean _add = visitedGrammars.add(grammar);
boolean _not = (!_add);
if (_not) {
return;
}
resource.getContents().add(grammar);
EList<AbstractMetamodelDeclaration> _metamodelDeclarations = grammar.getMetamodelDeclarations();
for (final AbstractMetamodelDeclaration metamodelDecl : _metamodelDeclarations) {
{
final EPackage pack = metamodelDecl.getEPackage();
final Resource packResource = pack.eResource();
String _string = packResource.getURI().toString();
String _nsURI = pack.getNsURI();
boolean _notEquals = (!Objects.equal(_string, _nsURI));
if (_notEquals) {
final ResourceSet packResourceSet = packResource.getResourceSet();
if ((packResourceSet != null)) {
EPackage topMost = pack;
while (((topMost.getESuperPackage() != null) && (topMost.getESuperPackage().eResource() == topMost.eResource()))) {
topMost = topMost.getESuperPackage();
}
if ((packResource.getContents().contains(topMost) && (packResource.getContents().size() == 1))) {
boolean _isEmpty = topMost.getEClassifiers().isEmpty();
boolean _not_1 = (!_isEmpty);
if (_not_1) {
packResource.setURI(URI.createURI(topMost.getNsURI()));
} else {
this.moveSubpackagesToNewResource(topMost, resource.getResourceSet());
}
}
boolean _equals = topMost.eResource().getURI().toString().equals(topMost.getNsURI());
boolean _not_2 = (!_equals);
if (_not_2) {
this.movePackageToNewResource(topMost, resource.getResourceSet());
}
}
}
}
}
EList<Grammar> _usedGrammars = grammar.getUsedGrammars();
for (final Grammar usedGrammar : _usedGrammars) {
this.addAllGrammarsToResource(resource, usedGrammar, visitedGrammars);
}
}
use of org.eclipse.emf.ecore.resource.ResourceSet in project tdi-studio-se by Talend.
the class ImportItemUtil method createResource.
private Resource createResource(ItemRecord itemRecord, IPath path, boolean byteArrayResource) throws FileNotFoundException {
Resource resource;
ResourceSet resourceSet = itemRecord.getResourceSet();
if (byteArrayResource) {
resource = new ByteArrayResource(getURI(path));
resourceSet.getResources().add(resource);
} else {
if (FileConstants.ITEM_EXTENSION.equals(path.getFileExtension())) {
String projectName = "";
if (itemRecord.getItemProject() != null) {
projectName = itemRecord.getItemProject().getTechnicalLabel();
projectName = projectName.toLowerCase();
}
// note: do similar code as the CwmResourceFactory
//$NON-NLS-1$
String business = projectName + "/businessProcess/";
//$NON-NLS-1$
String context = projectName + "/context/";
//$NON-NLS-1$
String process = projectName + "/process/";
//$NON-NLS-1$
String joblet = projectName + "/joblets/";
String pathString = path.toPortableString();
pathString = pathString.toLowerCase();
// PTODO, maybe will bring bugs, like mr job,route, maybe jobscript
if (pathString.contains(process) || pathString.contains(context) || pathString.contains(business) || pathString.contains(joblet)) {
resource = new TalendXMIResource(getURI(path));
} else {
resource = new CwmResource(getURI(path));
}
resourceSet.getResources().add(resource);
} else {
resource = resourceSet.createResource(getURI(path));
}
}
return resource;
}
use of org.eclipse.emf.ecore.resource.ResourceSet in project benchmarx by eMoflon.
the class MediniQVTFamiliesToPersonsConfig method saveModels.
/**
* Allows to save the current state of the source and target models
*
* @param name : Filename
*/
public void saveModels(String name) {
ResourceSet set = new ResourceSetImpl();
set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
URI srcURI = URI.createFileURI(RESULTPATH + "/" + name + "Family.xmi");
URI trgURI = URI.createFileURI(RESULTPATH + "/" + name + "Person.xmi");
Resource resSource = set.createResource(srcURI);
Resource resTarget = set.createResource(trgURI);
EObject colSource = EcoreUtil.copy(getSourceModel());
EObject colTarget = EcoreUtil.copy(getTargetModel());
resSource.getContents().add(colSource);
resTarget.getContents().add(colTarget);
try {
resSource.save(null);
resTarget.save(null);
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-xtend by eclipse.
the class EclipseFileSystemTest method testIssue383.
@Test
public void testIssue383() {
if ((this.fs instanceof AbstractFileSystemSupport)) {
final AbstractFileSystemSupport afs = ((AbstractFileSystemSupport) this.fs);
final IProject px = this.createProject("px");
this.createProject("py");
final ResourceSet rs = this.resourceSetProvider.get(px);
final Resource rx = rs.createResource(URI.createPlatformResourceURI("px/foo/xxxx", true));
final Resource rxb = rs.createResource(URI.createPlatformResourceURI("px/bar/yyyy", true));
final Resource ry = rs.createResource(URI.createPlatformResourceURI("py/bar/xxxx", true));
Path pathx = afs.getPath(rx);
Assert.assertEquals("/px/foo/xxxx", pathx.toString());
Path pathxb = afs.getPath(rxb);
Assert.assertEquals("/px/bar/yyyy", pathxb.toString());
Path pathy = afs.getPath(ry);
Assert.assertEquals("/py/bar/xxxx", pathy.toString());
} else {
Assert.fail("fs is no AbstractFileSystemSupport");
}
}
Aggregations