groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From frenchy48 <>
Subject changing dynamically the name of classes in a source code
Date Sun, 27 Mar 2016 15:38:57 GMT
Before asking a question I'l have first to explain WHY this question.  

I have been writing a book about programming (for beginners)  

For the labs I use  a small subset of Groovy  
now my labs are slightly boring so I decided to write a small graphical
library to facilitate the design of funnier experiments.  

This small library is built around about 20 groovy classes and provides a
simple framework to do some graphical programming.  

The people going to use this codes are not english speaking people.  
But it's not a big problem when limiting the use of english to some keywords
(for, while, if,...) or a limited number of types such as List or Map.  

But if I introduce more classes it may be a problem.  

So I started thinking about internationalisation of code.  

For my limited number of classes I implemented a "methodMissing" feature
that implements a translation of method names.  
it works (though error handling is not perfect and can be confusing)  

Now I was wondering if I could translate the name of this library's classes
at runtime.
(there are already languages such as Scratch which are translated in the
user's language -including keywords ... but I don't need to go that far-)  

And here are my questions : how to do that and is it worth the trouble?  

I toyed with the idea of using ASTTransformation but I really don't know how
to visit my class names and if I can change them at runtime.  
Since the programming features are limited the students are not going to use
the constructors of the classes (there are only factories).
So the only places where the class names should be changed is when declaring
variables or parameter types.  
(I could sed the source code but I would rather not)  

so is this transformation doable? when? (parsing or semantic?) how?
(performance is not an issue and  students program through the

(for sure error handling is going to be even more problematic when the user
sees a message pertaining to a class which is "under the hood")  

Any advice?  


member of Grumpy Old Programmers
View this message in context:
Sent from the Groovy Users mailing list archive at

View raw message