if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)) {
return;
}
PsiDocumentManager.getInstance(project).commitAllDocuments();
final PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
final List<PsiFieldMember> fieldMembers = chooseFields(file, editor, project, propertiesComponent);
if (fieldMembers == null || fieldMembers.isEmpty()) return;
ApplicationManager.getApplication().runWriteAction(new Runnable() {
CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);
PsiElementFactory psiElementFactory = JavaPsiFacade.getInstance(project).getElementFactory();
@Override
public void run() {
PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
PsiClass clazz = PsiTreeUtil.getParentOfType(element, PsiClass.class);
PsiClass builderClass = clazz.findInnerClassByName(BUILDER_CLASS_NAME, false);
if (builderClass == null) {
builderClass = (PsiClass) clazz.add(psiElementFactory.createClass(BUILDER_CLASS_NAME));
// builder classes are static and final
builderClass.getModifierList().setModifierProperty(PsiModifier.STATIC, true);
builderClass.getModifierList().setModifierProperty(PsiModifier.FINAL, true);
}
boolean finalSetters = propertiesComponent.getBoolean(PROP_FINALSETTERS, false);
boolean newBuilderMethod = propertiesComponent.getBoolean(PROP_NEWBUILDERMETHOD, false);
boolean copyConstructor = propertiesComponent.getBoolean(PROP_COPYCONSTRUCTOR, false);
boolean withNotation = propertiesComponent.getBoolean(PROP_WITHNOTATION, false);
StringBuilder constructorTakingBuilder = new StringBuilder();
constructorTakingBuilder.append("private ").append(clazz.getName()).append("(").append(builderClass.getName()).append(" builder) {");
for (PsiFieldMember member : fieldMembers) {