From 89dffc97f534a7753351549075613994f93f8344 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Mon, 26 Aug 2013 15:00:26 +0400 Subject: [PATCH] cal property name: accept without any other checks non-letter prefixes (IDEA-112585) --- .../impl/source/codeStyle/JavaCodeStyleManagerImpl.java | 2 +- .../generateConstructor/afterFieldPrefixCoincidence1.java | 7 +++++++ .../generateConstructor/beforeFieldPrefixCoincidence1.java | 4 ++++ .../com/intellij/codeInsight/GenerateConstructorTest.java | 7 ++++++- 4 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 java/java-tests/testData/codeInsight/generateConstructor/afterFieldPrefixCoincidence1.java create mode 100644 java/java-tests/testData/codeInsight/generateConstructor/beforeFieldPrefixCoincidence1.java diff --git a/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/JavaCodeStyleManagerImpl.java b/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/JavaCodeStyleManagerImpl.java index 2822fcfc81f5..a0d029da58e9 100644 --- a/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/JavaCodeStyleManagerImpl.java +++ b/java/java-impl/src/com/intellij/psi/impl/source/codeStyle/JavaCodeStyleManagerImpl.java @@ -752,7 +752,7 @@ public class JavaCodeStyleManagerImpl extends JavaCodeStyleManager { 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)))) { + (!Character.isLetter(prefix.charAt(pLength - 1)) || Character.isUpperCase(name.charAt(pLength)))) { name = name.substring(pLength); doDecapitalize = true; } diff --git a/java/java-tests/testData/codeInsight/generateConstructor/afterFieldPrefixCoincidence1.java b/java/java-tests/testData/codeInsight/generateConstructor/afterFieldPrefixCoincidence1.java new file mode 100644 index 000000000000..29be0de779ed --- /dev/null +++ b/java/java-tests/testData/codeInsight/generateConstructor/afterFieldPrefixCoincidence1.java @@ -0,0 +1,7 @@ +class Test { + private int _foo; + + Test(int foo) { + _foo = foo; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/generateConstructor/beforeFieldPrefixCoincidence1.java b/java/java-tests/testData/codeInsight/generateConstructor/beforeFieldPrefixCoincidence1.java new file mode 100644 index 000000000000..8acd4dc129fd --- /dev/null +++ b/java/java-tests/testData/codeInsight/generateConstructor/beforeFieldPrefixCoincidence1.java @@ -0,0 +1,4 @@ +class Test { + private int _foo; + +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/GenerateConstructorTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/GenerateConstructorTest.java index 3fb5b7c848f4..5ef9e70a8093 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/GenerateConstructorTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/GenerateConstructorTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,6 +55,11 @@ public class GenerateConstructorTest extends LightCodeInsightTestCase { doTest(); } + public void testFieldPrefixCoincidence1() throws Exception { + CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings().FIELD_NAME_PREFIX = "_"; + doTest(); + } + private void doTest() throws Exception { doTest(false); }