Hi, I am working on a language to represent JVM class files (https://github.com/ftomassetti/MpsByteCode). More specifically I am working on representing the index of the ConstantPoolElements. The index of the each element of the ConstantPool is the 1-based position of the element in the pool BUT some kinds of elements get two spaces, so they count double. For example:
- 1 A
- 2 B
- 3 C (counts double)
- 5 D
- 6 E (counts double)
- 8 F
The other thing to consider is that theConstantPool can contain thousands of elements.
I would rather avoid having the index stored in a property because it is a calculated value. I thought about using memoization and store that value using the putUserObject/getUserObject system, however I would need to clear that cache when the list changes. I tried to attach a listener to the whole ClassPool. I have two problems with this:
- when can I attach the listener? For now I am using a trick: I add a read only element in the editor of the ClassPool and in the block calculating the string to return I invoke the function to attach the listener, I then just return an empty string. In this way I know that every time the user edit the model there is the listener in place
- however if I do that I need to somehow refresh the cell showing the index of each component. I was thinking to use: editorContext.getEditorComponent().findNodeCell(<class pool element>).requestRelayout()
This solution seems way to complex than needed. Do you have better ideas? Something I am missing?
By the way implementing this solution I get an exception rather obscure to me:
jetbrains.mps.classloading.ModuleClassLoader$ModuleClassLoaderIsDisposedException: ClassLoader of the module 'me.tomassetti.bytecode [language]' is disposed and not operable!