use of org.eclipse.emf.ecore.EObject in project benchmarx by eMoflon.
the class ChangeRecorder method registerDescendants.
private void registerDescendants(EObject modelElement) {
String uri = modelPath + "#//" + EcoreUtil.getRelativeURIFragmentPath(null, modelElement);
uris.put(modelElement, uri);
for (EObject child : modelElement.eContents()) {
this.registerDescendants(child);
}
}
use of org.eclipse.emf.ecore.EObject 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.EObject in project benchmarx by eMoflon.
the class ChangeRecorder method WriteFullElement.
private void WriteFullElement(EObject element, String type) {
buffer.append("\t\t<");
buffer.append(type);
buffer.append(" xsi:type=\"");
EClass eClass = element.eClass();
EPackage ePackage = (EPackage) eClass.eContainer();
buffer.append(ePackage.getNsPrefix());
buffer.append(":");
buffer.append(eClass.getName());
buffer.append("\" xmlns:");
buffer.append(ePackage.getNsPrefix());
buffer.append("=\"");
buffer.append(ePackage.getNsURI());
buffer.append("\"");
for (EAttribute att : eClass.getEAllAttributes()) {
if (element.eIsSet(att)) {
Object value = element.eGet(att);
WriteAttribute(att.getName(), toCompatibleString(value));
}
}
buffer.append(" />\n");
this.RegisterNewElement(element, this.changeCounter, type);
}
use of org.eclipse.emf.ecore.EObject in project xtext-xtend by eclipse.
the class CompilationUnitImpl method toXtendMemberDeclaration.
public MemberDeclaration toXtendMemberDeclaration(final XtendMember delegate) {
final Function1<XtendMember, XtendMemberDeclarationImpl<? extends XtendMember>> _function = (XtendMember it) -> {
XtendMemberDeclarationImpl<? extends XtendMember> _switchResult = null;
boolean _matched = false;
if (delegate instanceof XtendTypeDeclaration) {
_matched = true;
_switchResult = this.toXtendTypeDeclaration(((XtendTypeDeclaration) delegate));
}
if (!_matched) {
if (delegate instanceof XtendFunction) {
_matched = true;
XtendMethodDeclarationImpl _xtendMethodDeclarationImpl = new XtendMethodDeclarationImpl();
final Procedure1<XtendMethodDeclarationImpl> _function_1 = (XtendMethodDeclarationImpl it_1) -> {
it_1.setDelegate(((XtendFunction) delegate));
it_1.setCompilationUnit(this);
};
_switchResult = ObjectExtensions.<XtendMethodDeclarationImpl>operator_doubleArrow(_xtendMethodDeclarationImpl, _function_1);
}
}
if (!_matched) {
if (delegate instanceof XtendConstructor) {
_matched = true;
XtendConstructorDeclarationImpl _xtendConstructorDeclarationImpl = new XtendConstructorDeclarationImpl();
final Procedure1<XtendConstructorDeclarationImpl> _function_1 = (XtendConstructorDeclarationImpl it_1) -> {
it_1.setDelegate(((XtendConstructor) delegate));
it_1.setCompilationUnit(this);
};
_switchResult = ObjectExtensions.<XtendConstructorDeclarationImpl>operator_doubleArrow(_xtendConstructorDeclarationImpl, _function_1);
}
}
if (!_matched) {
if (delegate instanceof XtendField) {
_matched = true;
XtendMemberDeclarationImpl<XtendField> _xifexpression = null;
EObject _eContainer = ((XtendField) delegate).eContainer();
if ((_eContainer instanceof XtendAnnotationType)) {
XtendAnnotationTypeElementDeclarationImpl _xtendAnnotationTypeElementDeclarationImpl = new XtendAnnotationTypeElementDeclarationImpl();
final Procedure1<XtendAnnotationTypeElementDeclarationImpl> _function_1 = (XtendAnnotationTypeElementDeclarationImpl it_1) -> {
it_1.setDelegate(((XtendField) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<XtendAnnotationTypeElementDeclarationImpl>operator_doubleArrow(_xtendAnnotationTypeElementDeclarationImpl, _function_1);
} else {
XtendFieldDeclarationImpl _xtendFieldDeclarationImpl = new XtendFieldDeclarationImpl();
final Procedure1<XtendFieldDeclarationImpl> _function_2 = (XtendFieldDeclarationImpl it_1) -> {
it_1.setDelegate(((XtendField) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<XtendFieldDeclarationImpl>operator_doubleArrow(_xtendFieldDeclarationImpl, _function_2);
}
_switchResult = _xifexpression;
}
}
if (!_matched) {
if (delegate instanceof XtendEnumLiteral) {
_matched = true;
XtendEnumerationValueDeclarationImpl _xtendEnumerationValueDeclarationImpl = new XtendEnumerationValueDeclarationImpl();
final Procedure1<XtendEnumerationValueDeclarationImpl> _function_1 = (XtendEnumerationValueDeclarationImpl it_1) -> {
it_1.setDelegate(((XtendEnumLiteral) delegate));
it_1.setCompilationUnit(this);
};
_switchResult = ObjectExtensions.<XtendEnumerationValueDeclarationImpl>operator_doubleArrow(_xtendEnumerationValueDeclarationImpl, _function_1);
}
}
return _switchResult;
};
return this.<XtendMember, XtendMemberDeclarationImpl<? extends XtendMember>>getOrCreate(delegate, _function);
}
use of org.eclipse.emf.ecore.EObject in project xtext-xtend by eclipse.
the class RefactoringIntegrationTest method performRenameTest.
protected void performRenameTest(IFile file, String originalContents, String oldName, String newName, IFile newFile) throws Exception {
IResourcesSetupUtil.waitForBuild();
ResourceSet resourceSet = resourceSetProvider.get(file.getProject());
XtextResource resource = (XtextResource) resourceSet.getResource(testHelper.uri(file), true);
EObject target = eObjectAtOffsetHelper.resolveElementAt(resource, originalContents.indexOf(oldName));
doRename(target, newName);
String contentsAfterRename = WorkbenchTestHelper.getContentsAsString(newFile);
assertEquals(originalContents.replace(oldName, newName), contentsAfterRename);
}
Aggregations