Access language and IllegalModelAccessError

Hi, In one of my projects, I've written a plugin, which creates a dialog whenever there's an error to the user. Since it is interfering with the MPS UI and also the plugin is reading and writing the model so I need to implement some synchronization procedure to access the model. I'm using Access Language by MPS to do that. And I have enclosed my call to method inside "command with" and "read action" and "write action block" but nothing seemed to work and I'm just getting IllegalModelAccesError.

11 comments
Comment actions Permalink

What is the stack trace of the exception? You can click on "IllegalModelAccessError" and a dialog will appear with two tabs, the second tab shows the stack trace.

Also, there's an option, "execute outside command", which you can try setting to false.

0
Comment actions Permalink

Hi Segej, thanks for replying. I tried setting "execute outside command" to false too. Here's the stack trace.

0
Comment actions Permalink


Also if I try doing this without "Access Language" using "Open API", I can't get the getRepository() method in the intention menu either using SRepository staticaly or using my mode instance. If I could get the repository then I'll be able to use getModelAccess() and runReadAction() and runWriteAction() methods.
I'm using MPS 3.4.1.

0
Comment actions Permalink

From the stack trace it looks like the exception happens in some code that was invoked via invokeLater() or some such method. That code (Faults.plugin.Dialog) has to acquire the model lock by itself since by the time it executes your event handler has already finished.

There is definitely a context parameter to get the current MPS project, and Project has method getRepository().

0
Comment actions Permalink

Yes you are right. I'm using invokeLater() method in my dialog class but I'm not using access language constructs there. I was just using access language constructs in the plugin where I was calling the method. Thanks. I would try that. I think that is the problem :)

0
Comment actions Permalink

As shown in the figure in my last comment this.current_model is my context parameter which is giving me the project but it still doesn't have getRepository() method. That is pretty weird.

0
Comment actions Permalink

Yes, but you can have additional context parameters, and one of these context parameters is MPS Project:



0
Comment actions Permalink

Thanks again taking out your time to reply. I would get back to you after checking what happens if i individually enclose my pieces of code in the access language constructs.

It's weird that I'm not getting project in the context parameters' intention. Is there a chance that they have removed it in the MPS 3.4.1?

0
Comment actions Permalink

Try importing the model containing MPSCommonDataKeys (press Ctrl-R and type MPSCommonDataKeys:

After that you should see MPS_PROJECT in the completion menu.

0
Comment actions Permalink

Yes, that worked. Thanks again :)

0
Comment actions Permalink

Hi again, so as suggested, enclosing the statements inside the run() method within invokeLater() method resolved the issue of IllegalModelAccesError. But if you enclose invokeLater() method within "read action", it won't resolve the problem.

0

Please sign in to leave a comment.