boolean () { final PsiManager manager = myMethod.getManager(); final Project project = myMethod.getProject(); final ReturnValueBeanBuilder beanClassBuilder = new ReturnValueBeanBuilder(); beanClassBuilder.setProject(project); beanClassBuilder.setFile(myMethod.getContainingFile()); beanClassBuilder.setTypeArguments(myTypeParameters); beanClassBuilder.setClassName(myClassName); beanClassBuilder.setPackageName(myPackageName); beanClassBuilder.setStatic(myCreateInnerClass && myMethod.hasModifierProperty(PsiModifier.STATIC)); final PsiType returnType = myMethod.getReturnType(); beanClassBuilder.setValueType(returnType); final String classString; try { classString = beanClassBuilder.buildBeanClass(); } catch (IOException e) { LOG.error(e); return false; } try { final PsiFileFactory factory = PsiFileFactory.getInstance(project); final PsiJavaFile psiFile = (PsiJavaFile)factory.createFileFromText(myClassName + ".java", JavaFileType.INSTANCE, classString); final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(manager.getProject()); if (myCreateInnerClass) { final PsiClass containingClass = myMethod.getContainingClass(); final PsiElement innerClass = containingClass.add(psiFile.getClasses()[0]); JavaCodeStyleManager.getInstance(project).shortenClassReferences(innerClass); } else { final PsiFile containingFile = myMethod.getContainingFile(); final PsiDirectory containingDirectory = containingFile.getContainingDirectory(); final PsiDirectory directory; if (myMoveDestination != null) { directory = myMoveDestination.getTargetDirectory(containingDirectory); } else { final Module module = ModuleUtilCore.findModuleForPsiElement(containingFile); directory = PackageUtil.findOrCreateDirectoryForPackage(module, myPackageName, containingDirectory, true, true); } if (directory != null) { final PsiElement shortenedFile = JavaCodeStyleManager.getInstance(project).shortenClassReferences(psiFile); final PsiElement reformattedFile = codeStyleManager.reformat(shortenedFile); directory.add(reformattedFile); } else { return false; } } } catch (IncorrectOperationException e) { LOG.info(e); return false; } return true; }