private boolean isReturnValueTypeMatching( ExecutableElement method, TypeMirror expectedReturnType) { return processingEnv.getTypeUtils().isAssignable( method.getReturnType(), expectedReturnType); }
boolean isLibraryGlideModule(TypeElement element) { return processingEnv.getTypeUtils().isAssignable(element.asType(), libraryGlideModuleType.asType()); }
boolean isAppGlideModule(TypeElement element) { return processingEnv.getTypeUtils().isAssignable(element.asType(), appGlideModuleType.asType()); }
public boolean isAssignable(TypeMirror type, String assignableType) { return typeUtils.isAssignable(type, elementUtils.getTypeElement(assignableType).asType()); }
private boolean isAssignable(String childClazz, String superClazz) { return processingEnv.getTypeUtils().isAssignable( processingEnv.getElementUtils().getTypeElement(childClazz).asType(), processingEnv.getElementUtils().getTypeElement(superClazz).asType()); } }
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()); }
private boolean validateElement(Element element) { return element.getKind().isClass() && processingEnv.getTypeUtils().isAssignable(element.asType(), processingEnv.getElementUtils().getTypeElement(INTERCEPTOR_FULL_NAME).asType()); }
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; }
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(); }
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;
@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; } }
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); }
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; }
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";
/** * 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)); }
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); }
/** * 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); } }
&& !typeUtils.isAssignable(ormLiteHelper.getTypedRuntimeExceptionDao(element), elementTypeMirror)) {
@Override public final boolean isAssignableFrom(final Class<?> type) { return types.isAssignable(types.erasure(toType(type)), types.erasure(this.typeMirror)); }
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); } }