Skip to content

Commit cde4a8f

Browse files
committed
Do not suggest invalid names while introducing variable
1 parent 25b8b03 commit cde4a8f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/com/goide/refactor/GoRefactoringUtil.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private static LinkedHashSet<String> getSuggestedNames(GoExpression expression,
167167
String name = StringUtil.decapitalize(callReference.getIdentifier().getText());
168168
for (String candidate : NameUtil.getSuggestionsByName(name, "", "", false, false, false)) {
169169
if (usedNames.contains(candidate)) continue;
170-
if (namesValidator != null && namesValidator.isKeyword(candidate, null)) continue;
170+
if (!isValidName(namesValidator, candidate)) continue;
171171
names.add(candidate);
172172
}
173173
}
@@ -179,7 +179,7 @@ private static LinkedHashSet<String> getSuggestedNames(GoExpression expression,
179179
boolean array = GoTypeUtil.isIterable(type) && !GoTypeUtil.isString(type);
180180
for (String candidate : NameUtil.getSuggestionsByName(typeText, "", "", false, false, array)) {
181181
if (usedNames.contains(candidate) || typeText.equals(candidate)) continue;
182-
if (namesValidator != null && namesValidator.isKeyword(candidate, null)) continue;
182+
if (!isValidName(namesValidator, candidate)) continue;
183183
names.add(candidate);
184184
}
185185
}
@@ -190,6 +190,10 @@ private static LinkedHashSet<String> getSuggestedNames(GoExpression expression,
190190
return names;
191191
}
192192

193+
private static boolean isValidName(NamesValidator namesValidator, String candidate) {
194+
return namesValidator != null && !namesValidator.isKeyword(candidate, null) && namesValidator.isIdentifier(candidate, null);
195+
}
196+
193197
@NotNull
194198
private static LinkedHashSet<String> getNamesInContext(PsiElement context) {
195199
if (context == null) return ContainerUtil.newLinkedHashSet();

0 commit comments

Comments
 (0)