Usage Examples
See also Entity Mutation and Entity Read topics.
Module
Search Module by Name
Rename Module
ModuleEntity
Creation
Creating a new ModuleEntity
, the legacy bridge will be created by the platform. An important part here is the entity source. To serialize an entity in project configuration files under the .idea folder, use JpsProjectFileEntitySource
.
Add Library Dependency to Module
A project-level library is added as a dependency to the module.
Searching for Module-Containing Path
Search for content roots and source roots with required URLs and determine the ModuleEntity
to which they belong.
Library
LibraryEntity
Creation
Creating a new LibraryEntity
, the legacy bridge will be created by the platform.
Searching for Library by Root Type and URL
Roots
Add Content Root and Source Root for Module
Adding Different Types of Library Roots
Two library roots of different types are defined, and a new exclude root is added.
Miscellaneous
Migration of Caches Relying on Library
/Module
Using Library
or Module
as a key on maps has a number of disadvantages:
Can’t be used as a key for collections that rely on hashcode calculation, as these objects are mutable by their nature.
The fact that they extend
Disposable
(see Disposer and Disposable) imposes additional difficulties.
To eliminate these shortcomings, use EntityPointer
. It represents a pointer to an entity which can be stored anywhere. The pointer can be obtained via WorkspaceEntity.createPointer()
. An instance of this class stores an internal ID of the entity and doesn't contain the pointer to the original storage, so it's ok to store them in long-living data structures as it won't create a memory leak.
The pointer will resolve to the same entity for the same storage and will survive modifications. If the entity is removed or replaced by a different one via MutableEntityStorage.replaceBySource()
, the pointer may either resolve to null
or to a completely different entity which reused the same internal ID. To be sure that the pointer resolves to the original entity, also subscribe to changes in the storage.