void (@NotNull PsiClass targetClass) { final Project project = myReferenceExpression.getProject(); JVMElementFactory factory = JVMElementFactories.getFactory(targetClass.getLanguage(), project); if (factory == null) factory = JavaPsiFacade.getElementFactory(project); PsiMember enclosingContext = null; PsiClass parentClass; do { enclosingContext = PsiTreeUtil.getParentOfType(enclosingContext == null ? myReferenceExpression : enclosingContext, PsiMethod.class, PsiField.class, PsiClassInitializer.class); parentClass = enclosingContext == null ? null : enclosingContext.getContainingClass(); } while (parentClass instanceof PsiAnonymousClass); ExpectedTypeInfo[] expectedTypes = CreateFromUsageUtils.guessExpectedTypes(myReferenceExpression, false); String fieldName = myReferenceExpression.getReferenceName(); assert fieldName != null; PsiField field = factory.createField(fieldName, PsiTypes.intType()); if (!targetClass.isInterface() && shouldCreateStaticMember(myReferenceExpression, targetClass)) { PsiUtil.setModifierProperty(field, PsiModifier.STATIC, true); } if (shouldCreateFinalMember(myReferenceExpression, targetClass)) { PsiUtil.setModifierProperty(field, PsiModifier.FINAL, true); } field = CreateFieldFromUsageHelper.insertField(targetClass, field, myReferenceExpression); setupVisibility(parentClass, targetClass, field.getModifierList()); createFieldFromUsageTemplate(targetClass, project, expectedTypes, field, false, myReferenceExpression); }