Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Advanced Scripting Environment (EASE) » Shouldn't the EcoreModule initialize its selectionModule?
Shouldn't the EcoreModule initialize its selectionModule? [message #1690009] Sun, 21 December 2014 04:43 Go to next message
Nicolas Rouquette is currently offline Nicolas RouquetteFriend
Messages: 157
Registered: July 2009
Senior Member
When the EcoreModule is instantiated, it also instantiates a SelectionModule but does not initialize it:


public class EcoreModule extends AbstractScriptModule {

protected SelectionModule selectionModule = new SelectionModule();
...


This means that if we try to get the selection, then we get an NPE:

In EcoreModule:


public EObject getSelection() {
Object selection = selectionModule.getCustomSelectionFromSelector(GMFSemanticSeletor.SELECTOR_ID);
if (selection instanceof EObject) {
...


because SelectionModule.getCustomSelectionFromSelector(...) needs to access the environment module.

To avoid this problem, I overloaded initialize() in EcoreModule so as to initialize its selection module:


diff --git a/plugins/org.eclipse.ease.modules.modeling/src/org/eclipse/ease/modules/modeling/EcoreModule.java b/plugins/org.eclipse.ease.modules.modeling/src/org/eclipse/ease/modules/modeling/EcoreModule.java
index 4daedce..dc25979 100644
--- a/plugins/org.eclipse.ease.modules.modeling/src/org/eclipse/ease/modules/modeling/EcoreModule.java
+++ b/plugins/org.eclipse.ease.modules.modeling/src/org/eclipse/ease/modules/modeling/EcoreModule.java
@@ -26,9 +26,11 @@ import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.ease.IScriptEngine;
import org.eclipse.ease.Logger;
import org.eclipse.ease.modules.AbstractScriptModule;
import org.eclipse.ease.modules.BootStrapper;
+import org.eclipse.ease.modules.IEnvironment;
import org.eclipse.ease.modules.IModuleWrapper;
import org.eclipse.ease.modules.ScriptParameter;
import org.eclipse.ease.modules.WrapToScript;
@@ -156,6 +158,12 @@ public class EcoreModule extends AbstractScriptModule {
return false;
}
};
+
+ @Override
+ public void initialize(final IScriptEngine engine, final IEnvironment environment) {
+ super.initialize(engine, environment);
+ selectionModule.initialize(engine, environment);
+ }

/**
* Initialized the module with the correct metamodèle. If this method is not called the module will at runtime ask with metamodel shall be used.


Is this correct?

- Nicolas.
Re: Shouldn't the EcoreModule initialize its selectionModule? [message #1690014 is a reply to message #1690009] Sun, 21 December 2014 20:16 Go to previous messageGo to next message
Christian Pontesegger is currently offline Christian PonteseggerFriend
Messages: 250
Registered: July 2009
Location: Graz, Austria
Senior Member
Dependencies should be defined declaratively as part of the module definition. Each module may define its own dependencies. Loading in the correct order will be handled automatically. Furthermore it is guaranteed that all dependencies are correctly loaded when the actual plugin is loaded. To get an instance of such a dependency use getEngile.getModule(module.class).

In theory your patch would be sufficient to initialize the SelectionModule correctly, but the EnvironmentModule would never know about the SelectionModule, which might resolve in other unwanted side effects.
Re: Shouldn't the EcoreModule initialize its selectionModule? [message #1690018 is a reply to message #1690014] Mon, 22 December 2014 00:59 Go to previous message
Nicolas Rouquette is currently offline Nicolas RouquetteFriend
Messages: 157
Registered: July 2009
Senior Member
Currently, the EcoreModule does not initialize its EcoreModule.selectionModule object.
This means that if a script calls getSelection() on the EcoreModule, there will be an NPE.
How do you suggest fixing this if not with the patch I proposed?

- Nicolas.
Previous Topic:Obsolete Ecore generated package extensions in EASE UI
Next Topic:Obsolete Ecore generated package extensions in EASE UI
Goto Forum:
  


Current Time: Fri Apr 26 19:30:13 GMT 2024

Powered by FUDForum. Page generated in 0.03624 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top