/*
 * Copyright 2000-2016 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.openapi.components.impl.stores;

import com.intellij.openapi.components.StateStorage;
import com.intellij.openapi.components.StateStorageOperation;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.components.TrackingPathMacroSubstitutor;
import com.intellij.util.messages.Topic;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public interface StateStorageManager {
  Topic<StorageManagerListener> STORAGE_TOPIC =
    new Topic<>("STORAGE_LISTENER", StorageManagerListener.class, Topic.BroadcastDirection.TO_PARENT);

  @Nullable
  TrackingPathMacroSubstitutor getMacroSubstitutor();

  @NotNull
  StateStorage getStateStorage(@NotNull Storage storageSpec);

  /**
   * Rename file
   * @param path System-independent full old path (/project/bar.iml or collapse $MODULE_FILE$)
   * @param newName Only new file name (foo.iml)
   */
  void rename(@NotNull String path, @NotNull String newName);

  @Nullable
  ExternalizationSession startExternalization();

  @Nullable
  StateStorage getOldStorage(@NotNull Object component, @NotNull String componentName, @NotNull StateStorageOperation operation);

  @NotNull
  String expandMacros(@NotNull String path);

  interface ExternalizationSession {
    void setState(@NotNull Storage[] storageSpecs, @NotNull Object component, @NotNull String componentName, @NotNull Object state);

    void setStateInOldStorage(@NotNull Object component, @NotNull String componentName, @NotNull Object state);

    /**
     * return empty list if nothing to save
     */
    @NotNull
    List<StateStorage.SaveSession> createSaveSessions();
  }
}
@@ -645,17 +645,16 @@
 l.stores
-;
 %0A%0Aimport
@@ -694,25 +694,24 @@
 StateStorage
-;
 %0Aimport com.
@@ -759,17 +759,16 @@
 peration
-;
 %0Aimport 
@@ -806,17 +806,16 @@
 .Storage
-;
 %0Aimport 
@@ -874,17 +874,16 @@
 stitutor
-;
 %0Aimport 
@@ -918,450 +918,154 @@
 opic
-;%0Aimport org.jetbrains.annotations.NotNull;%0Aimport org.jetbrains.annotations.Nullable;%0A%0Aimport java.util.List;%0A%0Apublic interface StateStorageManager %7B%0A  Topic%3CStorageManagerListener%3E STORAGE_TOPIC =%0A    new Topic%3C%3E(%22STORAGE_LISTENER%22, StorageManagerListener.class, Topic.BroadcastDirection.TO_PARENT);%0A%0A  @Nullable%0A  TrackingPathMacroSubstitutor getMacroSubstitutor();%0A%0A  @NotNull%0A  StateStorage getStateStorage(@NotNull Storage storageSpec);
+%0A%0Ainterface StateStorageManager %7B%0A  val macroSubstitutor: TrackingPathMacroSubstitutor?%0A%0A  fun getStateStorage(storageSpec: Storage): StateStorage
 %0A%0A  
@@ -1180,16 +1180,23 @@
 _FILE$)%0A
+   * *%0A
    * @pa
@@ -1248,20 +1248,19 @@
 /%0A  
-void
+fun
  rename(
 @Not
@@ -1259,53 +1259,29 @@
 ame(
-@NotNull String path, @NotNull
+path:
  String
+,
  newName
 );%0A%0A
@@ -1276,34 +1276,38 @@
  newName
-);%0A%0A  @Nullable%0A  
+: String)%0A%0A  fun start
 External
@@ -1317,21 +1317,12 @@
 tion
-Session start
+(): 
 Exte
@@ -1336,211 +1336,167 @@
 tion
-();%0A%0A  @Nullable%0A  StateStorage getOldStorage(@NotNull Object component, @NotNull String componentName, @NotNull StateStorageOperation operation);%0A%0A  @NotNull%0A  String expandMacros(@NotNull String path);
+Session?%0A%0A  fun getOldStorage(component: Any, componentName: String, operation: StateStorageOperation): StateStorage?%0A%0A  fun expandMacros(path: String): String
 %0A%0A  
@@ -1530,28 +1530,27 @@
 ssion %7B%0A    
-void
+fun
  setState(@N
@@ -1551,132 +1551,97 @@
 ate(
-@NotNull Storage%5B%5D storageSpecs, @NotNull Object component, @NotNull String componentName, @NotNull Object state);
+storageSpecs: Array%3CStorage%3E, component: Any, componentName: String, state: Any)
 %0A%0A    
-void
+fun
  set
@@ -1662,89 +1662,58 @@
 age(
-@NotNull Object component, @NotNull String componentName, @NotNull Object state);
+component: Any, componentName: String, state: Any)
 %0A%0A  
@@ -1778,20 +1778,33 @@
     
-@NotNull%0A   
+fun createSaveSessions():
  Lis
@@ -1834,30 +1834,156 @@
 ion%3E
- createSaveSessions();
+%0A  %7D%0A%0A  companion object %7B%0A    val STORAGE_TOPIC = Topic(%22STORAGE_LISTENER%22, StorageManagerListener::class.java, Topic.BroadcastDirection.TO_PARENT)
 %0A  %7D

convert StateStorageManager to kotlin