Search in sources :

Example 41 with EReference

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

the class ReferenceAliasWhereEntryImpl method setReference.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setReference(EReference newReference) {
    EReference oldReference = reference;
    reference = newReference;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, Bug287941TestLanguagePackage.REFERENCE_ALIAS_WHERE_ENTRY__REFERENCE, oldReference, reference));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) EReference(org.eclipse.emf.ecore.EReference)

Example 42 with EReference

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

the class SubselectWhereEntryImpl method setReference.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setReference(EReference newReference) {
    EReference oldReference = reference;
    reference = newReference;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, Bug287941TestLanguagePackage.SUBSELECT_WHERE_ENTRY__REFERENCE, oldReference, reference));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) EReference(org.eclipse.emf.ecore.EReference)

Example 43 with EReference

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

the class DefaultLinkedPositionGroupCalculator method getLinkedPositionGroup.

@Override
public Provider<LinkedPositionGroup> getLinkedPositionGroup(IRenameElementContext renameElementContext, IProgressMonitor monitor) {
    final SubMonitor progress = SubMonitor.convert(monitor, 100);
    final XtextEditor editor = (XtextEditor) renameElementContext.getTriggeringEditor();
    IProject project = projectUtil.getProject(renameElementContext.getContextResourceURI());
    if (project == null)
        throw new IllegalStateException("Could not determine project for context resource " + renameElementContext.getContextResourceURI());
    RefactoringResourceSetProvider resourceSetProvider = new CachingResourceSetProvider(DefaultLinkedPositionGroupCalculator.this.resourceSetProvider);
    ResourceSet resourceSet = resourceSetProvider.get(project);
    EObject targetElement = resourceSet.getEObject(renameElementContext.getTargetElementURI(), true);
    if (targetElement == null)
        throw new IllegalStateException("Target element could not be loaded");
    if (monitor.isCanceled()) {
        throw new OperationCanceledException();
    }
    IRenameStrategy.Provider strategyProvider = globalServiceProvider.findService(targetElement, IRenameStrategy.Provider.class);
    IRenameStrategy renameStrategy = null;
    try {
        renameStrategy = strategyProvider.get(targetElement, renameElementContext);
    } catch (NoSuchStrategyException exc) {
    // handle in next line
    }
    if (renameStrategy == null)
        throw new IllegalArgumentException("Cannot find a rename strategy for " + notNull(renameElementContext.getTargetElementURI()));
    String newName = renameStrategy.getOriginalName();
    IResourceServiceProvider resourceServiceProvider = resourceServiceProviderRegistry.getResourceServiceProvider(renameElementContext.getTargetElementURI());
    IDependentElementsCalculator dependentElementsCalculator = resourceServiceProvider.get(IDependentElementsCalculator.class);
    Iterable<URI> dependentElementURIs = dependentElementsCalculator.getDependentElementURIs(targetElement, progress.newChild(10));
    if (monitor.isCanceled()) {
        throw new OperationCanceledException();
    }
    LocalResourceRefactoringUpdateAcceptor updateAcceptor = updateAcceptorProvider.get();
    updateAcceptor.setLocalResourceURI(renameElementContext.getContextResourceURI());
    renameStrategy.createDeclarationUpdates(newName, resourceSet, updateAcceptor);
    if (monitor.isCanceled()) {
        throw new OperationCanceledException();
    }
    Map<URI, URI> original2newEObjectURI = renamedElementTracker.renameAndTrack(concat(Collections.singleton(renameElementContext.getTargetElementURI()), dependentElementURIs), newName, resourceSet, renameStrategy, progress.newChild(10));
    if (monitor.isCanceled()) {
        throw new OperationCanceledException();
    }
    ElementRenameArguments elementRenameArguments = new ElementRenameArguments(renameElementContext.getTargetElementURI(), newName, renameStrategy, original2newEObjectURI, resourceSetProvider);
    final List<IReferenceDescription> referenceDescriptions = newArrayList();
    IReferenceFinder.Acceptor referenceAcceptor = new IReferenceFinder.Acceptor() {

        @Override
        public void accept(IReferenceDescription referenceDescription) {
            referenceDescriptions.add(referenceDescription);
        }

        @Override
        public void accept(EObject source, URI sourceURI, EReference eReference, int index, EObject targetOrProxy, URI targetURI) {
            referenceDescriptions.add(new DefaultReferenceDescription(EcoreUtil2.getFragmentPathURI(source), targetURI, eReference, index, null));
        }
    };
    if (monitor.isCanceled()) {
        throw new OperationCanceledException();
    }
    referenceFinder.findReferences(targetURIConverter.fromIterable(elementRenameArguments.getRenamedElementURIs()), resourceSet.getResource(renameElementContext.getContextResourceURI(), true), referenceAcceptor, progress.newChild(10));
    if (monitor.isCanceled()) {
        throw new OperationCanceledException();
    }
    referenceUpdater.createReferenceUpdates(elementRenameArguments, referenceDescriptions, updateAcceptor, progress.newChild(60));
    final List<ReplaceEdit> textEdits = updateAcceptor.getTextEdits();
    if (monitor.isCanceled()) {
        throw new OperationCanceledException();
    }
    final IRenameStrategy renameStrategy2 = renameStrategy;
    return new Provider<LinkedPositionGroup>() {

        @Override
        public LinkedPositionGroup get() {
            LinkedPositionGroup linkedGroup = createLinkedGroupFromReplaceEdits(textEdits, editor, renameStrategy2.getOriginalName(), progress.newChild(10));
            return linkedGroup;
        }
    };
}
Also used : IRenameStrategy(org.eclipse.xtext.ui.refactoring.IRenameStrategy) ElementRenameArguments(org.eclipse.xtext.ui.refactoring.ElementRenameArguments) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) URI(org.eclipse.emf.common.util.URI) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) EObject(org.eclipse.emf.ecore.EObject) IDependentElementsCalculator(org.eclipse.xtext.ui.refactoring.IDependentElementsCalculator) DefaultReferenceDescription(org.eclipse.xtext.resource.impl.DefaultReferenceDescription) CachingResourceSetProvider(org.eclipse.xtext.ui.refactoring.impl.CachingResourceSetProvider) NoSuchStrategyException(org.eclipse.xtext.ui.refactoring.IRenameStrategy.Provider.NoSuchStrategyException) EReference(org.eclipse.emf.ecore.EReference) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) IRefactoringUpdateAcceptor(org.eclipse.xtext.ui.refactoring.IRefactoringUpdateAcceptor) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) SubMonitor(org.eclipse.core.runtime.SubMonitor) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IProject(org.eclipse.core.resources.IProject) CachingResourceSetProvider(org.eclipse.xtext.ui.refactoring.impl.CachingResourceSetProvider) IGlobalServiceProvider(org.eclipse.xtext.resource.IGlobalServiceProvider) RefactoringResourceSetProvider(org.eclipse.xtext.ui.refactoring.impl.RefactoringResourceSetProvider) IResourceServiceProvider(org.eclipse.xtext.resource.IResourceServiceProvider) Provider(com.google.inject.Provider) LinkedPositionGroup(org.eclipse.jface.text.link.LinkedPositionGroup) IReferenceFinder(org.eclipse.xtext.findReferences.IReferenceFinder) RefactoringResourceSetProvider(org.eclipse.xtext.ui.refactoring.impl.RefactoringResourceSetProvider) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit)

