Search in sources :

Example 46 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 47 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 48 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 49 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 50 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)138 TypeElement (javax.lang.model.element.TypeElement)82 TypeMirror (javax.lang.model.type.TypeMirror)75 ExecutableElement (javax.lang.model.element.ExecutableElement)38 Element (javax.lang.model.element.Element)28 VariableElement (javax.lang.model.element.VariableElement)26 AnnotationMirror (javax.lang.model.element.AnnotationMirror)19 Test (org.junit.Test)19 ArrayType (javax.lang.model.type.ArrayType)15 ArrayList (java.util.ArrayList)14 List (java.util.List)10 Map (java.util.Map)9 AbstractJClass (com.helger.jcodemodel.AbstractJClass)8 HashSet (java.util.HashSet)8 AnnotationValue (javax.lang.model.element.AnnotationValue)8 HashMap (java.util.HashMap)6 TypeParameterElement (javax.lang.model.element.TypeParameterElement)6 Types (javax.lang.model.util.Types)6 Name (javax.lang.model.element.Name)5 PackageElement (javax.lang.model.element.PackageElement)5