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


Java DoNotCall类代码示例

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


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

示例1: matchMethodInvocation

import com.google.errorprone.annotations.DoNotCall; //导入依赖的package包/类
@Override
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {
  DoNotCall doNotCall = ASTHelpers.getAnnotation(tree, DoNotCall.class);
  if (doNotCall == null) {
    return NO_MATCH;
  }
  StringBuilder message = new StringBuilder("This method should not be called");
  if (doNotCall.value().isEmpty()) {
    message.append(", see its documentation for details.");
  } else {
    message.append(": ").append(doNotCall.value());
  }
  return buildDescription(tree).setMessage(message.toString()).build();
}
 
开发者ID:google,项目名称:error-prone,代码行数:15,代码来源:DoNotCallChecker.java

示例2: matchMethod

import com.google.errorprone.annotations.DoNotCall; //导入依赖的package包/类
@Override
public Description matchMethod(MethodTree tree, VisitorState state) {
  MethodSymbol symbol = ASTHelpers.getSymbol(tree);
  if (symbol == null) {
    return NO_MATCH;
  }
  if (hasAnnotation(tree, DoNotCall.class, state)) {
    if (symbol.getModifiers().contains(Modifier.ABSTRACT)) {
      return NO_MATCH;
    }
    if (symbol.getModifiers().contains(Modifier.FINAL)) {
      return NO_MATCH;
    }
    if (symbol.owner.enclClass().getModifiers().contains(Modifier.FINAL)) {
      return NO_MATCH;
    }
    return buildDescription(tree)
        .setMessage("Methods annotated with @DoNotCall should be final.")
        .addFix(SuggestedFixes.addModifiers(tree, state, Modifier.FINAL))
        .build();
  }
  return findSuperMethods(symbol, state.getTypes())
      .stream()
      .filter(s -> hasAnnotation(s, DoNotCall.class, state))
      .findAny()
      .map(
          s -> {
            String message =
                String.format(
                    "Method overrides %s in %s which is annotated @DoNotCall,"
                        + " it should also be annotated.",
                    s.getSimpleName(), s.owner.getSimpleName());
            return buildDescription(tree)
                .setMessage(message)
                .addFix(
                    SuggestedFix.builder()
                        .addImport(DoNotCall.class.getName())
                        .prefixWith(tree, "@DoNotCall ")
                        .build())
                .build();
          })
      .orElse(NO_MATCH);
}
 
开发者ID:google,项目名称:error-prone,代码行数:44,代码来源:DoNotCallChecker.java

示例3: addAll

import com.google.errorprone.annotations.DoNotCall; //导入依赖的package包/类
/** @deprecated Use {@link #addTransitive} to avoid excessive memory use. */
@Deprecated
@DoNotCall
public NestedSetBuilder<E> addAll(NestedSet<? extends E> elements) {
  throw new UnsupportedOperationException();
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:7,代码来源:NestedSetBuilder.java


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