mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
disable assign param to field (IDEA-173747; IDEA-173689)
inapplicable types or already assigned
This commit is contained in:
@@ -46,7 +46,7 @@ public class AssignFieldFromParameterAction extends BaseIntentionAction {
|
||||
return false;
|
||||
}
|
||||
final PsiField field = findFieldToAssign(project, myParameter);
|
||||
if (field == null) return false;
|
||||
if (field == null || type == null || !field.getType().isAssignableFrom(type)) return false;
|
||||
if (!field.getLanguage().isKindOf(JavaLanguage.INSTANCE)) return false;
|
||||
setText(CodeInsightBundle.message("intention.assign.field.from.parameter.text", field.getName()));
|
||||
|
||||
|
||||
@@ -112,9 +112,9 @@ public final class FieldFromParameterUtils {
|
||||
for (PsiReference reference : ReferencesSearch.search(parameter, new LocalSearchScope(parameter.getDeclarationScope()), false)) {
|
||||
if (!(reference instanceof PsiReferenceExpression)) continue;
|
||||
final PsiReferenceExpression expression = (PsiReferenceExpression)reference;
|
||||
if (!(expression.getParent() instanceof PsiAssignmentExpression)) continue;
|
||||
final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression)expression.getParent();
|
||||
if (assignmentExpression.getRExpression() != expression) continue;
|
||||
PsiAssignmentExpression assignmentExpression = PsiTreeUtil.getParentOfType(expression, PsiAssignmentExpression.class, true, PsiClass.class);
|
||||
if (assignmentExpression == null) continue;
|
||||
if (!PsiTreeUtil.isAncestor(assignmentExpression.getRExpression(), expression, false)) continue;
|
||||
final PsiExpression lExpression = assignmentExpression.getLExpression();
|
||||
if (!(lExpression instanceof PsiReferenceExpression)) continue;
|
||||
final PsiElement element = ((PsiReferenceExpression)lExpression).resolve();
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Assign Parameter to Field 'myA'" "false"
|
||||
|
||||
class Person {
|
||||
int myA;
|
||||
int myId;
|
||||
void f(int <caret>a, String id) {
|
||||
this.myA = foo(a);
|
||||
}
|
||||
int foo(int a) {return a;}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Assign Parameter to Field 'myId'" "false"
|
||||
|
||||
class Person {
|
||||
int a;
|
||||
int myId;
|
||||
void f(int a, String id<caret>) {
|
||||
this.a = foo(a);
|
||||
}
|
||||
int foo(int a) {return a;}
|
||||
}
|
||||
Reference in New Issue
Block a user