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
19 comments
Comment actions Permalink

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.

0
Comment actions Permalink

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?

0
Comment actions Permalink

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.

0
Comment actions Permalink

Thank you Sir.

I'll try although the explanation in "http://www.sergeydmitriev.com/mps/doc/generator.html" is too simple to a stranger.

0
Comment actions Permalink

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.

0
Comment actions Permalink

But  the class name "abc" in template don't  support reference macro.Is there any way to get "B1" for "abc"?

0
Comment actions Permalink

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
0
Comment actions Permalink

What is the difference with what I write above

0
Comment actions Permalink

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

-


0
Comment actions Permalink

Hm... there is no difference but on my PC everything worked well....

0
Comment actions Permalink

The project you attached before had no query method for class name.

0
Comment actions Permalink

Could you send me a full stacktrace.

0
Comment actions Permalink

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
0
Comment actions Permalink

Is it a setting problem?

0
Comment actions Permalink

Or the version of the JDK(My version is jdk1.5.0_07)

0
Comment actions Permalink

Or something needs to be set in project root in IDEA?

0
Comment actions Permalink

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

0
Comment actions Permalink

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.

0
Comment actions Permalink

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.

0

Please sign in to leave a comment.