protected boolean isLocallyUsed(EObject target, EObject containerToFindUsage) { if (readAndWriteTracking.isRead(target)) { return true; } Collection<Setting> usages = XbaseUsageCrossReferencer.find(target, containerToFindUsage); // for non-private members it is enough to check that there are usages if (!(target instanceof JvmOperation) || ((JvmOperation)target).getVisibility()!=JvmVisibility.PRIVATE) { return !usages.isEmpty(); } else { // for private members it has to be checked if all usages are within the operation EObject targetSourceElem = associations.getPrimarySourceElement(target); for (Setting s : usages) { if (s.getEObject() instanceof XAbstractFeatureCall) { XAbstractFeatureCall fc = (XAbstractFeatureCall) s.getEObject(); // when the feature call does not call itself or the call is // from another function, then it is locally used if (fc.getFeature() != target || !EcoreUtil.isAncestor(targetSourceElem, fc)) return true; } else { return true; } } return false; } }
protected void addAnnotationsForReferences(EObject referencedElement, List<String> matchingNames) { IDocument document = getSourceViewer().getDocument(); // Determine all references to the EObject Map<EObject, Collection<Setting>> map = EcoreUtil.UsageCrossReferencer.find(Collections.singleton(textResource)); Collection<Setting> referencingObjects = map.get(referencedElement); if (referencingObjects == null) { // No references found return; } // Highlight the token in the text for the referencing objects for (Setting setting : referencingObjects) { EObject referencingElement = setting.getEObject(); // Search through all tokens in the elements that reference the element at the // caret position for (String name : matchingNames) { int index = getIndexOf(referencingElement, name); if (index > 0) { addAnnotation(document, de.darwinspl.preferences.resource.dwprofile.ui.DwprofilePositionCategory.PROXY, name, index, name.length()); } } } }
protected void addAnnotationsForReferences(EObject referencedElement, List<String> matchingNames) { IDocument document = getSourceViewer().getDocument(); // Determine all references to the EObject Map<EObject, Collection<Setting>> map = EcoreUtil.UsageCrossReferencer.find(Collections.singleton(textResource)); Collection<Setting> referencingObjects = map.get(referencedElement); if (referencingObjects == null) { // No references found return; } // Highlight the token in the text for the referencing objects for (Setting setting : referencingObjects) { EObject referencingElement = setting.getEObject(); // Search through all tokens in the elements that reference the element at the // caret position for (String name : matchingNames) { int index = getIndexOf(referencingElement, name); if (index > 0) { addAnnotation(document, eu.hyvar.feature.expression.resource.hyexpression.ui.HyexpressionPositionCategory.PROXY, name, index, name.length()); } } } }
protected void addAnnotationsForReferences(EObject referencedElement, List<String> matchingNames) { IDocument document = getSourceViewer().getDocument(); // Determine all references to the EObject Map<EObject, Collection<Setting>> map = EcoreUtil.UsageCrossReferencer.find(Collections.singleton(textResource)); Collection<Setting> referencingObjects = map.get(referencedElement); if (referencingObjects == null) { // No references found return; } // Highlight the token in the text for the referencing objects for (Setting setting : referencingObjects) { EObject referencingElement = setting.getEObject(); // Search through all tokens in the elements that reference the element at the // caret position for (String name : matchingNames) { int index = getIndexOf(referencingElement, name); if (index > 0) { addAnnotation(document, eu.hyvar.context.contextValidity.resource.hyvalidityformula.ui.HyvalidityformulaPositionCategory.PROXY, name, index, name.length()); } } } }
protected void addAnnotationsForReferences(EObject referencedElement, List<String> matchingNames) { IDocument document = getSourceViewer().getDocument(); // Determine all references to the EObject Map<EObject, Collection<Setting>> map = EcoreUtil.UsageCrossReferencer.find(Collections.singleton(textResource)); Collection<Setting> referencingObjects = map.get(referencedElement); if (referencingObjects == null) { // No references found return; } // Highlight the token in the text for the referencing objects for (Setting setting : referencingObjects) { EObject referencingElement = setting.getEObject(); // Search through all tokens in the elements that reference the element at the // caret position for (String name : matchingNames) { int index = getIndexOf(referencingElement, name); if (index > 0) { addAnnotation(document, eu.hyvar.dataValues.resource.hydatavalue.ui.HydatavaluePositionCategory.PROXY, name, index, name.length()); } } } }
protected void addAnnotationsForReferences(EObject referencedElement, List<String> matchingNames) { IDocument document = getSourceViewer().getDocument(); // Determine all references to the EObject Map<EObject, Collection<Setting>> map = EcoreUtil.UsageCrossReferencer.find(Collections.singleton(textResource)); Collection<Setting> referencingObjects = map.get(referencedElement); if (referencingObjects == null) { // No references found return; } // Highlight the token in the text for the referencing objects for (Setting setting : referencingObjects) { EObject referencingElement = setting.getEObject(); // Search through all tokens in the elements that reference the element at the // caret position for (String name : matchingNames) { int index = getIndexOf(referencingElement, name); if (index > 0) { addAnnotation(document, eu.hyvar.feature.mapping.resource.hymapping.ui.HymappingPositionCategory.PROXY, name, index, name.length()); } } } }
protected void addAnnotationsForReferences(EObject referencedElement, List<String> matchingNames) { IDocument document = getSourceViewer().getDocument(); // Determine all references to the EObject Map<EObject, Collection<Setting>> map = EcoreUtil.UsageCrossReferencer.find(Collections.singleton(textResource)); Collection<Setting> referencingObjects = map.get(referencedElement); if (referencingObjects == null) { // No references found return; } // Highlight the token in the text for the referencing objects for (Setting setting : referencingObjects) { EObject referencingElement = setting.getEObject(); // Search through all tokens in the elements that reference the element at the // caret position for (String name : matchingNames) { int index = getIndexOf(referencingElement, name); if (index > 0) { addAnnotation(document, eu.hyvar.feature.constraint.resource.hyconstraints.ui.HyconstraintsPositionCategory.PROXY, name, index, name.length()); } } } }
protected void addAnnotationsForReferences(EObject referencedElement, List<String> matchingNames) { IDocument document = getSourceViewer().getDocument(); // Determine all references to the EObject Map<EObject, Collection<Setting>> map = EcoreUtil.UsageCrossReferencer.find(Collections.singleton(textResource)); Collection<Setting> referencingObjects = map.get(referencedElement); if (referencingObjects == null) { // No references found return; } // Highlight the token in the text for the referencing objects for (Setting setting : referencingObjects) { EObject referencingElement = setting.getEObject(); // Search through all tokens in the elements that reference the element at the // caret position for (String name : matchingNames) { int index = getIndexOf(referencingElement, name); if (index > 0) { addAnnotation(document, eu.hyvar.mspl.manifest.resource.hymanifest.ui.HymanifestPositionCategory.PROXY, name, index, name.length()); } } } }
public List<Method> findFieldReferences(IResourceDescriptions descriptions, Class element){ List<Method> usages = new ArrayList<Method>(); Iterable<IEObjectDescription> exportedObjectsByType = descriptions.getExportedObjectsByType(element.eClass()); final ArrayList<EObject> gather = new ArrayList<>(); exportedObjectsByType.forEach((e) -> { EObject eObjectOrProxy = e.getEObjectOrProxy(); EObject resolve = EcoreUtil.resolve(eObjectOrProxy, element); gather.add(resolve); }); element.getFields().listIterator().forEachRemaining((a) -> { Collection<Setting> references = EcoreUtil.UsageCrossReferencer.find(a, gather); references.forEach((f) -> { usages.add((Method) f.getEObject().eContainer()); }); }); return usages; }
@Override protected Object adapt(Object element) { final Object res; final EObject eObject = IdeMappingUtils.adapt(element, EObject.class); if (eObject != null) { res = eObject; } else { final Setting setting = IdeMappingUtils.adapt(element, Setting.class); if (setting != null) { res = setting; } else { res = super.adapt(element); } } return res; }
/** * {@inheritDoc} * * @see org.eclipse.mylyn.docs.intent.mapping.connector.IConnector#getName(org.eclipse.mylyn.docs.intent.mapping.base.ILocation) */ public String getName(ILocation location) { final String res; final Object element = getElement(location); if (element instanceof Setting) { final Setting setting = (Setting)element; res = getName(setting.getEObject(), setting.getEStructuralFeature(), ((IEObjectLocation)location) .getIndex()); } else if (element instanceof EObject) { res = getName((EObject)element, null, 0); } else { // the located element has been deleted... res = null; } return res; }
private Set<Resource> findCrossReferenceResource(Resource resource) { if (tempSet.contains(resource)) { return Collections.emptySet(); } tempSet.add(resource); Set<Resource> unloadResourceList = new LinkedHashSet<Resource>(); Map<EObject, Collection<Setting>> find = EcoreUtil.CrossReferencer.find(resource.getContents()); for (Iterator<?> iterator = find.keySet().iterator(); iterator.hasNext();) { EObject type = (EObject) iterator.next(); if (ProjectUtil.isModelFile(type.eResource())) { unloadResourceList.add(type.eResource()); Set<Resource> referenceResource = findCrossReferenceResource(resource); if(!referenceResource.isEmpty()) { unloadResourceList.addAll(referenceResource); } } } return unloadResourceList; }
private void pruneDanglingReferences(final EPlan plan) { TransactionUtils.writing(plan, new Runnable() { @Override @SuppressWarnings("unchecked") public void run() { Map<EObject, Collection<Setting>> proxiesMap = UnresolvedProxyCrossReferencer.find(plan); for (EObject proxy : proxiesMap.keySet()) { for (Setting setting : proxiesMap.get(proxy)) { EStructuralFeature feature = setting.getEStructuralFeature(); if (feature instanceof EReference) { Object newValue = null; if (feature.isMany()) { newValue = new ArrayList((Collection)setting.get(true)); ((Collection)newValue).remove(proxy); } setting.set(newValue); } } } } }); }
/** * Delete the given incoming cross references to the given model element from any * other model element in the given project. * * @param inverseReferences a collection of inverse references * @param modelElement * the model element */ public static void deleteIncomingCrossReferencesFromParent(Collection<Setting> inverseReferences, EObject modelElement) { for (final Setting setting : inverseReferences) { final EStructuralFeature eStructuralFeature = setting.getEStructuralFeature(); final EReference reference = (EReference) eStructuralFeature; if (reference.isContainer() || reference.isContainment() || !reference.isChangeable()) { continue; } final EObject opposite = setting.getEObject(); if (eStructuralFeature.isMany()) { ((EList<?>) opposite.eGet(eStructuralFeature)).remove(modelElement); } else { if (opposite instanceof Map.Entry<?, ?> && eStructuralFeature.getName().equals("key")) { logWarning("Incoming cross reference for model element " + modelElement + " is a map key."); } opposite.eUnset(eStructuralFeature); } } }
/** * Delete all outgoing cross references of the given model element to any element in the given collection. * * @param collection the collection * @param modelElement * the model element */ public static void deleteOutgoingCrossReferences(IdEObjectCollection collection, EObject modelElement) { final Set<EObject> allModelElements = new LinkedHashSet<EObject>(); allModelElements.add(modelElement); allModelElements.addAll(ModelUtil.getAllContainedModelElements(modelElement, false)); final List<SettingWithReferencedElement> crossReferences = collectOutgoingCrossReferences(collection, allModelElements); for (final SettingWithReferencedElement settingWithReferencedElement : crossReferences) { final Setting setting = settingWithReferencedElement.getSetting(); if (!settingWithReferencedElement.getSetting().getEStructuralFeature().isMany()) { setting.getEObject().eUnset(setting.getEStructuralFeature()); } else { final List<?> references = (List<?>) setting.getEObject().eGet(setting.getEStructuralFeature()); references.remove(settingWithReferencedElement.getReferencedElement()); } } }
@SuppressWarnings("javadoc") @Test public void testResolveAllBuiltInTypes() { BuiltInTypeScope scope = BuiltInTypeScope.get(resourceSet); scope.getSingleElement(QualifiedName.create("any")); // trigger loading Assert.assertEquals(5, resourceSet.getResources().size()); EcoreUtil.resolveAll(resourceSet); Assert.assertEquals(5, resourceSet.getResources().size()); Map<EObject, Collection<Setting>> unresolvedProxies = EcoreUtil.UnresolvedProxyCrossReferencer .find(resourceSet); Assert.assertTrue(unresolvedProxies.toString(), unresolvedProxies.isEmpty()); }
@Test public void initLocationSetting() throws Exception { final IBase base = new BaseRegistryTests.TestBase(); base.getFactory().addDescriptor(ICouple.class, new BaseElementFactory.FactoryDescriptor<TestCouple>( TestCouple.class)); final TestEObjectContainerLocation container = new TestEObjectContainerLocation(); container.setContainer(base); final Copier copier = new Copier(); final List<EObject> eObjects = new ArrayList<EObject>(copier.copyAll(AnydslPackage.eINSTANCE .eContents())); copier.copyReferences(); final EClass producerEClass = (EClass)copier.get(AnydslPackage.eINSTANCE.getProducer()); final Resource resource = createResource("test.xmi"); resource.getContents().addAll(eObjects); container.setResource(resource); eObjectContainerHelper.updateEObjectContainer(container.getContainer(), container, resource); final IEObjectLocation location = new TestEObjectLocation(); location.setContainer(container); final TestEObjectContainerConnector testEObjectContainerConnector = new TestEObjectContainerConnector(); MappingUtils.getConnectorRegistry().register(testEObjectContainerConnector); final EObjectConnector eObjectConnector = new EObjectConnector(); MappingUtils.getConnectorRegistry().register(eObjectConnector); super.initLocation(container, location, ((InternalEObject)producerEClass).eSetting( EcorePackage.eINSTANCE.getENamedElement_Name())); final Object element = eObjectConnector.getElement(location); assertTrue(element instanceof Setting); assertEquals(producerEClass, ((Setting)element).getEObject()); assertEquals(EcorePackage.eINSTANCE.getENamedElement_Name(), ((Setting)element) .getEStructuralFeature()); assertEquals("Producer", ((Setting)element).get(true)); assertEquals(EcorePackage.eINSTANCE.getENamedElement_Name().getName(), location.getFeatureName()); MappingUtils.getConnectorRegistry().unregister(testEObjectContainerConnector); MappingUtils.getConnectorRegistry().unregister(eObjectConnector); }
public void assertEObjectLocation(IEObjectLocation location, EObject expectedEObject, EStructuralFeature expectedFeature, Object expectedValue) { final Object element = MappingUtils.getConnectorRegistry().getElement(location); if (element instanceof Setting) { final Setting setting = (Setting)element; assertEquals(expectedEObject, setting.getEObject()); assertEquals(expectedFeature, setting.getEStructuralFeature()); assertEquals(expectedValue, setting.get(true)); } else if (element instanceof EObject) { assertEquals(expectedEObject, element); } else { assertNull(location.getContainer()); } }
/** * {@inheritDoc} * * @see org.eclipse.mylyn.docs.intent.mapping.connector.IConnector#getLocationType(java.lang.Class, * java.lang.Object) */ public Class<? extends ILocation> getLocationType(Class<? extends ILocationContainer> containerType, Object element) { final Class<? extends ILocation> res; if (IEObjectContainer.class.isAssignableFrom(containerType) && (element instanceof EObject || element instanceof Setting)) { res = getType(); } else { res = null; } return res; }
@Override protected void initLocation(ILocationContainer container, ILocation location, Object element) { final IEObjectLocation toInit = (IEObjectLocation)location; final EObject eObject; final String featureName; final int index; if (element instanceof Setting) { final Setting setting = (Setting)element; eObject = setting.getEObject(); final EStructuralFeature feature = ((Setting)element).getEStructuralFeature(); featureName = feature.getName(); if (feature.isMany()) { index = ((List<?>)eObject.eGet(feature, true)).indexOf(setting.get(true)); } else { index = 0; } } else { eObject = getEObject((IEObjectContainer)container, (EObject)element); featureName = null; index = 0; } final String uriFragment = eObject.eResource().getURIFragment(eObject); toInit.setURIFragment(uriFragment); toInit.setFeatureName(featureName); toInit.setSavedURIFragment(getSavedURIFragment((IEObjectContainer)container, uriFragment)); toInit.setIndex(index); }
private View getReferencigView(EObject eObject) { Collection<Setting> inverseReferences = myCrossReferenceAdapter .getInverseReferences(eObject, true); for (Setting setting : inverseReferences) { if (setting.getEObject() instanceof View && setting.getEStructuralFeature() == NotationPackage.eINSTANCE .getView_Element()) { return (View) setting.getEObject(); } } return null; }
@Override protected Setting getTarget(EStructuralFeature eStructuralFeature, EObject eObject, EObject copyEObject) { if (DUPLICATE_FILTERING_REFERENCES.contains(eStructuralFeature) && isAlreadyUpToDate(eStructuralFeature, eObject, copyEObject)) { return null; } return super.getTarget(eStructuralFeature, eObject, copyEObject); }
/** * * {@inheritDoc} * * @see org.eclipse.emf.emfstore.internal.common.model.IdEObjectCollection#deleteModelElement(org.eclipse.emf.ecore.EObject) */ public void deleteModelElement(final EObject modelElement) { if (!this.contains(modelElement)) { throw new IllegalArgumentException("Cannot delete a model element that is not contained in this project."); } // remove cross references ModelUtil.deleteOutgoingCrossReferences(this, modelElement); final Collection<Setting> crossReferences = UsageCrossReferencer.find(modelElement, this); ModelUtil.deleteIncomingCrossReferencesFromParent(crossReferences, modelElement); // remove containment final EObject containerModelElement = ModelUtil.getContainerModelElement(modelElement); if (containerModelElement == null) { // removeModelElementAndChildrenFromCache(modelElement); // getEobjectsIdMap().remove(modelElement); getModelElements().remove(modelElement); } else { final EReference containmentFeature = modelElement.eContainmentFeature(); if (containmentFeature.isMany()) { final EList<?> containmentList = (EList<?>) containerModelElement.eGet(containmentFeature); containmentList.remove(modelElement); } else { containerModelElement.eSet(containmentFeature, null); } removeModelElementAndChildrenFromResource(modelElement); } }
private List<SettingWithReferencedElement> collectIngoingCrossReferences(IdEObjectCollection collection, Set<EObject> allModelElements) { final List<SettingWithReferencedElement> settings = new ArrayList<SettingWithReferencedElement>(); for (final EObject modelElement : allModelElements) { final Collection<Setting> inverseReferences = projectSpace.findInverseCrossReferences(modelElement); for (final Setting setting : inverseReferences) { if (!ModelUtil.shouldBeCollected(collection, allModelElements, setting.getEObject())) { continue; } final EReference reference = (EReference) setting.getEStructuralFeature(); final EClassifier eType = reference.getEType(); if (reference.isContainer() || reference.isContainment() || !reference.isChangeable() || !(eType instanceof EClass)) { continue; } final SettingWithReferencedElement settingWithReferencedElement = new SettingWithReferencedElement( setting, modelElement); settings.add(settingWithReferencedElement); } } return settings; }
@Override public Void apply(Setting crossReference) { EObject referencingObject = crossReference.getEObject(); EStructuralFeature referencingFeature = crossReference.getEStructuralFeature(); if (referencingFeature instanceof EReference && ((EReference) referencingFeature).isContainment()) { LOGGER.warn(String.format("There should not be a containment reference from %s (%s) to %s.", referencingObject.toString(), referencingFeature.getName(), original.toString())); return null; } if (referencingFeature.getUpperBound() > 1 || referencingFeature.getUpperBound() == -1) { Object value = referencingObject.eGet(referencingFeature); if (value instanceof List) { @SuppressWarnings("unchecked") List<EObject> valueList = (List<EObject>) value; for (int i = 0; i < valueList.size(); ++i) { if (valueList.get(i) == original) { valueList.set(i, replacement); } } } else { LOGGER.warn(String.format("We got a feature with upper bound %d that is no list but %s", referencingFeature.getUpperBound(), value.getClass().getSimpleName())); } } else { referencingObject.eSet(referencingFeature, replacement); } return null; }
/** * Replaces all cross references in the given resource sets. * * @param processor * The replacement processor to be used. * @param additionalResourceSets * The resource sets that shall be considered besides the ones of the EObjects to be * replaced. */ public static void replaceCrossReferences(CrossReferenceReplacer processor, ResourceSet... additionalResourceSets) { Set<Setting> crossReferences = new HashSet<Setting>(); ArrayList<ResourceSet> resourceSets = new ArrayList<ResourceSet>(); addResourceSetIfNotNull(processor.getOriginal(), resourceSets); addResourceSetIfNotNull(processor.getReplacement(), resourceSets); resourceSets.addAll(Lists.newArrayList(additionalResourceSets)); for (ResourceSet rs : resourceSets) { crossReferences.addAll(EcoreUtil.UsageCrossReferencer.find(processor.getOriginal(), rs)); } for (Setting crossReference : crossReferences) { processor.apply(crossReference); } }
/** * * Collect all <code>OperationInterfaceContainer</code>'s connected with the specified operation interface container.<br> * Resulting set of operation interface containers are in position to provide operation interfaces, required by the specified container.<br> * <br> * @param opInterfaceContainer Operation interface container for which the method collects potential containers. * @return Set of Operation interface containers that can require the operation interface provided by the specified container of the same type. */ public static Set<OperationInterfaceContainer> collectPotentialyResolveConteiners (OperationInterfaceContainer opInterfaceContainer) { Collection<Setting> find = EcoreUtil.UsageCrossReferencer.find(opInterfaceContainer, opInterfaceContainer.eResource()); Set<OperationInterfaceContainer> potentialContainers = new HashSet<OperationInterfaceContainer>(); for (Setting setting : find) { EObject obj = setting.getEObject(); if (obj instanceof Connection) { Connection c = (Connection) obj; if (c instanceof InternalConnection) { InternalConnection ic = (InternalConnection) c; if (ic.getTarget() == opInterfaceContainer) { potentialContainers.add((OperationInterfaceContainer)ic.getSource()); } } else if (c instanceof ExternalConnection) { ExternalConnection ec = (ExternalConnection) c; if (ec.getTarget() == opInterfaceContainer) { potentialContainers.add((OperationInterfaceContainer)ec.getSource()); } } } } return potentialContainers; }
/** * * Collect all operation interfaces that could be required by specified <code>OperationInterfaceContainer</code>. * * Operation interface can be required by <code>OperationInterfaceContainer</code> if it's container<br> * have <code>Connection</code> to the specified <code>OperationInterfaceContainer</code>. * * @param opInterfaceContainer Operation interface container for which the method collects potentially required operation interfaces. * @return Set of operation interfaces that could be required by the specified <code>OperationInterfaceContainer</code>. */ public static Set<OperationInterface> collectPotentialyRequiredInterfaces(OperationInterfaceContainer opInterfaceContainer){ Collection<Setting> find = EcoreUtil.UsageCrossReferencer.find(opInterfaceContainer, opInterfaceContainer.eResource()); Set<OperationInterface> interfaces = new HashSet<OperationInterface>(); Set<OperationInterfaceContainer> providerServices = new HashSet<OperationInterfaceContainer>(); for (Setting setting : find) { EObject obj = setting.getEObject(); if (obj instanceof Connection) { Connection c = (Connection) obj; if (c instanceof InternalConnection) { InternalConnection ic = (InternalConnection) c; if(ic.getSource() == opInterfaceContainer){ providerServices.add(ic.getTarget()); } } else if (c instanceof ExternalConnection) { ExternalConnection ec = (ExternalConnection) c; if(ec.getSource() == opInterfaceContainer){ providerServices.add(ec.getTarget()); } } } } for (OperationInterfaceContainer provider : providerServices) { interfaces.addAll(provider.getProvidedInterfaces()); } return interfaces; }
private static Collection<Element> getOwnedAndTypedElements(final EObject eObject) { final Collection<Element> ownedAndTypedElements = new LinkedHashSet<>(getOwnedElements(eObject)); final Collection<Setting> settings = EcoreUtil.UsageCrossReferencer.find(eObject, eObject.eResource()); for (final Setting s : settings) { if (s.getEStructuralFeature() == UMLPackage.Literals.TYPED_ELEMENT__TYPE) { ownedAndTypedElements.add((Element) s.getEObject()); } } return ownedAndTypedElements; }
public Setting dynamicSetting(final InternalEObject owner, final DynamicValueHolder settings, final int dynamicFeatureID) { return new EStructuralFeature.Setting() { public EObject getEObject() { return owner; } public EStructuralFeature getEStructuralFeature() { return eStructuralFeature; } public Object get(boolean resolve) { return BasicSettingDelegate.this.dynamicGet(owner, settings, dynamicFeatureID, resolve, true); } public boolean isSet() { return BasicSettingDelegate.this.dynamicIsSet(owner, settings, dynamicFeatureID); } public void set(Object newValue) { BasicSettingDelegate.this.dynamicSet(owner, settings, dynamicFeatureID, newValue); } public void unset() { BasicSettingDelegate.this.dynamicUnset(owner, settings, dynamicFeatureID); } }; }
/** * Creates a setting for the owner and this delegate's feature. * @param owner the owner for the setting. * @return a new setting. */ protected Setting setting(final InternalEObject owner) { return new EStructuralFeature.Setting() { public EObject getEObject() { return owner; } public EStructuralFeature getEStructuralFeature() { return eStructuralFeature; } public Object get(boolean resolve) { return Stateless.this.get(owner, resolve, true); } public boolean isSet() { return Stateless.this.isSet(owner); } public void set(Object newValue) { Stateless.this.set(owner, newValue); } public void unset() { Stateless.this.unset(owner); } }; }
public static Collection<EObject> collectViews(final Iterable<? extends EObject> data, final Resource theNotationResource) { final Collection<EObject> views = new ArrayList<>(); if (theNotationResource != null) { for (final EObject e : data) { final Collection<Setting> theNotationReferences = EcoreUtil.UsageCrossReferencer .find(e, theNotationResource); for (final Setting setting : theNotationReferences) { views.add(setting.getEObject()); } } } return views; }
@Override protected EStructuralFeature.Internal.SettingDelegate eSettingDelegate(final EStructuralFeature eFeature) { FragmentationType type = EMFFragUtil.getFragmentationType(eFeature); if (type == FragmentationType.None || type == FragmentationType.FragmentsContainment) { return ((EStructuralFeature.Internal) eFeature).getSettingDelegate(); } else { return new EStructuralFeatureImpl.InternalSettingDelegateMany(EStructuralFeatureImpl.InternalSettingDelegateMany.DATA_DYNAMIC, eFeature) { @Override protected Setting createDynamicSetting(InternalEObject owner) { int kind = EcoreEList.Generic.kind(eFeature); return new FValueSetList(kind, FInternalObjectImpl.class, FInternalObjectImpl.this, eFeature); } }; } }
@Override protected void installProxies(EObject obj, IDiagnosticProducer producer, Multimap<Setting, INode> settingsToLink) { super.installProxies(obj, producer, settingsToLink); if (obj instanceof NullCrossRef) ((NullCrossRef) obj).setRef(null); }
@Test public void updateEObjectContainerSettingLocationChanged() throws Exception { final IBase base = new BaseRegistryTests.TestBase(); base.getFactory().addDescriptor(IReport.class, new BaseElementFactory.FactoryDescriptor<TestReport>( TestReport.class)); base.getFactory().addDescriptor(ICouple.class, new BaseElementFactory.FactoryDescriptor<TestCouple>( TestCouple.class)); final TestEObjectContainerLocation container = new TestEObjectContainerLocation(); container.setContainer(base); final Copier copier = new Copier(); final List<EObject> eObjects = new ArrayList<EObject>(copier.copyAll(AnydslPackage.eINSTANCE .eContents())); copier.copyReferences(); final EClass producerEClass = (EClass)copier.get(AnydslPackage.eINSTANCE.getProducer()); final Resource resource = createResource("test.xmi"); resource.getContents().addAll(eObjects); container.setResource(resource); eObjectContainerHelper.updateEObjectContainer(container.getContainer(), container, resource); final IEObjectLocation location = new TestEObjectLocation(); location.setContainer(container); final ILocation target = new TestTextLocation(); final ILink link = new BaseElementFactoryTests.TestLink(); location.getTargetLinks().add(link); link.setSource(location); target.getSourceLinks().add(link); link.setTarget(target); final TestEObjectContainerConnector connector = new TestEObjectContainerConnector(); MappingUtils.getConnectorRegistry().register(connector); super.initLocation(container, location, new Setting() { public void unset() { // nothing to do here } public void set(Object newValue) { // nothing to do here } public boolean isSet() { return false; } public EStructuralFeature getEStructuralFeature() { return EcorePackage.eINSTANCE.getEClass_Interface(); } public EObject getEObject() { return producerEClass; } public Object get(boolean resolve) { return producerEClass.getName(); } }); producerEClass.setInterface(!producerEClass.isInterface()); eObjectContainerHelper.updateEObjectContainer(container.getContainer(), container, resource); assertEquals(1, base.getReports().size()); final IReport report = base.getReports().get(0); assertEquals(link, report.getLink()); assertTrue(report.getDescription().contains("Producer")); assertTrue(report.getDescription().contains(location.getURIFragment())); assertTrue(report.getDescription().contains( "feature interface value false has been changed to true.")); MappingUtils.getConnectorRegistry().unregister(connector); }
@Test public void updateEObjectContainerSettingLocationManyRemoved() throws Exception { final IBase base = new BaseRegistryTests.TestBase(); base.getFactory().addDescriptor(IReport.class, new BaseElementFactory.FactoryDescriptor<TestReport>( TestReport.class)); base.getFactory().addDescriptor(ICouple.class, new BaseElementFactory.FactoryDescriptor<TestCouple>( TestCouple.class)); final TestEObjectContainerLocation container = new TestEObjectContainerLocation(); container.setContainer(base); final Copier copier = new Copier(); final List<EObject> eObjects = new ArrayList<EObject>(copier.copyAll(AnydslPackage.eINSTANCE .eContents())); copier.copyReferences(); final EClass foodEClass = (EClass)copier.get(AnydslPackage.eINSTANCE.getFood()); final Resource resource = createResource("test.xmi"); resource.getContents().addAll(eObjects); container.setResource(resource); eObjectContainerHelper.updateEObjectContainer(container.getContainer(), container, resource); final IEObjectLocation location = new TestEObjectLocation(); location.setContainer(container); final ILocation target = new TestTextLocation(); final ILink link = new BaseElementFactoryTests.TestLink(); location.getTargetLinks().add(link); link.setSource(location); target.getSourceLinks().add(link); link.setTarget(target); final TestEObjectContainerConnector connector = new TestEObjectContainerConnector(); MappingUtils.getConnectorRegistry().register(connector); super.initLocation(container, location, new Setting() { public void unset() { // nothing to do here } public void set(Object newValue) { // nothing to do here } public boolean isSet() { return false; } public EStructuralFeature getEStructuralFeature() { return EcorePackage.eINSTANCE.getEClass_EOperations(); } public EObject getEObject() { return foodEClass; } public Object get(boolean resolve) { return foodEClass.getEOperations().get(1); } }); foodEClass.getEOperations().remove(1); eObjectContainerHelper.updateEObjectContainer(container.getContainer(), container, resource); assertEquals(1, base.getReports().size()); final IReport report = base.getReports().get(0); assertEquals(link, report.getLink()); assertTrue(report.getDescription().contains("Food")); assertTrue(report.getDescription().contains(location.getURIFragment())); assertTrue(report.getDescription().contains("has been removed from feature eOperations.")); MappingUtils.getConnectorRegistry().unregister(connector); }
protected IEObjectLocation createEObjectLocation(Copier copier, TestEObjectContainerLocation container) throws Exception { final TestEObjectLocation res; final EObject eObject = copier.get(original[0]); if (original[1] != null) { final EStructuralFeature feature = (EStructuralFeature)original[1]; final Object value; if (original[2] instanceof EObject) { value = copier.get(original[2]); } else { value = original[2]; } res = (TestEObjectLocation)MappingUtils.getConnectorRegistry().createLocation(container, new Setting() { public void unset() { // nothing to do here } public void set(Object newValue) { // nothing to do here } public boolean isSet() { return false; } public EStructuralFeature getEStructuralFeature() { return feature; } public EObject getEObject() { return eObject; } public Object get(boolean resolve) { return value; } }); } else { res = (TestEObjectLocation)MappingUtils.getConnectorRegistry().createLocation(container, eObject); } res.setObject(eObject); return res; }