mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 330693: Improve suggested variable name in Extract Local Variable
https://bugs.eclipse.org/bugs/show_bug.cgi?id=330693
This commit is contained in:
parent
54165f3720
commit
6361cd4231
2 changed files with 22 additions and 8 deletions
|
@ -506,8 +506,8 @@ class Foo {
|
|||
Foo<int> getFoo();
|
||||
|
||||
int main() {
|
||||
Foo<int> getFoo0 = getFoo();
|
||||
getFoo0;
|
||||
Foo<int> foo = getFoo();
|
||||
foo;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -540,8 +540,8 @@ class Foo {
|
|||
bar::Foo<int> getFoo();
|
||||
|
||||
int main() {
|
||||
bar::Foo<int> getFoo0 = getFoo();
|
||||
getFoo0;
|
||||
bar::Foo<int> foo = getFoo();
|
||||
foo;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -317,10 +317,24 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
|
|||
|
||||
public String guessTempName() {
|
||||
String[] proposals= guessTempNames();
|
||||
if (proposals.length == 0)
|
||||
if (proposals.length == 0) {
|
||||
return info.getName();
|
||||
else
|
||||
return proposals[0];
|
||||
} else {
|
||||
String name = getLastCamelCasePart(proposals[proposals.length - 1]);
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
private String getLastCamelCasePart(String string) {
|
||||
if (string.length() == 0) {
|
||||
return string;
|
||||
}
|
||||
int index = string.length() - 1;
|
||||
while (index > 0
|
||||
&& (Character.isLowerCase(string.charAt(index)) || Character.isDigit(string.charAt(index)))) {
|
||||
--index;
|
||||
}
|
||||
return string.substring(index).toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -394,7 +408,7 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
|
|||
tmpName[len++] = c;
|
||||
}
|
||||
}
|
||||
name = new String(tmpName, 0, len);
|
||||
name = getLastCamelCasePart(new String(tmpName, 0, len));
|
||||
if (name.length() > 0) {
|
||||
if (nameAvailable(name, guessedTempNames, scope)) {
|
||||
guessedTempNames.add(name);
|
||||
|
|
Loading…
Add table
Reference in a new issue