use of org.eclipse.xtext.impl.GeneratedMetamodelImpl in project xtext-core by eclipse.
the class XtextLinkingService method createPackage.
private List<EObject> createPackage(GeneratedMetamodel generatedMetamodel, ILeafNode text) {
final String nsURI = getMetamodelNsURI(text);
final URI uri = URI.createURI(nsURI);
if (uri == null || isReferencedByUsedGrammar(generatedMetamodel, nsURI))
return Collections.emptyList();
EPackage pack = ((GeneratedMetamodelImpl) generatedMetamodel).basicGetEPackage();
if (pack != null && !pack.eIsProxy())
return singletonList((EObject) pack);
final EPackage generatedEPackage = EcoreFactory.eINSTANCE.createEPackage();
generatedEPackage.setName(generatedMetamodel.getName());
generatedEPackage.setNsPrefix(generatedMetamodel.getName());
generatedEPackage.setNsURI(nsURI);
final Resource generatedPackageResource = new EcoreResourceFactoryImpl().createResource(uri);
XtextResourceSet resourceSet = (XtextResourceSet) generatedMetamodel.eResource().getResourceSet();
if (!resourceSet.getURIResourceMap().containsKey(generatedPackageResource.getURI())) {
generatedMetamodel.eResource().getResourceSet().getResources().add(generatedPackageResource);
} else {
generatedPackageResource.setURI(URI.createURI(nsURI + "_" + generatedMetamodel.hashCode()));
generatedMetamodel.eResource().getResourceSet().getResources().add(generatedPackageResource);
}
generatedPackageResource.getContents().add(generatedEPackage);
return Collections.<EObject>singletonList(generatedEPackage);
}
Aggregations