PsiField (final PsiClass destClass, final PsiField psiField, final PsiElement anchorMember, final PsiField forwardReference) { final PsiClass parentClass = PsiTreeUtil.getParentOfType(anchorMember, PsiClass.class); if (anchorMember instanceof PsiField && anchorMember.getParent() == parentClass && destClass == parentClass && ((PsiField)anchorMember).hasModifierProperty(PsiModifier.STATIC) == psiField.hasModifierProperty(PsiModifier.STATIC)) { return (PsiField)destClass.addBefore(psiField, anchorMember); } else if (anchorMember instanceof PsiClassInitializer && anchorMember.getParent() == parentClass && destClass == parentClass) { PsiField field = (PsiField)destClass.addBefore(psiField, anchorMember); destClass.addBefore(CodeEditUtil.createLineFeed(field.getManager()), anchorMember); return field; } else { if (forwardReference != null &&forwardReference.getParent() == destClass) { return (PsiField)destClass.addAfter(psiField, forwardReference); } return (PsiField)destClass.add(psiField); } }