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