Java Code Examples for com.intellij.util.LineSeparator#LF

The following examples show how to use com.intellij.util.LineSeparator#LF . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DiffUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: IoFileBasedStorage.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void doSave(@Nullable Element element) throws IOException {
  if (myLineSeparator == null) {
    myLineSeparator = isUseLfLineSeparatorByDefault() ? LineSeparator.LF : LineSeparator.getSystemLineSeparator();
  }

  byte[] content = element == null ? null : StorageUtil.writeToBytes(element, myLineSeparator.getSeparatorString());
  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);
  }
  else {
    FileUtil.createParentDirs(myFile);

    StorageUtil.writeFile(myFile, content, isUseXmlProlog() ? myLineSeparator : null);
  }
}
 
Example 3
Source File: ExternalDiffToolUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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;

  ThrowableComputable<String,RuntimeException> action = () -> {
    return content.getDocument().getText();
  };
  String contentData = AccessRule.read(action);
  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);
}
 
Example 4
Source File: Platform.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
default LineSeparator getLineSeparator() {
  if(isWindows()) {
    return LineSeparator.CRLF;
  }
  return LineSeparator.LF;
}
 
Example 5
Source File: StorageUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 6
Source File: VfsFileBasedStorage.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void doSave(@Nullable Element element) throws IOException {
  if (myLineSeparator == null) {
    myLineSeparator = isUseLfLineSeparatorByDefault() ? LineSeparator.LF : LineSeparator.getSystemLineSeparator();
  }

  byte[] content = element == null ? null : StorageUtil.writeToBytes(element, myLineSeparator.getSeparatorString());
  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);
  }
}
 
Example 7
Source File: ConvertToUnixLineSeparatorsAction.java    From consulo with Apache License 2.0 4 votes vote down vote up
public ConvertToUnixLineSeparatorsAction() {
  super(ApplicationBundle.message("combobox.crlf.unix"), LineSeparator.LF);
}