IDEA-52806 JAVA: smarter parameter name completion for Builder-style-methods

This commit is contained in:
peter
2011-10-12 15:44:03 +02:00
parent d716bc6935
commit 1c878bdc94
5 changed files with 15 additions and 0 deletions

View File

@@ -110,6 +110,9 @@ public class JavaMemberNameCompletionContributor extends CompletionContributor {
if (variableKind == VariableKind.PARAMETER) {
final PsiMethod method = PsiTreeUtil.getParentOfType(var, PsiMethod.class);
propertyName = PropertyUtil.getPropertyName(method);
if (method != null && method.getName().startsWith("with")) {
propertyName = StringUtil.decapitalize(method.getName().substring(4));
}
}
final PsiType type = var.getType();

View File

@@ -52,6 +52,7 @@ public class JavaCodeStyleManagerImpl extends JavaCodeStyleManager {
@NonNls private static final String IS_PREFIX = "is";
@NonNls private static final String FIND_PREFIX = "find";
@NonNls private static final String CREATE_PREFIX = "create";
@NonNls private static final String WITH_PREFIX = "with";
@NonNls private static final String SET_PREFIX = "set";
private final Project myProject;

View File

@@ -0,0 +1,4 @@
public class Builder {
public Builder withSomething(String so<caret>) {}
}

View File

@@ -0,0 +1,4 @@
public class Builder {
public Builder withSomething(String something<caret>) {}
}

View File

@@ -78,6 +78,9 @@ public class VariablesCompletionTest extends CompletionTestCase {
public void testUniqueNameInFor() throws Exception {
doTest(getTestName(false) + ".java", getTestName(false) + "_after.java");
}
public void testWithBuilderParameter() throws Exception {
doTest(getTestName(false) + ".java", getTestName(false) + "_after.java");
}
private void doTest(String before, String after) throws Exception {
configureByFile(FILE_PREFIX + "locals/" + before);