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


Java CodeFormatterFacade类代码示例

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


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

示例1: performOnElement

import com.intellij.psi.impl.source.codeStyle.CodeFormatterFacade; //导入依赖的package包/类
protected void performOnElement(@NotNull final PsiElement element, @NotNull final Editor editor) {
  final Document document = editor.getDocument();

  final TextRange textRange = getTextRange(element, editor);
  if (textRange.isEmpty()) return;
  final String text = textRange.substring(element.getContainingFile().getText());

  final List<String> subStrings = StringUtil.split(text, "\n", true);
  final String prefix = getPrefix(element);
  final String postfix = getPostfix(element);

  final StringBuilder stringBuilder = new StringBuilder();
  appendPrefix(element, text, stringBuilder);

  for (String string : subStrings) {
    final String startTrimmed = StringUtil.trimStart(string.trim(), prefix.trim());
    final String str = StringUtil.trimEnd(startTrimmed, postfix.trim());
    final String finalString = str.trim();
    if (!StringUtil.isEmptyOrSpaces(finalString))
      stringBuilder.append(finalString).append(" ");
  }
  appendPostfix(element, text, stringBuilder);

  final String replacementText = stringBuilder.toString();

  CommandProcessor.getInstance().executeCommand(element.getProject(), new Runnable() {
    @Override
    public void run() {
      document.replaceString(textRange.getStartOffset(), textRange.getEndOffset(),
                             replacementText);
      final CodeFormatterFacade codeFormatter = new CodeFormatterFacade(
                                      CodeStyleSettingsManager.getSettings(element.getProject()), element.getLanguage());
      codeFormatter.doWrapLongLinesIfNecessary(editor, element.getProject(), document,
                                               textRange.getStartOffset(),
                                               textRange.getStartOffset() + replacementText.length() + 1);
    }
  }, null, document);

}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:40,代码来源:ParagraphFillHandler.java

示例2: getFormatterFacade

import com.intellij.psi.impl.source.codeStyle.CodeFormatterFacade; //导入依赖的package包/类
@NotNull
private CodeFormatterFacade getFormatterFacade(@NotNull FileViewProvider viewProvider) {
  final CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(myPsiManager.getProject());
  final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myPsiManager.getProject());
  final Document document = viewProvider.getDocument();
  assert document != null;
  final CodeFormatterFacade codeFormatter = new CodeFormatterFacade(styleSettings, viewProvider.getBaseLanguage());

  documentManager.commitDocument(document);
  return codeFormatter;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:PostprocessReformattingAspect.java

示例3: performOnElement

import com.intellij.psi.impl.source.codeStyle.CodeFormatterFacade; //导入依赖的package包/类
protected void performOnElement(@NotNull final PsiElement element, @NotNull final Editor editor) {
  final Document document = editor.getDocument();

  final TextRange textRange = getTextRange(element, editor);
  if (textRange.isEmpty()) return;
  final String text = textRange.substring(element.getContainingFile().getText());

  final List<String> subStrings = StringUtil.split(text, "\n", true);
  final String prefix = getPrefix(element);
  final String postfix = getPostfix(element);

  final StringBuilder stringBuilder = new StringBuilder();
  appendPrefix(element, text, stringBuilder);

  for (String string : subStrings) {
    final String startTrimmed = StringUtil.trimStart(string.trim(), prefix.trim());
    final String str = StringUtil.trimEnd(startTrimmed, postfix.trim());
    final String finalString = str.trim();
    if (!StringUtil.isEmptyOrSpaces(finalString))
      stringBuilder.append(finalString).append(" ");
  }
  appendPostfix(element, text, stringBuilder);

  final String replacementText = stringBuilder.toString();

  CommandProcessor.getInstance().executeCommand(element.getProject(), new Runnable() {
    @Override
    public void run() {
      document.replaceString(textRange.getStartOffset(), textRange.getEndOffset(),
                             replacementText);
      final CodeFormatterFacade codeFormatter = new CodeFormatterFacade(
                                      CodeStyleSettingsManager.getSettings(element.getProject()));
      codeFormatter.doWrapLongLinesIfNecessary(editor, element.getProject(), document,
                                               textRange.getStartOffset(),
                                               textRange.getStartOffset() + replacementText.length() + 1);
    }
  }, null, document);

}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:40,代码来源:ParagraphFillHandler.java

示例4: getFormatterFacade

import com.intellij.psi.impl.source.codeStyle.CodeFormatterFacade; //导入依赖的package包/类
private CodeFormatterFacade getFormatterFacade(final FileViewProvider viewProvider) {
  final CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(myPsiManager.getProject());
  final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myPsiManager.getProject());
  final Document document = viewProvider.getDocument();
  assert document != null;
  final CodeFormatterFacade codeFormatter = new CodeFormatterFacade(styleSettings);

  documentManager.commitDocument(document);
  return codeFormatter;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:11,代码来源:PostprocessReformattingAspect.java

