mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
create getter from usage: return type fixed when field with name already exist
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Create Getter" "true"
|
||||
public class Test {
|
||||
Integer field;
|
||||
public foo() {
|
||||
getField();
|
||||
}
|
||||
|
||||
public Integer getField() {
|
||||
return field;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// "Create Getter" "true"
|
||||
public class Test {
|
||||
Integer field;
|
||||
public foo() {
|
||||
get<caret>Field();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user