PsiElement (PsiClass targetClass, GrEnumConstant constant, @Nullable PsiElement anchor) { if (targetClass instanceof GrEnumTypeDefinition enumeration) { final GrEnumConstantList constantList = enumeration.getEnumConstantList(); if (constantList != null) { ASTNode node = constantList.getNode(); node.addLeaf(GroovyTokenTypes.mCOMMA, ",", node.getFirstChildNode()); return constantList.addBefore(constant, constantList.getFirstChild()); } else { final PsiElement parent = constant.getParent(); assert parent instanceof GrEnumConstantList; final GrEnumConstantList constListCopy = ((GrEnumConstantList)targetClass.add(parent)); return constListCopy.getEnumConstants()[0]; } } return (anchor != null ? targetClass.addAfter(constant, anchor) : targetClass.add(constant)); }