Skip to content

Commit

Permalink
Bugfix: if only camelCase and snake_case is selected in the options
Browse files Browse the repository at this point in the history
  • Loading branch information
wagner-netnexus committed Dec 21, 2021
1 parent 43691de commit e2c4058
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 34 deletions.
11 changes: 5 additions & 6 deletions META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin>
<id>de.netnexus.camelcaseplugin</id>
<name>CamelCase</name>
<version>3.0.10</version>
<version>3.0.11</version>
<vendor email="[email protected]" url="http://netnexus.de?src=camelCase">NetNexus</vendor>

<description><![CDATA[
Expand All @@ -16,10 +16,9 @@
<change-notes><![CDATA[
<p>If you have any comments please let me know.</p>
<p>Release 3.0.10:
<p>Release 3.0.11:
<ul>
<li>Single word bugfix (Foo => FOO => foo)</li>
<li>Pascal Case with space bugfix (foo foo => Foo Foo)</li>
<li>Bugfix: if only camelCase and snake_case is selected in the options</li>
</ul>
</p>
Expand Down Expand Up @@ -55,8 +54,8 @@

<extensions defaultExtensionNs="com.intellij">
<!-- Add your extensions here -->
<projectService serviceInterface="de.netnexus.CamelCasePlugin.CamelCaseConfig"
serviceImplementation="de.netnexus.CamelCasePlugin.CamelCaseConfig"/>
<projectService
serviceImplementation="de.netnexus.CamelCasePlugin.CamelCaseConfig"/>
<projectConfigurable groupId="editor" displayName="Camel Case" id="preferences.CamelCasePlugin"
instance="de.netnexus.CamelCasePlugin.CamelCasePluginConfigurable"/>
</extensions>
Expand Down
31 changes: 3 additions & 28 deletions src/de/netnexus/CamelCasePlugin/Conversion.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

class Conversion {


private static final String CONVERSION_SNAKE_CASE = "snake_case";
private static final String CONVERSION_SPACE_CASE = "space case";
private static final String CONVERSION_KEBAB_CASE = "kebab-case";
private static final String CONVERSION_UPPER_SNAKE_CASE = "SNAKE_CASE";
Expand All @@ -33,7 +31,7 @@ static String transform(String text,
boolean useLowerSnakeCase,
String[] conversionList) {
String newText, appendText = "";
boolean repeat;
boolean repeat = true;
int iterations = 0;
String next = null;

Expand All @@ -53,14 +51,11 @@ static String transform(String text,
if (isLowerCase && text.contains("_")) {
// snake_case to space case
if (next == null) {
next = getNext(CONVERSION_SNAKE_CASE, conversionList);
repeat = true;
next = getNext(CONVERSION_LOWER_SNAKE_CASE, conversionList);
} else {
if (next.equals(CONVERSION_SPACE_CASE)) {
repeat = !useSpaceCase;
next = getNext(CONVERSION_SPACE_CASE, conversionList);
} else {
repeat = true;
}
}
newText = text.replace('_', ' ');
Expand All @@ -69,94 +64,74 @@ static String transform(String text,
// space case to Camel Case
if (next == null) {
next = getNext(CONVERSION_SPACE_CASE, conversionList);
repeat = true;
} else {
newText = WordUtils.capitalize(text);
if (next.equals(CONVERSION_PASCAL_CASE_SPACE)) {
repeat = !usePascalCaseWithSpace;
next = getNext(CONVERSION_PASCAL_CASE_SPACE, conversionList);
} else {
repeat = true;
}
}

} else if (isUpperCase(text.charAt(0)) && isLowerCase(text.charAt(1)) && text.contains(" ")) {
// Camel Case to kebab-case
if (next == null) {
next = getNext(CONVERSION_PASCAL_CASE_SPACE, conversionList);
repeat = true;
} else {
newText = text.toLowerCase().replace(' ', '-');
if (next.equals(CONVERSION_KEBAB_CASE)) {
repeat = !useKebabCase;
next = getNext(CONVERSION_KEBAB_CASE, conversionList);
} else {
repeat = true;
}
}

} else if (isLowerCase && text.contains("-") || (isLowerCase && !text.contains(" "))) {
// kebab-case to SNAKE_CASE
if (next == null) {
next = getNext(CONVERSION_KEBAB_CASE, conversionList);
repeat = true;
} else {
newText = text.replace('-', '_').toUpperCase();
if (next.equals(CONVERSION_UPPER_SNAKE_CASE)) {
repeat = !useUpperSnakeCase;
next = getNext(CONVERSION_UPPER_SNAKE_CASE, conversionList);
} else {
repeat = true;
}
}

} else if ((isUpperCase && text.contains("_")) || (isLowerCase && !text.contains("_") && !text.contains(" ")) || (isUpperCase && !text.contains(" "))) {
// SNAKE_CASE to PascalCase
if (next == null) {
next = getNext(CONVERSION_UPPER_SNAKE_CASE, conversionList);
repeat = true;
} else {
newText = Conversion.toCamelCase(text.toLowerCase());
if (next.equals(CONVERSION_PASCAL_CASE)) {
repeat = !usePascalCase;
next = getNext(CONVERSION_PASCAL_CASE, conversionList);
} else {
repeat = true;
}
}

} else if (!isUpperCase && text.substring(0, 1).equals(text.substring(0, 1).toUpperCase()) && !text.contains("_")) {
// PascalCase to camelCase
if (next == null) {
next = getNext(CONVERSION_PASCAL_CASE, conversionList);
repeat = true;
} else {
newText = text.substring(0, 1).toLowerCase() + text.substring(1);
if (next.equals(CONVERSION_CAMEL_CASE)) {
repeat = !useCamelCase;
next = getNext(CONVERSION_CAMEL_CASE, conversionList);
} else {
repeat = true;
}
}

} else {
// camelCase to snake_case
if (next == null) {
next = getNext(CONVERSION_CAMEL_CASE, conversionList);
repeat = true;
} else {
newText = Conversion.toSnakeCase(text);
if (next.equals(CONVERSION_LOWER_SNAKE_CASE)) {
repeat = !useLowerSnakeCase;
next = getNext(CONVERSION_LOWER_SNAKE_CASE, conversionList);
} else {
repeat = true;
}
}

}
if (iterations++ > 10) {
if (iterations++ > 20) {
repeat = false;
}
text = newText;
Expand Down

0 comments on commit e2c4058

Please sign in to comment.