Java Code Examples for org.eclipse.emf.ecore.EStructuralFeature#isChangeable()

The following examples show how to use org.eclipse.emf.ecore.EStructuralFeature#isChangeable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigurationModelWizard.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the names of the features representing global elements.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected Collection<String> getInitialObjectNames ()
{
    if ( initialObjectNames == null )
    {
        initialObjectNames = new ArrayList<String> ();
        for ( EStructuralFeature eStructuralFeature : ExtendedMetaData.INSTANCE.getAllElements ( ExtendedMetaData.INSTANCE.getDocumentRoot ( configurationPackage ) ) )
        {
            if ( eStructuralFeature.isChangeable () )
            {
                EClassifier eClassifier = eStructuralFeature.getEType ();
                if ( eClassifier instanceof EClass )
                {
                    EClass eClass = (EClass)eClassifier;
                    if ( !eClass.isAbstract () )
                    {
                        initialObjectNames.add ( eStructuralFeature.getName () );
                    }
                }
            }
        }
        Collections.sort ( initialObjectNames, CommonPlugin.INSTANCE.getComparator () );
    }
    return initialObjectNames;
}
 
Example 2
Source File: BeansModelWizard.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the names of the features representing global elements.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
protected Collection<String> getInitialObjectNames() {
	if (initialObjectNames == null) {
		initialObjectNames = new ArrayList<String>();
		for (EStructuralFeature eStructuralFeature : ExtendedMetaData.INSTANCE.getAllElements(ExtendedMetaData.INSTANCE.getDocumentRoot(beansPackage))) {
			if (eStructuralFeature.isChangeable()) {
				EClassifier eClassifier = eStructuralFeature.getEType();
				if (eClassifier instanceof EClass) {
					EClass eClass = (EClass)eClassifier;
					if (!eClass.isAbstract()) {
						initialObjectNames.add(eStructuralFeature.getName());
					}
				}
			}
		}
		Collections.sort(initialObjectNames, CommonPlugin.INSTANCE.getComparator());
	}
	return initialObjectNames;
}
 
Example 3
Source File: EMFGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private void replaceReferencesInGeneratedPackages(final List<EPackage> generatedPackages, final Map<EObject, EObject> eNamedElementMapping) {
  final TreeIterator<EObject> packageContentIterator = EcoreUtil.<EObject>getAllContents(generatedPackages);
  while (packageContentIterator.hasNext()) {
    {
      final EObject current = packageContentIterator.next();
      EList<EStructuralFeature> _eAllStructuralFeatures = current.eClass().getEAllStructuralFeatures();
      final EStructuralFeature[] crossReferenceFeatures = ((EClassImpl.FeatureSubsetSupplier) _eAllStructuralFeatures).crossReferences();
      if ((crossReferenceFeatures != null)) {
        for (final EStructuralFeature crossReferenceFeature : crossReferenceFeatures) {
          boolean _isChangeable = crossReferenceFeature.isChangeable();
          if (_isChangeable) {
            final EReference reference = ((EReference) crossReferenceFeature);
            boolean _isMany = reference.isMany();
            if (_isMany) {
              Object _eGet = current.eGet(reference);
              final List<EObject> values = ((List<EObject>) _eGet);
              for (final EObject value : values) {
                boolean _containsKey = eNamedElementMapping.containsKey(value);
                if (_containsKey) {
                  EcoreUtil.replace(current, reference, value, eNamedElementMapping.get(value));
                }
              }
            } else {
              Object _eGet_1 = current.eGet(reference);
              final EObject value_1 = ((EObject) _eGet_1);
              boolean _containsKey_1 = eNamedElementMapping.containsKey(value_1);
              if (_containsKey_1) {
                EcoreUtil.replace(current, reference, value_1, eNamedElementMapping.get(value_1));
              }
            }
          }
        }
      }
    }
  }
}
 
Example 4
Source File: BackwardConverter.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Determines whether a certain feature should be ignored during conversion.
 */
protected boolean ignore(EStructuralFeature feature) {
    return feature.isTransient()
            || !feature.isChangeable()
            ||
            // according to
            // http://www.eclipse.org/newsportal/article.php?id=26780&group=eclipse.tools.emf
            // the following three references need to be ignored
            EcorePackage.eINSTANCE.getEClass_ESuperTypes().equals(feature)
            || EcorePackage.eINSTANCE.getETypedElement_EType().equals(
                    feature)
            || EcorePackage.eINSTANCE.getEOperation_EExceptions().equals(
                    feature);
}
 
