Search in sources :

Example 1 with ErrorType

use of javax.lang.model.type.ErrorType in project androidannotations by androidannotations.

the class CoreValidatorHelper method isSharedPreference.

public void isSharedPreference(Element element, ElementValidation valid) {
    TypeMirror type = element.asType();
    if (element instanceof ExecutableElement) {
        element = ((ExecutableElement) element).getParameters().get(0);
        type = element.asType();
    }
    /*
		 * The type is not available yet because it has just been generated
		 */
    if (type instanceof ErrorType || type.getKind() == TypeKind.ERROR) {
        String elementTypeName = type.toString();
        boolean sharedPrefValidatedInRound = false;
        if (elementTypeName.endsWith(classSuffix())) {
            String prefTypeName = elementTypeName.substring(0, elementTypeName.length() - classSuffix().length());
            prefTypeName = prefTypeName.replace(classSuffix() + ".", ".");
            Set<? extends Element> sharedPrefElements = validatedModel().getRootAnnotatedElements(SharedPref.class.getName());
            for (Element sharedPrefElement : sharedPrefElements) {
                TypeElement sharedPrefTypeElement = (TypeElement) sharedPrefElement;
                String sharedPrefQualifiedName = sharedPrefTypeElement.getQualifiedName().toString();
                if (sharedPrefQualifiedName.endsWith(prefTypeName)) {
                    sharedPrefValidatedInRound = true;
                    break;
                }
            }
        }
        if (!sharedPrefValidatedInRound) {
            valid.invalidate();
        }
    } else {
        extendsType(element, SharedPreferencesHelper.class.getName(), valid);
    }
}
Also used : ErrorType(javax.lang.model.type.ErrorType) TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) VariableElement(javax.lang.model.element.VariableElement) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) DefaultString(org.androidannotations.annotations.sharedpreferences.DefaultString) SharedPref(org.androidannotations.annotations.sharedpreferences.SharedPref) SharedPreferencesHelper(org.androidannotations.api.sharedpreferences.SharedPreferencesHelper)

Example 2 with ErrorType

use of javax.lang.model.type.ErrorType in project javapoet by square.

the class AbstractTypesTest method getErrorType.

@Test
public void getErrorType() {
    ErrorType errorType = new DeclaredTypeAsErrorType(getTypes().getDeclaredType(getElement(Set.class)));
    assertThat(TypeName.get(errorType)).isEqualTo(ClassName.get(Set.class));
}
Also used : Set(java.util.Set) ErrorType(javax.lang.model.type.ErrorType) Test(org.junit.Test)

Aggregations

ErrorType (javax.lang.model.type.ErrorType)2 Set (java.util.Set)1 Element (javax.lang.model.element.Element)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 TypeElement (javax.lang.model.element.TypeElement)1 VariableElement (javax.lang.model.element.VariableElement)1 TypeMirror (javax.lang.model.type.TypeMirror)1 DefaultString (org.androidannotations.annotations.sharedpreferences.DefaultString)1 SharedPref (org.androidannotations.annotations.sharedpreferences.SharedPref)1 SharedPreferencesHelper (org.androidannotations.api.sharedpreferences.SharedPreferencesHelper)1 Test (org.junit.Test)1