From ecbea7d7fb1c1510873662c6b2ced81d0357b511 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Tue, 19 Jul 2022 09:17:27 +0200 Subject: [PATCH] [name suggestion] prefer CamelCase names for locals (IDEA-297161) GitOrigin-RevId: e2f019772f56cd9208346e85a6e73c834f5576c5 --- .../replaceAll2_after.java | 6 +++--- .../refactoring/introduceField/after1.java | 4 ++-- .../refactoring/JavaIntroduceVariableTest.java | 17 ++--------------- .../NameSuggestionsByExpressionTest.java | 18 ++---------------- .../com/intellij/psi/codeStyle/NameUtil.java | 4 ++-- 5 files changed, 11 insertions(+), 38 deletions(-) diff --git a/java/java-tests/testData/refactoring/inplaceIntroduceParameter/replaceAll2_after.java b/java/java-tests/testData/refactoring/inplaceIntroduceParameter/replaceAll2_after.java index ecd91369aead..34e1b6695dfc 100644 --- a/java/java-tests/testData/refactoring/inplaceIntroduceParameter/replaceAll2_after.java +++ b/java/java-tests/testData/refactoring/inplaceIntroduceParameter/replaceAll2_after.java @@ -3,10 +3,10 @@ public class ATest { public static final String FOO1 = "foo1"; String m_interval = ""; - void foo(String m_interval1) { - if (FOO.equals(m_interval1.substring(1))) { + void foo(String mInterval) { + if (FOO.equals(mInterval.substring(1))) { System.out.println(FOO); - } else if (FOO1.equals(m_interval1.substring(1))) { + } else if (FOO1.equals(mInterval.substring(1))) { System.out.println(); } } diff --git a/java/java-tests/testData/refactoring/introduceField/after1.java b/java/java-tests/testData/refactoring/introduceField/after1.java index 3d0240c0cc4e..bbe6d0488ca4 100644 --- a/java/java-tests/testData/refactoring/introduceField/after1.java +++ b/java/java-tests/testData/refactoring/introduceField/after1.java @@ -1,8 +1,8 @@ class InStaticInitializer { - public static final String hello_world = "Hello World"; + public static final String helloWorld = "Hello World"; static { - System.out.println(hello_world); + System.out.println(helloWorld); } //Field must be placed before initializer or illegal forward reference will happen } \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/refactoring/JavaIntroduceVariableTest.java b/java/java-tests/testSrc/com/intellij/java/refactoring/JavaIntroduceVariableTest.java index aca6412a082e..1f91ea95b2e5 100644 --- a/java/java-tests/testSrc/com/intellij/java/refactoring/JavaIntroduceVariableTest.java +++ b/java/java-tests/testSrc/com/intellij/java/refactoring/JavaIntroduceVariableTest.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.java.refactoring; import com.intellij.openapi.util.text.StringUtil; @@ -35,6 +21,7 @@ public class JavaIntroduceVariableTest extends LightJavaCodeInsightTestCase { doTest("getA(\"SimpleName\")", "simpleName", "name"); doTest("getA(\"simpleName\")", "simpleName", "name"); doTest("getA(\"simpleClass\")", "simpleClass", "aClass"); + doTest("getA(\"simple_class\")", "simpleClass", "simple_class", "aClass"); doTest("getA(\"short\")", "aShort"); doTest("getA(\"boolean\")", "aBoolean"); doTest("getA().getB(1, \"name\")", "name"); diff --git a/java/java-tests/testSrc/com/intellij/java/refactoring/NameSuggestionsByExpressionTest.java b/java/java-tests/testSrc/com/intellij/java/refactoring/NameSuggestionsByExpressionTest.java index 2c68012f333b..ed7dafe043bd 100644 --- a/java/java-tests/testSrc/com/intellij/java/refactoring/NameSuggestionsByExpressionTest.java +++ b/java/java-tests/testSrc/com/intellij/java/refactoring/NameSuggestionsByExpressionTest.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.java.refactoring; import com.intellij.psi.PsiExpression; @@ -33,7 +19,7 @@ public class NameSuggestionsByExpressionTest extends LightJavaCodeInsightFixture SuggestedNameInfo nameInfo = JavaCodeStyleManager.getInstance(getProject()) .suggestVariableName(VariableKind.LOCAL_VARIABLE, null, expression, null); Assert.assertArrayEquals("Suggested: " + Arrays.toString(nameInfo.names), - new String[] {"string_with_spaces", "stringWithSpaces", "with_spaces", "withSpaces", "spaces", "string", "s"}, + new String[] {"stringWithSpaces", "string_with_spaces", "withSpaces", "with_spaces", "spaces", "string", "s"}, nameInfo.names); } diff --git a/platform/util/text-matching/src/com/intellij/psi/codeStyle/NameUtil.java b/platform/util/text-matching/src/com/intellij/psi/codeStyle/NameUtil.java index de8d0f8e32c4..1ed67bbfbea6 100644 --- a/platform/util/text-matching/src/com/intellij/psi/codeStyle/NameUtil.java +++ b/platform/util/text-matching/src/com/intellij/psi/codeStyle/NameUtil.java @@ -1,4 +1,4 @@ -// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.psi.codeStyle; import com.intellij.openapi.util.text.Strings; @@ -193,8 +193,8 @@ public final class NameUtil { continue; } - answer.add(compoundSuggestion(prefix, upperCaseStyle, words, wordCount, startWord, c, isArray, false) + suffix); answer.add(compoundSuggestion(prefix, upperCaseStyle, words, wordCount, startWord, c, isArray, true) + suffix); + answer.add(compoundSuggestion(prefix, upperCaseStyle, words, wordCount, startWord, c, isArray, false) + suffix); } return answer; }