PsiClass (PsiMethod method, ReadWriteAccessDetector.Access[] accessors) { if (isUseExistingClass()) { return getExistingClass(); } final ParameterObjectBuilder beanClassBuilder = new ParameterObjectBuilder(); beanClassBuilder.setVisibility(isCreateInnerClass() ? PsiModifier.PRIVATE : PsiModifier.PUBLIC); beanClassBuilder.setProject(method.getProject()); beanClassBuilder.setFile(method.getContainingFile()); beanClassBuilder.setTypeArguments(getTypeParameters()); beanClassBuilder.setClassName(getClassName()); beanClassBuilder.setPackageName(getPackageName()); PsiParameter[] parameters = method.getParameterList().getParameters(); final ParameterInfoImpl[] parameterInfos = getParamsToMerge(); for (int i = 0; i < parameterInfos.length; i++) { PsiParameter parameter = parameters[parameterInfos[i].getOldIndex()]; final boolean setterRequired = accessors[i] == ReadWriteAccessDetector.Access.Write; final String newName = parameterInfos[i].getName(); beanClassBuilder .addField(parameter, newName, parameterInfos[i].getTypeWrapper().getType(method), setterRequired); } final String classString = beanClassBuilder.buildBeanClass(); try { final PsiFileFactory factory = PsiFileFactory.getInstance(method.getProject()); final PsiJavaFile newFile = (PsiJavaFile)factory.createFileFromText(getClassName() + ".java", JavaFileType.INSTANCE, classString); if (isCreateInnerClass()) { final PsiClass containingClass = method.getContainingClass(); final PsiClass[] classes = newFile.getClasses(); assert classes.length > 0 : classString; final PsiClass innerClass = (PsiClass)containingClass.add(classes[0]); PsiUtil.setModifierProperty(innerClass, PsiModifier.STATIC, true); return (PsiClass)JavaCodeStyleManager.getInstance(newFile.getProject()).shortenClassReferences(innerClass); } else { final PsiFile containingFile = method.getContainingFile(); final PsiDirectory containingDirectory = containingFile.getContainingDirectory(); final PsiDirectory directory; final MoveDestination moveDestination = getMoveDestination(); if (moveDestination != null) { directory = moveDestination.getTargetDirectory(containingDirectory); } else { final Module module = ModuleUtilCore.findModuleForPsiElement(containingFile); directory = PackageUtil.findOrCreateDirectoryForPackage(module, getPackageName(), containingDirectory, true, true); } if (directory != null) { PsiFile file = directory.findFile(newFile.getName()); if (file == null) { final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(method.getManager().getProject()); final PsiElement shortenedFile = JavaCodeStyleManager.getInstance(newFile.getProject()).shortenClassReferences(newFile); final PsiElement reformattedFile = codeStyleManager.reformat(shortenedFile); file = (PsiFile)directory.add(reformattedFile); } return ((PsiJavaFile)file).getClasses()[0]; } } } catch (IncorrectOperationException e) { LOG.error(e); } return null; }