Accessing Fielddeclarations in a StatementList / Expression
Hi,
i am pretty new to MPS (working with it for a about a week now), but I am very excited about the possibilites and it is very polished already at this quite early release.
However now I am stuck with a problem and I would need your help.
Just to give you some background information:
As part of a research project and my PhD I have developed a "component framework" which allows a software engineer to run a component system in a (real time) java environments. (Related, but completely different: OSGi, Spring).
Anyway, my goal is to use MPS to give the component developers a custom "component-orientated" development environment to implement their components without the need to "think in Standard-Java".
I have therefore created a concept "component" which has following children:
FieldDeclaration field 0..n
InternalComponentOperation internalop 0..n
InternalComponentOperation is another concept which has a method body of Concept type Statement list.
Now, if a user instanciates a Component he should be able to access the declared child of type FieldDeclaration as part of the expression / statement in the body of InternalComponentOperation - just like you would expect that from Standard-Java to access private attributes.
Example:
component Component A {
component internal fields:
Object myField= new Object();
internal operations:
internal operation example() {
// this is the StatementList and I would like to something like this:
myField.toString();
}
}
Can you please give me a pointer on how to achieve this? Perhaps create a "Getter-Concept" that extends Expression and is referencing the FieldDeclaration?
Thanks & Best regards,
Ludwig
Please sign in to leave a comment.
Ludwig,
You are absolutely right - you need a "reference" concept to reference your field declaration. This concept should extend Expression to be used in place of Expressions and should have a reference to the declaration of a corresponding field. You can look how we've implemented the same thing in BaseLanguage - see LocalVariableDeclaration & LocalVariableReference (ctrl-N to navigate to concepts).
Btw, we call such "reference" concepts "smart references". There's a bit written about them here: http://www.jetbrains.net/confluence/display/MPS/Structure#Structure-smartreferences
Regards,
Mihail
Mihail,
thank you very much for the pointer!
Just for the future if others try to achieve the same: I tried to implement the concept extending the expression concept but then it didn't show up properly in the editor.
However when extending VariableReference did the trick.
Best regards,
Ludwig
Ludwig,
That's strange that you solution didn't work. There aren't any heuristics for VariableDeclaration in MPS, so it's not necessary to inherit it (but preferrable in your case).
I've attached a project where this is done without inheriting from VariableReference.
Mihail
Attachment(s):
test.zip
Screen shot 2009-12-23 at 5.55.49 PM.png
Dear Mihail,
please excuse the delay in my reply, but I was off during the season.
Thanks for your screenshot and the test project, however I cannot open the project as the test language is missing- I only get the sandbox.
I just tried again to extend basic Expression and I could reproduce it- only after I extend VariableReference everything works like a charm.
Rds,
Ludwig
Sorry, I'll repost it once again.
I've tested this project on current 1.1 build.
Ludwig, if you could send me a test example with this problem shown, I could look at it and say why the solution doesn't work.
Regards,
Mihail
Attachment(s):
test.zip
Dear Mihail,
thanks I could now open the project.
The difference between our two projects is that for "your" Component you reference your own concept of ComponentFieldDeclaration, while I use the baselanguage "FieldDeclaration" concept.
Perhaps this helps.
Ludwig
P.S: I will try to update this thread with an example as soon as possible
Ludwig,
It seems that it works with baseLanguage's FieldDeclaration also.
Example in attachment.
Sincerely,
Mihail
Attachment(s):
test.zip
Hi Mihail,
tried your new test project- I get the error "not a legal statement" (same as in my project).
Please find screen shot attached.
Very strange...
Ludwig
Attachment(s):
error.png
Ludwig,
Nothing strange in this fact. Try to write the same code in Java - it won't compile. As baseLanguage is generated into java code, we've introduced such check. For all ExpressionStatements MPS checks that expression inside of it has "isLegalAsStatement" concept property set to true, otherwise reports an error.
So, you can continue writing your statement when you see such an error. When a legal statement will be written, the error will disappear.
Sincerely,
Mihail
Mihail-
you are right, sorry- i was too quick on the error message on this one.
The latest test project works fine for me as well- I can reference the field from the statement list body.
Please find attached a current version of my project (please ignore most of the stuff, especially the area around the TATransitionTable, it is all highly experimental :-))
I have a Component Concept with a list of field declarations and a FieldDeclarationReference extending Expression.
In the sandbox solution i am not able to access the field i in ComponentA - only after I change the language so FieldDeclarationReference extends VariableReference.
Hope that helps,
Ludwig
Attachment(s):
Components.zip
error.png
Ludwig,
There is no editor for your FieldDeclarationReference - that's the problem :-)
Regards,
Mihail.
*ouch* :-[
Thanks, that was it.
Thank you very much for your patience and your help.
This just adds to my love for this product.
<!TextGen not found for 'jetbrains.mps.component.structure.FieldDeclarationReference'!> = 280;
how to solve this problem, any idea?