void (PsiExpression initializerExpression, PsiField field, PsiMethod enclosingConstructor, final PsiClass parentClass) { try { PsiClass aClass = field.getContainingClass(); PsiMethod[] constructors = aClass.getConstructors(); boolean added = false; for (PsiMethod constructor : constructors) { if (constructor == enclosingConstructor) continue; PsiCodeBlock body = constructor.getBody(); if (body == null) continue; PsiStatement[] statements = body.getStatements(); if (statements.length > 0) { PsiStatement first = statements[0]; if (first instanceof PsiExpressionStatement) { PsiExpression expression = ((PsiExpressionStatement)first).getExpression(); if (expression instanceof PsiMethodCallExpression) { @NonNls String text = ((PsiMethodCallExpression)expression).getMethodExpression().getText(); if ("this".equals(text)) { continue; } } } } PsiStatement assignment = createAssignment(field, initializerExpression, body.getLastChild(), parentClass); assignment = (PsiStatement) body.add(assignment); ChangeContextUtil.decodeContextInfo(assignment, field.getContainingClass(), RefactoringChangeUtil.createThisExpression(field.getManager(), null)); added = true; } if (!added && enclosingConstructor == null) { PsiElementFactory factory = JavaPsiFacade.getElementFactory(field.getProject()); PsiMethod constructor = (PsiMethod)aClass.add(factory.createConstructor()); final PsiCodeBlock body = constructor.getBody(); PsiStatement assignment = createAssignment(field, initializerExpression, body.getLastChild(), parentClass); assignment = (PsiStatement) body.add(assignment); ChangeContextUtil.decodeContextInfo(assignment, field.getContainingClass(), RefactoringChangeUtil.createThisExpression(field.getManager(), null)); } } catch (IncorrectOperationException e) { LOG.error(e); } }