Search in sources :

Example 26 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-eclipse by eclipse.

the class AbstractTemplateVariableResolver method getEClassifierForGrammar.

protected EClassifier getEClassifierForGrammar(String fqnClassName, Grammar grammar) {
    int dotIndex = fqnClassName.indexOf('.');
    String packageName = null;
    String className = fqnClassName;
    if (dotIndex > 0) {
        packageName = fqnClassName.substring(0, dotIndex);
        className = fqnClassName.substring(dotIndex + 1);
    }
    List<AbstractMetamodelDeclaration> allMetamodelDeclarations = GrammarUtil.allMetamodelDeclarations(grammar);
    for (AbstractMetamodelDeclaration decl : allMetamodelDeclarations) {
        EPackage pack = decl.getEPackage();
        if (packageName == null || pack.getName().equals(packageName)) {
            EClassifier eClassifier = pack.getEClassifier(className);
            if (eClassifier != null) {
                return eClassifier;
            }
        }
    }
    return null;
}
Also used : EClassifier(org.eclipse.emf.ecore.EClassifier) AbstractMetamodelDeclaration(org.eclipse.xtext.AbstractMetamodelDeclaration) EPackage(org.eclipse.emf.ecore.EPackage)

Example 27 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-eclipse by eclipse.

the class EmfResourceReferenceUpdater method createReferenceUpdates.

@Override
protected void createReferenceUpdates(ElementRenameArguments elementRenameArguments, Multimap<URI, IReferenceDescription> resource2references, ResourceSet resourceSet, IRefactoringUpdateAcceptor updateAcceptor, IProgressMonitor monitor) {
    for (URI referringResourceURI : resource2references.keySet()) {
        try {
            if (monitor.isCanceled())
                throw new OperationCanceledException();
            Resource referringResource = resourceSet.getResource(referringResourceURI, false);
            EObject refactoredElement = resourceSet.getEObject(elementRenameArguments.getNewElementURI(elementRenameArguments.getTargetElementURI()), true);
            if (referringResource != refactoredElement.eResource()) {
                if (refactoredElement instanceof EClassifier) {
                    for (IReferenceDescription reference : resource2references.get(referringResourceURI)) {
                        EObject source = referringResource.getEObject(reference.getSourceEObjectUri().fragment());
                        if (source == null) {
                            LOG.error("Couldn't find source element " + reference.getSourceEObjectUri() + " in " + referringResource.getURI());
                        } else {
                            EObject referringEReference = source.eContainer();
                            if (referringEReference != null && referringEReference instanceof EReference)
                                ((EReference) referringEReference).setEType((EClassifier) refactoredElement);
                        }
                    }
                }
                changeUtil.addSaveAsUpdate(referringResource, updateAcceptor);
            }
        } catch (OperationCanceledException e) {
            throw e;
        } catch (Exception exc) {
            throw new WrappedException(exc);
        }
    }
}
Also used : WrappedException(org.eclipse.emf.common.util.WrappedException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) EClassifier(org.eclipse.emf.ecore.EClassifier) URI(org.eclipse.emf.common.util.URI) EReference(org.eclipse.emf.ecore.EReference) WrappedException(org.eclipse.emf.common.util.WrappedException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription)

Example 28 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project Palladio-Editors-Sirius by PalladioSimulator.

the class PCMServices method setParameterValue.

/**
 * Sets the value of the {@link EStructuralFeature} on the given {@link EObject} to the parsed
 * value literal.
 *
 * @param parameter
 *            the feature to set
 * @param owningEObject
 *            the object for which the feature will be set
 * @param valueLiteral
 *            the literal representing the new value
 */
public void setParameterValue(final EStructuralFeature parameter, final EObject owningEObject, final String valueLiteral) {
    final EClassifier eType = parameter.getEType();
    Object value = null;
    if (valueLiteral == null && eType != null) {
        value = parameter.isMany() ? null : eType.getDefaultValue();
    } else if (eType instanceof EDataType) {
        final EFactory factory = eType.getEPackage().getEFactoryInstance();
        final EDataType eDataType = (EDataType) eType;
        if (eDataType.isSerializable()) {
            try {
                value = factory.createFromString(eDataType, valueLiteral);
            } catch (final Throwable e) {
            // At development time, the real factory may not be
            // available. Just return null.
            // 
            }
        }
    }
    owningEObject.eSet(parameter, value);
}
Also used : EFactory(org.eclipse.emf.ecore.EFactory) EDataType(org.eclipse.emf.ecore.EDataType) EClassifier(org.eclipse.emf.ecore.EClassifier) EObject(org.eclipse.emf.ecore.EObject)

Example 29 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class TypeRefImpl method setClassifier.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setClassifier(EClassifier newClassifier) {
    EClassifier oldClassifier = classifier;
    classifier = newClassifier;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, XtextGrammarTestPackage.TYPE_REF__CLASSIFIER, oldClassifier, classifier));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) EClassifier(org.eclipse.emf.ecore.EClassifier)

Example 30 with EClassifier

use of org.eclipse.emf.ecore.EClassifier in project xtext-core by eclipse.

the class TypeRefImpl method setClassifier.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setClassifier(EClassifier newClassifier) {
    EClassifier oldClassifier = classifier;
    classifier = newClassifier;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, XtextTerminalsTestLanguagePackage.TYPE_REF__CLASSIFIER, oldClassifier, classifier));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) EClassifier(org.eclipse.emf.ecore.EClassifier)

Aggregations

EClassifier (org.eclipse.emf.ecore.EClassifier)192 EClass (org.eclipse.emf.ecore.EClass)132 Test (org.junit.Test)81 EPackage (org.eclipse.emf.ecore.EPackage)75 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)61 EObject (org.eclipse.emf.ecore.EObject)23 EReference (org.eclipse.emf.ecore.EReference)21 AbstractRule (org.eclipse.xtext.AbstractRule)19 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)18 Grammar (org.eclipse.xtext.Grammar)16 EDataType (org.eclipse.emf.ecore.EDataType)13 XtextResource (org.eclipse.xtext.resource.XtextResource)12 AbstractElement (org.eclipse.xtext.AbstractElement)11 EEnum (org.eclipse.emf.ecore.EEnum)8 ParserRule (org.eclipse.xtext.ParserRule)8 EAttribute (org.eclipse.emf.ecore.EAttribute)7 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)7 AbstractMetamodelDeclaration (org.eclipse.xtext.AbstractMetamodelDeclaration)7 Assignment (org.eclipse.xtext.Assignment)7 ArrayList (java.util.ArrayList)6