@NotNull private static File createTempFile(@NotNull final DocumentContent content, @NotNull String tempFileName) throws IOException { FileDocumentManager.getInstance().saveDocument(content.getDocument()); LineSeparator separator = content.getLineSeparator(); if (separator == null) separator = LineSeparator.getSystemLineSeparator(); Charset charset = content.getCharset(); if (charset == null) charset = Charset.defaultCharset(); String contentData = ApplicationManager.getApplication().runReadAction(new Computable<String>() { @Override public String compute() { return content.getDocument().getText(); } }); if (separator != LineSeparator.LF) { contentData = StringUtil.convertLineSeparators(contentData, separator.getSeparatorString()); } byte[] bytes = contentData.getBytes(charset); return createFile(bytes, tempFileName); }
@NotNull public static JComponent createTitle(@NotNull String title, @Nullable Charset charset, @Nullable LineSeparator separator, boolean readOnly) { if (readOnly) title += " " + DiffBundle.message("diff.content.read.only.content.title.suffix"); JPanel panel = new JPanel(new BorderLayout()); panel.setBorder(IdeBorderFactory.createEmptyBorder(0, 4, 0, 4)); panel.add(createTitlePanel(title), BorderLayout.CENTER); if (charset != null && separator != null) { JPanel panel2 = new JPanel(); panel2.setLayout(new BoxLayout(panel2, BoxLayout.X_AXIS)); panel2.add(createCharsetPanel(charset)); panel2.add(Box.createRigidArea(new Dimension(4, 0))); panel2.add(createSeparatorPanel(separator)); panel.add(panel2, BorderLayout.EAST); } else if (charset != null) { panel.add(createCharsetPanel(charset), BorderLayout.EAST); } else if (separator != null) { panel.add(createSeparatorPanel(separator), BorderLayout.EAST); } return panel; }
@NotNull private static JComponent createSeparatorPanel(@NotNull LineSeparator separator) { JLabel label = new JLabel(separator.name()); Color color; if (separator == LineSeparator.CRLF) { color = JBColor.RED; } else if (separator == LineSeparator.LF) { color = JBColor.BLUE; } else if (separator == LineSeparator.CR) { color = JBColor.MAGENTA; } else { color = JBColor.BLACK; } label.setForeground(color); return label; }
static JComponent createComponentForTitle(@Nullable String title, @Nullable final LineSeparator sep1, @Nullable final LineSeparator sep2, boolean left) { if (sep1 != null && sep2 != null && !sep1.equals(sep2)) { LineSeparator separator = left ? sep1 : sep2; JPanel bottomPanel = new JPanel(new BorderLayout()); JLabel sepLabel = new JLabel(separator.name()); sepLabel.setForeground(separator.equals(LineSeparator.CRLF) ? JBColor.RED : PlatformColors.BLUE); bottomPanel.add(sepLabel, left ? BorderLayout.EAST : BorderLayout.WEST); JPanel panel = new JPanel(new BorderLayout()); panel.add(new JLabel(title == null ? "" : title)); panel.add(bottomPanel, BorderLayout.SOUTH); return panel; } else { return new JBLabel(title == null ? "" : title); } }
@Test public void testDetectSeparators() { assertEquals(null, StringUtil.detectSeparators("")); assertEquals(null, StringUtil.detectSeparators("asd")); assertEquals(null, StringUtil.detectSeparators("asd\t")); assertEquals(LineSeparator.LF, StringUtil.detectSeparators("asd\n")); assertEquals(LineSeparator.LF, StringUtil.detectSeparators("asd\nads\r")); assertEquals(LineSeparator.LF, StringUtil.detectSeparators("asd\nads\n")); assertEquals(LineSeparator.CR, StringUtil.detectSeparators("asd\r")); assertEquals(LineSeparator.CR, StringUtil.detectSeparators("asd\rads\r")); assertEquals(LineSeparator.CR, StringUtil.detectSeparators("asd\rads\n")); assertEquals(LineSeparator.CRLF, StringUtil.detectSeparators("asd\r\n")); assertEquals(LineSeparator.CRLF, StringUtil.detectSeparators("asd\r\nads\r")); assertEquals(LineSeparator.CRLF, StringUtil.detectSeparators("asd\r\nads\n")); }
private void applySettings(VirtualFile file) { if (file == null) return; if (!Utils.isEnabled(CodeStyleSettingsManager.getInstance(myProject).getCurrentSettings())) return; final String filePath = Utils.getFilePath(myProject, file); final List<EditorConfig.OutPair> outPairs = SettingsProviderComponent.getInstance().getOutPairs(myProject, filePath); final String lineEndings = Utils.configValueForKey(outPairs, lineEndingsKey); if (!lineEndings.isEmpty()) { try { LineSeparator separator = LineSeparator.valueOf(lineEndings.toUpperCase(Locale.US)); String oldSeparator = file.getDetectedLineSeparator(); String newSeparator = separator.getSeparatorString(); if (!StringUtil.equals(oldSeparator, newSeparator)) { file.setDetectedLineSeparator(newSeparator); if (!statusBarUpdated) { statusBarUpdated = true; updateStatusBar(); } } } catch (IllegalArgumentException e) { Utils.invalidConfigMessage(myProject, lineEndings, lineEndingsKey, filePath); } } }
private void setTitles(@NotNull DiffRequest data) { LineSeparator sep1 = data.getContents()[0].getLineSeparator(); LineSeparator sep2 = data.getContents()[1].getLineSeparator(); String title1 = addReadOnly(data.getContentTitles()[0], myLeftSide.getEditor()); String title2 = addReadOnly(data.getContentTitles()[1], myRightSide.getEditor()); if (title1 != null && title2 != null && sep1 != null && sep2 != null && !sep1.equals(sep2)) { setTitle1(createComponentForTitle(title1, sep1, true)); setTitle2(createComponentForTitle(title2, sep2, false)); } else { setTitle1(new JBLabel(title1 == null ? "" : title1)); setTitle2(new JBLabel(title2 == null ? "" : title2)); } }
@NotNull private JPanel createMessagePanel(@Nullable LineSeparator sep1, @Nullable LineSeparator sep2) { String message; if (DiffUtil.oneIsUnknown(myRequest.getContents()[0], myRequest.getContents()[1])) { message = DiffBundle.message("diff.can.not.show.unknown"); } else if (LineSeparator.knownAndDifferent(sep1, sep2)) { message = DiffBundle.message("diff.contents.have.differences.only.in.line.separators.message.text"); } else { message = DiffBundle.message("diff.contents.are.identical.message.text"); } final JLabel label = new JLabel(message); label.setForeground(UIUtil.getInactiveTextColor()); final JPanel wrapper = new JPanel(new GridBagLayout()); wrapper.add(label, new GridBagConstraints(0,0,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(1,1,1,1), 0,0)); return wrapper; }
private int recalculateFileOffset(@NotNull PsiFile file, @NotNull PsiElement position, Editor editor) { int offset = position.getTextOffset();; VirtualFile virtualFile = file.getVirtualFile(); if (null == virtualFile) { // In memory file, the position doesn't change. return offset; } // Get the separator, checking the file if we don't know yet. May still return null. String separator = LoadTextUtil.detectLineSeparator(virtualFile, true); // IntelliJ IDEA normalizes file line endings, so if file line endings is // CRLF - then we have to shift an offset so Haxe compiler could get proper offset if (LineSeparator.CRLF.getSeparatorString().equals(separator)) { int lineNumber = com.intellij.openapi.util.text.StringUtil.offsetToLineNumber(editor.getDocument().getText(), offset); offset += lineNumber; } return offset; }
private void applySettings(VirtualFile file) { if (file == null || !file.isInLocalFileSystem()) return; final String filePath = file.getCanonicalPath(); final List<EditorConfig.OutPair> outPairs = SettingsProviderComponent.getInstance().getOutPairs(filePath); final String lineEndings = Utils.configValueForKey(outPairs, lineEndingsKey); if (!lineEndings.isEmpty()) { try { LineSeparator separator = LineSeparator.valueOf(lineEndings.toUpperCase(Locale.US)); String oldSeparator = file.getDetectedLineSeparator(); String newSeparator = separator.getSeparatorString(); if (!StringUtil.equals(oldSeparator, newSeparator)) { file.setDetectedLineSeparator(newSeparator); if (!statusBarUpdated) { statusBarUpdated = true; updateStatusBar(); } LOG.debug(Utils.appliedConfigMessage(lineEndings, lineEndingsKey, filePath)); } } catch (IllegalArgumentException e) { LOG.warn(Utils.invalidConfigMessage(lineEndings, lineEndingsKey, filePath)); } } }
@Nonnull public static JComponent createTitle(@Nonnull String title, @Nullable Charset charset, @Nullable LineSeparator separator, boolean readOnly) { if (readOnly) title += " " + DiffBundle.message("diff.content.read.only.content.title.suffix"); JPanel panel = new JPanel(new BorderLayout()); panel.setBorder(IdeBorderFactory.createEmptyBorder(0, 4, 0, 4)); panel.add(new JBLabel(title).setCopyable(true), BorderLayout.CENTER); if (charset != null && separator != null) { JPanel panel2 = new JPanel(); panel2.setLayout(new BoxLayout(panel2, BoxLayout.X_AXIS)); panel2.add(createCharsetPanel(charset)); panel2.add(Box.createRigidArea(new Dimension(4, 0))); panel2.add(createSeparatorPanel(separator)); panel.add(panel2, BorderLayout.EAST); } else if (charset != null) { panel.add(createCharsetPanel(charset), BorderLayout.EAST); } else if (separator != null) { panel.add(createSeparatorPanel(separator), BorderLayout.EAST); } return panel; }
@Nonnull private static JComponent createSeparatorPanel(@Nonnull LineSeparator separator) { JLabel label = new JLabel(separator.name()); Color color; if (separator == LineSeparator.CRLF) { color = JBColor.RED; } else if (separator == LineSeparator.LF) { color = JBColor.BLUE; } else if (separator == LineSeparator.CR) { color = JBColor.MAGENTA; } else { color = JBColor.BLACK; } label.setForeground(color); return label; }
@Nonnull private static DocumentContent createImpl(@Nullable Project project, @Nonnull String text, @Nullable FileType fileType, @javax.annotation.Nullable String fileName, @Nullable VirtualFile highlightFile, @javax.annotation.Nullable Charset charset, @javax.annotation.Nullable Boolean bom, boolean respectLineSeparators, boolean readOnly) { if (UnknownFileType.INSTANCE == fileType) fileType = PlainTextFileType.INSTANCE; // TODO: detect invalid (different across the file) separators ? LineSeparator separator = respectLineSeparators ? StringUtil.detectSeparators(text) : null; String correctedContent = StringUtil.convertLineSeparators(text); Document document = createDocument(project, correctedContent, fileType, fileName, readOnly); DocumentContent content = new DocumentContentImpl(project, document, fileType, highlightFile, separator, charset, bom); if (fileName != null) content.putUserData(DiffUserDataKeysEx.FILE_NAME, fileName); return content; }
@Nonnull private static DocumentContent createFromBytesImpl(@javax.annotation.Nullable Project project, @Nonnull byte[] content, @Nonnull FileType fileType, @Nonnull String fileName, @javax.annotation.Nullable VirtualFile highlightFile, @Nonnull Charset charset) { Charset bomCharset = CharsetToolkit.guessFromBOM(content); boolean isBOM = bomCharset != null; if (isBOM) charset = bomCharset; boolean malformedContent = false; String text = CharsetToolkit.tryDecodeString(content, charset); LineSeparator separator = StringUtil.detectSeparators(text); String correctedContent = StringUtil.convertLineSeparators(text); DocumentContent documentContent = createImpl(project, correctedContent, fileType, fileName, highlightFile, charset, isBOM, true, true); if (malformedContent) { String notificationText = "Content was decoded with errors (using " + "'" + charset.name() + "' charset)"; DiffUtil.addNotification(DiffNotifications.createNotification(notificationText, LightColors.RED), documentContent); } return documentContent; }
private void writeXposedInitFileInternal() { if (mXposedInitFile == null || !mXposedInitFile.exists()) { mXposedInitFile = createXposedInitFile(); } Charset charset = mXposedInitFile.getCharset(); String lineSep = mXposedInitFile.getDetectedLineSeparator(); if (lineSep == null) { lineSep = LineSeparator.getSystemLineSeparator().getSeparatorString(); } OutputStream out = null; OutputStreamWriter writer = null; try { out = mXposedInitFile.getOutputStream(this); writer = new OutputStreamWriter(out, charset); for (String hookClassNames : mDeclaredXposedHooks) { writer.write(hookClassNames); writer.write(lineSep); } } catch (IOException e) { throw new XposedPluginException("Failed to write to assets/xposed_init file", e); } finally { IOUtils.silentlyClose(writer); IOUtils.silentlyClose(out); } LOG.debug("Successfully wrote xposed_init file"); mLastModificationTime = mXposedInitFile.getTimeStamp(); }
public FileAwareDocumentContent(@Nullable Project project, @NotNull Document document, @Nullable FileType fileType, @Nullable VirtualFile highlightFile, @Nullable LineSeparator separator, @Nullable Charset charset) { super(document, fileType, highlightFile, separator, charset); myProject = project; }
public DocumentContentImpl(@NotNull Document document, @Nullable FileType type, @Nullable VirtualFile highlightFile, @Nullable LineSeparator separator, @Nullable Charset charset) { myDocument = document; myType = type; myHighlightFile = highlightFile; mySeparator = separator; myCharset = charset; }
@Nullable private static JComponent createTitle(@NotNull String title, @NotNull DiffContent content, boolean equalCharsets, boolean equalSeparators, @Nullable Editor editor) { if (content instanceof EmptyContent) return null; Charset charset = equalCharsets ? null : ((DocumentContent)content).getCharset(); LineSeparator separator = equalSeparators ? null : ((DocumentContent)content).getLineSeparator(); boolean isReadOnly = editor == null || editor.isViewer() || !canMakeWritable(editor.getDocument()); return createTitle(title, charset, separator, isReadOnly); }
@NotNull private static DocumentContent createImpl(@NotNull String text, @Nullable FileType type, @Nullable VirtualFile highlightFile, @Nullable Charset charset, boolean respectLineSeparators, boolean readOnly) { // TODO: detect invalid (different across the file) separators ? LineSeparator separator = respectLineSeparators ? StringUtil.detectSeparators(text) : null; Document document = EditorFactory.getInstance().createDocument(StringUtil.convertLineSeparators(text)); if (readOnly) document.setReadOnly(true); return new DocumentContentImpl(document, type, highlightFile, separator, charset); }
public static void changeLineSeparators(@NotNull final Project project, @NotNull final VirtualFile virtualFile, @NotNull final String newSeparator) { FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance(); Document document = fileDocumentManager.getCachedDocument(virtualFile); if (document != null) { fileDocumentManager.saveDocument(document); } String currentSeparator = LoadTextUtil.detectLineSeparator(virtualFile, false); final String commandText; if (StringUtil.isEmpty(currentSeparator)) { commandText = "Changed line separators to " + LineSeparator.fromString(newSeparator); } else { commandText = String.format("Changed line separators from %s to %s", LineSeparator.fromString(currentSeparator), LineSeparator.fromString(newSeparator)); } new WriteCommandAction(project, commandText) { @Override protected void run(@NotNull Result result) throws Throwable { try { LoadTextUtil.changeLineSeparators(project, virtualFile, newSeparator, this); } catch (IOException e) { LOG.info(e); } } }.execute(); }
@Override public String getDetectedLineSeparator() { if (getFlagInt(SYSTEM_LINE_SEPARATOR_DETECTED)) { return LineSeparator.getSystemLineSeparator().getSeparatorString(); } return super.getDetectedLineSeparator(); }
public void setFileContentsAreIdentical() { if (myTopMessageDiffPanel == null || myTopMessageDiffPanel instanceof FileContentsAreIdenticalDiffPanel) { LineSeparator sep1 = myData.getContent1() == null ? null : myData.getContent1().getLineSeparator(); LineSeparator sep2 = myData.getContent2() == null ? null : myData.getContent2().getLineSeparator(); if (LineSeparator.knownAndDifferent(sep1, sep2)) { myTopMessageDiffPanel = new LineSeparatorsOnlyDiffPanel(); } else { myTopMessageDiffPanel = new FileContentsAreIdenticalDiffPanel(); } myPanel.insertTopComponent(myTopMessageDiffPanel); } }
private void setTitles(@NotNull DiffRequest data) { LineSeparator sep1 = data.getContents()[0].getLineSeparator(); LineSeparator sep2 = data.getContents()[1].getLineSeparator(); String title1 = addReadOnly(data.getContentTitles()[0], myLeftSide.getEditor()); String title2 = addReadOnly(data.getContentTitles()[1], myRightSide.getEditor()); setTitle1(createComponentForTitle(title1, sep1, sep2, true)); setTitle2(createComponentForTitle(title2, sep1, sep2, false)); }
private static LineSeparator detectLineSeparators(String actual) { char[] chars = CharArrayUtil.fromSequence(actual); for (char c : chars) { if (c == '\r') { return LineSeparator.CRLF; } else if (c == '\n') { // if we are here, there was no \r before return LineSeparator.LF; } } return LineSeparator.LF; }
protected boolean sendData(@NotNull String data) { try { mySkipOneLine = true; myExecutor.write(data + LineSeparator.CRLF.getSeparatorString()); return true; } catch (SvnBindException e) { // TODO: handle this more carefully LOG.info(e); } return false; }
static JComponent createComponentForTitle(@Nullable String title, @NotNull final LineSeparator separator, boolean left) { JPanel bottomPanel = new JPanel(new BorderLayout()); JLabel sepLabel = new JLabel(separator.name()); sepLabel.setForeground(separator.equals(LineSeparator.CRLF) ? JBColor.RED : PlatformColors.BLUE); bottomPanel.add(sepLabel, left ? BorderLayout.EAST : BorderLayout.WEST); JPanel panel = new JPanel(new BorderLayout()); panel.add(new JLabel(title == null ? "" : title)); panel.add(bottomPanel, BorderLayout.SOUTH); return panel; }
public static void changeLineSeparators(@NotNull final Project project, @NotNull final VirtualFile virtualFile, @NotNull final String newSeparator) { FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance(); Document document = fileDocumentManager.getCachedDocument(virtualFile); if (document != null) { fileDocumentManager.saveDocument(document); } String currentSeparator = LoadTextUtil.detectLineSeparator(virtualFile, false); final String commandText; if (StringUtil.isEmpty(currentSeparator)) { commandText = "Changed line separators to " + LineSeparator.fromString(newSeparator); } else { commandText = String.format("Changed line separators from %s to %s", LineSeparator.fromString(currentSeparator), LineSeparator.fromString(newSeparator)); } CommandProcessor commandProcessor = CommandProcessor.getInstance(); commandProcessor.executeCommand(project, new Runnable() { @Override public void run() { try { LoadTextUtil.changeLineSeparators(project, virtualFile, newSeparator, this); } catch (IOException e) { LOG.warn(e); } } }, commandText, null); }
public DocumentContentImpl(@Nullable Project project, @Nonnull Document document, @Nullable FileType type, @Nullable VirtualFile highlightFile, @javax.annotation.Nullable LineSeparator separator, @Nullable Charset charset, @Nullable Boolean bom) { myProject = project; myDocument = document; myType = type; myHighlightFile = highlightFile; mySeparator = separator; myCharset = charset; myBOM = bom; }
@Nonnull private static File createTempFile(@Nonnull final DocumentContent content, @Nonnull FileNameInfo fileName) throws IOException { FileDocumentManager.getInstance().saveDocument(content.getDocument()); LineSeparator separator = content.getLineSeparator(); if (separator == null) separator = LineSeparator.getSystemLineSeparator(); Charset charset = content.getCharset(); if (charset == null) charset = Charset.defaultCharset(); Boolean hasBom = content.hasBom(); if (hasBom == null) hasBom = CharsetToolkit.getMandatoryBom(charset) != null; String contentData = ReadAction.compute(() -> { return content.getDocument().getText(); }); if (separator != LineSeparator.LF) { contentData = StringUtil.convertLineSeparators(contentData, separator.getSeparatorString()); } byte[] bytes = contentData.getBytes(charset); byte[] bom = hasBom ? CharsetToolkit.getPossibleBom(charset) : null; if (bom != null) { bytes = ArrayUtil.mergeArrays(bom, bytes); } return createFile(bytes, fileName); }
@Nullable private static JComponent createTitle(@Nonnull String title, @Nonnull DiffContent content, boolean equalCharsets, boolean equalSeparators, @Nullable Editor editor) { if (content instanceof EmptyContent) return null; Charset charset = equalCharsets ? null : ((DocumentContent)content).getCharset(); LineSeparator separator = equalSeparators ? null : ((DocumentContent)content).getLineSeparator(); boolean isReadOnly = editor == null || editor.isViewer() || !canMakeWritable(editor.getDocument()); return createTitle(title, charset, separator, isReadOnly); }
private void setTitles(@Nonnull DiffRequest data) { LineSeparator sep1 = data.getContents()[0].getLineSeparator(); LineSeparator sep2 = data.getContents()[1].getLineSeparator(); String title1 = addReadOnly(data.getContentTitles()[0], myLeftSide.getEditor()); String title2 = addReadOnly(data.getContentTitles()[1], myRightSide.getEditor()); setTitle1(createComponentForTitle(title1, sep1, sep2, true)); setTitle2(createComponentForTitle(title2, sep1, sep2, false)); }
@Nonnull public static VirtualFile writeFile(@Nullable File file, @Nonnull Object requestor, @Nullable VirtualFile virtualFile, @Nonnull BufferExposingByteArrayOutputStream content, @Nullable LineSeparator lineSeparatorIfPrependXmlProlog) throws IOException { AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(StorageUtil.class); try { if (file != null && (virtualFile == null || !virtualFile.isValid())) { virtualFile = getOrCreateVirtualFile(requestor, file); } assert virtualFile != null; OutputStream out = virtualFile.getOutputStream(requestor); try { if (lineSeparatorIfPrependXmlProlog != null) { out.write(XML_PROLOG); out.write(lineSeparatorIfPrependXmlProlog.getSeparatorBytes()); } content.writeTo(out); } finally { out.close(); } return virtualFile; } catch (FileNotFoundException e) { if (virtualFile == null) { throw e; } else { throw new ReadOnlyModificationException(virtualFile); } } finally { token.finish(); } }
@Nonnull public static LineSeparator detectLineSeparators(@Nonnull CharSequence chars, @Nullable LineSeparator defaultSeparator) { for (int i = 0, n = chars.length(); i < n; i++) { char c = chars.charAt(i); if (c == '\r') { return LineSeparator.CRLF; } else if (c == '\n') { // if we are here, there was no \r before return LineSeparator.LF; } } return defaultSeparator == null ? LineSeparator.getSystemLineSeparator() : defaultSeparator; }
@Override protected void doSave(@Nullable Element element) throws IOException { if (myLineSeparator == null) { myLineSeparator = isUseLfLineSeparatorByDefault() ? LineSeparator.LF : LineSeparator.getSystemLineSeparator(); } BufferExposingByteArrayOutputStream content = element == null ? null : StorageUtil.writeToBytes(element, myLineSeparator.getSeparatorString()); if (ApplicationManager.getApplication().isUnitTestMode() && StringUtil.startsWithChar(myFile.getPath(), '$')) { throw new StateStorageException("It seems like some macros were not expanded for path: " + myFile.getPath()); } try { if (myStreamProvider != null && myStreamProvider.isEnabled()) { // stream provider always use LF separator saveForProvider(myLineSeparator == LineSeparator.LF ? content : null, element); } } catch (Throwable e) { LOG.error(e); } if (content == null) { StorageUtil.deleteFile(myFile, this, getVirtualFile()); myCachedVirtualFile = null; } else { VirtualFile file = getVirtualFile(); if (file == null || !file.exists()) { FileUtil.createParentDirs(myFile); file = null; } myCachedVirtualFile = StorageUtil.writeFile(myFile, this, file, content, isUseXmlProlog() ? myLineSeparator : null); } }
public static void changeLineSeparators(@Nonnull final Project project, @Nonnull final VirtualFile virtualFile, @Nonnull final String newSeparator) { FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance(); Document document = fileDocumentManager.getCachedDocument(virtualFile); if (document != null) { fileDocumentManager.saveDocument(document); } String currentSeparator = LoadTextUtil.detectLineSeparator(virtualFile, false); final String commandText; if (StringUtil.isEmpty(currentSeparator)) { commandText = "Changed line separators to " + LineSeparator.fromString(newSeparator); } else { commandText = String.format("Changed line separators from %s to %s", LineSeparator.fromString(currentSeparator), LineSeparator.fromString(newSeparator)); } new WriteCommandAction(project, commandText) { @Override protected void run(@Nonnull Result result) throws Throwable { try { LoadTextUtil.changeLineSeparators(project, virtualFile, newSeparator, this); } catch (IOException e) { LOG.info(e); } } }.execute(); }
@Nullable @Override public LineSeparator getLineSeparator() { return null; }
@Nullable private static LineSeparator getSeparator(@NotNull VirtualFile file) { String s = LoadTextUtil.detectLineSeparator(file, true); if (s == null) return null; return LineSeparator.fromString(s); }