Search in sources :

Example 26 with EPackage

use of org.eclipse.emf.ecore.EPackage in project dsl-devkit by dsldevkit.

the class ImportImplCustom method getPackageName.

/**
 * {@inheritDoc} Returns either the defined package alias, or the package's namespace prefix, or null if neither is set.
 */
@Override
public String getPackageName() {
    final String result = getName();
    if (result != null) {
        return result;
    }
    final EPackage p = getPackage();
    if (p != null) {
        return p.getNsPrefix();
    }
    return null;
}
Also used : EPackage(org.eclipse.emf.ecore.EPackage)

Example 27 with EPackage

use of org.eclipse.emf.ecore.EPackage in project dsl-devkit by dsldevkit.

the class ImportImpl method setPackage.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setPackage(EPackage newPackage) {
    EPackage oldPackage = package_;
    package_ = newPackage;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, ValidPackage.IMPORT__PACKAGE, oldPackage, package_));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) EPackage(org.eclipse.emf.ecore.EPackage)

Example 28 with EPackage

use of org.eclipse.emf.ecore.EPackage in project InformationSystem by ObeoNetwork.

the class ISMigrationParticipant method getType.

@Override
public EClassifier getType(EPackage ePackage, String name, String loadedVersion) {
    String ePackageURI = ePackage.getNsURI();
    String newEPackageURI = null;
    String newEClassName = null;
    EClassLocation newEClass = getNewEClass(ePackageURI, name);
    if (newEClass != null) {
        newEPackageURI = newEClass.getEPackageNsURI();
        newEClassName = newEClass.getEClassName();
    } else {
        // Try to convert EPackage
        newEPackageURI = ePackageURI;
        newEClassName = name;
    }
    // Get Classifier from registry
    if (newEPackageURI != null && newEClassName != null) {
        EPackage newEPackage = getPackageFromRegistry(newEPackageURI);
        if (newEPackage != null) {
            EClassifier eClassifier = newEPackage.getEClassifier(newEClassName);
            if (eClassifier != null) {
                return eClassifier;
            }
        }
    }
    return super.getType(ePackage, name, loadedVersion);
}
Also used : EClassifier(org.eclipse.emf.ecore.EClassifier) EPackage(org.eclipse.emf.ecore.EPackage)

Example 29 with EPackage

use of org.eclipse.emf.ecore.EPackage in project InformationSystem by ObeoNetwork.

the class TypesServices method createTypesFromOtherTypes.

public Collection<StructuredType> createTypesFromOtherTypes(Namespace namespace, Collection<StructuredType> types, Collection<Reference> references, String sourceTypeName, String targetTypeName) {
    String uri = PACKAGES_URI.get(targetTypeName);
    EFactory factory = getEFactory(uri);
    EPackage ePackage = factory.getEPackage();
    EClass eClass = (EClass) ePackage.getEClassifier(targetTypeName);
    Map<StructuredType, StructuredType> mappingsTypes = new HashMap<StructuredType, StructuredType>();
    Map<Reference, Reference> mappingsReferences = new HashMap<Reference, Reference>();
    Collection<StructuredType> result = new ArrayList<StructuredType>();
    // Create types
    for (StructuredType type : types) {
        EObject eObject = factory.create(eClass);
        if (eObject instanceof StructuredType) {
            StructuredType type2 = (StructuredType) eObject;
            type2.setName(type.getName());
            type2.getAssociatedTypes().add(type);
            type2.setDescription(type.getDescription());
            namespace.getTypes().add(type2);
            mappingsTypes.put(type, type2);
            result.add(type2);
        }
    }
    // Create references
    for (Reference reference : references) {
        StructuredType sourceType = mappingsTypes.get(reference.getContainingType());
        StructuredType targetType = mappingsTypes.get(reference.getReferencedType());
        Reference newReference = EnvironmentFactory.eINSTANCE.createReference();
        sourceType.getOwnedReferences().add(newReference);
        newReference.setReferencedType(targetType);
        newReference.setDescription(reference.getDescription());
        newReference.setIsComposite(reference.isIsComposite());
        newReference.setIsIdentifier(reference.isIsIdentifier());
        newReference.setMultiplicity(reference.getMultiplicity());
        newReference.setName(reference.getName());
        newReference.setNavigable(reference.isNavigable());
        mappingsReferences.put(reference, newReference);
    }
    // Set opposite references
    for (Reference reference : references) {
        if (reference.getOppositeOf() != null) {
            Reference newReference = mappingsReferences.get(reference);
            if (newReference.getOppositeOf() == null) {
                Reference newOppositeReference = mappingsReferences.get(reference.getOppositeOf());
                newReference.setOppositeOf(newOppositeReference);
            }
        }
    }
    return result;
}
Also used : EFactory(org.eclipse.emf.ecore.EFactory) EClass(org.eclipse.emf.ecore.EClass) HashMap(java.util.HashMap) Reference(org.obeonetwork.dsl.environment.Reference) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) EPackage(org.eclipse.emf.ecore.EPackage) StructuredType(org.obeonetwork.dsl.environment.StructuredType)

