IDEA-111362 Generate constructor removes "m" from variable name

This commit is contained in:
peter
2013-08-01 15:55:45 +02:00
parent c2099f41be
commit 83a2d9cb96
4 changed files with 23 additions and 2 deletions

View File

@@ -748,8 +748,11 @@ public class JavaCodeStyleManagerImpl extends JavaCodeStyleManager {
String suffix = getSuffixByVariableKind(variableKind);
boolean doDecapitalize = false;
if (name.startsWith(prefix) && name.length() > prefix.length()) {
name = name.substring(prefix.length());
int pLength = prefix.length();
if (pLength > 0 && name.startsWith(prefix) && name.length() > pLength &&
// check it's not just a long camel word that happens to begin with the specified prefix
(!Character.isJavaIdentifierPart(prefix.charAt(pLength - 1)) || Character.isUpperCase(name.charAt(pLength)))) {
name = name.substring(pLength);
doDecapitalize = true;
}

View File

@@ -0,0 +1,8 @@
class Parent {
Object menu;
Parent(Object menu) {
this.menu = menu;
}
}

View File

@@ -0,0 +1,5 @@
class Parent {
Object menu;
<caret>
}

View File

@@ -50,6 +50,11 @@ public class GenerateConstructorTest extends LightCodeInsightTestCase {
public void testFinalFieldPreselection() throws Exception { doTest(true); }
public void testSubstitution() throws Exception { doTest(true); }
public void testFieldPrefixCoincidence() throws Exception {
CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings().FIELD_NAME_PREFIX = "m";
doTest();
}
private void doTest() throws Exception {
doTest(false);
}