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


Java Scope.getSymbolsByName方法代码示例

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


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

示例1: alreadyDefinedIn

import com.sun.tools.javac.code.Scope; //导入方法依赖的package包/类
public boolean alreadyDefinedIn(CharSequence name, TypeMirror returnType, List<TypeMirror> paramTypes, TypeElement enclClass) {
    ClassSymbol clazz = (ClassSymbol)enclClass;
    Scope scope = clazz.members();
    Name n = names.fromString(name.toString());
    ListBuffer<Type> buff = new ListBuffer<>();
    for (TypeMirror tm : paramTypes) {
        buff.append((Type)tm);
    }
    for (Symbol sym : scope.getSymbolsByName(n, Scope.LookupKind.NON_RECURSIVE)) {
        if(sym.type instanceof ExecutableType &&
                jctypes.containsTypeEquivalent(sym.type.asMethodType().getParameterTypes(), buff.toList()) &&
                jctypes.isSameType(sym.type.asMethodType().getReturnType(), (Type)returnType))
            return true;
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:ElementsService.java

示例2: findSuperConstructorInType

import com.sun.tools.javac.code.Scope; //导入方法依赖的package包/类
/**
 * based heavily on {@link ASTHelpers#findSuperMethodInType(Symbol.MethodSymbol, Type, Types)},
 * but works for constructors
 */
@Nullable
private static Symbol.MethodSymbol findSuperConstructorInType(
    Symbol.MethodSymbol methodSymbol, Type superType, Types types) {
  Preconditions.checkArgument(methodSymbol.isConstructor(), "only accepts constructor methods");
  Scope scope = superType.tsym.members();
  for (Symbol sym : scope.getSymbolsByName(methodSymbol.name)) {
    if (sym != null
        && sym.isConstructor()
        && ((sym.flags() & Flags.SYNTHETIC) == 0)
        && hasSameArgTypes((Symbol.MethodSymbol) sym, methodSymbol, types)) {
      return (Symbol.MethodSymbol) sym;
    }
  }
  return null;
}
 
开发者ID:uber,项目名称:NullAway,代码行数:20,代码来源:NullAway.java

示例3: findSuperMethodInType

import com.sun.tools.javac.code.Scope; //导入方法依赖的package包/类
@Nullable
public static MethodSymbol findSuperMethodInType(
    MethodSymbol methodSymbol, Type superType, Types types) {
  if (methodSymbol.isStatic() || superType.equals(methodSymbol.owner.type)) {
    return null;
  }

  Scope scope = superType.tsym.members();
  for (Symbol sym : scope.getSymbolsByName(methodSymbol.name)) {
    if (sym != null
        && !sym.isStatic()
        && ((sym.flags() & Flags.SYNTHETIC) == 0)
        && sym.name.contentEquals(methodSymbol.name)
        && methodSymbol.overrides(
            sym, (TypeSymbol) methodSymbol.owner, types, /* checkResult= */ true)) {
      return (MethodSymbol) sym;
    }
  }
  return null;
}
 
开发者ID:google,项目名称:error-prone,代码行数:21,代码来源:ASTHelpers.java

示例4: findMatchingMethods

import com.sun.tools.javac.code.Scope; //导入方法依赖的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

示例5: implementsEquals

import com.sun.tools.javac.code.Scope; //导入方法依赖的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

示例6: getMatchingMethod

import com.sun.tools.javac.code.Scope; //导入方法依赖的package包/类
private static MethodSymbol getMatchingMethod(
    Type type, Name name, Predicate<MethodSymbol> predicate) {
  Scope scope = type.tsym.members();
  for (Symbol sym : scope.getSymbolsByName(name)) {
    if (!(sym instanceof MethodSymbol)) {
      continue;
    }
    MethodSymbol methodSymbol = (MethodSymbol) sym;
    if (predicate.apply(methodSymbol)) {
      return methodSymbol;
    }
  }
  return null;
}
 
开发者ID:google,项目名称:error-prone,代码行数:15,代码来源:BadAnnotationImplementation.java


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