@Override public boolean isSatisfied(VariableElement param) { TypeMirror elementType = param.asType(); TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(typeName); if (typeElement != null) { TypeMirror expectedType = typeElement.asType(); return annotationHelper.isSubtype(elementType, expectedType); } return false; }
protected boolean extendsType(Element element, String typeQualifiedName) { TypeMirror elementType = element.asType(); TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(typeQualifiedName); if (typeElement != null) { TypeMirror expectedType = typeElement.asType(); return annotationHelper.isSubtype(elementType, expectedType); } return false; }
@Override public boolean isSatisfied(VariableElement parameter) { TypeMirror elementType = parameter.asType(); for (String type : types) { TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(type); if (typeElement != null) { TypeMirror expectedType = typeElement.asType(); if (annotationHelper.isSubtype(elementType, expectedType)) { return true; } } } return false; }
public void extendsOneOfTypes(Element element, List<String> typeQualifiedNames, ElementValidation valid) { TypeMirror elementType = element.asType(); for (String typeQualifiedName : typeQualifiedNames) { TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(typeQualifiedName); if (typeElement != null) { TypeMirror expectedType = typeElement.asType(); if (annotationHelper.isSubtype(elementType, expectedType)) { return; } } } valid.addError("%s can only be used on an element that extends one of the following classes: " + typeQualifiedNames); }
public void extendsListOfView(Element element, ElementValidation valid) { DeclaredType elementType = (DeclaredType) element.asType(); List<? extends TypeMirror> elementTypeArguments = elementType.getTypeArguments(); TypeMirror viewType = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.VIEW).asType(); if (!elementType.toString().equals(CanonicalNameConstants.LIST) && elementTypeArguments.size() == 1 && !annotationHelper.isSubtype(elementTypeArguments.get(0), viewType)) { valid.invalidate(); valid.addError("%s can only be used on a " + CanonicalNameConstants.LIST + " of elements extending " + CanonicalNameConstants.VIEW); } }
public void restInterfaceHasFormConverter(Element element, ElementValidation validation) { Element restInterface = element.getEnclosingElement().getEnclosingElement(); if (restInterface.getAnnotation(Rest.class) == null) { return; } List<DeclaredType> converters = annotationHelper.extractAnnotationClassArrayParameter(restInterface, Rest.class.getCanonicalName(), "converters"); boolean formConverterFound = false; TypeMirror formConverter = annotationHelper.getElementUtils().getTypeElement(FORM_HTTP_MESSAGE_CONVERTER).asType(); for (DeclaredType converter : converters) { if (formConverter != null && annotationHelper.isSubtype(converter, formConverter)) { formConverterFound = true; break; } } if (!formConverterFound) { validation.addError(element, "%s annotated method parameter must be in a @Rest annotated interface which uses at least one " // + FORM_HTTP_MESSAGE_CONVERTER + " (or subtype)"); } }
public void childFragmentUsedOnlyIfEnclosingClassIsFragment(Element element, ElementValidation validation) { boolean childFragment = annotationHelper.extractAnnotationParameter(element, "childFragment"); if (childFragment) { TypeElement fragment = annotationHelper.getElementUtils().getTypeElement(CanonicalNameConstants.FRAGMENT); TypeElement supportFragment = annotationHelper.getElementUtils().getTypeElement(CanonicalNameConstants.SUPPORT_V4_FRAGMENT); TypeElement androidxFragment = annotationHelper.getElementUtils().getTypeElement(CanonicalNameConstants.ANDROIDX_FRAGMENT); boolean enclosingElementIsFragment = false; TypeElement enclosingElement = (TypeElement) element.getEnclosingElement(); if (fragment != null && annotationHelper.isSubtype(enclosingElement, fragment)) { enclosingElementIsFragment = true; } else if (supportFragment != null && annotationHelper.isSubtype(enclosingElement, supportFragment)) { enclosingElementIsFragment = true; } else if (androidxFragment != null && annotationHelper.isSubtype(enclosingElement, androidxFragment)) { enclosingElementIsFragment = true; } if (!enclosingElementIsFragment) { validation.addError(element, "The 'childFragmentManager' parameter only can be used if the class containing the annotated field is either subclass of " + CanonicalNameConstants.FRAGMENT + ", " + CanonicalNameConstants.SUPPORT_V4_FRAGMENT + " or " + CanonicalNameConstants.ANDROIDX_FRAGMENT); } } }
public void canBePutInABundle(Element element, ElementValidation valid) { TypeMirror typeMirror = element.asType(); String typeString = element.asType().toString(); if (!isKnownBundleCompatibleType(typeString)) { if (typeMirror instanceof ArrayType) { ArrayType arrayType = (ArrayType) element.asType(); typeMirror = arrayType.getComponentType(); } if (typeMirror.getKind() != TypeKind.NONE) { TypeMirror parcelableType = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.PARCELABLE).asType(); TypeMirror serializableType = annotationHelper.typeElementFromQualifiedName("java.io.Serializable").asType(); if (typeString.startsWith(CanonicalNameConstants.SPARSE_ARRAY)) { DeclaredType declaredType = (DeclaredType) typeMirror; List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments(); if (typeArguments.size() != 1 || !annotationHelper.isSubtype(typeArguments.get(0), parcelableType)) { valid.addError("Unrecognized type. The type argument of SparseArray should implement Parcelable."); } } else if (!annotationHelper.isSubtype(typeMirror, parcelableType) && !annotationHelper.isSubtype(typeMirror, serializableType) && !parcelerHelper.isParcelType(typeMirror)) { valid.addError("Unrecognized type. Please let your attribute be primitive or implement Serializable or Parcelable or an annotated Parceler bean."); } } } }
public void getChildFragmentManagerMethodIsAvailable(Element element, ElementValidation validation) { boolean childFragment = annotationHelper.extractAnnotationParameter(element, "childFragment"); if (childFragment) { TypeElement enclosingElement = (TypeElement) element.getEnclosingElement(); TypeElement fragment = annotationHelper.getElementUtils().getTypeElement(CanonicalNameConstants.FRAGMENT); TypeElement supportFragment = annotationHelper.getElementUtils().getTypeElement(CanonicalNameConstants.SUPPORT_V4_FRAGMENT); TypeElement androidxFragment = annotationHelper.getElementUtils().getTypeElement(CanonicalNameConstants.ANDROIDX_FRAGMENT); if (supportFragment != null && annotationHelper.isSubtype(enclosingElement, supportFragment)) { if (!methodIsAvailableIn(supportFragment, "getChildFragmentManager")) { validation.addError(element, "The 'childFragmentManager' parameter only can be used if the getChildFragmentManager() method is available in " + CanonicalNameConstants.SUPPORT_V4_FRAGMENT + ", update your support library version."); } } else if (androidxFragment != null && annotationHelper.isSubtype(enclosingElement, androidxFragment)) { if (!methodIsAvailableIn(androidxFragment, "getChildFragmentManager")) { validation.addError(element, "The 'childFragmentManager' parameter only can be used if the getChildFragmentManager() method is available in " + CanonicalNameConstants.ANDROIDX_FRAGMENT + ", update your support library version."); } } else if (fragment != null && annotationHelper.isSubtype(enclosingElement, fragment) && environment().getAndroidManifest().getMinSdkVersion() < 17) { validation.addError(element, "The 'childFragmentManager' parameter only can be used if the getChildFragmentManager() method is available in " + CanonicalNameConstants.FRAGMENT + " (from API 17). Increment 'minSdkVersion' or use " + CanonicalNameConstants.SUPPORT_V4_FRAGMENT + " or " + CanonicalNameConstants.ANDROIDX_FRAGMENT + "."); } } }
public void validateRestSimpleParameter(Element element, String requiredClass, String parameterName, ElementValidation validation) { TypeMirror requiredType = annotationHelper.typeElementFromQualifiedName(requiredClass).asType(); DeclaredType paramterType = annotationHelper.extractAnnotationClassParameter(element, annotationHelper.getTarget(), parameterName); if (paramterType != null) { if (annotationHelper.isSubtype(paramterType, requiredType)) { Element parameterElement = paramterType.asElement(); if (parameterElement.getKind().isClass()) { if (!annotationHelper.isAbstract(parameterElement)) { if (parameterElement.getAnnotation(EBean.class) != null) { typeIsValid(EBean.class, paramterType, validation); return; } List<ExecutableElement> constructors = ElementFilter.constructorsIn(parameterElement.getEnclosedElements()); for (ExecutableElement constructor : constructors) { if (annotationHelper.isPublic(constructor) && constructor.getParameters().isEmpty()) { return; } } validation.addError(element, "The " + parameterName + " class must have a public no argument constructor or must be annotated with @EBean"); } else { validation.addError(element, "The " + parameterName + " class must not be abstract"); } } else { validation.addError(element, "The " + parameterName + " class must be a class"); } } else { validation.addError(element, "The " + parameterName + " class must be a subtype of " + requiredClass); } } }
if (annotationHelper.isSubtype(erasedInterceptorType, clientHttpRequestInterceptorTypeErased)) { Element interceptorElement = interceptorType.asElement(); if (interceptorElement.getKind().isClass()) {
if (annotationHelper.isSubtype(erasedConverterType, httpMessageConverterTypeErased)) { Element converterElement = converterType.asElement(); if (converterElement.getKind().isClass()) {
protected boolean extendsType(Element element, String typeQualifiedName) { TypeMirror elementType = element.asType(); TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(typeQualifiedName); if (typeElement != null) { TypeMirror expectedType = typeElement.asType(); return annotationHelper.isSubtype(elementType, expectedType); } return false; }
@Override public boolean isSatisfied(VariableElement param) { TypeMirror elementType = param.asType(); TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(typeName); if (typeElement != null) { TypeMirror expectedType = typeElement.asType(); return annotationHelper.isSubtype(elementType, expectedType); } return false; }
@Override public boolean isSatisfied(VariableElement parameter) { TypeMirror elementType = parameter.asType(); for (String type : types) { TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(type); if (typeElement != null) { TypeMirror expectedType = typeElement.asType(); if (annotationHelper.isSubtype(elementType, expectedType)) { return true; } } } return false; }
public void extendsListOfView(Element element, ElementValidation valid) { DeclaredType elementType = (DeclaredType) element.asType(); List<? extends TypeMirror> elementTypeArguments = elementType.getTypeArguments(); TypeMirror viewType = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.VIEW).asType(); if (!elementType.toString().equals(CanonicalNameConstants.LIST) && elementTypeArguments.size() == 1 && !annotationHelper.isSubtype(elementTypeArguments.get(0), viewType)) { valid.invalidate(); valid.addError("%s can only be used on a " + CanonicalNameConstants.LIST + " of elements extending " + CanonicalNameConstants.VIEW); } }
public void extendsOneOfTypes(Element element, List<String> typeQualifiedNames, ElementValidation valid) { TypeMirror elementType = element.asType(); for (String typeQualifiedName : typeQualifiedNames) { TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(typeQualifiedName); if (typeElement != null) { TypeMirror expectedType = typeElement.asType(); if (annotationHelper.isSubtype(elementType, expectedType)) { return; } } } valid.addError("%s can only be used on an element that extends one of the following classes: " + typeQualifiedNames); }
public void childFragmentUsedOnlyIfEnclosingClassIsFragment(Element element, ElementValidation validation) { boolean childFragment = annotationHelper.extractAnnotationParameter(element, "childFragment"); if (childFragment) { TypeElement fragment = annotationHelper.getElementUtils().getTypeElement(CanonicalNameConstants.FRAGMENT); TypeElement supportFragment = annotationHelper.getElementUtils().getTypeElement(CanonicalNameConstants.SUPPORT_V4_FRAGMENT); TypeElement androidxFragment = annotationHelper.getElementUtils().getTypeElement(CanonicalNameConstants.ANDROIDX_FRAGMENT); boolean enclosingElementIsFragment = false; TypeElement enclosingElement = (TypeElement) element.getEnclosingElement(); if (fragment != null && annotationHelper.isSubtype(enclosingElement, fragment)) { enclosingElementIsFragment = true; } else if (supportFragment != null && annotationHelper.isSubtype(enclosingElement, supportFragment)) { enclosingElementIsFragment = true; } else if (androidxFragment != null && annotationHelper.isSubtype(enclosingElement, androidxFragment)) { enclosingElementIsFragment = true; } if (!enclosingElementIsFragment) { validation.addError(element, "The 'childFragmentManager' parameter only can be used if the class containing the annotated field is either subclass of " + CanonicalNameConstants.FRAGMENT + ", " + CanonicalNameConstants.SUPPORT_V4_FRAGMENT + " or " + CanonicalNameConstants.ANDROIDX_FRAGMENT); } } }
public void canBePutInABundle(Element element, ElementValidation valid) { TypeMirror typeMirror = element.asType(); String typeString = element.asType().toString(); if (!isKnownBundleCompatibleType(typeString)) { if (typeMirror instanceof ArrayType) { ArrayType arrayType = (ArrayType) element.asType(); typeMirror = arrayType.getComponentType(); } if (typeMirror.getKind() != TypeKind.NONE) { TypeMirror parcelableType = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.PARCELABLE).asType(); TypeMirror serializableType = annotationHelper.typeElementFromQualifiedName("java.io.Serializable").asType(); if (typeString.startsWith(CanonicalNameConstants.SPARSE_ARRAY)) { DeclaredType declaredType = (DeclaredType) typeMirror; List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments(); if (typeArguments.size() != 1 || !annotationHelper.isSubtype(typeArguments.get(0), parcelableType)) { valid.addError("Unrecognized type. The type argument of SparseArray should implement Parcelable."); } } else if (!annotationHelper.isSubtype(typeMirror, parcelableType) && !annotationHelper.isSubtype(typeMirror, serializableType) && !parcelerHelper.isParcelType(typeMirror)) { valid.addError("Unrecognized type. Please let your attribute be primitive or implement Serializable or Parcelable or an annotated Parceler bean."); } } } }