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


Java VisitorState.getName方法代码示例

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


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

示例1: implementsEquals

import com.google.errorprone.VisitorState; //导入方法依赖的package包/类
/** Check if the method declares or inherits an implementation of .equals() */
public static boolean implementsEquals(Type type, VisitorState state) {
  Name equalsName = state.getName("equals");
  Symbol objectEquals = getOnlyMember(state, state.getSymtab().objectType, "equals");
  for (Type sup : state.getTypes().closure(type)) {
    if (sup.tsym.isInterface()) {
      continue;
    }
    if (ASTHelpers.isSameType(sup, state.getSymtab().objectType, state)) {
      return false;
    }
    Scope scope = sup.tsym.members();
    if (scope == null) {
      continue;
    }
    for (Symbol sym : scope.getSymbolsByName(equalsName)) {
      if (sym.overrides(objectEquals, type.tsym, state.getTypes(), /* checkResult= */ false)) {
        return true;
      }
    }
  }
  return false;
}
 
开发者ID:google,项目名称:error-prone,代码行数:24,代码来源:ReferenceEquality.java

示例2: hasAnnotation

import com.google.errorprone.VisitorState; //导入方法依赖的package包/类
/**
 * Determines whether a symbol has an annotation of the given type. This includes annotations
 * inherited from superclasses due to {@code @Inherited}.
 *
 * @param annotationClass the binary class name of the annotation (e.g.
 *     "javax.annotation.Nullable", or "some.package.OuterClassName$InnerClassName")
 */
public static boolean hasAnnotation(Symbol sym, String annotationClass, VisitorState state) {
  Name annotationName = state.getName(annotationClass);
  Symbol annotationSym;
  synchronized (state.context) {
    annotationSym =
        state.getSymtab().enterClass(state.inferModule(annotationName), annotationName);
  }
  try {
    annotationSym.complete();
  } catch (CompletionFailure e) {
    // @Inherited won't work if the annotation isn't on the classpath, but we can still check
    // if it's present directly
  }
  Symbol inheritedSym = state.getSymtab().inheritedType.tsym;

  if ((sym == null) || (annotationSym == null)) {
    return false;
  }
  if ((sym instanceof ClassSymbol) && (annotationSym.attribute(inheritedSym) != null)) {
    while (sym != null) {
      if (sym.attribute(annotationSym) != null) {
        return true;
      }
      sym = ((ClassSymbol) sym).getSuperclass().tsym;
    }
    return false;
  } else {
    return sym.attribute(annotationSym) != null;
  }
}
 
开发者ID:google,项目名称:error-prone,代码行数:38,代码来源:ASTHelpers.java


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