use of org.eclipse.emf.codegen.ecore.genmodel.GenModel in project xtext-core by eclipse.
the class AbstractPortableURIsTest 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.GenModel in project xtext-core by eclipse.
the class GenModelUtil2 method getGenPackage.
public static GenPackage getGenPackage(final EPackage pkg, final ResourceSet resourceSet) {
final String nsURI = pkg.getNsURI();
String location = null;
Resource _eResource = pkg.eResource();
URI _uRI = null;
if (_eResource != null) {
_uRI = _eResource.getURI();
}
boolean _tripleNotEquals = (_uRI != null);
if (_tripleNotEquals) {
location = pkg.eResource().getURI().toString();
}
final Resource genModelResource = GenModelUtil2.getGenModelResource(location, nsURI, resourceSet);
if ((genModelResource != null)) {
EList<EObject> _contents = genModelResource.getContents();
for (final EObject model : _contents) {
if ((model instanceof GenModel)) {
final GenPackage genPkg = ((GenModel) model).findGenPackage(pkg);
if ((genPkg != null)) {
genPkg.getEcorePackage().getEClassifiers();
return genPkg;
}
}
}
StringConcatenation _builder = new StringConcatenation();
_builder.append("No GenPackage for NsURI ");
_builder.append(nsURI);
_builder.append(" found in ");
URI _uRI_1 = genModelResource.getURI();
_builder.append(_uRI_1);
throw new RuntimeException(_builder.toString());
}
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("No GenPackage for NsURI ");
_builder_1.append(nsURI);
_builder_1.append(".");
throw new RuntimeException(_builder_1.toString());
}
Aggregations