Example 44 with EReference

use of org.eclipse.emf.ecore.EReference 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 45 with EReference

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

the class RefactoringCrossReferenceSerializer method getCrossRefText.

public String getCrossRefText(EObject owner, CrossReference crossref, EObject target, RefTextEvaluator refTextEvaluator, ITextRegion linkTextRegion, StatusWrapper status) {
    try {
        final EReference ref = GrammarUtil.getReference(crossref, owner.eClass());
        final IScope scope = scopeProvider.getScope(owner, ref);
        if (scope == null) {
            throw new IllegalStateException("Could not create scope for the given cross reference.");
        }
        String ruleName = linkingHelper.getRuleNameFrom(crossref);
        Iterable<IEObjectDescription> descriptionsForCrossRef = scope.getElements(target);
        String bestRefText = null;
        List<String> badNames = new ArrayList<String>();
        for (IEObjectDescription desc : descriptionsForCrossRef) {
            try {
                String unconvertedRefText = qualifiedNameConverter.toString(desc.getName());
                String convertedRefText = valueConverter.toString(unconvertedRefText, ruleName);
                if (refTextEvaluator.isValid(desc) && (bestRefText == null || refTextEvaluator.isBetterThan(convertedRefText, bestRefText)))
                    bestRefText = convertedRefText;
            } catch (ValueConverterException e) {
                // this is a problem only if we don't find any matching value
                badNames.add(desc.getName().toString());
            }
        }
        if (bestRefText == null && !badNames.isEmpty()) {
            status.add(WARNING, "Misconfigured language: New reference text has invalid syntax. Following names are in the scope: " + IterableExtensions.join(badNames, ", "), owner, linkTextRegion);
        }
        return bestRefText;
    } catch (Exception exc) {
        log.error(exc.getMessage(), exc);
        status.add(ERROR, exc.getMessage(), owner, linkTextRegion);
        return null;
    }
}
Also used : ArrayList(java.util.ArrayList) IScope(org.eclipse.xtext.scoping.IScope) ValueConverterException(org.eclipse.xtext.conversion.ValueConverterException) EReference(org.eclipse.emf.ecore.EReference) ValueConverterException(org.eclipse.xtext.conversion.ValueConverterException) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Aggregations

EReference (org.eclipse.emf.ecore.EReference)229 EObject (org.eclipse.emf.ecore.EObject)118 EClass (org.eclipse.emf.ecore.EClass)58 List (java.util.List)52 ArrayList (java.util.ArrayList)48 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)37 Test (org.junit.Test)31 EAttribute (org.eclipse.emf.ecore.EAttribute)29 PalladioSelectEObjectDialog (org.palladiosimulator.editors.commons.dialogs.selection.PalladioSelectEObjectDialog)28 EClassifier (org.eclipse.emf.ecore.EClassifier)21 Resource (org.eclipse.emf.ecore.resource.Resource)21 IdEObject (org.bimserver.emf.IdEObject)18 EList (org.eclipse.emf.common.util.EList)17 IScope (org.eclipse.xtext.scoping.IScope)15 HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)14 InternalEObject (org.eclipse.emf.ecore.InternalEObject)14 URI (org.eclipse.emf.common.util.URI)13 EPackage (org.eclipse.emf.ecore.EPackage)12 AbstractEList (org.eclipse.emf.common.util.AbstractEList)10 CrossReference (org.eclipse.xtext.CrossReference)10