Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.common.xtext/src/org/eclipse/papyrus/uml/textedit/common/xtext/scoping/UmlCommonScopeProvider.java')
-rw-r--r--plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.common.xtext/src/org/eclipse/papyrus/uml/textedit/common/xtext/scoping/UmlCommonScopeProvider.java82
1 files changed, 20 insertions, 62 deletions
diff --git a/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.common.xtext/src/org/eclipse/papyrus/uml/textedit/common/xtext/scoping/UmlCommonScopeProvider.java b/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.common.xtext/src/org/eclipse/papyrus/uml/textedit/common/xtext/scoping/UmlCommonScopeProvider.java
index 5facfab7571..c4e06832562 100644
--- a/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.common.xtext/src/org/eclipse/papyrus/uml/textedit/common/xtext/scoping/UmlCommonScopeProvider.java
+++ b/plugins/uml/textedit/org.eclipse.papyrus.uml.textedit.common.xtext/src/org/eclipse/papyrus/uml/textedit/common/xtext/scoping/UmlCommonScopeProvider.java
@@ -1,21 +1,13 @@
-/*
- * generated by Xtext
- */
package org.eclipse.papyrus.uml.textedit.common.xtext.scoping;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.papyrus.uml.textedit.common.xtext.umlCommon.QualifiedName;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PlatformUI;
+import org.eclipse.papyrus.uml.xtext.integration.core.ContextElementUtil;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.ElementImport;
import org.eclipse.uml2.uml.NamedElement;
@@ -37,48 +29,12 @@ import org.eclipse.xtext.scoping.impl.SimpleScope;
*/
public class UmlCommonScopeProvider extends AbstractDeclarativeScopeProvider {
- /** the edited model */
- private Namespace model = null;
-
- /** the edited element */
- private Element contextElement = null;
-
/**
*
* Constructor.
*
*/
public UmlCommonScopeProvider() {
- initModel();
- }
-
- /**
- *
- * This method initializes the fields {@link #model} {@link #contextElement} thanks to the current selection
- *
- */
- protected void initModel() {
- IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- ISelection mySelection = activePage.getSelection();
- if(mySelection instanceof IStructuredSelection) {
- Object first = ((IStructuredSelection)mySelection).getFirstElement();
- if(first != null) {
- if(first instanceof IAdaptable) {
- Element el = (Element)((IAdaptable)first).getAdapter(Element.class);
- this.contextElement = el;
- if(el != null) {
- List<Namespace> namespaces = el.getNearestPackage().allNamespaces();
- if(namespaces.size() == 0) {
- this.model = el.getNearestPackage();
- } else {
- this.model = namespaces.get(namespaces.size() - 1);
- }
- }
- }
- }
- }
- Assert.isNotNull(contextElement, "I can't find the edited element"); //$NON-NLS-1$
- Assert.isNotNull(this.model, "I can't find the model owning the edited element"); //$NON-NLS-1$
}
/**
@@ -87,21 +43,21 @@ public class UmlCommonScopeProvider extends AbstractDeclarativeScopeProvider {
* @return
* {@link #model}
*/
- protected Namespace getModel() {
- return this.model;
- }
+ protected Namespace getModel(EObject xtextElement) {
+ EObject semanticElement = ContextElementUtil.getContextElement(xtextElement.eResource());
+ if(semanticElement instanceof Element) {
+ Element element = (Element)semanticElement;
+ List<Namespace> namespaces = element.getNearestPackage().allNamespaces();
+ if(namespaces.size() == 0) {
+ return element.getNearestPackage();
+ } else {
+ return namespaces.get(namespaces.size() - 1);
+ }
+ }
- /**
- * Getter for {@link #contextElement}
- *
- * @return
- * {@link #contextElement}
- */
- protected Element getContextElement() {
- return this.contextElement;
+ return null;
}
-
/**
* Rule for computing the scope of PropertyRule
*
@@ -124,7 +80,7 @@ public class UmlCommonScopeProvider extends AbstractDeclarativeScopeProvider {
*/
protected IScope create___TypeRule_type___Scope(org.eclipse.papyrus.uml.textedit.common.xtext.umlCommon.TypeRule ctx) {
if(ctx.getPath() == null) {
- Iterator<EObject> i = org.eclipse.papyrus.infra.gmfdiag.xtext.glue.edit.part.PopupXtextEditorHelper.context.eResource().getAllContents();
+ Iterator<EObject> i = ContextElementUtil.getContextElement(ctx.eResource()).eResource().getAllContents();
List<EObject> allContent = new ArrayList<EObject>();
while(i.hasNext()) {
EObject object = i.next();
@@ -216,8 +172,9 @@ public class UmlCommonScopeProvider extends AbstractDeclarativeScopeProvider {
namespaces.add(pImport.getImportedPackage());
}
for(ElementImport eImport : visited.getElementImports()) {
- if(eImport.getImportedElement() instanceof Namespace)
+ if(eImport.getImportedElement() instanceof Namespace) {
namespaces.add((Namespace)eImport.getImportedElement());
+ }
}
return namespaces;
@@ -237,8 +194,9 @@ public class UmlCommonScopeProvider extends AbstractDeclarativeScopeProvider {
namespaces.addAll(getImportedNamespaces(visited));
// then retrieves owned namespaces
for(NamedElement n : visited.getOwnedMembers()) {
- if(n instanceof Namespace)
+ if(n instanceof Namespace) {
namespaces.add((Namespace)n);
+ }
}
return namespaces;
}
@@ -254,8 +212,8 @@ public class UmlCommonScopeProvider extends AbstractDeclarativeScopeProvider {
Namespace parentNameSpace = ((QualifiedName)ctx.eContainer()).getPath();
visibleNamespaces.addAll(getOwnedAndImportedNamespaces(parentNameSpace));
} else {
- visibleNamespaces.add(getModel());
- visibleNamespaces.addAll(getImportedNamespaces(getModel()));
+ visibleNamespaces.add(getModel(ctx));
+ visibleNamespaces.addAll(getImportedNamespaces(getModel(ctx)));
}
Iterable<IEObjectDescription> iterableIEobjectDescription = Scopes.scopedElementsFor(visibleNamespaces);
return new SimpleScope(iterableIEobjectDescription);

Back to the top