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

Java FormatterException类代码示例

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

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



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

示例1: validate

import com.google.googlejavaformat.java.FormatterException; //导入依赖的package包/类
@Override
public boolean validate(Path file) {
  if (!isJavaFile(file)) {
    log.get().debug(file + " is not a java file");
    return true;
  }

  log.get().info("Validating '" + file + "'");
  try (InputStream inputStream = Files.newInputStream(file)) {
    String unformatterContent = IOUtils.toString(inputStream);
    String formattedContent = new Formatter().formatSource(unformatterContent);
    return unformatterContent.equals(formattedContent);
  } catch (IOException | FormatterException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:Cosium,项目名称:maven-git-code-format,代码行数:17,代码来源:JavaFormatter.java


示例2: formatInternal

import com.google.googlejavaformat.java.FormatterException; //导入依赖的package包/类
private void formatInternal(Formatter formatter, PsiFile file, List<Range<Integer>> ranges)
    throws IncorrectOperationException {
  ApplicationManager.getApplication().assertWriteAccessAllowed();
  PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
  CheckUtil.checkWritable(file);

  Document document = PsiDocumentManager.getInstance(getProject()).getDocument(file);
  if (document != null) {
    try {
      List<Replacement> replacements =
          formatter
              .getFormatReplacements(document.getText(), ranges)
              .stream()
              .sorted(
                  comparing((Replacement r) -> r.getReplaceRange().lowerEndpoint()).reversed())
              .collect(Collectors.toList());
      performReplacements(document, replacements);
    } catch (FormatterException e) {
      // Do not format on errors
    }
  }
}
 
开发者ID:google,项目名称:google-java-format,代码行数:23,代码来源:GoogleJavaFormatCodeStyleManager.java


示例3: formatJava

import com.google.googlejavaformat.java.FormatterException; //导入依赖的package包/类
private static String formatJava(Context context, String src) throws FormatterException {
    AppSetting setting = new AppSetting(context);
    JavaFormatterOptions.Builder builder = JavaFormatterOptions.builder();
    builder.style(setting.getFormatType() == 0
            ? JavaFormatterOptions.Style.GOOGLE : JavaFormatterOptions.Style.AOSP);
    return new Formatter(builder.build()).formatSource(src);
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:8,代码来源:FormatFactory.java


示例4: openWriter

import com.google.googlejavaformat.java.FormatterException; //导入依赖的package包/类
@Override
public Writer openWriter() throws IOException {
  final StringBuilder stringBuilder = new StringBuilder(DEFAULT_FILE_SIZE);
  return new Writer() {
    @Override
    public void write(char[] chars, int start, int end) throws IOException {
      stringBuilder.append(chars, start, end - start);
    }

    @Override
    public void flush() throws IOException {}

    @Override
    public void close() throws IOException {
      try {
        formatter.formatSource(
            CharSource.wrap(stringBuilder),
            new CharSink() {
              @Override
              public Writer openStream() throws IOException {
                return fileObject.openWriter();
              }
            });
      } catch (FormatterException e) {
        // An exception will happen when the code being formatted has an error. It's better to
        // log the exception and emit unformatted code so the developer can view the code which
        // caused a problem.
        try (Writer writer = fileObject.openWriter()) {
          writer.append(stringBuilder.toString());
        }
        if (messager != null) {
          messager.printMessage(Diagnostic.Kind.NOTE, "Error formatting " + getName());
        }
      }
    }
  };
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:38,代码来源:FormattingJavaFileObject.java


示例5: formatJavaSource

import com.google.googlejavaformat.java.FormatterException; //导入依赖的package包/类
private static String formatJavaSource(
    final Formatter formatter, final Path javaFile, final String source) {
  final String formattedSource;
  try {
    formattedSource = formatter.formatSource(source);
  } catch (final FormatterException e) {
    throw new IllegalStateException("Could not format source in file " + javaFile, e);
  }
  return formattedSource;
}
 
开发者ID:spotify,项目名称:bazel-tools,代码行数:11,代码来源:Main.java


示例6: execute

import com.google.googlejavaformat.java.FormatterException; //导入依赖的package包/类
public List<String> execute(Parser parser, String astJson) {
    List<String> synthesizedPrograms = new LinkedList<>();
    List<DSubTree> asts = getASTsFromNN(astJson);

    classLoader = URLClassLoader.newInstance(parser.classpathURLs);

    CompilationUnit cu = parser.cu;
    List<String> programs = new ArrayList<>();
    for (DSubTree ast : asts) {
        Visitor visitor = new Visitor(ast, new Document(parser.source), cu, mode);
        try {
            cu.accept(visitor);
            if (visitor.synthesizedProgram == null)
                continue;
            String program = visitor.synthesizedProgram.replaceAll("\\s", "");
            if (! programs.contains(program)) {
                String formattedProgram = new Formatter().formatSource(visitor.synthesizedProgram);
                programs.add(program);
                synthesizedPrograms.add(formattedProgram);
            }
        } catch (SynthesisException|FormatterException e) {
            // do nothing and try next ast
        }
    }

    return synthesizedPrograms;
}
 
开发者ID:capergroup,项目名称:bayou,代码行数:28,代码来源:Synthesizer.java


示例7: formatGoogleStyle

import com.google.googlejavaformat.java.FormatterException; //导入依赖的package包/类
public static String formatGoogleStyle(final String content) {
  try {
    return getGoogleFormatter().formatSource(content);
  } catch (FormatterException e) {
    return content;
  }
}
 
开发者ID:mopemope,项目名称:meghanada-server,代码行数:8,代码来源:JavaFormatter.java


示例8: generateSource

import com.google.googlejavaformat.java.FormatterException; //导入依赖的package包/类
private static String generateSource(Metadata metadata, Feature<?>... features) {
  SourceBuilder sourceBuilder = SourceStringBuilder.simple(features);
  new CodeGenerator().writeBuilderSource(sourceBuilder, metadata);
  try {
    return new Formatter().formatSource(sourceBuilder.toString());
  } catch (FormatterException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:google,项目名称:FreeBuilder,代码行数:10,代码来源:DefaultedPropertiesSourceTest.java


示例9: maybeFormat

import com.google.googlejavaformat.java.FormatterException; //导入依赖的package包/类
private String maybeFormat(String input) {
  try {
    return new Formatter().formatSource(input);
  } catch (FormatterException e) {
    return input;
  }
}
 
开发者ID:google,项目名称:error-prone,代码行数:8,代码来源:BugCheckerRefactoringTestHelper.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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