1
0
Fork 0
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:
Emanuel Graf 2011-01-04 12:18:01 +00:00
parent 54165f3720
commit 6361cd4231
2 changed files with 22 additions and 8 deletions

View file

@ -506,8 +506,8 @@ class Foo {
Foo<int> getFoo(); Foo<int> getFoo();
int main() { int main() {
Foo<int> getFoo0 = getFoo(); Foo<int> foo = getFoo();
getFoo0; foo;
return 0; return 0;
} }
@ -540,8 +540,8 @@ class Foo {
bar::Foo<int> getFoo(); bar::Foo<int> getFoo();
int main() { int main() {
bar::Foo<int> getFoo0 = getFoo(); bar::Foo<int> foo = getFoo();
getFoo0; foo;
return 0; return 0;
} }

View file

@ -317,10 +317,24 @@ public class ExtractLocalVariableRefactoring extends CRefactoring {
public String guessTempName() { public String guessTempName() {
String[] proposals= guessTempNames(); String[] proposals= guessTempNames();
if (proposals.length == 0) if (proposals.length == 0) {
return info.getName(); return info.getName();
else } else {
return proposals[0]; 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; tmpName[len++] = c;
} }
} }
name = new String(tmpName, 0, len); name = getLastCamelCasePart(new String(tmpName, 0, len));
if (name.length() > 0) { if (name.length() > 0) {
if (nameAvailable(name, guessedTempNames, scope)) { if (nameAvailable(name, guessedTempNames, scope)) {
guessedTempNames.add(name); guessedTempNames.add(name);