GrVariableDeclaration (String @Nullable [] modifiers, @Nullable String initializer, @Nullable PsiType type, String... identifiers) { @NlsSafe StringBuilder text = writeModifiers(modifiers); if (type != null && type != PsiTypes.nullType()) { final PsiType unboxed = TypesUtil.unboxPrimitiveTypeWrapper(type); final String typeText = getTypeText(unboxed); text.append(typeText).append(" "); } else if (text.length() == 0) { text.insert(0, "def "); } if (identifiers.length > 1 && initializer != null) { text.append('('); } text.append(String.join(", ", identifiers)); if (identifiers.length > 1 && initializer != null) { text.append(')'); } if (!StringUtil.isEmptyOrSpaces(initializer)) { text.append(" = ").append(initializer); } GrTopStatement[] topStatements = createGroovyFileChecked(text).getTopStatements(); if (topStatements.length == 0 || !(topStatements[0] instanceof GrVariableDeclaration)) { topStatements = createGroovyFileChecked("def " + text).getTopStatements(); } if (topStatements.length == 0 || !(topStatements[0] instanceof GrVariableDeclaration statement)) { throw new RuntimeException("Invalid arguments, text = " + text); } //todo switch-case formatting should work without this hack CodeEditUtil.markToReformatBefore(statement.getNode().findLeafElementAt(0), true); return statement; }