feat: update naming convention functionality
Updated naming convention features by simplifying key case formatter construction and expanding the naming convention enum. Also performed a refactor to layout and formatting across various files for improved readability. Added new test cases to validate the update to naming convention.
This commit is contained in:
parent
f933ea91eb
commit
027016921f
@ -2,21 +2,39 @@ package de.marhali.easyi18n.settings;
|
|||||||
|
|
||||||
import com.google.common.base.CaseFormat;
|
import com.google.common.base.CaseFormat;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public enum NamingConvention {
|
public enum NamingConvention {
|
||||||
SNAKE_CASE("Snake"),
|
SNAKE_CASE("Snake Case"),
|
||||||
CAMEL_CASE("Camel"),;
|
|
||||||
|
CAMEL_CASE("Camel Case"),
|
||||||
|
|
||||||
|
CAMEL_CASE_UPPERCASE("Camel Case Uppercase"),
|
||||||
|
;
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
private NamingConvention(String name) {
|
private NamingConvention(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return super.name().toLowerCase();
|
return super.name().toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
static public NamingConvention fromSelector(String name) {
|
static public NamingConvention fromSelector(String name) {
|
||||||
String formated = name.replace(" ", "_");
|
String formated = name.replace(" ", "_");
|
||||||
return valueOf(formated.toUpperCase());
|
return valueOf(formated.toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public String[] getEnumNames() {
|
||||||
|
return Arrays.stream(NamingConvention.values())
|
||||||
|
.map(NamingConvention::getName)
|
||||||
|
.toArray(String[]::new);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,31 +9,55 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* API to access the project-specific configuration for this plugin.
|
* API to access the project-specific configuration for this plugin.
|
||||||
|
*
|
||||||
* @author marhaliu
|
* @author marhaliu
|
||||||
*/
|
*/
|
||||||
public interface ProjectSettings {
|
public interface ProjectSettings {
|
||||||
// Resource Configuration
|
// Resource Configuration
|
||||||
@Nullable String getLocalesDirectory();
|
@Nullable
|
||||||
@NotNull FolderStrategyType getFolderStrategy();
|
String getLocalesDirectory();
|
||||||
@NotNull ParserStrategyType getParserStrategy();
|
|
||||||
@NotNull String getFilePattern();
|
@NotNull
|
||||||
|
FolderStrategyType getFolderStrategy();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
ParserStrategyType getParserStrategy();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
String getFilePattern();
|
||||||
|
|
||||||
boolean isIncludeSubDirs();
|
boolean isIncludeSubDirs();
|
||||||
|
|
||||||
boolean isSorting();
|
boolean isSorting();
|
||||||
|
|
||||||
// Editor Configuration
|
// Editor Configuration
|
||||||
@Nullable String getNamespaceDelimiter();
|
@Nullable
|
||||||
@NotNull String getSectionDelimiter();
|
String getNamespaceDelimiter();
|
||||||
@Nullable String getContextDelimiter();
|
|
||||||
@Nullable String getPluralDelimiter();
|
@NotNull
|
||||||
@Nullable String getDefaultNamespace();
|
String getSectionDelimiter();
|
||||||
@NotNull String getPreviewLocale();
|
|
||||||
|
@Nullable
|
||||||
|
String getContextDelimiter();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
String getPluralDelimiter();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
String getDefaultNamespace();
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
String getPreviewLocale();
|
||||||
|
|
||||||
boolean isNestedKeys();
|
boolean isNestedKeys();
|
||||||
|
|
||||||
boolean isAssistance();
|
boolean isAssistance();
|
||||||
|
|
||||||
// Experimental Configuration
|
// Experimental Configuration
|
||||||
boolean isAlwaysFold();
|
boolean isAlwaysFold();
|
||||||
|
|
||||||
String getFlavorTemplate();
|
String getFlavorTemplate();
|
||||||
@NotNull NamingConvention getCaseFormat();
|
|
||||||
|
@NotNull
|
||||||
|
NamingConvention getCaseFormat();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -231,12 +231,9 @@ public class ProjectSettingsComponent extends ProjectSettingsComponentState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private JComponent constructKeyCaseFormater() {
|
private JComponent constructKeyCaseFormater() {
|
||||||
KeyCaseFormater = new ComboBox<>(bundle.getString("settings.experimental.key-naming-format.items").split(ArrayMapper.SPLITERATOR_REGEX));
|
KeyCaseFormater = new ComboBox<>(NamingConvention.getEnumNames());
|
||||||
KeyCaseFormater.setToolTipText(bundle.getString("settings.experimental.key-naming-format.tooltip"));
|
KeyCaseFormater.setToolTipText(bundle.getString("settings.experimental.key-naming-format.tooltip"));
|
||||||
KeyCaseFormater.setMinimumAndPreferredWidth(120);
|
KeyCaseFormater.setMinimumAndPreferredWidth(120);
|
||||||
KeyCaseFormater.addActionListener(e -> {
|
|
||||||
|
|
||||||
});
|
|
||||||
return KeyCaseFormater;
|
return KeyCaseFormater;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -99,6 +99,7 @@ public class ProjectSettingsComponentState {
|
|||||||
|
|
||||||
alwaysFold.setSelected(state.isAlwaysFold());
|
alwaysFold.setSelected(state.isAlwaysFold());
|
||||||
flavorTemplate.setText(state.getFlavorTemplate());
|
flavorTemplate.setText(state.getFlavorTemplate());
|
||||||
KeyCaseFormater.setSelectedItem(state.getCaseFormat().name());
|
KeyCaseFormater.setSelectedItem(state.getCaseFormat().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -66,6 +66,7 @@ public class ProjectSettingsState implements ProjectSettings {
|
|||||||
*/
|
*/
|
||||||
@Property
|
@Property
|
||||||
private String flavorTemplate;
|
private String flavorTemplate;
|
||||||
|
|
||||||
@Property
|
@Property
|
||||||
private NamingConvention caseFormat;
|
private NamingConvention caseFormat;
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package de.marhali.easyi18n;
|
|||||||
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
||||||
import de.marhali.easyi18n.io.folder.FolderStrategyType;
|
import de.marhali.easyi18n.io.folder.FolderStrategyType;
|
||||||
import de.marhali.easyi18n.model.KeyPath;
|
import de.marhali.easyi18n.model.KeyPath;
|
||||||
|
import de.marhali.easyi18n.settings.NamingConvention;
|
||||||
import de.marhali.easyi18n.settings.ProjectSettings;
|
import de.marhali.easyi18n.settings.ProjectSettings;
|
||||||
import de.marhali.easyi18n.util.KeyPathConverter;
|
import de.marhali.easyi18n.util.KeyPathConverter;
|
||||||
|
|
||||||
@ -172,6 +173,11 @@ public class KeyPathConverterTest {
|
|||||||
public boolean isIncludeSubDirs() {
|
public boolean isIncludeSubDirs() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull NamingConvention getCaseFormat() {
|
||||||
|
return NamingConvention.CAMEL_CASE;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,6 +22,7 @@ import java.util.Objects;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* End-to-end test case.
|
* End-to-end test case.
|
||||||
|
*
|
||||||
* @author marhali
|
* @author marhali
|
||||||
*/
|
*/
|
||||||
public abstract class EndToEndTestCase extends BasePlatformTestCase {
|
public abstract class EndToEndTestCase extends BasePlatformTestCase {
|
||||||
@ -57,7 +58,8 @@ public abstract class EndToEndTestCase extends BasePlatformTestCase {
|
|||||||
out.setLocalesDirectory(tempPath.toString());
|
out.setLocalesDirectory(tempPath.toString());
|
||||||
ProjectSettingsService.get(getProject()).setState(out);
|
ProjectSettingsService.get(getProject()).setState(out);
|
||||||
|
|
||||||
InstanceManager.get(getProject()).store().saveToPersistenceLayer(success -> {});
|
InstanceManager.get(getProject()).store().saveToPersistenceLayer(success -> {
|
||||||
|
});
|
||||||
|
|
||||||
// Compare file structure and contents
|
// Compare file structure and contents
|
||||||
IOFileFilter fileFilter = TrueFileFilter.INSTANCE;
|
IOFileFilter fileFilter = TrueFileFilter.INSTANCE;
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import de.marhali.easyi18n.io.parser.properties.PropertiesMapper;
|
|||||||
import de.marhali.easyi18n.io.parser.properties.SortableProperties;
|
import de.marhali.easyi18n.io.parser.properties.SortableProperties;
|
||||||
import de.marhali.easyi18n.model.TranslationData;
|
import de.marhali.easyi18n.model.TranslationData;
|
||||||
import de.marhali.easyi18n.model.KeyPath;
|
import de.marhali.easyi18n.model.KeyPath;
|
||||||
|
import de.marhali.easyi18n.settings.NamingConvention;
|
||||||
import de.marhali.easyi18n.settings.ProjectSettings;
|
import de.marhali.easyi18n.settings.ProjectSettings;
|
||||||
import de.marhali.easyi18n.util.KeyPathConverter;
|
import de.marhali.easyi18n.util.KeyPathConverter;
|
||||||
|
|
||||||
@ -19,6 +20,7 @@ import java.util.*;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link PropertiesMapper}.
|
* Unit tests for {@link PropertiesMapper}.
|
||||||
|
*
|
||||||
* @author marhali
|
* @author marhali
|
||||||
*/
|
*/
|
||||||
public class PropertiesMapperTest extends AbstractMapperTest {
|
public class PropertiesMapperTest extends AbstractMapperTest {
|
||||||
@ -245,6 +247,11 @@ public class PropertiesMapperTest extends AbstractMapperTest {
|
|||||||
public boolean isIncludeSubDirs() {
|
public boolean isIncludeSubDirs() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull NamingConvention getCaseFormat() {
|
||||||
|
return NamingConvention.CAMEL_CASE;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -7,6 +7,7 @@ import de.marhali.easyi18n.settings.presets.DefaultPreset;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for the project settings service itself.
|
* Tests for the project settings service itself.
|
||||||
|
*
|
||||||
* @author marhali
|
* @author marhali
|
||||||
*/
|
*/
|
||||||
public class ProjectSettingsServiceTest extends BasePlatformTestCase {
|
public class ProjectSettingsServiceTest extends BasePlatformTestCase {
|
||||||
@ -35,4 +36,12 @@ public class ProjectSettingsServiceTest extends BasePlatformTestCase {
|
|||||||
ProjectSettingsState after = XmlSerializerUtil.createCopy(previous);
|
ProjectSettingsState after = XmlSerializerUtil.createCopy(previous);
|
||||||
assertEquals("mySinglePropTest", after.getLocalesDirectory());
|
assertEquals("mySinglePropTest", after.getLocalesDirectory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testPersistenceFormatCase() {
|
||||||
|
ProjectSettingsState previous = new ProjectSettingsState();
|
||||||
|
assertEquals(previous.getCaseFormat(), NamingConvention.CAMEL_CASE);
|
||||||
|
previous.setCaseFormat(NamingConvention.SNAKE_CASE);
|
||||||
|
ProjectSettingsState after = XmlSerializerUtil.createCopy(previous);
|
||||||
|
assertEquals(after.getCaseFormat(), NamingConvention.SNAKE_CASE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user