本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}