Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » 'static' variables for EVL invariants(can a variable be persisted between calls to the invariant?)
'static' variables for EVL invariants [message #537221] Tue, 01 June 2010 15:50 Go to next message
Endre Balogh is currently offline Endre BaloghFriend
Messages: 38
Registered: May 2010
Member
Hello,

I'm trying to create the following invariant for my model: I have an abstract class NamedElement with several concrete subclasses. I want them all to have their names defined (check : self.name.isDefined()). I also want to provide a quick fix that assigns default names to unnamed instances, such as for the class Entity, the unnamed objects will be called Entity1, Entity2, etc.

I ran into two problems:

Is it possible to persist a variable's value between calls to the invariant? The purpose would be to keep a counter when renaming objects, although this isn't a very good solution, since I can't keep a different counter for all subclasses, i.e. the unnamed instances would be named Entity1, Package2, Package3, Entity4 etc.

How can I reach all instances of the subclass I'm checking? I can't use the invariant's context, since that is the abstract parent class. I tried combinations of self.eClass() and self.type() with .all, .allInstances and .allOfType, but no methods/properties with these name could be found. Getting that list would allow me to count how many objects of that type have their name set to their class name concatenated with a number.

Response to any of the two questions would be appreciated, as well as other indications in case I took a completely wrong approach, or if you have a simpler solution to my problem.

Cheers
Endre

L.E. I just ran into the _Model.getAllOfType() method, and have implemented the quickfix in the following manner:
do {
var i = 1;
for (o in _Model.getAllOfType(self.eClass().name).select( t | t.name.isDefined() ) ){
i = i + 1;
}
self.name = self.eClass().name + i;
}

I know this isn't exactly what I stated in my original post, but it seems that, for t.name, the "matches" method that works with regular expressions isn't defined. This has basically solved my problem. My first question about persistent variables still remains, and a new one has arised:
What is wrong with my script? After 3-4 applications of the quickfix, nothing happens anymore when I try applying it again, while the following exception is thrown in the original Eclipse instance:

java.lang.NullPointerException
at org.eclipse.epsilon.emc.emf.transactions.EmfModelTransaction .start(EmfModelTransaction.java:27)
at org.eclipse.epsilon.eol.models.transactions.NestedModelTrans actionSupport.startTransaction(NestedModelTransactionSupport .java:44)
at org.eclipse.epsilon.eol.models.transactions.CompositeModelTr ansactionSupport.startTransaction(CompositeModelTransactionS upport.java:36)
at org.eclipse.epsilon.evl.EvlFixInstance.perform(EvlFixInstanc e.java:75)
at org.eclipse.epsilon.evl.emf.validation.ExecuteEvlFixCommand. execute(ExecuteEvlFixCommand.java:39)
at org.eclipse.emf.workspace.EMFCommandOperation.doExecute(EMFC ommandOperation.java:119)
at org.eclipse.emf.workspace.AbstractEMFOperation.execute(Abstr actEMFOperation.java:150)
at org.eclipse.core.commands.operations.DefaultOperationHistory .execute(DefaultOperationHistory.java:511)
at org.eclipse.emf.workspace.impl.WorkspaceCommandStackImpl.doE xecute(WorkspaceCommandStackImpl.java:208)
at org.eclipse.emf.transaction.impl.AbstractTransactionalComman dStack.execute(AbstractTransactionalCommandStack.java:165)
at org.eclipse.emf.transaction.impl.AbstractTransactionalComman dStack.execute(AbstractTransactionalCommandStack.java:219)
at org.eclipse.epsilon.evl.emf.validation.EvlMarkerResolution.r un(EvlMarkerResolution.java:55)
at org.eclipse.ui.internal.views.markers.QuickFixPage$12.run(Qu ickFixPage.java:596)
at org.eclipse.jface.operation.ModalContext.runInCurrentThread( ModalContext.java:464)
at org.eclipse.jface.operation.ModalContext.run(ModalContext.ja va:372)
at org.eclipse.jface.wizard.WizardDialog.run(WizardDialog.java: 944)
at org.eclipse.ui.internal.views.markers.QuickFixPage.performFi nish(QuickFixPage.java:576)
at org.eclipse.ui.internal.views.markers.QuickFixWizard$1.run(Q uickFixWizard.java:96)
at org.eclipse.jface.operation.ModalContext.runInCurrentThread( ModalContext.java:464)
at org.eclipse.jface.operation.ModalContext.run(ModalContext.ja va:372)
at org.eclipse.jface.wizard.WizardDialog.run(WizardDialog.java: 944)
at org.eclipse.ui.internal.views.markers.QuickFixWizard.perform Finish(QuickFixWizard.java:105)
at org.eclipse.jface.wizard.WizardDialog.finishPressed(WizardDi alog.java:752)
at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDi alog.java:373)
at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.jav a:624)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListe ner.java:228)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3910)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3503)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:825 )
at org.eclipse.jface.window.Window.open(Window.java:801)
at org.eclipse.ui.internal.views.markers.QuickFixHandler.execut e(QuickFixHandler.java:166)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(Handle rProxy.java:294)
at org.eclipse.core.commands.Command.executeWithChecks(Command. java:476)
at org.eclipse.core.commands.ParameterizedCommand.executeWithCh ecks(ParameterizedCommand.java:508)
at org.eclipse.ui.internal.handlers.HandlerService.executeComma nd(HandlerService.java:169)
at org.eclipse.ui.internal.handlers.SlaveHandlerService.execute Command(SlaveHandlerService.java:241)
at org.eclipse.ui.internal.handlers.SlaveHandlerService.execute Command(SlaveHandlerService.java:241)
at org.eclipse.ui.menus.CommandContributionItem.handleWidgetSel ection(CommandContributionItem.java:770)
at org.eclipse.ui.menus.CommandContributionItem.access$10(Comma ndContributionItem.java:756)
at org.eclipse.ui.menus.CommandContributionItem$5.handleEvent(C ommandContributionItem.java:746)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3910)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3503)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2405)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2369)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:22 21)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
at org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:493)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start (IDEApplication.java:113)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:194)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:368)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 559)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
at org.eclipse.equinox.launcher.Main.main(Main.java:1287)

