// Meta - a "minimal" approach to adding meta-level to Java objects // (implementing the interface IMeta) // We allocate one extra field for each Java object to make it // reasoning-compatible (reasoning-compatible = extensible with // fields of any name at runtime). // // We couldn't go for 0 extra fields (meta values must be linked // directly from the object) and there are no half fields in // Java... so there you go. // // Also, if you don't use any meta data, you are probably not // reasoning about anything. The point of reasoning in JavaX is // to attach information to objects directly used in the program. // Possible information contained in the meta field: // Origin, destination, security level, sender, cost center, // purpose, list of reifications, ... // So here it is. THE FIELD YOU HAVE BEEN WAITING FOR! // [We also have IMeta to retrofit foreign classes (rare but // probably useful).] ////////////////////// // The "meta" field // ////////////////////// // Generic meta value of any kind, but the typical case is it's a // Map with extra field values for the object etc. // "meta" is volatile to avoid synchronization; but you can also synchronize on // _tempMetaMutex() which is usually the object itself. Collections // and maps are exempt from using the collections's monitor as the meta // mutex because their monitor tends to be held for long operations // (e.g. cloneList). For those we use a substantially more complex // algorithm using a weakMap. Probably overkill. I may reconsider. volatile O meta; // The meta field is not transient, thus by default it will be // persisted like anything else unless you customize your object // to suppress or modulate this. // ...and the interface methods public void _setMeta(O meta) { this.meta = meta; } public O _getMeta() { ret meta; } // MOST functions are implemented in IMeta (default implementations) // Scaffolding convenience functions bool scaffoldingEnabled aka scaffolding aka scaffolded() { ret main scaffoldingEnabled(this); } bool scaffoldingEnabled(O o) { ret main scaffoldingEnabled(o); } // Implementing setMetaToString S toString_base() { ret super.toString(); } toString { O o = metaGet toString(this); if (o cast S) ret o; if (o cast IF1) ret str(o.get(this)); ret toString_base(); }
Began life as a copy of #1031838
download show line numbers debug dex old transpilations
Travelled to 8 computer(s): bhatertpkbcr, ekrmjmnbrukm, elmgxqgtpvxh, gjtlkbvenryc, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx, wnsclhtenguj
No comments. add comment
Snippet ID: | #1033864 |
Snippet name: | Meta mix-in |
Eternal ID of this version: | #1033864/7 |
Text MD5: | b872ccb8917ed705c894db17febfce0d |
Author: | stefan |
Category: | javax / reasoning |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-09-07 04:31:22 |
Source code size: | 2368 bytes / 64 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 211 / 8268 |
Version history: | 6 change(s) |
Referenced in: | [show references] |