create getter from usage: return type fixed when field with name already exist

This commit is contained in:
anna
2010-07-23 20:49:21 +04:00
parent 19e299f9ed
commit 5c430dd73a
3 changed files with 21 additions and 2 deletions

View File

@@ -187,8 +187,9 @@ public class CreatePropertyFromUsageFix extends CreateFromUsageBaseFix {
LOG.assertTrue(callText != null, myMethodCall.getMethodExpression());
PsiType[] expectedTypes;
PsiType type;
PsiField field = targetClass.findFieldByName(fieldName, true);
if (callText.startsWith(GET_PREFIX)) {
expectedTypes = CreateFromUsageUtils.guessType(myMethodCall, false);
expectedTypes = field != null ? new PsiType[]{field.getType()} : CreateFromUsageUtils.guessType(myMethodCall, false);
type = expectedTypes[0];
}
else if (callText.startsWith(IS_PREFIX)) {
@@ -206,7 +207,7 @@ public class CreatePropertyFromUsageFix extends CreateFromUsageBaseFix {
IdeDocumentHistory.getInstance(project).includeCurrentPlaceAsChangePlace();
try {
PsiField field = targetClass.findFieldByName(fieldName, true);
if (field == null) {
field = factory.createField(fieldName, type);
PsiUtil.setModifierProperty(field, PsiModifier.STATIC, isStatic);

View File

@@ -0,0 +1,11 @@
// "Create Getter" "true"
public class Test {
Integer field;
public foo() {
getField();
}
public Integer getField() {
return field;
}
}

View File

@@ -0,0 +1,7 @@
// "Create Getter" "true"
public class Test {
Integer field;
public foo() {
get<caret>Field();
}
}