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


Java AppliedFix类代码示例

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


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

示例1: messageForFixes

import com.google.errorprone.fixes.AppliedFix; //导入依赖的package包/类
private static String messageForFixes(Description description, List<AppliedFix> appliedFixes) {
  StringBuilder messageBuilder = new StringBuilder(description.getMessage());
  boolean first = true;
  for (AppliedFix appliedFix : appliedFixes) {
    if (first) {
      messageBuilder.append("\nDid you mean ");
    } else {
      messageBuilder.append(" or ");
    }
    if (appliedFix.isRemoveLine()) {
      messageBuilder.append("to remove this line");
    } else {
      messageBuilder.append("'").append(appliedFix.getNewCodeSnippet()).append("'");
    }
    first = false;
  }
  if (!first) { // appended at least one suggested fix to the message
    messageBuilder.append("?");
  }
  return messageBuilder.toString();
}
 
开发者ID:google,项目名称:error-prone,代码行数:22,代码来源:JavacErrorDescriptionListener.java

示例2: JavacErrorDescriptionListener

import com.google.errorprone.fixes.AppliedFix; //导入依赖的package包/类
private JavacErrorDescriptionListener(
    Log log, EndPosTable endPositions, JavaFileObject sourceFile, boolean dontUseErrors) {
  this.log = log;
  this.sourceFile = sourceFile;
  this.dontUseErrors = dontUseErrors;
  checkNotNull(endPositions);
  try {
    CharSequence sourceFileContent = sourceFile.getCharContent(true);
    fixToAppliedFix = fix -> AppliedFix.fromSource(sourceFileContent, endPositions).apply(fix);
  } catch (IOException e) {
    throw new IOError(e);
  }
}
 
开发者ID:google,项目名称:error-prone,代码行数:14,代码来源:JavacErrorDescriptionListener.java

示例3: onDescribed

import com.google.errorprone.fixes.AppliedFix; //导入依赖的package包/类
@Override
public void onDescribed(Description description) {
  List<AppliedFix> appliedFixes =
      description
          .fixes
          .stream()
          .map(fixToAppliedFix)
          .filter(Objects::nonNull)
          .collect(Collectors.toCollection(ArrayList::new));

  String message = messageForFixes(description, appliedFixes);
  // Swap the log's source and the current file's source; then be sure to swap them back later.
  JavaFileObject originalSource = log.useSource(sourceFile);
  switch (description.severity) {
    case ERROR:
      if (dontUseErrors) {
        log.warning((DiagnosticPosition) description.node, MESSAGE_BUNDLE_KEY, message);
      } else {
        log.error((DiagnosticPosition) description.node, MESSAGE_BUNDLE_KEY, message);
      }
      break;
    case WARNING:
      log.warning((DiagnosticPosition) description.node, MESSAGE_BUNDLE_KEY, message);
      break;
    case SUGGESTION:
      log.note((DiagnosticPosition) description.node, MESSAGE_BUNDLE_KEY, message);
      break;
    default:
      break;
  }

  if (originalSource != null) {
    log.useSource(originalSource);
  }
}
 
开发者ID:google,项目名称:error-prone,代码行数:36,代码来源:JavacErrorDescriptionListener.java

示例4: 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类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。