mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-178297 Please improve suggested variable names for Java Optional<> types
This commit is contained in:
+5
-1
@@ -348,7 +348,11 @@ public class JavaCodeStyleManagerImpl extends JavaCodeStyleManager {
|
||||
|
||||
if (psiClass != null && CommonClassNames.JAVA_UTIL_OPTIONAL.equals(psiClass.getQualifiedName()) && ((PsiClassType)type).getParameterCount() == 1) {
|
||||
PsiType optionalContent = ((PsiClassType)type).getParameters()[0];
|
||||
Collections.addAll(suggestions, suggestVariableNameByType(optionalContent, variableKind, correctKeywords, false));
|
||||
String[] contentSuggestions = suggestVariableNameByType(optionalContent, variableKind, correctKeywords, false);
|
||||
Collections.addAll(suggestions, contentSuggestions);
|
||||
for (String s : contentSuggestions) {
|
||||
Collections.addAll(suggestions, getSuggestionsByName("optional" + StringUtil.capitalize(s), variableKind, false, correctKeywords));
|
||||
}
|
||||
}
|
||||
|
||||
suggestNamesFromGenericParameters(type, variableKind, suggestions, correctKeywords);
|
||||
|
||||
@@ -94,7 +94,7 @@ class Foo {{
|
||||
Optional<Foo> <caret>o = Optional.of(typeValue);
|
||||
}}
|
||||
""")
|
||||
assert suggestions == ["typeValue1", "value", "foo", "fooOptional", "optional", "o"]
|
||||
assert suggestions == ["typeValue1", "value", "foo", "optionalFoo", "fooOptional", "optional", "o"]
|
||||
}
|
||||
|
||||
void "test by Optional_ofNullable initializer"() {
|
||||
@@ -105,7 +105,7 @@ class Foo {{
|
||||
Optional<Foo> <caret>o = Optional.ofNullable(typeValue);
|
||||
}}
|
||||
""")
|
||||
assert suggestions == ["typeValue1", "value", "foo", "fooOptional", "optional", "o"]
|
||||
assert suggestions == ["typeValue1", "value", "foo", "optionalFoo", "fooOptional", "optional", "o"]
|
||||
}
|
||||
|
||||
void "test by Optional_of initializer with constructor"() {
|
||||
@@ -115,7 +115,7 @@ class Foo {{
|
||||
Optional<Foo> <caret>o = Optional.ofNullable(new Foo());
|
||||
}}
|
||||
""")
|
||||
assert suggestions == ["foo", "fooOptional", "optional", "o"]
|
||||
assert suggestions == ["foo", "optionalFoo", "fooOptional", "optional", "o"]
|
||||
}
|
||||
|
||||
void "test by Optional_flatMap"() {
|
||||
@@ -129,7 +129,7 @@ class Person {
|
||||
}
|
||||
class Car {}
|
||||
""")
|
||||
assert suggestions == ["car", "carOptional", "optional", "o"]
|
||||
assert suggestions == ["car", "optionalCar", "carOptional", "optional", "o"]
|
||||
}
|
||||
|
||||
private doTestSuggestionAvailable(String text, String... expectedSuggestions) {
|
||||
|
||||
Reference in New Issue
Block a user