本文整理了Java中javax.lang.model.util.Types.isAssignable()
方法的一些代码示例,展示了Types.isAssignable()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Types.isAssignable()
方法的具体详情如下:
包路径:javax.lang.model.util.Types
类名称:Types
方法名:isAssignable
[英]Tests whether one type is assignable to another.
[中]测试一种类型是否可分配给另一种类型。
代码示例来源:origin: bumptech/glide
private boolean isReturnValueTypeMatching(
ExecutableElement method, TypeMirror expectedReturnType) {
return processingEnv.getTypeUtils().isAssignable(
method.getReturnType(), expectedReturnType);
}
代码示例来源:origin: bumptech/glide
boolean isLibraryGlideModule(TypeElement element) {
return processingEnv.getTypeUtils().isAssignable(element.asType(),
libraryGlideModuleType.asType());
}
代码示例来源:origin: bumptech/glide
boolean isAppGlideModule(TypeElement element) {
return processingEnv.getTypeUtils().isAssignable(element.asType(),
appGlideModuleType.asType());
}
代码示例来源:origin: f2prateek/dart
public boolean isAssignable(TypeMirror type, String assignableType) {
return typeUtils.isAssignable(type, elementUtils.getTypeElement(assignableType).asType());
}
代码示例来源:origin: bingoogolapple/BGABadgeView-Android
private boolean isAssignable(String childClazz, String superClazz) {
return processingEnv.getTypeUtils().isAssignable(
processingEnv.getElementUtils().getTypeElement(childClazz).asType(),
processingEnv.getElementUtils().getTypeElement(superClazz).asType());
}
}
代码示例来源:origin: querydsl/querydsl
private boolean isAssignable(TypeMirror type, TypeMirror iface) {
return env.getTypeUtils().isAssignable(type, iface)
// XXX Eclipse 3.6 support
|| env.getTypeUtils().erasure(type).toString().equals(iface.toString());
}
代码示例来源:origin: chenenyu/Router
private boolean validateElement(Element element) {
return element.getKind().isClass() && processingEnv.getTypeUtils().isAssignable(element.asType(),
processingEnv.getElementUtils().getTypeElement(INTERCEPTOR_FULL_NAME).asType());
}
代码示例来源:origin: airbnb/epoxy
private static boolean areParamsTheSame(ExecutableElement method1, MethodSpec method2,
Types types, Elements elements) {
List<? extends VariableElement> params1 = method1.getParameters();
List<ParameterSpec> params2 = method2.parameters;
if (params1.size() != params2.size()) {
return false;
}
for (int i = 0; i < params1.size(); i++) {
VariableElement param1 = params1.get(i);
ParameterSpec param2 = params2.get(i);
TypeMirror param1Type = types.erasure(param1.asType());
TypeMirror param2Type =
types.erasure(KotlinUtilsKt.getTypeMirror(param2.type.toString(), elements));
// If a param is a type variable then we don't need an exact type match, it just needs to
// be assignable
if (param1.asType().getKind() == TypeKind.TYPEVAR) {
if (!types.isAssignable(param2Type, param1Type)) {
return false;
}
} else if (!param1Type.toString().equals(param2Type.toString())) {
return false;
}
}
return true;
}
代码示例来源:origin: immutables/immutables
private Set<String> useProvidedTypesForServices(TypeElement typeElement, ImmutableList<TypeMirror> typesMirrors) {
List<String> wrongTypes = Lists.newArrayList();
List<String> types = Lists.newArrayList();
for (TypeMirror typeMirror : typesMirrors) {
if (typeMirror.getKind() != TypeKind.DECLARED
|| !processing().getTypeUtils().isAssignable(typeElement.asType(), typeMirror)) {
wrongTypes.add(typeMirror.toString());
} else {
types.add(typeMirror.toString());
}
}
if (!wrongTypes.isEmpty()) {
processing().getMessager().printMessage(
Diagnostic.Kind.ERROR,
"@Metainf.Service(value = {...}) contains types that are not implemented by "
+ typeElement.getSimpleName()
+ ": " + wrongTypes,
typeElement,
AnnotationMirrors.findAnnotation(typeElement.getAnnotationMirrors(), Metainf.Service.class));
}
return FluentIterable.from(types).toSet();
}
代码示例来源:origin: org.jboss.logging/jboss-logging-processor
break;
case 1:
if (types.isAssignable(stringType, params.get(0).asType())) {
stringConstructor = true;
} else if (types.isAssignable(params.get(0).asType(), throwableType)) {
throwableConstructor = true;
if (types.isAssignable(stringType, params.get(0).asType())
&& types.isAssignable(params.get(1).asType(), throwableType)) {
stringAndThrowableConstructor = true;
} else if (types.isAssignable(params.get(0).asType(), throwableType)
&& types.isAssignable(stringType, params.get(1).asType())) {
throwableAndStringConstructor = true;
代码示例来源:origin: robolectric/robolectric
@Override
public Void visitVariable(VariableElement elem, TypeElement parent) {
this.parent = parent;
TypeMirror impClass = helpers.getImplementedClass(imp);
if (impClass != null) {
TypeMirror elemType = elem.asType();
if (!types.isAssignable(impClass, elemType)) {
error("@RealObject with type <" + elemType + ">; expected <" + impClass + '>');
}
typeVisitor.visit(elemType, elem);
}
return null;
}
}
代码示例来源:origin: androidannotations/androidannotations
public void typeOrTargetValueHasAnnotation(Class<? extends Annotation> annotation, Element element, ElementValidation valid) {
Element targetElement = findTargetElement(element, valid);
if (targetElement == null) {
return;
}
DeclaredType targetAnnotationClassValue = annotationHelper.extractAnnotationClassParameter(element);
if (targetAnnotationClassValue != null) {
targetElement = targetAnnotationClassValue.asElement();
if (!annotationHelper.getTypeUtils().isAssignable(targetAnnotationClassValue, targetElement.asType())) {
valid.addError("The value of %s must be assignable into the annotated field");
}
}
typeHasValidAnnotation(annotation, targetElement, valid);
}
代码示例来源:origin: org.jboss.logging/jboss-logging-processor
private boolean assignablePropertyFound(final TypeMirror valueType, final Set<TypeMirror> propertyTypes) {
if (propertyTypes != null) {
for (TypeMirror propertyType : propertyTypes) {
if (types.isAssignable(types.erasure(valueType), types.erasure(propertyType))) {
return true;
}
}
}
return false;
}
代码示例来源:origin: sockeqwe/fragmentargs
for (int i = 0; i < arrayListTypes.length; i++) {
TypeMirror tm = getArrayListType(arrayListTypes[i]);
if (types.isAssignable(type, tm)) {
return arrayListOps[i];
if (types.isAssignable(type,
getWildcardType(ArrayList.class.getName(), "android.os.Parcelable"))) {
return "ParcelableArrayList";
getWildcardType("android.util.SparseArray", "android.os.Parcelable");
if (types.isAssignable(type, sparseParcelableArray)) {
return "SparseParcelableArray";
if (types.isAssignable(type, elements.getTypeElement("android.os.Parcelable").asType())) {
return "Parcelable";
if (types.isAssignable(type, elements.getTypeElement(Serializable.class.getName()).asType())) {
return "Serializable";
代码示例来源:origin: org.jboss.logging/jboss-logging-processor
/**
* Creates a new descriptor that is not primitive.
*
* @param processingEnv the annotation processing environment.
* @param type the class name of the return type.
*/
private AptThrowableType(final ProcessingEnvironment processingEnv, final TypeMirror type) {
super(processingEnv, type);
this.type = type;
this.delegate = types.asElement(type);
stringType = ElementHelper.toType(elements, String.class);
throwableType = ElementHelper.toType(elements, Throwable.class);
final TypeMirror runtimeException = ElementHelper.toType(elements, RuntimeException.class);
final TypeMirror error = ElementHelper.toType(elements, Error.class);
isChecked = !(types.isAssignable(runtimeException, type) && types.isAssignable(error, type));
}
代码示例来源:origin: immutables/immutables
protected BoundAccess(TypeMirror type, String name, boolean callable) {
this.name = name;
this.callable = callable;
this.type = boxed(type);
this.boxed = this.type != type;
this.containedType = boxed(inferContainedType(type));
this.invokable = types.isAssignable(type, invokableType);
}
代码示例来源:origin: org.jboss.logging/jboss-logging-processor
/**
* Checks the type, if an array the type of the array is checked, against the class. If the element type is
* assignable to the class type.
*
* @param typeMirror the type to test
* @param type the type the element needs to be assignable to
*
* @return {@code true} if the element type is assignable to the class type, otherwise {@code false}
*/
private boolean isTypeAssignableFrom(final TypeMirror typeMirror, final TypeMirror type) {
TypeMirror t = typeMirror;
if (t.getKind() == TypeKind.ARRAY) {
t = ((ArrayType) t).getComponentType();
}
if (types.isAssignable(types.erasure(t), ElementHelper.toType(elements, Collection.class))) {
// We only need the first type
t = types.erasure(ElementHelper.getTypeArguments(t).iterator().next());
}
return types.isAssignable(t, type);
}
}
代码示例来源:origin: androidannotations/androidannotations
&& !typeUtils.isAssignable(ormLiteHelper.getTypedRuntimeExceptionDao(element), elementTypeMirror)) {
代码示例来源:origin: org.jboss.logging/jboss-logging-processor
@Override
public final boolean isAssignableFrom(final Class<?> type) {
return types.isAssignable(types.erasure(toType(type)), types.erasure(this.typeMirror));
}
代码示例来源:origin: org.jboss.logging/jboss-logging-processor
private void init() {
if (isThrowable()) {
// The resolved type needs to be used in cases where a Supplier is being returned
TypeMirror throwableReturnType = resolvedType;
if (method.isAnnotatedWith(ConstructType.class)) {
final TypeElement constructTypeValue = ElementHelper.getClassAnnotationValue(method, ConstructType.class);
// Shouldn't be null
if (constructTypeValue == null) {
throw new ProcessingException(method, "Class not defined for the ConstructType");
}
throwableReturnType = constructTypeValue.asType();
if (!types.isAssignable(throwableReturnType, resolvedType)) {
throw new ProcessingException(method, "The requested type %s can not be assigned to %s.", throwableReturnType, resolvedType);
}
}
throwableType = ThrowableTypeFactory.forReturnType(processingEnv, throwableReturnType, method);
}
}
内容来源于网络,如有侵权,请联系作者删除!