"id" parameter of the @Storage annotation
http://confluence.jetbrains.net/display/IDEADEV/Persisting+State+of+Components says the following:
[quote]
The "id" parameter of the @Storage annotation can be used to exclude specific fields from serialization in specific formats. If you do not need to exclude anything, you can set the id to an arbitrary string value.
[/quote]
What does that mean?
How does one exclude fields with the help of that?
Can you use this to save some settings to .ipr and some other settings from the same state class to .iws?
Please sign in to leave a comment.
The funny thing is that I don't know. :) Looks like none of our own components use this possibility, and I wasn't quite able to figure out from the implementation code how it was intended to be used.
There is a differnet mechanism that allows you to split your state into multiple files, but this only works for creating new files (inspection profiles or run configurations), not for appending state to an existing file such as the workspace file.
And what is that other mechanism?
Hm, I've had a quick glimpse at the source myself.
Isn't it meant this way?
@State(
name = "FooSettings",
storages = {
@Storage(file = PROJECT_FILE),
@Storage(file = PROJECT_CONFIG_DIR + "/foo.xml", scheme = DIRECTORY_BASED)
@Storage(id = "workspace", isDefault = false, file = StoragePathMacros.WORKSPACE_FILE)
}
)
public class FooSettings implements PersistentStateComponent<FooSettings> {
private String projectSetting;
private String workspaceSetting;
public static FooSettings getInstance(Project project) {
return ServiceManager.getService(project, FooSettings.class);
}
public String getProjectSetting() {
return projectSetting;
}
public void setProjectSetting(String projectSetting) {
this.projectSetting = projectSetting;
}
@StorageId("workspace")
public String getWorkspaceSetting() {
return workspaceSetting;
}
public void setWorkspaceSetting(String workspaceSetting) {
this.workspaceSetting = workspaceSetting;
}
@Override
public FooSettings getState() {
return this;
}
@Override
public void loadState(FooSettings state) {
XmlSerializerUtil.copyBean(state, this);
}
}
Now "projectSetting" should go to *.ipr or .idea/foo.xml and "workspaceSetting" should go to *.iws or .idea/workspace.xml, shouldn't they?
I didn't test this though.
The StateSplitter interface.
You're probably right. Haven't tried it myself either. :)
Maybe you should try it and add it to the documentation if it works like expected. :-)