[Updated on: Tue, 01 June 2010 16:24]

Report message to a moderator

Re: 'static' variables for EVL invariants [message #537263 is a reply to message #537221] Tue, 01 June 2010 17:33 Go to previous messageGo to next message
Dimitrios Kolovos is currently offline Dimitrios KolovosFriend
Messages: 1776
Registered: July 2009
Senior Member
Hi Endre,

For the following metamodel

abstract class A {
attr String name;
}

class B extends A {}

class C extends A {}

I'd define the constraint as follows:

context A {

constraint HasName {

check : self.name.isDefined()

message : "Unnamed " + self.eClass().name

fix {

title : "Assign default name"

do {
var i = 1;
while (A.all.exists(a|a.name = a.eClass().name + i)) {
i = i+1;
}
self.name = self.eClass().name + i;
}
}

}

}

(I've written this constraint off the top of my head. If it contains any
logic/syntax errors you can't resolve, please let me know and I'll check
it in Eclipse)

Cheers,
Dimitris



On 01/06/2010 16:50, Endre Balogh wrote:
> Hello,
>
> I'm trying to create the following invariant for my model: I have an
> abstract class NamedElement with several concrete subclasses. I want
> them all to have their names defined (check : self.name.isDefined()). I
> also want to provide a quick fix that assigns default names to unnamed
> instances, such as for the class Entity, the unnamed objects will be
> called Entity1, Entity2, etc.
>
> I ran into two problems:
> Is it possible to persist a variable's value between calls to the
> invariant? The purpose would be to keep a counter when renaming objects,
> although this isn't a very good solution, since I can't keep a different
> counter for all subclasses, i.e. the unnamed instances would be named
> Entity1, Package2, Package3, Entity4 etc.
>
> How can I reach all instances of the subclass I'm checking? I can't use
> the invariant's context, since that is the abstract parent class. I
> tried combinations of self.eClass() and self.type() with .all,
> .allInstances and .allOfType, but no methods/properties with these name
> could be found. Getting that list would allow me to count how many
> objects of that type have their name set to their class name
> concatenated with a number.
>
> Response to any of the two questions would be appreciated, as well as
> other indications in case I took a completely wrong approach, or if you
> have a simpler solution to my problem.
>
> Cheers
> Endre
Re: 'static' variables for EVL invariants [message #537338 is a reply to message #537263] Wed, 02 June 2010 06:08 Go to previous messageGo to next message
Endre Balogh is currently offline Endre BaloghFriend
Messages: 38
Registered: May 2010
Member
Hi Dimitris,
Thanks for the reply Smile

Quote:
(I've written this constraint off the top of my head. If it contains any logic/syntax errors you can't resolve, please let me know and I'll check it in Eclipse)


Your solution was actually great, with the following correction:

Quote:
For the following metamodel

abstract class A {
attr String name;
}

class B extends A {}

class C extends A {}


The actual solution is this:

context A {

   constraint HasName {

     check : self.name.isDefined()

     message : "Unnamed " + self.eClass().name

     fix {

       title : "Assign default name"

       do {
         var i = 1;
         while (A.all.exists(a|a.name = *****self*****.eClass().name + i)) {
           i = i+1;
         }
         self.name = self.eClass().name + i;
       }
     }

   }

}


With "a.name = a.eClass().name + i", the following occures: if there is an instance of B named B1, then the next unnamed instance of C will be named C2, since for B1, B1.name=B1.eClass().name+i

However, the NullPointerException thrown in the original Eclipse instance still occurs, and I can't point out the cause. Sometimes it appears after a single application of the quickfix, other times it takes 2 or 3 applications. The only solution is to validate the model again, after which the fix can be applied again without any problems (until the exception if thrown again). It's not that much of a problem, it is just two clicks to validate again, but it gets annoying after a while. Is this a known issue or something?

Cheers,
Endre

L.E. The exception is thrown for other fixes also.

[Updated on: Wed, 02 June 2010 06:23]

Report message to a moderator

Re: 'static' variables for EVL invariants [message #537369 is a reply to message #537338] Wed, 02 June 2010 08:40 Go to previous messageGo to next message
Dimitrios Kolovos is currently offline Dimitrios KolovosFriend
Messages: 1776
Registered: July 2009
Senior Member
Hi Endre,

Could you please file a bug report using the following link and attach a
minimal configuration (metamodels, models, EVL files etc) that I can use
to reproduce this?

https://bugs.eclipse.org/bugs/enter_bug.cgi?product=GMT& component=Epsilon

Cheers,
Dimitris

Endre Balogh wrote:

<snip/>

>
> However, the NullPointerException thrown in the original Eclipse
> instance still occurs, and I can't point out the cause. Sometimes it
> appears after a single application of the quickfix, other times it takes
> 2 or 3 applications. The only solution is to validate the model again,
> after which the fix can be applied again without any problems (until the
> exception if thrown again). It's not that much of a problem, it is just
> two clicks to validate again, but it gets annoying after a while. Is
> this a known issue or something?
>
> Cheers,
> Endre
Re: 'static' variables for EVL invariants [message #537397 is a reply to message #537369] Wed, 02 June 2010 10:20 Go to previous messageGo to next message
Endre Balogh is currently offline Endre BaloghFriend
Messages: 38
Registered: May 2010
Member
Hi Dimitris,

Bug submitted.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=315371

Cheers,
Endre
Re: 'static' variables for EVL invariants [message #589656 is a reply to message #537221] Tue, 01 June 2010 17:33 Go to previous messageGo to next message
Dimitrios Kolovos is currently offline Dimitrios KolovosFriend
Messages: 1776
Registered: July 2009
Senior Member
Hi Endre,

For the following metamodel

abstract class A {
attr String name;
}

class B extends A {}

class C extends A {}

I'd define the constraint as follows:

context A {

constraint HasName {

check : self.name.isDefined()

message : "Unnamed " + self.eClass().name

fix {

title : "Assign default name"

do {
var i = 1;
while (A.all.exists(a|a.name = a.eClass().name + i)) {
i = i+1;
}
self.name = self.eClass().name + i;
}
}

}

}

(I've written this constraint off the top of my head. If it contains any
logic/syntax errors you can't resolve, please let me know and I'll check
it in Eclipse)

Cheers,
Dimitris



On 01/06/2010 16:50, Endre Balogh wrote:
> Hello,
>
> I'm trying to create the following invariant for my model: I have an
> abstract class NamedElement with several concrete subclasses. I want
> them all to have their names defined (check : self.name.isDefined()). I
> also want to provide a quick fix that assigns default names to unnamed
> instances, such as for the class Entity, the unnamed objects will be
> called Entity1, Entity2, etc.
>
> I ran into two problems:
> Is it possible to persist a variable's value between calls to the
> invariant? The purpose would be to keep a counter when renaming objects,
> although this isn't a very good solution, since I can't keep a different
> counter for all subclasses, i.e. the unnamed instances would be named
> Entity1, Package2, Package3, Entity4 etc.
>
> How can I reach all instances of the subclass I'm checking? I can't use
> the invariant's context, since that is the abstract parent class. I
> tried combinations of self.eClass() and self.type() with .all,
> .allInstances and .allOfType, but no methods/properties with these name
> could be found. Getting that list would allow me to count how many
> objects of that type have their name set to their class name
> concatenated with a number.
>
> Response to any of the two questions would be appreciated, as well as
> other indications in case I took a completely wrong approach, or if you
> have a simpler solution to my problem.
>
> Cheers
> Endre
Re: 'static' variables for EVL invariants [message #589701 is a reply to message #537263] Wed, 02 June 2010 06:08 Go to previous messageGo to next message
Endre Balogh is currently offline Endre BaloghFriend
Messages: 38
Registered: May 2010
Member
Hi Dimitris,
Thanks for the reply :)

Quote:
> (I've written this constraint off the top of my head. If it contains any logic/syntax errors you can't resolve, please let me know and I'll check it in Eclipse)


Your solution was actually great, with the following correction:

Quote:
> For the following metamodel
>
> abstract class A {
> attr String name;
> }
>
> class B extends A {}
>
> class C extends A {}


The actual solution is this:

context A {

constraint HasName {

check : self.name.isDefined()

message : "Unnamed " + self.eClass().name

fix {

title : "Assign default name"

do {
var i = 1;
while (A.all.exists(a|a.name = *****self*****.eClass().name + i)) {
i = i+1;
}
self.name = self.eClass().name + i;
}
}

}

}

With "a.name = a.eClass().name + i", the following occures: if there is an instance of B named B1, then the next unnamed instance of C will be named C2, since for B1, B1.name=B1.eClass().name+i

However, the NullPointerException thrown in the original Eclipse instance still occurs, and I can't point out the cause. Sometimes it appears after a single application of the quickfix, other times it takes 2 or 3 applications. The only solution is to validate the model again, after which the fix can be applied again without any problems (until the exception if thrown again). It's not that much of a problem, it is just two clicks to validate again, but it gets annoying after a while. Is this a known issue or something?

Cheers,
Endre
Re: 'static' variables for EVL invariants [message #589723 is a reply to message #589701] Wed, 02 June 2010 08:40 Go to previous messageGo to next message
Dimitrios Kolovos is currently offline Dimitrios KolovosFriend
Messages: 1776
Registered: July 2009
Senior Member
Hi Endre,

Could you please file a bug report using the following link and attach a
minimal configuration (metamodels, models, EVL files etc) that I can use
to reproduce this?

https://bugs.eclipse.org/bugs/enter_bug.cgi?product=GMT& component=Epsilon

Cheers,
Dimitris

Endre Balogh wrote:

<snip/>

>
> However, the NullPointerException thrown in the original Eclipse
> instance still occurs, and I can't point out the cause. Sometimes it
> appears after a single application of the quickfix, other times it takes
> 2 or 3 applications. The only solution is to validate the model again,
> after which the fix can be applied again without any problems (until the
> exception if thrown again). It's not that much of a problem, it is just
> two clicks to validate again, but it gets annoying after a while. Is
> this a known issue or something?
>
> Cheers,
> Endre
Re: 'static' variables for EVL invariants [message #589749 is a reply to message #537369] Wed, 02 June 2010 10:20 Go to previous message
Endre Balogh is currently offline Endre BaloghFriend
Messages: 38
Registered: May 2010
Member
Hi Dimitris,

Bug submitted.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=315371

Cheers,
Endre
Previous Topic:Performance problems with if-then-else-if structures
Next Topic:import EGL into EGL
Goto Forum:
  


Current Time: Fri Apr 26 10:25:08 GMT 2024

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

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

Back to the top