com.sun.tools.javac.code.Types.membersClosure()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(117)

本文整理了Java中com.sun.tools.javac.code.Types.membersClosure()方法的一些代码示例,展示了Types.membersClosure()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Types.membersClosure()方法的具体详情如下:
包路径:com.sun.tools.javac.code.Types
类名称:Types
方法名:membersClosure

Types.membersClosure介绍

暂无

代码示例

代码示例来源:origin: google/error-prone

Types types = state.getTypes();
Iterable<Symbol> members =
  types.membersClosure(getType(tree), /*skipInterface=*/ false).getSymbols();

代码示例来源:origin: google/error-prone

for (Symbol sym : types.membersClosure(getType(tree), /*skipInterface=*/ false).getSymbols()) {
 if (!(sym instanceof MethodSymbol)) {
  continue;

代码示例来源:origin: google/error-prone

private static boolean finalNoOverrides(Type type, VisitorState state) {
 if (type == null) {
  return false;
 }
 // We don't flag use of toString() on non-final objects because sub classes might have a
 // meaningful toString() override.
 if (!type.isFinal()) {
  return false;
 }
 Types types = state.getTypes();
 Names names = Names.instance(state.context);
 // find Object.toString
 MethodSymbol toString =
   (MethodSymbol) state.getSymtab().objectType.tsym.members().findFirst(names.toString);
 // We explore the superclasses of the receiver type as well as the interfaces it
 // implements and we collect all overrides of java.lang.Object.toString(). If one of those
 // overrides is present, then we don't flag it.
 return Iterables.isEmpty(
   types
     .membersClosure(type, /* skipInterface= */ false)
     .getSymbolsByName(
       names.toString,
       m ->
         m != toString
           && m.overrides(toString, type.tsym, types, /* checkResult= */ false)));
}

代码示例来源:origin: google/error-prone

state
  .getTypes()
  .membersClosure(
    ASTHelpers.getType(memberSelectTree.getExpression()),
    /* skipInterface= */ false);

代码示例来源:origin: konsoletyper/teavm-javac

MethodSymbol get(MethodSymbol ms, TypeSymbol origin, boolean checkResult, Filter<Symbol> implFilter) {
  SoftReference<Map<TypeSymbol, Entry>> ref_cache = _map.get(ms);
  Map<TypeSymbol, Entry> cache = ref_cache != null ? ref_cache.get() : null;
  if (cache == null) {
    cache = new HashMap<TypeSymbol, Entry>();
    _map.put(ms, new SoftReference<Map<TypeSymbol, Entry>>(cache));
  }
  Entry e = cache.get(origin);
  CompoundScope members = membersClosure(origin.type, true);
  if (e == null ||
      !e.matches(implFilter, checkResult, members.getMark())) {
    MethodSymbol impl = implementationInternal(ms, origin, checkResult, implFilter);
    cache.put(origin, new Entry(impl, implFilter, checkResult, members.getMark()));
    return impl;
  }
  else {
    return e.cachedImpl;
  }
}

代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac

MethodSymbol get(MethodSymbol ms, TypeSymbol origin, boolean checkResult, Filter<Symbol> implFilter) {
  SoftReference<Map<TypeSymbol, Entry>> ref_cache = _map.get(ms);
  Map<TypeSymbol, Entry> cache = ref_cache != null ? ref_cache.get() : null;
  if (cache == null) {
    cache = new HashMap<TypeSymbol, Entry>();
    _map.put(ms, new SoftReference<Map<TypeSymbol, Entry>>(cache));
  }
  Entry e = cache.get(origin);
  CompoundScope members = membersClosure(origin.type, true);
  if (e == null ||
      !e.matches(implFilter, checkResult, members.getMark())) {
    MethodSymbol impl = implementationInternal(ms, origin, checkResult, implFilter);
    cache.put(origin, new Entry(impl, implFilter, checkResult, members.getMark()));
    return impl;
  }
  else {
    return e.cachedImpl;
  }
}

代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac

FunctionDescriptor get(TypeSymbol origin) throws FunctionDescriptorLookupError {
  Entry e = _map.get(origin);
  CompoundScope members = membersClosure(origin.type, false);
  if (e == null ||
      !e.matches(members.getMark())) {
    FunctionDescriptor descRes = findDescriptorInternal(origin, members);
    _map.put(origin, new Entry(descRes, members.getMark()));
    return descRes;
  }
  else {
    return e.cachedDescRes;
  }
}

代码示例来源:origin: konsoletyper/teavm-javac

FunctionDescriptor get(TypeSymbol origin) throws FunctionDescriptorLookupError {
  Entry e = _map.get(origin);
  CompoundScope members = membersClosure(origin.type, false);
  if (e == null ||
      !e.matches(members.getMark())) {
    FunctionDescriptor descRes = findDescriptorInternal(origin, members);
    _map.put(origin, new Entry(descRes, members.getMark()));
    return descRes;
  }
  else {
    return e.cachedDescRes;
  }
}

代码示例来源:origin: com.google.errorprone/error_prone_core

Types types = state.getTypes();
Iterable<Symbol> members =
  types.membersClosure(getType(tree), /*skipInterface=*/ false).getSymbols();

代码示例来源:origin: com.google.errorprone/error_prone_core

private static boolean finalNoOverrides(Type type, VisitorState state) {
 if (type == null) {
  return false;
 }
 // We don't flag use of toString() on non-final objects because sub classes might have a
 // meaningful toString() override.
 if (!type.isFinal()) {
  return false;
 }
 Types types = state.getTypes();
 Names names = Names.instance(state.context);
 // find Object.toString
 MethodSymbol toString =
   (MethodSymbol) state.getSymtab().objectType.tsym.members().findFirst(names.toString);
 // We explore the superclasses of the receiver type as well as the interfaces it
 // implements and we collect all overrides of java.lang.Object.toString(). If one of those
 // overrides is present, then we don't flag it.
 return Iterables.isEmpty(
   types
     .membersClosure(type, /* skipInterface= */ false)
     .getSymbolsByName(
       names.toString,
       m ->
         m != toString
           && m.overrides(toString, type.tsym, types, /* checkResult= */ false)));
}

代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac

public List<MethodSymbol> interfaceCandidates(Type site, MethodSymbol ms) {
  Filter<Symbol> filter = new MethodFilter(ms, site);
  List<MethodSymbol> candidates = List.nil();
    for (Symbol s : membersClosure(site, false).getElements(filter)) {
      if (!site.tsym.isInterface() && !s.owner.isInterface()) {
        return List.of((MethodSymbol)s);
      } else if (!candidates.contains(s)) {
        candidates = candidates.prepend((MethodSymbol)s);
      }
    }
    return prune(candidates);
  }

代码示例来源:origin: konsoletyper/teavm-javac

public List<MethodSymbol> interfaceCandidates(Type site, MethodSymbol ms) {
  Filter<Symbol> filter = new MethodFilter(ms, site);
  List<MethodSymbol> candidates = List.nil();
    for (Symbol s : membersClosure(site, false).getElements(filter)) {
      if (!site.tsym.isInterface() && !s.owner.isInterface()) {
        return List.of((MethodSymbol)s);
      } else if (!candidates.contains(s)) {
        candidates = candidates.prepend((MethodSymbol)s);
      }
    }
    return prune(candidates);
  }

代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac

for (Symbol m1 : types.membersClosure(site, false).getElementsByName(sym.name, cf)) {
  if (!sym.overrides(m1, site.tsym, types, false)) {
    if (m1 == sym) {
  for (Symbol m2 : types.membersClosure(site, false).getElementsByName(sym.name, cf)) {
    if (m2 == m1) continue;

代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac

/** Check that all static methods accessible from 'site' are
 *  mutually compatible (JLS 8.4.8).
 *
 *  @param pos  Position to be used for error reporting.
 *  @param site The class whose methods are checked.
 *  @param sym  The method symbol to be checked.
 */
void checkHideClashes(DiagnosticPosition pos, Type site, MethodSymbol sym) {
  ClashFilter cf = new ClashFilter(site);
  //for each method m1 that is a member of 'site'...
  for (Symbol s : types.membersClosure(site, true).getElementsByName(sym.name, cf)) {
    //if (i) the signature of 'sym' is not a subsignature of m1 (seen as
    //a member of 'site') and (ii) 'sym' has the same erasure as m1, issue an error
    if (!types.isSubSignature(sym.type, types.memberType(site, s), allowStrictMethodClashCheck)) {
      if (types.hasSameArgs(s.erasure(types), sym.erasure(types))) {
        log.error(pos,
            "name.clash.same.erasure.no.hide",
            sym, sym.location(),
            s, s.location());
        return;
      } else {
        checkPotentiallyAmbiguousOverloads(pos, site, sym, (MethodSymbol)s);
      }
    }
   }
 }

代码示例来源:origin: konsoletyper/teavm-javac

for (Symbol m1 : types.membersClosure(site, false).getElementsByName(sym.name, cf)) {
  if (!sym.overrides(m1, site.tsym, types, false)) {
    if (m1 == sym) {
  for (Symbol m2 : types.membersClosure(site, false).getElementsByName(sym.name, cf)) {
    if (m2 == m1) continue;

代码示例来源:origin: konsoletyper/teavm-javac

/** Check that all static methods accessible from 'site' are
 *  mutually compatible (JLS 8.4.8).
 *
 *  @param pos  Position to be used for error reporting.
 *  @param site The class whose methods are checked.
 *  @param sym  The method symbol to be checked.
 */
void checkHideClashes(DiagnosticPosition pos, Type site, MethodSymbol sym) {
  ClashFilter cf = new ClashFilter(site);
  //for each method m1 that is a member of 'site'...
  for (Symbol s : types.membersClosure(site, true).getElementsByName(sym.name, cf)) {
    //if (i) the signature of 'sym' is not a subsignature of m1 (seen as
    //a member of 'site') and (ii) 'sym' has the same erasure as m1, issue an error
    if (!types.isSubSignature(sym.type, types.memberType(site, s), allowStrictMethodClashCheck)) {
      if (types.hasSameArgs(s.erasure(types), sym.erasure(types))) {
        log.error(pos,
            "name.clash.same.erasure.no.hide",
            sym, sym.location(),
            s, s.location());
        return;
      } else {
        checkPotentiallyAmbiguousOverloads(pos, site, sym, (MethodSymbol)s);
      }
    }
   }
 }

代码示例来源:origin: konsoletyper/teavm-javac

/**
 * Find the minimal set of methods that are overridden by the functional
 * descriptor in 'origin'. All returned methods are assumed to have different
 * erased signatures.
 */
public List<Symbol> functionalInterfaceBridges(TypeSymbol origin) {
  Assert.check(isFunctionalInterface(origin));
  Symbol descSym = findDescriptorSymbol(origin);
  CompoundScope members = membersClosure(origin.type, false);
  ListBuffer<Symbol> overridden = new ListBuffer<>();
  outer: for (Symbol m2 : members.getElementsByName(descSym.name, bridgeFilter)) {
    if (m2 == descSym) continue;
    else if (descSym.overrides(m2, origin, Types.this, false)) {
      for (Symbol m3 : overridden) {
        if (isSameType(m3.erasure(Types.this), m2.erasure(Types.this)) ||
            (m3.overrides(m2, origin, Types.this, false) &&
            (pendingBridges((ClassSymbol)origin, m3.enclClass()) ||
            (((MethodSymbol)m2).binaryImplementation((ClassSymbol)m3.owner, Types.this) != null)))) {
          continue outer;
        }
      }
      overridden.add(m2);
    }
  }
  return overridden.toList();
}
//where

代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac

/**
 * Find the minimal set of methods that are overridden by the functional
 * descriptor in 'origin'. All returned methods are assumed to have different
 * erased signatures.
 */
public List<Symbol> functionalInterfaceBridges(TypeSymbol origin) {
  Assert.check(isFunctionalInterface(origin));
  Symbol descSym = findDescriptorSymbol(origin);
  CompoundScope members = membersClosure(origin.type, false);
  ListBuffer<Symbol> overridden = new ListBuffer<>();
  outer: for (Symbol m2 : members.getElementsByName(descSym.name, bridgeFilter)) {
    if (m2 == descSym) continue;
    else if (descSym.overrides(m2, origin, Types.this, false)) {
      for (Symbol m3 : overridden) {
        if (isSameType(m3.erasure(Types.this), m2.erasure(Types.this)) ||
            (m3.overrides(m2, origin, Types.this, false) &&
            (pendingBridges((ClassSymbol)origin, m3.enclClass()) ||
            (((MethodSymbol)m2).binaryImplementation((ClassSymbol)m3.owner, Types.this) != null)))) {
          continue outer;
        }
      }
      overridden.add(m2);
    }
  }
  return overridden.toList();
}
//where

代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac

void checkDefaultMethodClashes(DiagnosticPosition pos, Type site) {
  DefaultMethodClashFilter dcf = new DefaultMethodClashFilter(site);
  for (Symbol m : types.membersClosure(site, false).getElements(dcf)) {
    Assert.check(m.kind == MTH);
    List<MethodSymbol> prov = types.interfaceCandidates(site, (MethodSymbol)m);

代码示例来源:origin: konsoletyper/teavm-javac

void checkDefaultMethodClashes(DiagnosticPosition pos, Type site) {
  DefaultMethodClashFilter dcf = new DefaultMethodClashFilter(site);
  for (Symbol m : types.membersClosure(site, false).getElements(dcf)) {
    Assert.check(m.kind == MTH);
    List<MethodSymbol> prov = types.interfaceCandidates(site, (MethodSymbol)m);

相关文章

Types类方法