• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java LineSeparator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.intellij.util.LineSeparator的典型用法代码示例。如果您正苦于以下问题:Java LineSeparator类的具体用法?Java LineSeparator怎么用?Java LineSeparator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



LineSeparator类属于com.intellij.util包,在下文中一共展示了LineSeparator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createTempFile

import com.intellij.util.LineSeparator; //导入依赖的package包/类
@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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:ExternalDiffToolUtil.java


示例2: createTitle

import com.intellij.util.LineSeparator; //导入依赖的package包/类
@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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:DiffUtil.java


示例3: createSeparatorPanel

import com.intellij.util.LineSeparator; //导入依赖的package包/类
@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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:DiffUtil.java


示例4: createComponentForTitle

import com.intellij.util.LineSeparator; //导入依赖的package包/类
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);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:DiffPanelImpl.java


示例5: testDetectSeparators

import com.intellij.util.LineSeparator; //导入依赖的package包/类
@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"));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:StringUtilTest.java


示例6: applySettings

import com.intellij.util.LineSeparator; //导入依赖的package包/类
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);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:LineEndingsManager.java


示例7: setTitles

import com.intellij.util.LineSeparator; //导入依赖的package包/类
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));
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:17,代码来源:DiffPanelImpl.java


示例8: createMessagePanel

import com.intellij.util.LineSeparator; //导入依赖的package包/类
@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;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:20,代码来源:EmptyDiffViewer.java


示例9: recalculateFileOffset

import com.intellij.util.LineSeparator; //导入依赖的package包/类
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;
}
 
开发者ID:HaxeFoundation,项目名称:intellij-haxe,代码行数:21,代码来源:HaxeCompilerServices.java


示例10: applySettings

import com.intellij.util.LineSeparator; //导入依赖的package包/类
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));
        }
    }
}
 
开发者ID:editorconfig,项目名称:editorconfig-jetbrains,代码行数:25,代码来源:LineEndingsManager.java


示例11: createTitle

import com.intellij.util.LineSeparator; //导入依赖的package包/类
@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;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:27,代码来源:DiffUtil.java


示例12: createSeparatorPanel

import com.intellij.util.LineSeparator; //导入依赖的package包/类
@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;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:20,代码来源:DiffUtil.java


示例13: createImpl

import com.intellij.util.LineSeparator; //导入依赖的package包/类
@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;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:24,代码来源:DiffContentFactoryImpl.java


示例14: createFromBytesImpl

import com.intellij.util.LineSeparator; //导入依赖的package包/类
@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;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:27,代码来源:DiffContentFactoryImpl.java


示例15: createComponentForTitle

import com.intellij.util.LineSeparator; //导入依赖的package包/类
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);
  }
}
 
开发者ID:consulo,项目名称:consulo,代码行数:18,代码来源:DiffPanelImpl.java


示例16: writeXposedInitFileInternal

import com.intellij.util.LineSeparator; //导入依赖的package包/类
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();
}
 
开发者ID:apsun,项目名称:XposedPlugin,代码行数:31,代码来源:XposedInitAssetManager.java


示例17: FileAwareDocumentContent

import com.intellij.util.LineSeparator; //导入依赖的package包/类
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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:FileAwareDocumentContent.java


示例18: DocumentContentImpl

import com.intellij.util.LineSeparator; //导入依赖的package包/类
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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:DocumentContentImpl.java


示例19: createImpl

import com.intellij.util.LineSeparator; //导入依赖的package包/类
@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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:DiffContentFactoryImpl.java


示例20: changeLineSeparators

import com.intellij.util.LineSeparator; //导入依赖的package包/类
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();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:33,代码来源:AbstractConvertLineSeparatorsAction.java



注:本文中的com.intellij.util.LineSeparator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EnvironmentOutcome类代码示例发布时间:2022-05-23
下一篇:
Java IAggregatableStream类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap