当前位置: 首页>>代码示例>>Java>>正文


Java LoadTextUtil.detectLineSeparator方法代码示例

本文整理汇总了Java中com.intellij.openapi.fileEditor.impl.LoadTextUtil.detectLineSeparator方法的典型用法代码示例。如果您正苦于以下问题:Java LoadTextUtil.detectLineSeparator方法的具体用法?Java LoadTextUtil.detectLineSeparator怎么用?Java LoadTextUtil.detectLineSeparator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.openapi.fileEditor.impl.LoadTextUtil的用法示例。


在下文中一共展示了LoadTextUtil.detectLineSeparator方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: recalculateFileOffset

import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的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

示例2: changeLineSeparators

import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的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

示例3: buildVisitor

import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
  return new PsiElementVisitor() {
    @Override
    public void visitFile(PsiFile file) {
      if (!file.getLanguage().equals(file.getViewProvider().getBaseLanguage())) {
        // There is a possible case that more than a single virtual file/editor contains more than one language (e.g. php and html).
        // We want to process a virtual file once than, hence, ignore all non-base psi files.
        return;
      }

      final Project project = holder.getProject();
      final String projectLineSeparator = FileDocumentManager.getInstance().getLineSeparator(null, project);

      final VirtualFile virtualFile = file.getVirtualFile();
      if (virtualFile == null || !AbstractConvertLineSeparatorsAction.shouldProcess(virtualFile, project)) {
        return;
      }

      final String curLineSeparator = LoadTextUtil.detectLineSeparator(virtualFile, true);
      if (curLineSeparator != null && !curLineSeparator.equals(projectLineSeparator)) {
        holder.registerProblem(
          file,
          "Line separators in the current file (" + StringUtil.escapeStringCharacters(curLineSeparator) + ") " +
          "differ from the project defaults (" + StringUtil.escapeStringCharacters(projectLineSeparator) + ")",
          SET_PROJECT_LINE_SEPARATORS);
      }
    }
  };
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:32,代码来源:InconsistentLineSeparatorsInspection.java

示例4: appendToFile

import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
public static void appendToFile(@NotNull VirtualFile file, @NotNull String text) throws IOException {
  String lineSeparator = LoadTextUtil.detectLineSeparator(file, true);
  if (lineSeparator == null) {
    lineSeparator = CodeStyleSettingsManager.getSettings(ProjectManagerEx.getInstanceEx().getDefaultProject()).getLineSeparator();
  }
  final String existingText = StringUtil.trimTrailing(VfsUtilCore.loadText(file));
  String content = (StringUtil.isNotEmpty(existingText) ? existingText + lineSeparator : "") +
                   StringUtil.convertLineSeparators(text, lineSeparator);
  VfsUtil.saveText(file, content);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:GradleModuleBuilder.java

示例5: changeLineSeparators

import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的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));
  }

  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);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:34,代码来源:AbstractConvertLineSeparatorsAction.java

示例6: buildVisitor

import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
  return new PsiElementVisitor() {
    @Override
    public void visitFile(PsiFile file) {
      if (!file.getLanguage().equals(file.getViewProvider().getBaseLanguage())) {
        // There is a possible case that more than a single virtual file/editor contains more than one language (e.g. php and html).
        // We want to process a virtual file once than, hence, ignore all non-base psi files.
        return;
      }

      final Project project = holder.getProject();
      final String projectLineSeparator = CodeStyleFacade.getInstance(project).getLineSeparator();
      if (projectLineSeparator == null) {
        return;
      }

      final VirtualFile virtualFile = file.getVirtualFile();
      if (virtualFile == null || !AbstractConvertLineSeparatorsAction.shouldProcess(virtualFile, project)) {
        return;
      }

      final String curLineSeparator = LoadTextUtil.detectLineSeparator(virtualFile, true);
      if (curLineSeparator != null && !curLineSeparator.equals(projectLineSeparator)) {
        holder.registerProblem(
          file,
          "Line separators in the current file (" + StringUtil.escapeStringCharacters(curLineSeparator) + ") " +
          "differ from the project defaults (" + StringUtil.escapeStringCharacters(projectLineSeparator) + ")",
          SET_PROJECT_LINE_SEPARATORS);
      }
    }
  };
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:35,代码来源:InconsistentLineSeparatorsInspection.java

示例7: changeLineSeparators

import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
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();
}
 
开发者ID:consulo,项目名称:consulo,代码行数:32,代码来源:AbstractConvertLineSeparatorsAction.java

示例8: buildVisitor

import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
@Nonnull
@Override
public PsiElementVisitor buildVisitor(@Nonnull final ProblemsHolder holder, boolean isOnTheFly) {
  return new PsiElementVisitor() {
    @Override
    public void visitFile(PsiFile file) {
      if (!file.getLanguage().equals(file.getViewProvider().getBaseLanguage())) {
        // There is a possible case that more than a single virtual file/editor contains more than one language (e.g. php and html).
        // We want to process a virtual file once than, hence, ignore all non-base psi files.
        return;
      }

      final Project project = holder.getProject();
      final String projectLineSeparator = CodeStyleFacade.getInstance(project).getLineSeparator();
      if (projectLineSeparator == null) {
        return;
      }

      final VirtualFile virtualFile = file.getVirtualFile();
      if (virtualFile == null || !AbstractConvertLineSeparatorsAction.shouldProcess(virtualFile, project)) {
        return;
      }

      final String curLineSeparator = LoadTextUtil.detectLineSeparator(virtualFile, true);
      if (curLineSeparator != null && !curLineSeparator.equals(projectLineSeparator)) {
        holder.registerProblem(
          file,
          "Line separators in the current file (" + StringUtil.escapeStringCharacters(curLineSeparator) + ") " +
          "differ from the project defaults (" + StringUtil.escapeStringCharacters(projectLineSeparator) + ")",
          SET_PROJECT_LINE_SEPARATORS);
      }
    }
  };
}
 
开发者ID:consulo,项目名称:consulo,代码行数:35,代码来源:InconsistentLineSeparatorsInspection.java

示例9: getSeparator

import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
@Nullable
private static LineSeparator getSeparator(@NotNull VirtualFile file) {
  String s = LoadTextUtil.detectLineSeparator(file, true);
  if (s == null) return null;
  return LineSeparator.fromString(s);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:FileDocumentContentImpl.java

示例10: getLineSeparator

import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
@Nullable
@Override
public String getLineSeparator(@NotNull VirtualFile file, boolean detect) {
  return LoadTextUtil.detectLineSeparator(file, detect);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:6,代码来源:DvcsPlatformFacadeImpl.java

示例11: getSeparator

import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
@javax.annotation.Nullable
private static LineSeparator getSeparator(@Nonnull VirtualFile file) {
  String s = LoadTextUtil.detectLineSeparator(file, true);
  if (s == null) return null;
  return LineSeparator.fromString(s);
}
 
开发者ID:consulo,项目名称:consulo,代码行数:7,代码来源:FileDocumentContentImpl.java

示例12: getLineSeparator

import com.intellij.openapi.fileEditor.impl.LoadTextUtil; //导入方法依赖的package包/类
@Nullable
@Override
public String getLineSeparator(@Nonnull VirtualFile file, boolean detect) {
  return LoadTextUtil.detectLineSeparator(file, detect);
}
 
开发者ID:consulo,项目名称:consulo,代码行数:6,代码来源:DvcsPlatformFacadeImpl.java


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