PsiClass (@NotNull Project project, @NotNull PsiClass fromClass) { final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project); final PsiClass resultClass = elementFactory.createEnum(StringUtil.defaultIfEmpty(fromClass.getName(), "UnknownClassName")); copyModifiers(fromClass.getModifierList(), resultClass.getModifierList()); rebuildTypeParameter(fromClass, resultClass); final List<PsiField> fields = Arrays.asList(fromClass.getFields()); if (!fields.isEmpty()) { final Iterator<PsiField> iterator = fields.iterator(); PsiElement prev = resultClass.add(rebuildField(project, iterator.next())); while (iterator.hasNext()) { PsiField curr = iterator.next(); //guarantees order of enum constants, should match declaration order prev = resultClass.addAfter(rebuildField(project, curr), prev); } } for (PsiMethod psiMethod : fromClass.getMethods()) { final String psiMethodName = psiMethod.getName(); //skip Enum virtual methods if ("values".equals(psiMethodName) || "valueOf".equals(psiMethodName)) { continue; } resultClass.add(rebuildMethod(project, psiMethod)); } return resultClass; }