use of org.eclipse.emf.codegen.ecore.genmodel.GenPackage in project xtext-xtend by eclipse.
the class URIsInEcoreFilesXtendTest method doTestResource.
protected void doTestResource(String platformPath, String... packageNames) {
Resource resource = resourceSet.getResource(URI.createPlatformPluginURI(platformPath, false), true);
assertNotNull(resource);
assertEquals(1, resource.getContents().size());
EObject obj = resource.getContents().get(0);
if (obj instanceof EPackage) {
assertEquals(packageNames[0], ((EPackage) obj).getName());
} else if (obj instanceof GenModel) {
GenModel model = (GenModel) obj;
List<GenPackage> packages = Lists.newArrayList(model.getGenPackages());
assertEquals(packageNames.length, packages.size());
ListExtensions.sortInplaceBy(packages, new Functions.Function1<GenPackage, String>() {
@Override
public String apply(GenPackage p) {
return p.getEcorePackage().getName();
}
});
List<String> packageNamesList = Arrays.asList(packageNames);
Collections.sort(packageNamesList);
for (int i = 0; i < packageNamesList.size(); i++) {
assertEquals(packageNamesList.get(i), packages.get(i).getEcorePackage().getName());
}
IStatus status = model.validate();
assertTrue(printLeafs(status), status.isOK());
EObject orig = EcoreUtil.copy(obj);
((GenModel) obj).reconcile();
if (!EcoreUtil.equals(orig, obj)) {
Predicate<EStructuralFeature> ignoreContainer = new Predicate<EStructuralFeature>() {
@Override
public boolean apply(EStructuralFeature f) {
if (f instanceof EReference) {
EReference casted = (EReference) f;
return !casted.isContainment();
}
return false;
}
};
String origAsString = EmfFormatter.objToStr(orig, ignoreContainer);
String newAsString = EmfFormatter.objToStr(obj, ignoreContainer);
throw new ComparisonFailure("Reconcile changed model", origAsString, newAsString);
}
} else {
fail("Unexpected root element type: " + obj.eClass().getName());
}
}
use of org.eclipse.emf.codegen.ecore.genmodel.GenPackage in project xtext-core by eclipse.
the class GenModelUtil2 method getGenClassifier.
public static GenClassifier getGenClassifier(final EClassifier cls, final ResourceSet resourceSet) {
final GenPackage genPackage = GenModelUtil2.getGenPackage(cls.getEPackage(), resourceSet);
EList<GenClassifier> _genClassifiers = genPackage.getGenClassifiers();
for (final GenClassifier genCls : _genClassifiers) {
String _name = cls.getName();
String _name_1 = genCls.getEcoreClassifier().getName();
boolean _equals = Objects.equal(_name, _name_1);
if (_equals) {
return genCls;
}
}
StringConcatenation _builder = new StringConcatenation();
_builder.append("No GenClassifier named \'");
String _name_2 = cls.getName();
_builder.append(_name_2);
_builder.append("\' found in GenModel ");
URI _uRI = genPackage.eResource().getURI();
_builder.append(_uRI);
throw new RuntimeException(_builder.toString());
}
use of org.eclipse.emf.codegen.ecore.genmodel.GenPackage in project xtext-core by eclipse.
the class GenModelUtil2 method getGenModelResource.
public static Resource getGenModelResource(final String locationInfo, final String nsURI, final ResourceSet resourceSet) {
final URI genModelURI = EcorePlugin.getEPackageNsURIToGenModelLocationMap(false).get(nsURI);
if ((genModelURI == null)) {
boolean _equals = Objects.equal(EcorePackage.eNS_URI, nsURI);
if (_equals) {
return null;
}
EList<Resource> _resources = resourceSet.getResources();
for (final Resource res : _resources) {
EList<EObject> _contents = res.getContents();
for (final EObject obj : _contents) {
if ((obj instanceof GenModel)) {
EList<GenPackage> _genPackages = ((GenModel) obj).getGenPackages();
for (final GenPackage genPackage : _genPackages) {
String _nSURI = genPackage.getNSURI();
boolean _equals_1 = Objects.equal(_nSURI, nsURI);
if (_equals_1) {
return genPackage.eResource();
}
}
}
}
}
StringConcatenation _builder = new StringConcatenation();
_builder.append("Could not find a GenModel for EPackage \'");
_builder.append(nsURI);
_builder.append("\'");
{
boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(locationInfo);
boolean _not = (!_isNullOrEmpty);
if (_not) {
_builder.append(" from ");
_builder.append(locationInfo);
}
}
_builder.append(".");
_builder.newLineIfNotEmpty();
_builder.append("If the missing GenModel has been generated via ");
String _simpleName = EMFGeneratorFragment2.class.getSimpleName();
_builder.append(_simpleName);
_builder.append(", make sure to run it first in the workflow.");
_builder.newLineIfNotEmpty();
_builder.append("If you have a *.genmodel-file, make sure to register it via StandaloneSetup.registerGenModelFile(String).");
_builder.newLine();
throw new RuntimeException(_builder.toString());
}
if ((resourceSet == null)) {
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("There is no ResourceSet for EPackage \'");
_builder_1.append(nsURI);
_builder_1.append("\'. Please make sure the EPackage has been loaded from a .ecore file and not from the generated Java file.");
throw new RuntimeException(_builder_1.toString());
}
final Resource genModelResource = resourceSet.getResource(genModelURI, true);
if ((genModelResource == null)) {
StringConcatenation _builder_2 = new StringConcatenation();
_builder_2.append("Error loading GenModel ");
_builder_2.append(genModelURI);
throw new RuntimeException(_builder_2.toString());
}
EList<EObject> _contents_1 = genModelResource.getContents();
for (final EObject content : _contents_1) {
if ((content instanceof GenModel)) {
((GenModel) content).reconcile();
}
}
return genModelResource;
}
use of org.eclipse.emf.codegen.ecore.genmodel.GenPackage in project xtext-core by eclipse.
the class EMFGeneratorFragment2 method getSaveAndReconcileGenModel.
protected GenModel getSaveAndReconcileGenModel(final Grammar grammar, final List<EPackage> packs, final ResourceSet rs) {
final GenModel genModel = this.getGenModel(rs, grammar);
genModel.initialize(packs);
EList<GenPackage> _genPackages = genModel.getGenPackages();
for (final GenPackage genPackage : _genPackages) {
{
genPackage.setBasePackage(this.getBasePackage(grammar));
if (this.suppressLoadInitialization) {
genPackage.setLoadInitialization(false);
}
if (((!this.getLanguage().getFileExtensions().isEmpty()) && packs.contains(genPackage.getEcorePackage()))) {
genPackage.setFileExtensions(IterableExtensions.join(this.getLanguage().getFileExtensions(), ","));
}
}
}
final Set<EPackage> referencedEPackages = this.getReferencedEPackages(packs);
final List<GenPackage> usedGenPackages = this.getGenPackagesForPackages(genModel, referencedEPackages);
this.reconcileMissingGenPackagesInUsedModels(usedGenPackages);
genModel.getUsedGenPackages().addAll(usedGenPackages);
this.saveResource(genModel.eResource());
new GenModelHelper().registerGenModel(genModel);
return genModel;
}
use of org.eclipse.emf.codegen.ecore.genmodel.GenPackage in project xtext-core by eclipse.
the class EMFGeneratorFragment2 method getGenModel.
protected GenModel getGenModel(final ResourceSet rs, final Grammar grammar) {
try {
final URI genModelUri = this.getGenModelUri(grammar);
final Resource resource = rs.getResource(genModelUri, false);
if ((resource != null)) {
resource.unload();
rs.getResources().remove(resource);
}
final Resource genModelFile = rs.createResource(genModelUri, ContentHandler.UNSPECIFIED_CONTENT_TYPE);
GenModel genModel = null;
boolean _exists = rs.getURIConverter().exists(genModelUri, null);
if (_exists) {
genModelFile.load(null);
boolean _hasFragment = genModelUri.hasFragment();
if (_hasFragment) {
EObject _eObject = genModelFile.getEObject(genModelUri.fragment());
genModel = ((GenModel) _eObject);
} else {
EObject _head = IterableExtensions.<EObject>head(genModelFile.getContents());
genModel = ((GenModel) _head);
}
} else {
genModel = new GenModelImpl() {
@Override
public GenPackage createGenPackage() {
return new GenPackageImpl() {
@Override
public String getSerializedPackageFilename() {
String _name = this.getName();
return (_name + ".loadinitialization_ecore");
}
};
}
};
genModel.setModelName(this.getModelName(grammar));
genModel.setModelPluginID(this.getModelPluginID());
genModel.setModelDirectory(this.getJavaModelDirectory());
if (this.generateEdit) {
genModel.setEditPluginID(this.getEditPluginID());
genModel.setEditDirectory(this.getEditDirectory());
}
if (this.generateEditor) {
genModel.setEditorPluginID(this.getEditorPluginID());
genModel.setEditorDirectory(this.getEditorDirectory());
}
genModel.setValidateModel(false);
genModel.setForceOverwrite(true);
genModel.setFacadeHelperClass(null);
genModel.setBundleManifest(true);
genModel.setUpdateClasspath(false);
genModel.setComplianceLevel(this.jdkLevel);
genModel.setRuntimeVersion(this.emfRuntimeVersion);
genModel.setRootExtendsClass("org.eclipse.emf.ecore.impl.MinimalEObjectImpl$Container");
genModel.setLineDelimiter(this.codeConfig.getLineDelimiter());
String _fileHeader = this.codeConfig.getFileHeader();
boolean _tripleNotEquals = (_fileHeader != null);
if (_tripleNotEquals) {
genModel.setCopyrightText(EMFGeneratorFragment2.trimMultiLineComment(this.codeConfig.getFileHeader()));
}
}
genModelFile.getContents().add(genModel);
return genModel;
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
Aggregations