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


Java AppliedFix.getNewCodeSnippet方法代码示例

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


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

示例1: onDescribed

import com.google.errorprone.fixes.AppliedFix; //导入方法依赖的package包/类
@Override
public void onDescribed(Description description) {
  JavaFileObject originalSource;
  // Swap the log's source and the current file's source; then be sure to swap them back later.
  originalSource = log.useSource(sourceFile);
  try {
    CharSequence content = sourceFile.getCharContent(true);

    // If endPositions were not computed (-Xjcov option was not passed), reparse the file
    // and compute the end positions so we can generate suggested fixes.
    if (endPositions == null) {
      boolean prevGenEndPos = compiler.genEndPos;
      compiler.genEndPos = true;
      // Reset the end positions for JDK8:
      JDKCompatible.resetEndPosMap(compiler, sourceFile);
      ErrorProneEndPosMap endPosMap = JDKCompatible.getEndPosMap(compiler.parse(sourceFile));
      compiler.genEndPos = prevGenEndPos;
      endPositions = new WrappedTreeMap(log, endPosMap);
    }

    AppliedFix fix = null;
    if (description.suggestedFix != null) {
      fix = AppliedFix.fromSource(content, endPositions).apply(description.suggestedFix);
    }
    final String message;
    if (description.suggestedFix == null || fix == null) {
      message = description.message;
    } else {
      if (fix.isRemoveLine()) {
        message = description.message + "\nDid you mean to remove this line?";
      } else {
        message = description.message + "\nDid you mean '" + fix.getNewCodeSnippet() + "'?";
      }
    }
    switch (description.severity) {
      case ERROR:
        log.error((DiagnosticPosition) description.node, MESSAGE_BUNDLE_KEY, message);
        break;
      case WARNING:
        log.warning((DiagnosticPosition) description.node, MESSAGE_BUNDLE_KEY, message);
        break;
      default:
        break;
    }
  } catch (IOException e) {
    throw new RuntimeException(e);
  } finally {
    if (originalSource != null) {
      log.useSource(originalSource);
    }
  }
}
 
开发者ID:diy1,项目名称:error-prone-aspirator,代码行数:53,代码来源:JavacErrorDescriptionListener.java


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