/** * This method may return null if the {@link TypeElement} cannot be found in the * processor classpath */ public TypeElement typeElementFromQualifiedName(String qualifiedName) { return getElementUtils().getTypeElement(qualifiedName); }
public OrmLiteValidatorHelper(AndroidAnnotationsEnvironment environment) { annotationHelper = new AnnotationHelper(environment); }
public void hasASqliteOpenHelperParametrizedType(Element element, ElementValidation valid) { TypeMirror helperType = annotationHelper.extractAnnotationParameter(element, OrmLiteDao.class.getName(), "helper"); TypeMirror openHelperType = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.SQLITE_OPEN_HELPER).asType(); if (!annotationHelper.isSubtype(helperType, openHelperType)) { valid.addError("%s helper() parameter must extend " + CanonicalNameConstants.SQLITE_OPEN_HELPER); } } }
private boolean isTypeParcelable(TypeMirror typeMirror) { TypeMirror parcelableType = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.PARCELABLE).asType(); return annotationHelper.isSubtype(typeMirror, parcelableType); }
public int[] extractAnnotationResIdValueParameter(Element element, String annotationName, String fieldName) { /* * Annotation value() parameter can be an int or an int[] */ Object annotationValue = extractAnnotationParameter(element, annotationName, fieldName); if (annotationValue == null) { // This case happened during refactoring, if the id has been changed // in the layout and compiler throws an error on the annotation // because the constant doesn't exists anymore return new int[0]; } int[] values; if (annotationValue.getClass().isArray()) { values = (int[]) annotationValue; } else { values = new int[1]; values[0] = (Integer) annotationValue; } return values; }
private void setOnRetainNonConfigurationInstance() throws JClassAlreadyExistsException { AnnotationHelper annotationHelper = new AnnotationHelper(getEnvironment()); TypeElement fragmentActivityTypeElement = getFragmentActivity(annotationHelper); TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(generatedClass._extends().fullName()); String onRetainNonConfigurationInstanceName = "onRetainNonConfigurationInstance"; if (fragmentActivityTypeElement != null && annotationHelper.isSubtype(typeElement.asType(), fragmentActivityTypeElement.asType())) { onRetainNonConfigurationInstanceName = "onRetainCustomNonConfigurationInstance"; } NonConfigurationHolder ncHolder = getNonConfigurationHolder(); JDefinedClass ncHolderClass = ncHolder.getGeneratedClass(); JMethod onRetainNonConfigurationInstanceMethod = generatedClass.method(PUBLIC, ncHolderClass, onRetainNonConfigurationInstanceName); onRetainNonConfigurationInstanceMethod.annotate(Override.class); JBlock methodBody = onRetainNonConfigurationInstanceMethod.body(); onRetainNonConfigurationInstance = methodBody.decl(ncHolderClass, "nonConfigurationInstanceState_", _new(ncHolderClass)); IJExpression superCall = _super().invoke(onRetainNonConfigurationInstanceMethod); methodBody.assign(onRetainNonConfigurationInstance.ref(ncHolder.getSuperNonConfigurationInstanceField()), superCall); onRetainNonConfigurationInstanceBindBlock = methodBody.blockSimple(); methodBody._return(onRetainNonConfigurationInstance); }
public List<String> extractAnnotationResources(Element element, String annotationName, IRInnerClass rInnerClass, boolean useElementName, String idFieldName, String resFieldName) { int[] values = extractAnnotationResIdValueParameter(element, annotationName, idFieldName); if (defaultResIdValue(values)) { String[] resNames = extractAnnotationResNameParameter(element, annotationName, resFieldName); if (defaultResName(resNames)) { String elementName = extractElementName(element, annotationName); String clickQualifiedId = rInnerClass.getIdQualifiedName(elementName); resourceIdQualifiedNames.add(clickQualifiedId);
Types typeUtils = annotationHelper.getTypeUtils(); if (!annotationHelper.isSubtype(elementTypeMirror, daoParametrizedType) && !annotationHelper.isSubtype(elementTypeMirror, runtimeExceptionDaoParametrizedType)) { valid.addError("%s can only be used on an element that extends " + daoParametrizedType.toString() // + " or " + runtimeExceptionDaoParametrizedType.toString()); if (annotationHelper.isSubtype(elementTypeMirror, runtimeExceptionDaoParametrizedType) // && !typeUtils.isAssignable(ormLiteHelper.getTypedRuntimeExceptionDao(element), elementTypeMirror)) { if (parameters.size() == 1) { TypeMirror type = parameters.get(0).asType(); if (annotationHelper.isSubtype(type, daoWithTypedParameters)) { hasConstructor = true;
public String generatedClassQualifiedNameFromQualifiedName(String qualifiedName) { TypeElement type = typeElementFromQualifiedName(qualifiedName); if (type.getNestingKind() == NestingKind.MEMBER) { String parentGeneratedClass = generatedClassQualifiedNameFromQualifiedName(type.getEnclosingElement().asType().toString()); return parentGeneratedClass + "." + type.getSimpleName().toString() + classSuffix(); } else { return qualifiedName + classSuffix(); } }
public String[] extractAnnotationResNameParameter(Element element, String annotationName, String fieldName) { /* * Annotation resName() parameter can be a String or a String[] */ Object annotationResName = extractAnnotationParameter(element, annotationName, fieldName); if (annotationResName == null) { // This case happened during refactoring, if the id has been changed // in the layout and compiler throws an error on the annotation // because the constant doesn't exists anymore return new String[0]; } String[] resNames; if (annotationResName.getClass().isArray()) { resNames = (String[]) annotationResName; } else { resNames = new String[1]; resNames[0] = (String) annotationResName; } return resNames; }
/** * Tests whether one type is a subtype of another. Any type is considered to be * a subtype of itself. */ public boolean isSubtype(TypeMirror potentialSubtype, TypeMirror potentialSupertype) { return getTypeUtils().isSubtype(potentialSubtype, potentialSupertype); }
private TypeElement getFragmentActivity(AnnotationHelper annotationHelper) { TypeElement supportFragmentActivity = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.FRAGMENT_ACTIVITY); if (supportFragmentActivity == null) { return annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.ANDROIDX_FRAGMENT_ACTIVITY); } return supportFragmentActivity; }
public boolean isSubtype(TypeElement t1, TypeElement t2) { return isSubtype(t1.asType(), t2.asType()); }
public String extractElementName(Element element, String annotationName) { String elementName = element.getSimpleName().toString(); int lastIndex = elementName.lastIndexOf(actionName(annotationName)); if (lastIndex != -1) { elementName = elementName.substring(0, lastIndex); } return elementName; }
private void setGetLastNonConfigurationInstance() throws JClassAlreadyExistsException { AnnotationHelper annotationHelper = new AnnotationHelper(getEnvironment()); TypeElement fragmentActivityTypeElement = getFragmentActivity(annotationHelper); TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(generatedClass._extends().fullName()); String getLastNonConfigurationInstanceName = "getLastNonConfigurationInstance"; if (fragmentActivityTypeElement != null && annotationHelper.isSubtype(typeElement.asType(), fragmentActivityTypeElement.asType())) { getLastNonConfigurationInstanceName = "getLastCustomNonConfigurationInstance"; } NonConfigurationHolder ncHolder = getNonConfigurationHolder(); JDefinedClass ncHolderClass = ncHolder.getGeneratedClass(); JFieldVar superNonConfigurationInstanceField = ncHolder.getSuperNonConfigurationInstanceField(); getLastNonConfigurationInstance = generatedClass.method(PUBLIC, Object.class, getLastNonConfigurationInstanceName); getLastNonConfigurationInstance.annotate(Override.class); JBlock body = getLastNonConfigurationInstance.body(); JVar nonConfigurationInstance = body.decl(ncHolderClass, "nonConfigurationInstance", cast(ncHolderClass, _super().invoke(getLastNonConfigurationInstance))); body._if(nonConfigurationInstance.eq(_null()))._then()._return(_null()); body._return(nonConfigurationInstance.ref(superNonConfigurationInstanceField)); }
public List<String> extractAnnotationResources(Element element, String annotationName, IRInnerClass rInnerClass, boolean useElementName, String idFieldName, String resFieldName) { int[] values = extractAnnotationResIdValueParameter(element, annotationName, idFieldName); if (defaultResIdValue(values)) { String[] resNames = extractAnnotationResNameParameter(element, annotationName, resFieldName); if (defaultResName(resNames)) { String elementName = extractElementName(element, annotationName); String clickQualifiedId = rInnerClass.getIdQualifiedName(elementName); resourceIdQualifiedNames.add(clickQualifiedId);
private boolean isTypeParcelable(TypeMirror typeMirror) { TypeMirror parcelableType = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.PARCELABLE).asType(); return annotationHelper.isSubtype(typeMirror, parcelableType); }
public String generatedClassQualifiedNameFromQualifiedName(String qualifiedName) { TypeElement type = typeElementFromQualifiedName(qualifiedName); if (type.getNestingKind() == NestingKind.MEMBER) { String parentGeneratedClass = generatedClassQualifiedNameFromQualifiedName(type.getEnclosingElement().asType().toString()); return parentGeneratedClass + "." + type.getSimpleName().toString() + classSuffix(); } else { return qualifiedName + classSuffix(); } }
public int[] extractAnnotationResIdValueParameter(Element element, String annotationName, String fieldName) { /* * Annotation value() parameter can be an int or an int[] */ Object annotationValue = extractAnnotationParameter(element, annotationName, fieldName); if (annotationValue == null) { // This case happened during refactoring, if the id has been changed // in the layout and compiler throws an error on the annotation // because the constant doesn't exists anymore return new int[0]; } int[] values; if (annotationValue.getClass().isArray()) { values = (int[]) annotationValue; } else { values = new int[1]; values[0] = (Integer) annotationValue; } return values; }
public String[] extractAnnotationResNameParameter(Element element, String annotationName, String fieldName) { /* * Annotation resName() parameter can be a String or a String[] */ Object annotationResName = extractAnnotationParameter(element, annotationName, fieldName); if (annotationResName == null) { // This case happened during refactoring, if the id has been changed // in the layout and compiler throws an error on the annotation // because the constant doesn't exists anymore return new String[0]; } String[] resNames; if (annotationResName.getClass().isArray()) { resNames = (String[]) annotationResName; } else { resNames = new String[1]; resNames[0] = (String) annotationResName; } return resNames; }