本文整理了Java中com.sun.tools.javac.code.Types.isSubtype()
方法的一些代码示例,展示了Types.isSubtype()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Types.isSubtype()
方法的具体详情如下:
包路径:com.sun.tools.javac.code.Types
类名称:Types
方法名:isSubtype
[英]Is t a subtype of s?
(not defined for Method and ForAll types)
[中]t是s的亚型吗?
(未为方法和所有类型定义)
代码示例来源:origin: google/error-prone
private static boolean isSubtype(Types types, Type t, Type s) {
return s != null && types.isSubtype(t, s);
}
代码示例来源:origin: google/error-prone
boolean isKnownCheckedException(VisitorState state, Type type) {
Types types = state.getTypes();
Symtab symtab = state.getSymtab();
// Check erasure for generics.
type = types.erasure(type);
return
// Has to be some Exception: A variable of type Throwable might be an Error.
types.isSubtype(type, symtab.exceptionType)
// Has to be some subtype: A variable of type Exception might be a RuntimeException.
&& !types.isSameType(type, symtab.exceptionType)
// Can't be of type RuntimeException.
&& !types.isSubtype(type, symtab.runtimeExceptionType);
}
};
代码示例来源:origin: uber/NullAway
private boolean thriftIsSetCall(Symbol.MethodSymbol symbol, Types types) {
Preconditions.checkNotNull(tbaseType);
// noinspection ConstantConditions
return tbaseType.isPresent()
&& symbol.getSimpleName().toString().startsWith("isSet")
// weeds out the isSet() method in TBase itself
&& symbol.getParameters().length() == 0
&& types.isSubtype(symbol.owner.type, tbaseType.get());
}
}
代码示例来源:origin: google/error-prone
/** Returns true if {@code erasure(s) <: erasure(t)}. */
public static boolean isSubtype(Type s, Type t, VisitorState state) {
if (s == null || t == null) {
return false;
}
if (SUBTYPE_UNDEFINED.contains(s.getTag()) || SUBTYPE_UNDEFINED.contains(t.getTag())) {
return false;
}
Types types = state.getTypes();
return types.isSubtype(types.erasure(s), types.erasure(t));
}
代码示例来源:origin: google/error-prone
/**
* Returns true if the lock expression corresponds to a {@code
* java.util.concurrent.locks.ReadWriteLock}.
*/
private static boolean isRWLock(GuardedByExpression guard, VisitorState state) {
Type guardType = guard.type();
if (guardType == null) {
return false;
}
Symbol rwLockSymbol = state.getSymbolFromString(JUC_READ_WRITE_LOCK);
if (rwLockSymbol == null) {
return false;
}
return state.getTypes().isSubtype(guardType, rwLockSymbol.type);
}
代码示例来源:origin: google/error-prone
@Override
public boolean matches(ExpressionTree expressionTree, VisitorState state) {
Symbol sym = ASTHelpers.getSymbol(expressionTree);
if (sym == null) {
return false;
}
if (!(sym instanceof MethodSymbol)) {
throw new IllegalArgumentException(
"DescendantOf matcher expects a method call but found "
+ sym.getClass()
+ ". Expression: "
+ expressionTree);
}
if (sym.isStatic()) {
return false;
}
if (methodName.equals(sym.toString())) {
Type accessedReferenceType = sym.owner.type;
Type collectionType = state.getTypeFromString(fullClassName);
if (collectionType != null) {
return state
.getTypes()
.isSubtype(accessedReferenceType, state.getTypes().erasure(collectionType));
}
}
return false;
}
}
代码示例来源:origin: google/error-prone
@Override
public boolean matches(ExpressionTree tree, VisitorState state) {
Types types = state.getTypes();
Type classType = state.getSymtab().classType;
Type runtimeExceptionType = state.getSymtab().runtimeExceptionType;
Type argType = getType(tree);
// Make sure that the argument is a Class<Something> (and not null/bottom).
if (!isSubtype(argType, classType, state) || argType.getTag() == BOT) {
return false;
}
List<Type> typeArguments = ((ClassType) argType).getTypeArguments();
Type exceptionType = Iterables.getFirst(typeArguments, null);
return types.isSubtype(exceptionType, runtimeExceptionType);
}
};
代码示例来源:origin: google/error-prone
for (Symbol member : members) {
Type owner = types.erasure(member.owner.type);
if (canonicalOwner == null || types.isSubtype(owner, canonicalOwner)) {
canonicalOwner = owner;
代码示例来源:origin: google/error-prone
if (types.isSubtype(componentType, charSequenceType)
&& !types.isSameType(componentType, charSequenceType)
&& !types.isSameType(componentType, stringType)) {
代码示例来源:origin: org.jvnet.sorcerer/sorcerer-javac
/**
* Is t a subtype of s?<br>
* (not defined for Method and ForAll types)
*/
final public boolean isSubtype(Type t, Type s) {
return isSubtype(t, s, true);
}
final public boolean isSubtypeNoCapture(Type t, Type s) {
代码示例来源:origin: cincheo/jsweet
com.sun.tools.javac.code.Type type = (com.sun.tools.javac.code.Type) typeMirror;
String typeName = type.tsym.getQualifiedName().toString();
if (typeName.startsWith("java.") && context.types.isSubtype(type, context.symtab.throwableType)) {
print(exprStr, expr);
print(" != null && ");
代码示例来源:origin: cincheo/jsweet
&& !context.types.isSubtype(classdecl.type, context.symtab.throwableType)
&& !Util.isSourceElement(context.modelTypes.asElement(superClassType))) {
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
/** Is given type a subtype or supertype of
* some of the types in given list?
*/
boolean intersects(Type t, List<Type> ts) {
for (List<Type> l = ts; l.nonEmpty(); l = l.tail)
if (types.isSubtype(t, l.head) || types.isSubtype(l.head, t)) return true;
return false;
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
/** check if a class is a subtype of Serializable, if that is available. */
private boolean isSerializable(ClassSymbol c) {
try {
syms.serializableType.complete();
}
catch (CompletionFailure e) {
return false;
}
return types.isSubtype(c.type, syms.serializableType);
}
代码示例来源:origin: sc.fiji/javac
/** check if a class is a subtype of Serializable, if that is available. */
private boolean isSerializable(ClassSymbol c) {
try {
syms.serializableType.complete();
}
catch (CompletionFailure e) {
return false;
}
return types.isSubtype(c.type, syms.serializableType);
}
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
public boolean isSubtype(TypeMirror t1, TypeMirror t2) {
validateTypeNotIn(t1, EXEC_OR_PKG);
validateTypeNotIn(t2, EXEC_OR_PKG);
return types.isSubtype((Type) t1, (Type) t2);
}
代码示例来源:origin: sc.fiji/javac
public boolean isSubtype(TypeMirror t1, TypeMirror t2) {
validateTypeNotIn(t1, EXEC_OR_PKG);
validateTypeNotIn(t2, EXEC_OR_PKG);
return types.isSubtype((Type) t1, (Type) t2);
}
代码示例来源:origin: com.google.errorprone/error_prone_check_api
/** Returns true if {@code erasure(s) <: erasure(t)}. */
public static boolean isSubtype(Type s, Type t, VisitorState state) {
if (s == null || t == null) {
return false;
}
Types types = state.getTypes();
return types.isSubtype(types.erasure(s), types.erasure(t));
}
代码示例来源:origin: cincheo/jsweet
&& (!overload.coreMethod.sym.getModifiers().contains(Modifier.ABSTRACT)
|| isInterfaceMethod(parent, methodDecl)
|| !context.types.isSubtype(parent.sym.type,
overload.coreMethod.sym.getEnclosingElement().type));
if (!overload.printed && !addCoreMethod && overload.coreMethod.type instanceof MethodType) {
代码示例来源:origin: org.kohsuke.sorcerer/sorcerer-javac
private List<Type> superClosure(Type t, Type s) {
List<Type> cl = List.nil();
for (List<Type> l = interfaces(t); l.nonEmpty(); l = l.tail) {
if (isSubtype(s, erasure(l.head))) {
cl = insert(cl, l.head);
} else {
cl = union(cl, superClosure(l.head, s));
}
}
return cl;
}
内容来源于网络,如有侵权,请联系作者删除!