IDEA插件:PersistentStateComponent不持久化xml [英] IDEA Plugin: PersistentStateComponent not persisting xml

查看:774
本文介绍了IDEA插件:PersistentStateComponent不持久化xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法让我的插件保持其状态. 显然,文件configProvider.xml永远不会被创建,@State注释也不会起作用.

I can not get my plugin to persist its state. The file configProvider.xml never gets created, nor does the @State annotation has any effect (apparently).

这是plugin.xml中的相关部分

This is the relevant part in the plugin.xml

<extensions defaultExtensionNs="com.intellij">
    <applicationService serviceImplementation="my.plugins.idea.vcs.ConfigProvider" serviceInterface="my.plugins.idea.vcs.ConfigProvider"/>
</extensions>

这是提供应保留的对象的类:

This is the Class providing the object that should get persisted:

import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import java.util.LinkedHashMap;

@State(
  name = "ConfigProvider",
  storages = {
@Storage(id = "main", file = "$APP_CONFIG$/configProvider.xml") 
  }
)
public class ConfigProvider  implements PersistentStateComponent<ConfigProvider.State> {

  private State state = new State();

  class State {
    public State() {}
    public LinkedHashMap<String, String> commitTypes = null;
    public Integer selectedDefaultCommitTypeIndex = null;
    public String jiraApiUrl;
    public String jiraAuthorization;
    public String jiraFilterId;
  } 

  public static ConfigProvider getInstance() {
return ServiceManager.getService(ConfigProvider.class);
  }

  @Override
  @org.jetbrains.annotations.Nullable
  public ConfigProvider.State getState() {
return state; // gets called regulary
  } 

  @Override
  public void loadState(ConfigProvider.State state) {
this.state = state; // not called at all
  }

}

我想念什么?

谢谢, 克里斯托弗

推荐答案

是否有帮助,使State类是公共的和静态的?

Does this help, making the State class public and static?

public static class State {
    //...
}

这篇关于IDEA插件:PersistentStateComponent不持久化xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