Example 30 with EPackage

use of org.eclipse.emf.ecore.EPackage in project InformationSystem by ObeoNetwork.

the class EcorebindingModelWizardSpec method createInitialModel.

/**
 *  (non-Javadoc)
 * @see org.obeonetwork.dsl.ecorebinding.presentation.EcorebindingModelWizard#createInitialModel()
 */
@Override
protected EObject createInitialModel() {
    IPath ecoreFilePath = this.ecoreSelectionWizardPage.getEcoreFilePath();
    ResourceSet ecorers = new ResourceSetImpl();
    Resource ecoreResource = ecorers.getResource(URI.createFileURI(ecoreFilePath.toFile().getAbsolutePath()), true);
    try {
        ecoreResource.load(new HashMap<String, String>());
    } catch (IOException e) {
        e.printStackTrace();
    }
    ResourceSet rs = new ResourceSetImpl();
    IPath ecoreBindingModelPath = ecoreFilePath;
    ecoreBindingModelPath = ecoreFilePath.removeFileExtension().addFileExtension("ecorebinding");
    Resource resource = rs.createResource(URI.createFileURI(ecoreBindingModelPath.toFile().getAbsolutePath()));
    BModel ecoreBindingModel = EcorebindingFactory.eINSTANCE.createBModel();
    List<EObject> contents = ecoreResource.getContents();
    for (EObject eObject : contents) {
        // We only support EPackage as root element.
        if (eObject instanceof EPackage) {
            EPackage rootPackage = (EPackage) eObject;
            BPackage ecoreBindingPackage = EcorebindingFactory.eINSTANCE.createBPackage();
            ecoreBindingPackage.setEcorePackage(rootPackage);
            ecoreBindingModel.getBPackages().add(ecoreBindingPackage);
            explore(rootPackage, ecoreBindingPackage);
        } else {
            throw new IllegalArgumentException("The Ecore Binding only supports EPackage as root element");
        }
    }
    resource.getContents().add(ecoreBindingModel);
    try {
        resource.save(new HashMap<String, String>());
    } catch (IOException e) {
        e.printStackTrace();
    }
    return ecoreBindingModel;
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) IPath(org.eclipse.core.runtime.IPath) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException) EPackage(org.eclipse.emf.ecore.EPackage) BPackage(org.obeonetwork.dsl.ecorebinding.BPackage) BModel(org.obeonetwork.dsl.ecorebinding.BModel) EObject(org.eclipse.emf.ecore.EObject)

Aggregations

EPackage (org.eclipse.emf.ecore.EPackage)424 ParserRule (org.eclipse.xtext.ParserRule)201 Action (org.eclipse.xtext.Action)196 Parameter (org.eclipse.xtext.Parameter)196 Test (org.junit.Test)101 EClass (org.eclipse.emf.ecore.EClass)85 Resource (org.eclipse.emf.ecore.resource.Resource)50 EObject (org.eclipse.emf.ecore.EObject)39 EClassifier (org.eclipse.emf.ecore.EClassifier)32 URI (org.eclipse.emf.common.util.URI)30 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)23 Grammar (org.eclipse.xtext.Grammar)22 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)16 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)15 GenPackage (org.eclipse.emf.codegen.ecore.genmodel.GenPackage)14 AbstractMetamodelDeclaration (org.eclipse.xtext.AbstractMetamodelDeclaration)14 XtextResource (org.eclipse.xtext.resource.XtextResource)14 EEnum (org.eclipse.emf.ecore.EEnum)13 EReference (org.eclipse.emf.ecore.EReference)12 IOException (java.io.IOException)11