use of org.eclipse.emf.ecore.EReference in project benchmarx by eMoflon.
the class ChangeRecorder method notifyChanged.
public void notifyChanged(Notification n) {
super.notifyChanged(n);
if (n.getEventType() == Notification.REMOVING_ADAPTER)
return;
EObject affectedElement = (EObject) n.getNotifier();
EStructuralFeature feature = (EStructuralFeature) n.getFeature();
if (feature == null) {
System.out.println("This comes unexpected.");
}
if (feature instanceof EReference) {
EReference reference = (EReference) feature;
if (reference.getUpperBound() == 1) {
if (reference.isContainment()) {
this.WriteStartChange("CompositionChange", feature);
this.WriteElement(affectedElement, "affectedElement");
if (n.getOldValue() != null) {
this.WriteElement((EObject) n.getOldValue(), "oldValue");
}
buffer.append(">\n");
if (n.getNewValue() != null) {
this.WriteFullElement((EObject) n.getNewValue(), "newValue");
}
this.WriteEndChange("CompositionChange");
} else {
if (reference.isContainer())
return;
this.WriteStartChange("AssociationChange", feature);
if (n.getNewValue() != null) {
this.WriteElement((EObject) n.getNewValue(), "newValue");
}
if (n.getOldValue() != null) {
this.WriteElement((EObject) n.getOldValue(), "oldValue");
}
this.WriteElement(affectedElement, "affectedElement");
this.WriteSelfClosingChange();
}
} else if (reference.isOrdered()) {
int position = n.getPosition();
if (reference.isContainment()) {
if (n.getEventType() == Notification.ADD) {
this.WriteStartChange("CompositionListInsertion", feature);
this.WriteElement(affectedElement, "affectedElement");
this.WritePosition(position);
buffer.append(">\n");
this.WriteFullElement((EObject) n.getNewValue(), "addedElement");
this.WriteEndChange("CompositionListInsertion");
} else if (n.getEventType() == Notification.REMOVE) {
this.WriteStartChange("CompositionListDeletion", feature);
this.WriteElement((EObject) n.getOldValue(), "deletedElement");
this.WriteElement(affectedElement, "affectedElement");
this.WritePosition(position);
this.WriteSelfClosingChange();
} else {
buffer.append("(Change type not supported)");
}
} else {
if (reference.isContainer())
return;
if (n.getEventType() == Notification.ADD) {
this.WriteStartChange("AssociationListInsertion", feature);
this.WriteElement((EObject) n.getNewValue(), "addedElement");
} else if (n.getEventType() == Notification.REMOVE) {
this.WriteStartChange("AssociationListDeletion", feature);
this.WriteElement((EObject) n.getOldValue(), "deletedElement");
} else {
buffer.append("(Change type not supported)");
}
this.WriteElement(affectedElement, "affectedElement");
this.WritePosition(position);
this.WriteSelfClosingChange();
}
} else {
if (reference.isContainment()) {
if (n.getEventType() == Notification.ADD) {
this.WriteStartChange("CompositionCollectionInsertion", feature);
this.WriteElement(affectedElement, "affectedElement");
buffer.append(">\n");
this.WriteFullElement((EObject) n.getNewValue(), "addedElement");
this.WriteEndChange("CompositionCollectionInsertion");
} else if (n.getEventType() == Notification.REMOVE) {
this.WriteStartChange("CompositionCollectionDeletion", feature);
this.WriteElement((EObject) n.getOldValue(), "deletedElement");
this.WriteElement(affectedElement, "affectedElement");
this.WriteSelfClosingChange();
} else {
System.out.println("Change type not supported");
}
} else {
if (n.getEventType() == Notification.ADD) {
this.WriteStartChange("AssociationCollectionInsertion", feature);
this.WriteElement((EObject) n.getNewValue(), "addedElement");
} else if (n.getEventType() == Notification.REMOVE) {
this.WriteStartChange("AssociationCollectionDeletion", feature);
this.WriteElement((EObject) n.getOldValue(), "deletedElement");
} else {
buffer.append("(Change type not supported)");
}
this.WriteElement(affectedElement, "affectedElement");
this.WriteSelfClosingChange();
}
}
} else {
if (feature.getUpperBound() == 1) {
this.WriteStartChange("AttributeChange", feature);
if (n.getNewStringValue() != null) {
this.WriteAttribute("newValue", toCompatibleString(n.getNewValue()));
}
if (n.getOldStringValue() != null) {
this.WriteAttribute("oldValue", toCompatibleString(n.getOldValue()));
}
this.WriteElement(affectedElement, "affectedElement");
this.WriteSelfClosingChange();
} else if (feature.isOrdered()) {
int position = n.getPosition();
if (n.getEventType() == Notification.ADD) {
this.WriteStartChange("AttributeListInsertion", feature);
this.WriteAttribute("addedValue", n.getNewStringValue());
} else if (n.getEventType() == Notification.REMOVE) {
this.WriteStartChange("AttributeListDeletion", feature);
this.WriteAttribute("deletedValue", n.getOldStringValue());
} else {
buffer.append("(Change type not supported)");
}
this.WriteElement(affectedElement, "affectedElement");
this.WritePosition(position);
this.WriteSelfClosingChange();
} else {
if (n.getEventType() == Notification.ADD) {
this.WriteStartChange("AttributeCollectionInsertion", feature);
this.WriteAttribute("addedValue", n.getNewStringValue());
} else if (n.getEventType() == Notification.REMOVE) {
this.WriteStartChange("AttributeCollectionDeletion", feature);
this.WriteAttribute("deletedValue", n.getOldStringValue());
} else {
System.out.println("Change type not supported");
}
this.WriteElement(affectedElement, "affectedElement");
this.WriteSelfClosingChange();
}
}
}
use of org.eclipse.emf.ecore.EReference in project xtext-xtend by eclipse.
the class XAnnotationExtensions method isProcessed.
/**
* Checks whether this annotation is pointing to a processed annotation, without resolving the proxy
*/
public boolean isProcessed(final XAnnotation it) {
Object _eGet = it.eGet(XAnnotationsPackage.Literals.XANNOTATION__ANNOTATION_TYPE, false);
final Object proxy = _eGet;
boolean _matched = false;
if (proxy instanceof EObject) {
boolean _eIsProxy = ((EObject) proxy).eIsProxy();
if (_eIsProxy) {
_matched = true;
final URI uri = ((InternalEObject) proxy).eProxyURI();
boolean _isCrossLinkFragment = this.encoder.isCrossLinkFragment(it.eResource(), uri.fragment());
if (_isCrossLinkFragment) {
final Triple<EObject, EReference, INode> triple = this.encoder.decode(it.eResource(), uri.fragment());
final List<EObject> candidates = this.linkingService.getLinkedObjects(triple.getFirst(), triple.getSecond(), triple.getThird());
boolean _isEmpty = candidates.isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
final EObject head = IterableExtensions.<EObject>head(candidates);
if ((head instanceof JvmAnnotationType)) {
return this.isActiveAnnotation(((JvmAnnotationType) head));
}
}
}
}
}
if (!_matched) {
if (proxy instanceof JvmAnnotationType) {
_matched = true;
return this.isActiveAnnotation(((JvmAnnotationType) proxy));
}
}
return false;
}
use of org.eclipse.emf.ecore.EReference in project xtext-xtend by eclipse.
the class EmfModelsTest method dumpFeatures.
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);
}
}
}
}
use of org.eclipse.emf.ecore.EReference in project xtext-xtend by eclipse.
the class URIsInEcoreFilesXtendTest method doTestResource.
protected void doTestResource(String platformPath, String... packageNames) {
Resource resource = resourceSet.getResource(URI.createPlatformPluginURI(platformPath, false), true);
assertNotNull(resource);
assertEquals(1, resource.getContents().size());
EObject obj = resource.getContents().get(0);
if (obj instanceof EPackage) {
assertEquals(packageNames[0], ((EPackage) obj).getName());
} else if (obj instanceof GenModel) {
GenModel model = (GenModel) obj;
List<GenPackage> packages = Lists.newArrayList(model.getGenPackages());
assertEquals(packageNames.length, packages.size());
ListExtensions.sortInplaceBy(packages, new Functions.Function1<GenPackage, String>() {
@Override
public String apply(GenPackage p) {
return p.getEcorePackage().getName();
}
});
List<String> packageNamesList = Arrays.asList(packageNames);
Collections.sort(packageNamesList);
for (int i = 0; i < packageNamesList.size(); i++) {
assertEquals(packageNamesList.get(i), packages.get(i).getEcorePackage().getName());
}
IStatus status = model.validate();
assertTrue(printLeafs(status), status.isOK());
EObject orig = EcoreUtil.copy(obj);
((GenModel) obj).reconcile();
if (!EcoreUtil.equals(orig, obj)) {
Predicate<EStructuralFeature> ignoreContainer = new Predicate<EStructuralFeature>() {
@Override
public boolean apply(EStructuralFeature f) {
if (f instanceof EReference) {
EReference casted = (EReference) f;
return !casted.isContainment();
}
return false;
}
};
String origAsString = EmfFormatter.objToStr(orig, ignoreContainer);
String newAsString = EmfFormatter.objToStr(obj, ignoreContainer);
throw new ComparisonFailure("Reconcile changed model", origAsString, newAsString);
}
} else {
fail("Unexpected root element type: " + obj.eClass().getName());
}
}
use of org.eclipse.emf.ecore.EReference in project Palladio-Editors-Sirius by PalladioSimulator.
the class AddSourceRole method getEventGroup.
private EventGroup getEventGroup(SourceRole role) {
Collection<Object> filter = new ArrayList<Object>();
filter.add(Repository.class);
filter.add(EventGroup.class);
// Additional Child References
Collection<EReference> additionalChildReferences = new ArrayList<EReference>();
// Creating the dialog
PalladioSelectEObjectDialog dialog = new PalladioSelectEObjectDialog(SHELL, filter, additionalChildReferences, role.eResource().getResourceSet());
// Setting the needed object type
dialog.setProvidedService(EventGroup.class);
dialog.open();
return (EventGroup) dialog.getResult();
}
Aggregations