use of org.eclipse.xtext.AbstractMetamodelDeclaration 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.xtext.AbstractMetamodelDeclaration in project xtext-core by eclipse.
the class TypeRefImpl method setMetamodel.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setMetamodel(AbstractMetamodelDeclaration newMetamodel) {
AbstractMetamodelDeclaration oldMetamodel = metamodel;
metamodel = newMetamodel;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, XtextPackage.TYPE_REF__METAMODEL, oldMetamodel, metamodel));
}
use of org.eclipse.xtext.AbstractMetamodelDeclaration in project xtext-core by eclipse.
the class Xtext2EcoreTransformer method collectEPackages.
private void collectEPackages() {
final List<AbstractMetamodelDeclaration> metamodelDeclarations = grammar.getMetamodelDeclarations();
final Map<String, GeneratedMetamodel> generateUs = Maps.newLinkedHashMap();
for (AbstractMetamodelDeclaration metamodelDeclaration : metamodelDeclarations) {
try {
if (metamodelDeclaration instanceof ReferencedMetamodel) {
// load imported metamodel
ReferencedMetamodel referencedMetamodel = (ReferencedMetamodel) metamodelDeclaration;
EPackage referencedEPackage = referencedMetamodel.getEPackage();
if (referencedEPackage != null)
collectClassInfosOf(referencedEPackage, referencedMetamodel);
} else if (metamodelDeclaration instanceof GeneratedMetamodel) {
String alias = Strings.emptyIfNull(metamodelDeclaration.getAlias());
if (generateUs.containsKey(alias)) {
GeneratedMetamodel prev = generateUs.get(alias);
if (prev != null) {
if (prev.getEPackage() != null) {
prev.getEPackage().eResource().getResourceSet().getResources().remove(prev.getEPackage().eResource());
}
prev.setEPackage(null);
}
generateUs.put(alias, null);
EPackage pack = metamodelDeclaration.getEPackage();
if (pack != null)
pack.eResource().getResourceSet().getResources().remove(pack.eResource());
metamodelDeclaration.setEPackage(null);
throw new TransformationException(TransformationErrorCode.AliasForMetamodelAlreadyExists, "Alias '" + alias + "' registered more than once.", metamodelDeclaration);
}
generateUs.put(alias, (GeneratedMetamodel) metamodelDeclaration);
} else
throw new IllegalStateException("unknown metamodelDeclaraton " + metamodelDeclaration);
} catch (TransformationException e) {
reportError(e);
}
}
for (GeneratedMetamodel metamodel : generateUs.values()) {
try {
if (metamodel != null)
addGeneratedEPackage(metamodel);
} catch (TransformationException e) {
reportError(e);
}
}
}
use of org.eclipse.xtext.AbstractMetamodelDeclaration in project xtext-core by eclipse.
the class Xtext2EcoreTransformer method getGeneratedPackages.
public List<EPackage> getGeneratedPackages() {
final List<EPackage> result = new ArrayList<EPackage>();
final ResourceSet resourceSet = grammar.eResource().getResourceSet();
if (resourceSet == null)
throw new NullPointerException("resourceSet may not be null");
Iterables.addAll(result, Iterables.filter(Iterables.transform(Iterables.filter(grammar.getMetamodelDeclarations(), GeneratedMetamodel.class), new Function<AbstractMetamodelDeclaration, EPackage>() {
@Override
public EPackage apply(AbstractMetamodelDeclaration param) {
EPackage pack = (EPackage) param.eGet(XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE, false);
if (pack != null && !pack.eIsProxy()) {
return pack;
}
return null;
}
}), Predicates.notNull()));
return getPackagesSortedByName(result);
}
use of org.eclipse.xtext.AbstractMetamodelDeclaration in project xtext-core by eclipse.
the class Xtext2EcoreTransformer method findMetamodel.
public AbstractMetamodelDeclaration findMetamodel(Grammar grammar, String alias, String containedClassifier) {
final List<AbstractMetamodelDeclaration> declarations = grammar.getMetamodelDeclarations();
AbstractMetamodelDeclaration result = null;
for (AbstractMetamodelDeclaration decl : declarations) {
if (isSameAlias(decl.getAlias(), alias)) {
EPackage pack = decl.getEPackage();
if (pack != null && pack.getEClassifier(containedClassifier) != null) {
if (result != null)
return null;
result = decl;
}
}
}
return result;
}
Aggregations