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:
JPilson 2024-04-20 18:44:18 +02:00
parent f933ea91eb
commit 027016921f
9 changed files with 87 additions and 22 deletions

View File

@ -2,21 +2,39 @@ package de.marhali.easyi18n.settings;
import com.google.common.base.CaseFormat;
import java.util.Arrays;
public enum NamingConvention {
SNAKE_CASE("Snake"),
CAMEL_CASE("Camel"),;
SNAKE_CASE("Snake Case"),
CAMEL_CASE("Camel Case"),
CAMEL_CASE_UPPERCASE("Camel Case Uppercase"),
;
private final String name;
private NamingConvention(String name) {
this.name = name;
}
public String getName() {
return this.name;
}
@Override
public String toString() {
return super.name().toLowerCase();
}
static public NamingConvention fromSelector(String name) {
String formated = name.replace(" ", "_");
return valueOf(formated.toUpperCase());
}
static public String[] getEnumNames() {
return Arrays.stream(NamingConvention.values())
.map(NamingConvention::getName)
.toArray(String[]::new);
}
}

View File

@ -9,31 +9,55 @@ import org.jetbrains.annotations.Nullable;
/**
* API to access the project-specific configuration for this plugin.
*
* @author marhaliu
*/
public interface ProjectSettings {
// Resource Configuration
@Nullable String getLocalesDirectory();
@NotNull FolderStrategyType getFolderStrategy();
@NotNull ParserStrategyType getParserStrategy();
@NotNull String getFilePattern();
@Nullable
String getLocalesDirectory();
@NotNull
FolderStrategyType getFolderStrategy();
@NotNull
ParserStrategyType getParserStrategy();
@NotNull
String getFilePattern();
boolean isIncludeSubDirs();
boolean isSorting();
// Editor Configuration
@Nullable String getNamespaceDelimiter();
@NotNull String getSectionDelimiter();
@Nullable String getContextDelimiter();
@Nullable String getPluralDelimiter();
@Nullable String getDefaultNamespace();
@NotNull String getPreviewLocale();
@Nullable
String getNamespaceDelimiter();
@NotNull
String getSectionDelimiter();
@Nullable
String getContextDelimiter();
@Nullable
String getPluralDelimiter();
@Nullable
String getDefaultNamespace();
@NotNull
String getPreviewLocale();
boolean isNestedKeys();
boolean isAssistance();
// Experimental Configuration
boolean isAlwaysFold();
String getFlavorTemplate();
@NotNull NamingConvention getCaseFormat();
@NotNull
NamingConvention getCaseFormat();
}

View File

@ -231,12 +231,9 @@ public class ProjectSettingsComponent extends ProjectSettingsComponentState {
}
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.setMinimumAndPreferredWidth(120);
KeyCaseFormater.addActionListener(e -> {
});
return KeyCaseFormater;
}

View File

@ -99,6 +99,7 @@ public class ProjectSettingsComponentState {
alwaysFold.setSelected(state.isAlwaysFold());
flavorTemplate.setText(state.getFlavorTemplate());
KeyCaseFormater.setSelectedItem(state.getCaseFormat().name());
KeyCaseFormater.setSelectedItem(state.getCaseFormat().getName());
}
}

View File

@ -66,6 +66,7 @@ public class ProjectSettingsState implements ProjectSettings {
*/
@Property
private String flavorTemplate;
@Property
private NamingConvention caseFormat;

View File

@ -3,6 +3,7 @@ package de.marhali.easyi18n;
import de.marhali.easyi18n.io.parser.ParserStrategyType;
import de.marhali.easyi18n.io.folder.FolderStrategyType;
import de.marhali.easyi18n.model.KeyPath;
import de.marhali.easyi18n.settings.NamingConvention;
import de.marhali.easyi18n.settings.ProjectSettings;
import de.marhali.easyi18n.util.KeyPathConverter;
@ -172,6 +173,11 @@ public class KeyPathConverterTest {
public boolean isIncludeSubDirs() {
return false;
}
@Override
public @NotNull NamingConvention getCaseFormat() {
return NamingConvention.CAMEL_CASE;
}
});
}
}

View File

@ -22,6 +22,7 @@ import java.util.Objects;
/**
* End-to-end test case.
*
* @author marhali
*/
public abstract class EndToEndTestCase extends BasePlatformTestCase {
@ -57,7 +58,8 @@ public abstract class EndToEndTestCase extends BasePlatformTestCase {
out.setLocalesDirectory(tempPath.toString());
ProjectSettingsService.get(getProject()).setState(out);
InstanceManager.get(getProject()).store().saveToPersistenceLayer(success -> {});
InstanceManager.get(getProject()).store().saveToPersistenceLayer(success -> {
});
// Compare file structure and contents
IOFileFilter fileFilter = TrueFileFilter.INSTANCE;

View File

@ -7,6 +7,7 @@ import de.marhali.easyi18n.io.parser.properties.PropertiesMapper;
import de.marhali.easyi18n.io.parser.properties.SortableProperties;
import de.marhali.easyi18n.model.TranslationData;
import de.marhali.easyi18n.model.KeyPath;
import de.marhali.easyi18n.settings.NamingConvention;
import de.marhali.easyi18n.settings.ProjectSettings;
import de.marhali.easyi18n.util.KeyPathConverter;
@ -19,6 +20,7 @@ import java.util.*;
/**
* Unit tests for {@link PropertiesMapper}.
*
* @author marhali
*/
public class PropertiesMapperTest extends AbstractMapperTest {
@ -245,6 +247,11 @@ public class PropertiesMapperTest extends AbstractMapperTest {
public boolean isIncludeSubDirs() {
return false;
}
@Override
public @NotNull NamingConvention getCaseFormat() {
return NamingConvention.CAMEL_CASE;
}
});
}
}

View File

@ -7,6 +7,7 @@ import de.marhali.easyi18n.settings.presets.DefaultPreset;
/**
* Tests for the project settings service itself.
*
* @author marhali
*/
public class ProjectSettingsServiceTest extends BasePlatformTestCase {
@ -35,4 +36,12 @@ public class ProjectSettingsServiceTest extends BasePlatformTestCase {
ProjectSettingsState after = XmlSerializerUtil.createCopy(previous);
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);
}
}