Problems about query method
Please refer to the attachment.
I want to achieve:
1. The className in template is got from the solution ABC's "Class Name(B)",
I created a macro for it, tried several ways for the query method, but failed.
2. About the parameter of method abc in template.
The number of the parameter of method abc in template is equal to that of the vlaue of the solution ABC's "C:";
Which macro should be used and how to write query method?
Thank you in advance.
Attachment(s):
simple.rar
Please sign in to leave a comment.
The project you attached to your post contains a query method. I found it in package ABC.generator.baseLanguage.template.main; in class Queries. You can see that it's set in the inspector view. BTW if you want to navigate from a query method to the IDEA window you can press control+B when the cursor is under the query method name.
I didn't understand what do you mean when you talk about number of parameters. What do you want to do with them.
BTW you can read about different macros here http://www.sergeydmitriev.com/mps/doc/generator.html. With most of the macros described you can associate some kind of a query method.
I know where to write query method.My problems are:
For example: I choose "B1" for "Class Name(B)" in Model ABC.
NO 1: I want to make the class name "abc" in generator's template equal "B1" In order to get "B1",I tried several ways .Such as:
-
A a= (A) sourceNode;
BRefer bRefer = (BRefer) a.getBrefer();
B b= bRefer .getB();
return b.getName();
-
But it didnn't work.
NO 2:If the content of "C:" in Model ABC is null,there is no parameter in the method "abc" in generator's template.And if I choose "C1" for "C:",there is one parameter in the method "abc" .And if I choose "C1,C2",there should be two parameters. How to achieve this with macros?And how to write query method?
In MPS when we reference to something we don't store it's name so if you create a property macro it won't help. You have to use another kind of macros: reference macros. Query method for reference macro will provide a node that you want to reference to.
I recommend you to read more about it in our generator documentation http://www.sergeydmitriev.com/mps/doc/generator.html. If you want to see examples consult query methods that are distributed with MPS. You can find them in root MPS directory in zip file Queries-Src.
Thank you Sir.
I'll try although the explanation in "http://www.sergeydmitriev.com/mps/doc/generator.html" is too simple to a stranger.
Reference macro is just a macro that sets reference i.e. returns a SNode. If you want to see how to create it you can look for example at structure or editorLanguage generators.
But the class name "abc" in template don't support reference macro.Is there any way to get "B1" for "abc"?
I understood what are you wanted to do. You only wanted to create a name for a class but it didn't work. I fixed this. See the file attached. You don't need to use reference macros :-)
In short you have to write this in query method instead of that you wrote.
A a = (A) sourceNode;
return a.getBRefer().getB().getName();
Attachment(s):
simple.zip
What is the difference with what I write above
There is still an error in the project you attached.Message:
-
model "ABC.generator.baseLanguage.template.main@templates" generation failed : jetbrains.mps.generator.GenerationFailedException: jetbrains.mps.generator.GenerationFailedException: java.lang.RuntimeException: Error invocation method: "propertyMacro_ClassName" in ABC.generator.baseLanguage.template.main.Queries
-
Hm... there is no difference but on my PC everything worked well....
The project you attached before had no query method for class name.
Could you send me a full stacktrace.
The attachment is the error messages in Dos frame.
The blow is in the MPS's message box.
-
ERROR executing builder for source: ClassConcept "abc"[1156827204368] in ABC.generator.baseLanguage.template.main@templates;
-- was source node: ClassConcept "abc"[1156827204368] in ABC.generator.baseLanguage.template.main@templates;
-- was template: ClassConcept "abc"[1156827204368] in ABC.generator.baseLanguage.template.main@templates;
model "ABC.generator.baseLanguage.template.main@templates" generation failed : jetbrains.mps.generator.GenerationFailedException: jetbrains.mps.generator.GenerationFailedException: java.lang.RuntimeException: Error invocation method: "propertyMacro_ClassName" in ABC.generator.baseLanguage.template.main.Queries
-
Attachment(s):
Dos.txt
Is it a setting problem?
Or the version of the JDK(My version is jdk1.5.0_07)
Or something needs to be set in project root in IDEA?
hi,
the macro code you posted in very beginning of this thread is absolutely correct :
-
A a= (A) sourceNode;
BRefer bRefer = (BRefer) a.getBrefer();
B b= bRefer .getB();
return b.getName();
-
but your stacktrace suggests that your actual code is different.
please, check the 1st line. It seems like you are trying to cast templeteNode to class ABC.A like:
A a = (A)templateNode;
Igor
I load the projects on "MPS root" directory,such as "fixedLengthReader" and want to generate the text file, but exactly the same mistake arises.
When I follow "TheSimplestLanguage",it also happens in the query method.
It must be a cofiguration problem,probably jdk.
very strange:(
I run MPS b292 (with jre from jdk 1.5.0_08), IDEA 5.1.2 b4267 (project jdk 1.5.0_08), WinXP
and everything works fine. it all worked with jdk 1.5.0_03 as well.