Search in sources :

Example 86 with EObject

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);
    }
}
Also used : EObject(org.eclipse.emf.ecore.EObject)

Example 87 with EObject

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();
        }
    }
}
Also used : EObject(org.eclipse.emf.ecore.EObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EReference(org.eclipse.emf.ecore.EReference)

Example 88 with EObject

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);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EAttribute(org.eclipse.emf.ecore.EAttribute) EObject(org.eclipse.emf.ecore.EObject) EPackage(org.eclipse.emf.ecore.EPackage)

Example 89 with EObject

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);
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendMethodDeclarationImpl(org.eclipse.xtend.core.macro.declaration.XtendMethodDeclarationImpl) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) XtendEnumerationValueDeclarationImpl(org.eclipse.xtend.core.macro.declaration.XtendEnumerationValueDeclarationImpl) XtendConstructorDeclarationImpl(org.eclipse.xtend.core.macro.declaration.XtendConstructorDeclarationImpl) XtendField(org.eclipse.xtend.core.xtend.XtendField) XtendFieldDeclarationImpl(org.eclipse.xtend.core.macro.declaration.XtendFieldDeclarationImpl) XtendAnnotationType(org.eclipse.xtend.core.xtend.XtendAnnotationType) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) EObject(org.eclipse.emf.ecore.EObject) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XtendAnnotationTypeElementDeclarationImpl(org.eclipse.xtend.core.macro.declaration.XtendAnnotationTypeElementDeclarationImpl) XtendEnumLiteral(org.eclipse.xtend.core.xtend.XtendEnumLiteral) XtendMemberDeclarationImpl(org.eclipse.xtend.core.macro.declaration.XtendMemberDeclarationImpl)

Example 90 with EObject

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);
}
Also used : EObject(org.eclipse.emf.ecore.EObject) XtextResource(org.eclipse.xtext.resource.XtextResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)7112 AntlrDatatypeRuleToken (org.eclipse.xtext.parser.antlr.AntlrDatatypeRuleToken)1950 Resource (org.eclipse.emf.ecore.resource.Resource)304 Test (org.junit.Test)301 IPropertiesEditionEvent (org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)262 PropertiesEditionEvent (org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent)262 ArrayList (java.util.ArrayList)207 GridData (org.eclipse.swt.layout.GridData)198 SelectionEvent (org.eclipse.swt.events.SelectionEvent)190 URI (org.eclipse.emf.common.util.URI)189 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)187 InternalEObject (org.eclipse.emf.ecore.InternalEObject)181 ReferencesTable (org.eclipse.emf.eef.runtime.ui.widgets.ReferencesTable)162 ReferencesTableListener (org.eclipse.emf.eef.runtime.ui.widgets.ReferencesTable.ReferencesTableListener)162 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)138 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)128 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)127 List (java.util.List)125 XtextResource (org.eclipse.xtext.resource.XtextResource)124 EReference (org.eclipse.emf.ecore.EReference)96