Search in sources :

Example 1 with DeclaredType

use of javax.lang.model.type.DeclaredType in project buck by facebook.

the class MoreElements method findAnnotation.

@Nullable
private static AnnotationMirror findAnnotation(CharSequence name, Element element) {
    for (AnnotationMirror annotationMirror : element.getAnnotationMirrors()) {
        DeclaredType annotationType = annotationMirror.getAnnotationType();
        TypeElement annotationTypeElement = (TypeElement) annotationType.asElement();
        if (annotationTypeElement.getQualifiedName().contentEquals(name)) {
            return annotationMirror;
        }
    }
    return null;
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeElement(javax.lang.model.element.TypeElement) DeclaredType(javax.lang.model.type.DeclaredType) Nullable(javax.annotation.Nullable)

Example 2 with DeclaredType

use of javax.lang.model.type.DeclaredType in project buck by facebook.

the class MoreElements method isSourceRetention.

public static boolean isSourceRetention(AnnotationMirror annotation) {
    DeclaredType annotationType = annotation.getAnnotationType();
    TypeElement annotationTypeElement = (TypeElement) annotationType.asElement();
    AnnotationMirror retentionAnnotation = findAnnotation("java.lang.annotation.Retention", annotationTypeElement);
    if (retentionAnnotation == null) {
        return false;
    }
    VariableElement retentionPolicy = (VariableElement) Preconditions.checkNotNull(findAnnotationValue(retentionAnnotation, "value"));
    return retentionPolicy.getSimpleName().contentEquals("SOURCE");
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeElement(javax.lang.model.element.TypeElement) VariableElement(javax.lang.model.element.VariableElement) DeclaredType(javax.lang.model.type.DeclaredType)

Example 3 with DeclaredType

use of javax.lang.model.type.DeclaredType in project hibernate-orm by hibernate.

the class XmlMetaEntity method getCollectionTypes.

private String[] getCollectionTypes(String propertyName, String explicitTargetEntity, String explicitMapKeyClass, ElementKind expectedElementKind) {
    for (Element elem : element.getEnclosedElements()) {
        if (!expectedElementKind.equals(elem.getKind())) {
            continue;
        }
        String elementPropertyName = elem.getSimpleName().toString();
        if (elem.getKind().equals(ElementKind.METHOD)) {
            elementPropertyName = StringUtil.getPropertyName(elementPropertyName);
        }
        if (!propertyName.equals(elementPropertyName)) {
            continue;
        }
        DeclaredType type = determineDeclaredType(elem);
        if (type == null) {
            continue;
        }
        return determineTypes(propertyName, explicitTargetEntity, explicitMapKeyClass, type);
    }
    return null;
}
Also used : TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) DeclaredType(javax.lang.model.type.DeclaredType)

Example 4 with DeclaredType

use of javax.lang.model.type.DeclaredType in project immutables by immutables.

the class TypeHierarchyCollector method collectUnresolvedInterface.

private void collectUnresolvedInterface(TypeMirror typeMirror, TypevarContext context) {
    if (typeMirror.getKind() == TypeKind.ERROR) {
        DeclaredType declaredType = toDeclaredType(typeMirror);
        String stringified = stringify(declaredType, context);
        implementedInterfaceNames.add(stringified);
    }
}
Also used : DeclaredType(javax.lang.model.type.DeclaredType)

Example 5 with DeclaredType

use of javax.lang.model.type.DeclaredType in project epoxy by airbnb.

the class HashCodeValidator method validateImplementsHashCode.

private void validateImplementsHashCode(TypeMirror mirror) throws EpoxyProcessorException {
    if (TypeName.get(mirror).isPrimitive()) {
        return;
    }
    if (mirror.getKind() == TypeKind.ARRAY) {
        validateArrayType((ArrayType) mirror);
        return;
    }
    if (!(mirror instanceof DeclaredType)) {
        return;
    }
    DeclaredType declaredType = (DeclaredType) mirror;
    Element element = typeUtils.asElement(mirror);
    TypeElement clazz = (TypeElement) element;
    if (isIterableType(clazz)) {
        validateIterableType(declaredType);
        return;
    }
    if (isAutoValueType(element)) {
        return;
    }
    if (isWhiteListedType(element)) {
        return;
    }
    if (!hasHashCodeInClassHierarchy(clazz)) {
        throwError("Attribute does not implement hashCode");
    }
}
Also used : TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) DeclaredType(javax.lang.model.type.DeclaredType)

Aggregations

DeclaredType (javax.lang.model.type.DeclaredType)339 TypeElement (javax.lang.model.element.TypeElement)204 TypeMirror (javax.lang.model.type.TypeMirror)176 ExecutableElement (javax.lang.model.element.ExecutableElement)114 Element (javax.lang.model.element.Element)86 VariableElement (javax.lang.model.element.VariableElement)73 AnnotationMirror (javax.lang.model.element.AnnotationMirror)53 ArrayList (java.util.ArrayList)46 ExecutableType (javax.lang.model.type.ExecutableType)41 ArrayType (javax.lang.model.type.ArrayType)36 HashSet (java.util.HashSet)27 List (java.util.List)27 AnnotationValue (javax.lang.model.element.AnnotationValue)25 Test (org.junit.Test)23 Map (java.util.Map)22 PackageElement (javax.lang.model.element.PackageElement)22 Types (javax.lang.model.util.Types)20 WildcardType (javax.lang.model.type.WildcardType)16 HashMap (java.util.HashMap)15 TypeKind (javax.lang.model.type.TypeKind)15