Example 5
Source File: EObjectFeatureMerger.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
private EObject merge(final EObject from, final EObject to, final Collection<Object> visitedObjects) {

		if (null == from || null == to) {
			return null;
		}

		// This is against cycles through EReferences.
		if (visitedObjects.contains(from) || visitedObjects.contains(to)) {
			return to;
		}

		visitedObjects.add(to);
		visitedObjects.add(from);

		final Collection<EStructuralFeature> fromFeatures = from.eClass().getEAllStructuralFeatures();

		for (final EStructuralFeature feature : fromFeatures) {
			if (-1 != to.eClass().getFeatureID(feature) && feature.isChangeable()) {
				if (from.eIsSet(feature)) {
					final Object fromValue = from.eGet(feature, true);
					final Object toValue = to.eGet(feature, true);
					if (null == toValue) {
						to.eSet(feature, fromValue);
					} else {
						if (feature.isMany()) {
							@SuppressWarnings("unchecked")
							final Collection<Object> toManyValue = (Collection<Object>) toValue;
							@SuppressWarnings("unchecked")
							final Collection<Object> fromManyValue = (Collection<Object>) fromValue;
							for (final Iterator<Object> itr = fromManyValue.iterator(); itr.hasNext(); /**/) {
								final Object fromElement = itr.next();
								if (!contains(toManyValue, fromElement)) {
									itr.remove();
									toManyValue.add(fromElement);
								}
							}
						} else {
							if (feature instanceof EAttribute) {
								to.eSet(feature, fromValue);
							} else if (feature instanceof EReference) {
								to.eSet(feature, merge((EObject) fromValue, (EObject) toValue, visitedObjects));
							}
						}
					}
				}
			}
		}
		return to;
	}
 
Example 6
Source File: EmfModelsTest.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public void dumpFeatures(final EClass eClassifier, final EObject obj) {
  EList<EStructuralFeature> _eAllStructuralFeatures = eClassifier.getEAllStructuralFeatures();
  for (final EStructuralFeature eStructuralFeature : _eAllStructuralFeatures) {
    try {
      String prefix = "get";
      if ((Objects.equal(eStructuralFeature.getEType(), EcorePackage.Literals.EBOOLEAN) && (eStructuralFeature.getUpperBound() == 1))) {
        prefix = "is";
      }
      String _firstUpper = Strings.toFirstUpper(eStructuralFeature.getName());
      final String getterName = (prefix + _firstUpper);
      final Method getter = obj.getClass().getMethod(getterName);
      boolean _isCustom = this.isCustom(getter);
      if (_isCustom) {
        String _name = eClassifier.getName();
        String _plus = (_name + ": Overridden getter ");
        String _plus_1 = (_plus + getterName);
        EmfModelsTest.LOGGER.debug(_plus_1);
      }
      boolean _isMany = eStructuralFeature.isMany();
      boolean _not = (!_isMany);
      if (_not) {
        boolean _isChangeable = eStructuralFeature.isChangeable();
        if (_isChangeable) {
          String _firstUpper_1 = Strings.toFirstUpper(eStructuralFeature.getName());
          final String setterName = ("set" + _firstUpper_1);
          final Method setter = obj.getClass().getMethod(setterName, 
            this.toJavaClass(eStructuralFeature.getEType()));
          boolean _isCustom_1 = this.isCustom(setter);
          if (_isCustom_1) {
            String _name_1 = eClassifier.getName();
            String _plus_2 = (_name_1 + ": Overridden setter ");
            String _name_2 = setter.getName();
            String _plus_3 = (_plus_2 + _name_2);
            EmfModelsTest.LOGGER.debug(_plus_3);
          }
        }
        if ((((eStructuralFeature instanceof EReference) && (!((EReference) eStructuralFeature).isContainment())) && 
          (((EReference) eStructuralFeature).getEOpposite() == null))) {
          String _firstUpper_2 = Strings.toFirstUpper(getterName);
          final String basicGetterName = ("basic" + _firstUpper_2);
          final Method basicGetter = obj.getClass().getMethod(basicGetterName);
          boolean _isCustom_2 = this.isCustom(basicGetter);
          if (_isCustom_2) {
            String _name_3 = eClassifier.getName();
            String _plus_4 = (_name_3 + ": Overridden basicGetter ");
            String _name_4 = basicGetter.getName();
            String _plus_5 = (_plus_4 + _name_4);
            EmfModelsTest.LOGGER.debug(_plus_5);
          }
        }
      }
    } catch (final Throwable _t) {
      if (_t instanceof Exception) {
        final Exception e = (Exception)_t;
        e.printStackTrace();
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
  }
}