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


Java Types.closure方法代码示例

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


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

示例1: isMapMethod

import com.sun.tools.javac.code.Types; //导入方法依赖的package包/类
private static boolean isMapMethod(Symbol.MethodSymbol symbol, Types types, String methodName) {
  if (!symbol.getSimpleName().toString().equals(methodName)) {
    return false;
  }
  Symbol owner = symbol.owner;
  if (owner.getQualifiedName().toString().equals("java.util.Map")) {
    return true;
  }
  com.sun.tools.javac.util.List<Type> supertypes = types.closure(owner.type);
  for (Type t : supertypes) {
    if (t.asElement().getQualifiedName().toString().equals("java.util.Map")) {
      return true;
    }
  }
  return false;
}
 
开发者ID:uber,项目名称:NullAway,代码行数:17,代码来源:AccessPath.java

示例2: getClosestOverriddenMethod

import com.sun.tools.javac.code.Types; //导入方法依赖的package包/类
/**
 * find the closest ancestor method in a superclass or superinterface that method overrides
 *
 * @param method the subclass method
 * @param types the types data structure from javac
 * @return closest overridden ancestor method, or <code>null</code> if method does not override
 *     anything
 */
@Nullable
private Symbol.MethodSymbol getClosestOverriddenMethod(Symbol.MethodSymbol method, Types types) {
  // taken from Error Prone MethodOverrides check
  Symbol.ClassSymbol owner = method.enclClass();
  for (Type s : types.closure(owner.type)) {
    if (s.equals(owner.type)) {
      continue;
    }
    for (Symbol m : s.tsym.members().getSymbolsByName(method.name)) {
      if (!(m instanceof Symbol.MethodSymbol)) {
        continue;
      }
      Symbol.MethodSymbol msym = (Symbol.MethodSymbol) m;
      if (msym.isStatic()) {
        continue;
      }
      if (method.overrides(msym, owner, types, /*checkReturn*/ false)) {
        return msym;
      }
    }
  }
  return null;
}
 
开发者ID:uber,项目名称:NullAway,代码行数:32,代码来源:NullAway.java

示例3: findMatchingMethods

import com.sun.tools.javac.code.Types; //导入方法依赖的package包/类
/**
 * Finds all methods in any superclass of {@code startClass} with a certain {@code name} that
 * match the given {@code predicate}.
 *
 * @return The (possibly empty) set of methods in any superclass that match {@code predicate} and
 *     have the given {@code name}.
 */
public static Set<MethodSymbol> findMatchingMethods(
    Name name, final Predicate<MethodSymbol> predicate, Type startClass, Types types) {
  Filter<Symbol> matchesMethodPredicate =
      sym -> sym instanceof MethodSymbol && predicate.apply((MethodSymbol) sym);

  Set<MethodSymbol> matchingMethods = new HashSet<>();
  // Iterate over all classes and interfaces that startClass inherits from.
  for (Type superClass : types.closure(startClass)) {
    // Iterate over all the methods declared in superClass.
    TypeSymbol superClassSymbol = superClass.tsym;
    Scope superClassSymbols = superClassSymbol.members();
    if (superClassSymbols != null) { // Can be null if superClass is a type variable
      for (Symbol symbol :
          superClassSymbols.getSymbolsByName(name, matchesMethodPredicate, NON_RECURSIVE)) {
        // By definition of the filter, we know that the symbol is a MethodSymbol.
        matchingMethods.add((MethodSymbol) symbol);
      }
    }
  }
  return matchingMethods;
}
 
开发者ID:google,项目名称:error-prone,代码行数:29,代码来源:ASTHelpers.java

示例4: getFirstOverride

import com.sun.tools.javac.code.Types; //导入方法依赖的package包/类
/**
 * Returns the {@link MethodSymbol} of the first method that sym overrides in its supertype
 * closure, or {@code null} if no such method exists.
 */
private MethodSymbol getFirstOverride(Symbol sym, Types types) {
  ClassSymbol owner = sym.enclClass();
  for (Type s : types.closure(owner.type)) {
    if (s == owner.type) {
      continue;
    }
    for (Symbol m : s.tsym.members().getSymbolsByName(sym.name)) {
      if (!(m instanceof MethodSymbol)) {
        continue;
      }
      MethodSymbol msym = (MethodSymbol) m;
      if (msym.isStatic()) {
        continue;
      }
      if (sym.overrides(msym, owner, types, /* checkResult= */ false)) {
        return msym;
      }
    }
  }
  return null;
}
 
开发者ID:google,项目名称:error-prone,代码行数:26,代码来源:MissingOverride.java

示例5: findSuperMethods

import com.sun.tools.javac.code.Types; //导入方法依赖的package包/类
public static Set<MethodSymbol> findSuperMethods(MethodSymbol methodSymbol, Types types) {
  Set<MethodSymbol> supers = new HashSet<MethodSymbol>();
  if (methodSymbol.isStatic()) {
    return supers;
  }

  TypeSymbol owner = (TypeSymbol) methodSymbol.owner;
  // Iterates over an ordered list of all super classes and interfaces.
  for (Type sup : types.closure(owner.type)) {
    if (sup == owner.type) {
      continue; // Skip the owner of the method
    }
    Scope scope = sup.tsym.members();
    for (Scope.Entry e = scope.lookup(methodSymbol.name); e.scope != null; e = e.next()) {
      if (e.sym != null
          && !e.sym.isStatic()
          && ((e.sym.flags() & Flags.SYNTHETIC) == 0)
          && e.sym.name.contentEquals(methodSymbol.name)
          && methodSymbol.overrides(e.sym, owner, types, true)) {
        supers.add((MethodSymbol) e.sym);
      }
    }
  }
  return supers;
}
 
开发者ID:diy1,项目名称:error-prone-aspirator,代码行数:26,代码来源:ASTHelpers.java


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