示例5: getFormatterFacade

import com.intellij.psi.impl.source.codeStyle.CodeFormatterFacade; //导入依赖的package包/类
@Nonnull
private CodeFormatterFacade getFormatterFacade(@Nonnull FileViewProvider viewProvider) {
  final CodeStyleSettings styleSettings = CodeStyle.getSettings(viewProvider.getPsi(viewProvider.getBaseLanguage()));
  final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(myPsiManager.getProject());
  final Document document = viewProvider.getDocument();
  assert document != null;
  final CodeFormatterFacade codeFormatter = new CodeFormatterFacade(styleSettings, viewProvider.getBaseLanguage());

  documentManager.commitDocument(document);
  return codeFormatter;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:12,代码来源:PostprocessReformattingAspect.java

示例6: execute

import com.intellij.psi.impl.source.codeStyle.CodeFormatterFacade; //导入依赖的package包/类
@Override
public void execute(@NotNull FileViewProvider viewProvider) {
  final CodeFormatterFacade codeFormatter = getFormatterFacade(viewProvider);
  codeFormatter.setReformatContext(true);
  codeFormatter.processText(viewProvider.getPsi(viewProvider.getBaseLanguage()), myRanges.ensureNonEmpty(), false);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:PostprocessReformattingAspect.java

示例7: execute

import com.intellij.psi.impl.source.codeStyle.CodeFormatterFacade; //导入依赖的package包/类
@Override
public void execute(FileViewProvider viewProvider) {
  final CodeFormatterFacade codeFormatter = getFormatterFacade(viewProvider);
  codeFormatter.processText(viewProvider.getPsi(viewProvider.getBaseLanguage()), myRanges.ensureNonEmpty(), false);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:6,代码来源:PostprocessReformattingAspect.java

示例8: performOnElement

import com.intellij.psi.impl.source.codeStyle.CodeFormatterFacade; //导入依赖的package包/类
protected void performOnElement(@Nonnull final PsiElement element, @Nonnull final Editor editor) {
  final Document document = editor.getDocument();

  final TextRange textRange = getTextRange(element, editor);
  if (textRange.isEmpty()) return;
  final String text = textRange.substring(element.getContainingFile().getText());

  final List<String> subStrings = StringUtil.split(text, "\n", true);
  final String prefix = getPrefix(element);
  final String postfix = getPostfix(element);

  final StringBuilder stringBuilder = new StringBuilder();
  appendPrefix(element, text, stringBuilder);

  for (String string : subStrings) {
    final String startTrimmed = StringUtil.trimStart(string.trim(), prefix.trim());
    final String str = StringUtil.trimEnd(startTrimmed, postfix.trim());
    final String finalString = str.trim();
    if (!StringUtil.isEmptyOrSpaces(finalString))
      stringBuilder.append(finalString).append(" ");
  }
  appendPostfix(element, text, stringBuilder);

  final String replacementText = stringBuilder.toString();

  CommandProcessor.getInstance().executeCommand(element.getProject(), () -> {
    document.replaceString(textRange.getStartOffset(), textRange.getEndOffset(),
                           replacementText);
    final CodeFormatterFacade codeFormatter = new CodeFormatterFacade(
            CodeStyleSettingsManager.getSettings(element.getProject()), element.getLanguage());

    final PsiFile file = element.getContainingFile();
    FormatterTagHandler formatterTagHandler = new FormatterTagHandler(CodeStyleSettingsManager.getSettings(file.getProject()));
    List<TextRange> enabledRanges = formatterTagHandler.getEnabledRanges(file.getNode(), TextRange.create(0, document.getTextLength()));

    codeFormatter.doWrapLongLinesIfNecessary(editor, element.getProject(), document,
                                             textRange.getStartOffset(),
                                             textRange.getStartOffset() + replacementText.length() + 1,
                                             enabledRanges);
  }, null, document);

}
 
开发者ID:consulo,项目名称:consulo,代码行数:43,代码来源:ParagraphFillHandler.java

示例9: execute

import com.intellij.psi.impl.source.codeStyle.CodeFormatterFacade; //导入依赖的package包/类
@Override
public void execute(@Nonnull FileViewProvider viewProvider) {
  final CodeFormatterFacade codeFormatter = getFormatterFacade(viewProvider);
  codeFormatter.setReformatContext(true);
  codeFormatter.processText(viewProvider.getPsi(viewProvider.getBaseLanguage()), myRanges.ensureNonEmpty(), false);
}
 
开发者ID:consulo,项目名称:consulo,代码行数:7,代码来源:PostprocessReformattingAspect.java


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