/** * Removes the element reference for the specified element, rebuild later * * @param element A method element. */ private void removeReference(MethodElement element) { PackageDependency dependency = null; MethodElement pkg = (MethodElement) LibraryUtil.getSelectable(element); if ((pkg == null) || ((dependency = getDependency(pkg, false)) == null)) { return; } dependency.removeReference(element); }
/** * Builds the dependency for a method element. * * <p>This creates an <code>ElementReference</code> for the given element that points to all the * referenced elements, and adds the given element as a dependent element to all the referenced * elements. This should only be called once for each method element. * * @param element A method element. * @return A <code>PackageDependency</code>. */ private PackageDependency buildDependencyFor(MethodElement element) { if (element == null) { return null; } IConfigurationManager configMgr = LibraryService.getInstance().getConfigurationManager(config); if (configMgr != null) { SupportingElementData seData = configMgr.getSupportingElementData(); if (seData != null && seData.isEnabled()) { seData.processVariabilityChildren(element, null); } } // Build the dependency on the selectable element/parent only MethodElement selectableElement = (MethodElement) LibraryUtil.getSelectable(element); if (selectableElement == null) { return null; } PackageDependency dependency = getDependency(selectableElement, true); // Remove any existing element reference for this element. dependency.removeReference(element); /* // Get the VariabilityElement. ContentElement baseElement = null; if (element instanceof ContentElement) { baseElement = (ContentElement) ((ContentElement) element) .getVariabilityBasedOnElement(); if (baseElement != null) { // Establish the package reference. EObject selectableBase = LibraryUtil.getSelectable(baseElement); if (selectableBase != null) { PackageReference pkgRef = dependency.getReference( selectableBase, true); if (!pkgRef.hasReference(element, baseElement)) { // Add the detail element reference to the package // reference. VariabilityElementReference ref = new VariabilityElementReference( element, baseElement); pkgRef.addReference(ref); } // Set the dependent of the referenced package. getDependency(selectableBase, true).addDependent( selectableElement); } } } List references = element.eCrossReferences(); // Update the dependents of those elements in the list. if (references != null && references.size() > 0) { // Get the selectable references for (Iterator it = references.iterator(); it.hasNext();) { EObject refElement = (EObject) it.next(); EObject selectableRef = LibraryUtil.getSelectable(refElement); if (selectableRef != null) { PackageReference pkgRef = dependency.getReference( selectableRef, true); if (element == selectableElement && refElement == selectableRef) { // No need to add this. continue; } if (!pkgRef.hasReference(element, refElement)) { GeneralReference ref = new GeneralReference(element, refElement); pkgRef.addReference(ref); } getDependency(selectableRef, true).addDependent( selectableElement); } } } */ List properties = LibraryUtil.getStructuralFeatures(element, true); for (int i = 0; i < properties.size(); i++) { EStructuralFeature f = (EStructuralFeature) properties.get(i); if (!(f instanceof EReference)) { continue; } EReference feature = (EReference) f; if (feature.isContainer() || feature.isContainment()) { continue; } if (element instanceof Task) { if (feature == UmaPackage.eINSTANCE.getTask_Steps()) { continue; } } if (element instanceof TaskDescriptor) { if (feature == UmaPackage.eINSTANCE.getTaskDescriptor_SelectedSteps()) { continue; } } Object value = TypeDefUtil.getInstance().eGet(element, feature); if (value == null) { continue; } MethodElement refElement = null; List values = null; int count = 0; if (feature.isMany()) { values = (List) value; if (values.size() > 0) { refElement = (MethodElement) values.get(count); } } else if (value instanceof MethodElement) { refElement = (MethodElement) value; if (replacerSet != null) { if (feature == UmaPackage.eINSTANCE.getVariabilityElement_VariabilityBasedOnElement()) { VariabilityElement ve = element instanceof VariabilityElement ? (VariabilityElement) element : null; VariabilityType type = ve == null ? null : ve.getVariabilityType(); if (type == VariabilityType.EXTENDS_REPLACES || type == VariabilityType.REPLACES) { replacerSet.add(ve); } } } } while (refElement != null) { boolean skip = false; if (feature == UmaPackage.eINSTANCE.getRole_Modifies()) { skip = true; } MethodElement selectableRef = skip ? null : (MethodElement) LibraryUtil.getSelectable(refElement); if (selectableRef != null) { PackageReference pkgRef = dependency.getReference(selectableRef, true); if (element == selectableElement && refElement == selectableRef) { // No need to add this. break; } ElementReference ref = pkgRef.getReference(element, refElement); if (ref == null) { ref = new ElementReference(element, refElement); pkgRef.addReference(ref); } ref.addFeature(feature); getDependency(selectableRef, true).addDependent(selectableElement); } refElement = null; if (values != null) { count++; if (count < values.size()) { refElement = (MethodElement) values.get(count); } } } } return dependency; }