create new interface for io operations

This commit is contained in:
Marcel Haßlinger 2021-11-03 11:07:04 +01:00
parent d2d8ef4cb4
commit 356038f987
2 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,51 @@
package de.marhali.easyi18n.io;
import com.intellij.openapi.project.Project;
import de.marhali.easyi18n.model.SettingsState;
import de.marhali.easyi18n.model.TranslationData;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.function.Consumer;
/**
* Primary interface for the exchange of translation data with the underlying IO system.
* The selection of the right IO strategy is done by the @canUse method (first match).
* Every strategy needs to be registered inside {@link de.marhali.easyi18n.DataStore}
*
* @author marhali
*/
public interface IOStrategy {
/**
* Decides whether this strategy should be applied or not. First matching one will be used.
* @param project IntelliJ project context
* @param localesPath Root directory which leads to all i18n files
* @param state Plugin configuration
* @return true if strategy is responsible for the found structure
*/
boolean canUse(@NotNull Project project, @NotNull String localesPath, @NotNull SettingsState state);
/**
* Loads the translation files and passes them in the result consumer.
* Result payload might be null if operation failed.
* @param project IntelliJ project context
* @param localesPath Root directory which leads to all i18n files
* @param state Plugin configuration
* @param result Passes loaded data
*/
void read(@NotNull Project project, @NotNull String localesPath, @NotNull SettingsState state,
@NotNull Consumer<@Nullable TranslationData> result);
/**
* Writes the provided translation data to the IO system.
* @param project InteliJ project context
* @param localesPath Root directory which leads to all i18n files
* @param state Plugin configuration
* @param data Translations to save
* @param result Indicates whether the operation was successful
*/
void write(@NotNull Project project, @NotNull String localesPath, @NotNull SettingsState state,
@NotNull TranslationData data, @NotNull Consumer<Boolean> result);
}

View File

@ -13,6 +13,7 @@ import java.util.function.Consumer;
* Can be implemented by various standards. Such as JSON, Properties-Bundle and so on.
* @author marhali
*/
@Deprecated
public interface TranslatorIO {
/**