baseLanguage Generator Issues

I am using the baseLanguage as the target for code generation. While doing this come across have several issues. Not sure whether these are limitations of MPS,  or of my knowledge of MPS.
  • In the generated Java text files, there are no imports statements. As a result these files do not compile. Is there a way to get the imports in the output?
  • The package name of the Java classes is defined by the model name. As I am working with business people as users of my language, I'd like to be able to change this. I have found the following long-running issue for this: http://youtrack.jetbrains.com/issue/MPS-5962?projectKey=MPS
  • I cannot find any way to set the root output folder of the generator. All code is generated in the same project as the model, but I'd like to generate to some other location. is this possible?
7 comments
1) Imports should be automatically added by BaseLanguage generator taking into account location (model name) of the used classes.

2) Currently it's a limitation of MPS. I'm not sure that referenced issue properly describes the problem which you are facing. To my understanding it's more about generating the model and being able to specify arbitrary package name for that model...

3) In the preferences of the Solution you should be able to modify property "Generator output path".
0
3) Found it :-), sometimes it is hard to just _find_ an option.
2) I will create an issue with a more precise description, then you can see whether it is the same.
1) Imports are not generated in specific circumstances:

Situation as floows:
Model:
Model.GIF

Generator OK:
Import-generator.GIF

Java Output OK:
import.GIF


Same model
Generator:
No-import-generator.GIF

Java Code without import:
No-import.GIF


If I refer to the BaseClass directly in the template the BaseClass is recognized and the import generated.
If I use a reference macro and return the string "BaseClass" the class is not recognized, and therefore the import is not generated.
0
there are several possibilities for solving this problem:
  • return node<Classifier> instead of string from the query within ReferenceMacro
  • use InternalClassifierType instead of Classifier type within template to point to the extended class and specify f.q. name of the extended class by property macro
  • return fully-qualified class name from the reference macro as a string in format: [<packageName>]<className> for example: [java.lang]String
  • return fully-qualified class name from reference macro: java.lang.String

in your case i suggest using second or third option if the target class can be generated by MPS and can be located in different model.
0
I have used option 4, returning a fully qualified name of the Java class and this works fine.

However, I have the same situation with two interfaces extending each other and get a baseLanguage textgen error when using option 4.  I have created the following issue for this: http://youtrack.jetbrains.com/issue/MPS-19178.  Tried option 3 as well, same result.
0
Option 1 is not available as the Classifier generated by the imported model is not available.  And 2 didn't work either, because the referred class cannot be found.
I am stuck for now.
0
You should be able to use option 2. In this case you should first generate model containing "target classifier" and then generate model referencing it.

In your situation, AFAIU, code generation & text generation were passed without any problems, but compilation process fails with "unresolved target classifier" problem which is reasonable - there is no target classifier.
0
I am using the following code:
referent : (outputNode, genContext, operationContext, node)->join(node<Classifier> | string) { 
  if (node.model == node.ruleSetType.model) { 
    return "com.i2s.ibml.core.base.generated.IBaseRuleSetTypeExtension"; 
  } else { 
    node<InternalClassifierType> result = new node<InternalClassifierType>(); 
    result.fqClassName = node.ruleSetType.genJavaExtendedInterfaceNameFQN(); 
    return result.classifier; 
    // return node.ruleSetType.genJavaExtendedInterfaceNameFQN(); 
  } 
}
prettyPrint();
I first tried to return the node<InternalClassifier>, but that is not node<Classifier>, so I get a type error.  Then I tried the above which gives an error message:
type java.lang.Object is not a subtype of node<Classifier>
prettyPrint();
As the result.classifier is a node<Classifier>  I added a typecast, but get the same error.  I also tried to ignore the error message and it compiles without problems. However, the result when running the generator is failing.  I get the following error messages and there is no code generated.
pre-process 'mod_markStatementsToExtract' (jetbrains.mps.baseLanguageInternal.generator.template.main@generator)
pre-processing finished
generating model 'model.rulesettypes@1_0' --> 'model.rulesettypes@1_1'
cannot resolve required reference; role: 'classifier' in output node [extendedInterface] ClassifierType <no ref>[2208487914143961038] in model.rulesettypes@1_1
--  -- was input node: [root] Ibml_GEN_RuleSetTypeExtension <no ref>[2208487914143960864] in model.rulesettypes@1_0
--  -- was reference macro: [smodelAttribute] ReferenceMacro <no ref>[6094601864009825860] in com.i2s.ibml.core.rulesettypes.generator.template.main@generator
cannot resolve required reference; role: 'classifier' in output node [extendedInterface] ClassifierType <no ref>[2208487914143961050] in model.rulesettypes@1_1
--  -- was input node: [root] Ibml_GEN_RuleSetTypeExtension <no ref>[2208487914143960867] in model.rulesettypes@1_0
--  -- was reference macro: [smodelAttribute] ReferenceMacro <no ref>[6094601864009825860] in com.i2s.ibml.core.rulesettypes.generator.template.main@generator
next minor step '1_1' --> '1_2'
broken reference 'classifier' in [extendedInterface] ClassifierType <no ref>[2208487914143961038] in model.rulesettypes@1_1
--  -- was input node: [extendedInterface] ClassifierType <no ref>[2208487914143961038] in model.rulesettypes@1_1
broken reference 'classifier' in [extendedInterface] ClassifierType <no ref>[2208487914143961050] in model.rulesettypes@1_1
--  -- was input node: [extendedInterface] ClassifierType <no ref>[2208487914143961050] in model.rulesettypes@1_1
unchanged, empty model '1_2' removed
model "model.rulesettypes" has been generated with errors

generation completed with errors in 30 ms
prettyPrint();
Can you explain how I should use the InternalClassifier to make it work ?
0

Please sign in to leave a comment.