void (@NotNull PsiElement psiFile, @NotNull GrImportStatement result) { final CodeStyleSettings rootSettings = CodeStyle.getSettings(psiFile.getContainingFile()); final GroovyCodeStyleSettings settings = rootSettings.getCustomSettings(GroovyCodeStyleSettings.class); final PackageEntryTable layoutTable = settings.IMPORT_LAYOUT_TABLE; final PackageEntry[] entries = layoutTable.getEntries(); PsiElement prev = result.getPrevSibling(); while (PsiImplUtil.isWhiteSpaceOrNls(prev)) { prev = prev.getPrevSibling(); } if (PsiImplUtil.hasElementType(prev, GroovyTokenTypes.mSEMI)) prev = prev.getPrevSibling(); if (PsiImplUtil.isWhiteSpaceOrNls(prev)) prev = prev.getPrevSibling(); ASTNode node = psiFile.getNode(); if (prev instanceof GrImportStatement) { final int idx_before = getPackageEntryIdx(entries, (GrImportStatement)prev); final int idx = getPackageEntryIdx(entries, result); final int spaceCount = getMaxSpaceCount(entries, idx_before, idx); //skip space and semicolon after import if (PsiImplUtil.isWhiteSpaceOrNls(prev.getNextSibling()) && PsiImplUtil .hasElementType(prev.getNextSibling().getNextSibling(), GroovyTokenTypes.mSEMI)) prev = prev.getNextSibling().getNextSibling(); while (PsiImplUtil.isWhiteSpaceOrNls(prev.getNextSibling())) { node.removeChild(prev.getNextSibling().getNode()); } node.addLeaf(GroovyTokenTypes.mNLS, StringUtil.repeat("\n", spaceCount + 1), result.getNode()); } else if (prev instanceof GrPackageDefinition) { node.addLeaf(GroovyTokenTypes.mNLS, StringUtil.repeat("\n", rootSettings.getCommonSettings(GroovyLanguage.INSTANCE).BLANK_LINES_AFTER_PACKAGE), result.getNode()); } }