mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
disable assign parameter to final field (IDEA-173815)
for constructors with chaining calls, for non-constructors
This commit is contained in:
@@ -48,6 +48,24 @@ public class AssignFieldFromParameterAction extends BaseIntentionAction {
|
||||
final PsiField field = findFieldToAssign(project, myParameter);
|
||||
if (field == null || type == null || !field.getType().isAssignableFrom(type)) return false;
|
||||
if (!field.getLanguage().isKindOf(JavaLanguage.INSTANCE)) return false;
|
||||
PsiElement scope = myParameter.getDeclarationScope();
|
||||
if (scope instanceof PsiMethod && field.hasModifierProperty(PsiModifier.FINAL)) {
|
||||
if (((PsiMethod)scope).isConstructor()) {
|
||||
PsiCodeBlock body = ((PsiMethod)scope).getBody();
|
||||
LOG.assertTrue(body != null);
|
||||
PsiStatement[] statements = body.getStatements();
|
||||
if (statements.length > 0 && statements[0] instanceof PsiExpressionStatement) {
|
||||
PsiExpression expression = ((PsiExpressionStatement)statements[0]).getExpression();
|
||||
if (expression instanceof PsiMethodCallExpression &&
|
||||
PsiKeyword.THIS.equals(((PsiMethodCallExpression)expression).getMethodExpression().getReferenceName())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
setText(CodeInsightBundle.message("intention.assign.field.from.parameter.text", field.getName()));
|
||||
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Assign Parameter to Field 'myStr'" "false"
|
||||
|
||||
|
||||
class Foo1 {
|
||||
final String myStr;
|
||||
Foo1(String str, int i) {
|
||||
myStr = (str);
|
||||
}
|
||||
|
||||
Foo1(String st<caret>r) {
|
||||
this(str, 2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user