Unexpected behavior of Class.forName in Concept's property constraints.

So i'm working on an MPS language that extends the baseLanguage. It will be run by deserializing the AST into XML and parsing and evaluating from an interpreter written in Java (using Graal's Truffle APi, not that it really matters). In this language i want to create a custom class instantiation expression that looks like this:

<Type> {

  <key>: <Expression>


so for instance an example of such an expression would be:

MyObject {

 someStringField: "Hello"

 someOtherObjectField: MyOtherObject {

       someOtherStringField : "World"



The node hierarchy is basically like this:


A constraint that I want for this Concept is that the key must be a field of <Type> (whether a declared field or a field of it's superclasses). So i created a property constraint for the KeyValue concept that looks something like this:

As you can see from my print statements when I try to invoke Class.forName to reflectively get the Classes fields and check if any of the match the property value (key). The issue is that when Class.forName is called the execution seems to exit the try clause, and goes to the finally clause, without triggering the catch clause, thus no error is printed whatsoever.


Otherwise, what's a better method to achieve this requirement?


Thanks in advance :)



You are supposed to inspect the ClassifierType not the Java class with Java reflexion:

myClassifierType.getMembers().ofConcept<FieldDeclaration>.where{it -> it.name :eq: "xxx"};


Thanks very much, works like a charm :D. Still trying to figure out my limits within MPS.


Please sign in to leave a comment.