Official Plugin SDK documentation: Persisting State of Components
According to the Implementing the PersistentStateComponent Interface section there are two ways to specify the object that will store the state of the component, whose implementation this intention action helps with.
There are dedicated actions for converting a target Java or Kotlin class to implement PersistentStateComponent
, and generate a simple implementation of it by
-
using a separate inner class for storing the component state
See example...
From:
public final class SomeService { }
To:
@State(name = "SomeService", storages = @Storage("<storage name>")) public final class SomeService implements PersistentStateComponent<SomeService.State> { private State myState = new State(); @Override public State getState() { return myState; } @Override public void loadState(State state) { myState = state; } static final class State { } }
-
using the component class itself for storing the state
See example...
From:
public final class SomeService { }
To:
@State(name = "SomeService", storages = @Storage("<storage name>")) public final class SomeService implements PersistentStateComponent<SomeService> { @Override public SomeService getState() { return this; } @Override public void loadState(SomeService state) { XmlSerializerUtil.copyBean(state, this); } }
Separate state object | Component class as state |
---|---|
![]() |
![]() |
The generated code is based on the aforementioned SDK document section, and is available when the following conditions are met:
- the class is not an enum, an interface, or an abstract class (or a value class either, in case of a Kotlin class)
- the class doesn't already implement
PersistentStateComponent