當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。