Search in sources :

Example 1 with TypeMirror

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

the class TreeResolver method getType.

@Nullable
public TypeMirror getType(TreePath path) {
    Tree tree = path.getLeaf();
    TypeMirror result = treesToTypes.get(tree);
    if (result != null) {
        return result;
    }
    treesToTypes.put(tree, resolveType(path));
    return treesToTypes.get(tree);
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) ArrayTypeTree(com.sun.source.tree.ArrayTypeTree) MethodTree(com.sun.source.tree.MethodTree) VariableTree(com.sun.source.tree.VariableTree) TypeParameterTree(com.sun.source.tree.TypeParameterTree) ParameterizedTypeTree(com.sun.source.tree.ParameterizedTypeTree) IdentifierTree(com.sun.source.tree.IdentifierTree) Tree(com.sun.source.tree.Tree) ClassTree(com.sun.source.tree.ClassTree) MemberSelectTree(com.sun.source.tree.MemberSelectTree) PrimitiveTypeTree(com.sun.source.tree.PrimitiveTypeTree) WildcardTree(com.sun.source.tree.WildcardTree) Nullable(com.facebook.buck.util.liteinfersupport.Nullable)

Example 2 with TypeMirror

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

the class JPAMetaModelEntityProcessor method modelGenerationNeedsToBeDeferred.

private boolean modelGenerationNeedsToBeDeferred(Collection<MetaEntity> entities, MetaEntity containedEntity) {
    ContainsAttributeTypeVisitor visitor = new ContainsAttributeTypeVisitor(containedEntity.getTypeElement(), context);
    for (MetaEntity entity : entities) {
        if (entity.equals(containedEntity)) {
            continue;
        }
        for (Element subElement : ElementFilter.fieldsIn(entity.getTypeElement().getEnclosedElements())) {
            TypeMirror mirror = subElement.asType();
            if (!TypeKind.DECLARED.equals(mirror.getKind())) {
                continue;
            }
            boolean contains = mirror.accept(visitor, subElement);
            if (contains) {
                return true;
            }
        }
        for (Element subElement : ElementFilter.methodsIn(entity.getTypeElement().getEnclosedElements())) {
            TypeMirror mirror = subElement.asType();
            if (!TypeKind.DECLARED.equals(mirror.getKind())) {
                continue;
            }
            boolean contains = mirror.accept(visitor, subElement);
            if (contains) {
                return true;
            }
        }
    }
    return false;
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) MetaEntity(org.hibernate.jpamodelgen.model.MetaEntity) AnnotationMetaEntity(org.hibernate.jpamodelgen.annotation.AnnotationMetaEntity) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element)

Example 3 with TypeMirror

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

the class BasicAttributeVisitor method visitExecutable.

@Override
public AnnotationMetaAttribute visitExecutable(ExecutableType t, Element p) {
    if (!p.getKind().equals(ElementKind.METHOD)) {
        return null;
    }
    String string = p.getSimpleName().toString();
    if (!StringUtil.isProperty(string, TypeUtils.toTypeString(t.getReturnType()))) {
        return null;
    }
    TypeMirror returnType = t.getReturnType();
    return returnType.accept(this, p);
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror)

Example 4 with TypeMirror

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

the class BasicAttributeVisitor method visitTypeVariable.

@Override
public AnnotationMetaAttribute visitTypeVariable(TypeVariable t, Element element) {
    // METAGEN-29 - for a type variable we use the upper bound
    TypeMirror mirror = t.getUpperBound();
    TypeMirror erasedType = context.getTypeUtils().erasure(mirror);
    return new AnnotationMetaSingleAttribute(entity, element, erasedType.toString());
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror)

Example 5 with TypeMirror

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

the class BasicAttributeVisitor method getFullyQualifiedClassNameOfTargetEntity.

private String getFullyQualifiedClassNameOfTargetEntity(AnnotationMirror mirror, String parameterName) {
    assert mirror != null;
    assert parameterName != null;
    String targetEntityName = null;
    Object parameterValue = TypeUtils.getAnnotationValue(mirror, parameterName);
    if (parameterValue != null) {
        TypeMirror parameterType = (TypeMirror) parameterValue;
        if (!parameterType.getKind().equals(TypeKind.VOID)) {
            targetEntityName = parameterType.toString();
        }
    }
    return targetEntityName;
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror)

Aggregations

TypeMirror (javax.lang.model.type.TypeMirror)1205 TypeElement (javax.lang.model.element.TypeElement)448 ExecutableElement (javax.lang.model.element.ExecutableElement)284 VariableElement (javax.lang.model.element.VariableElement)261 Element (javax.lang.model.element.Element)210 DeclaredType (javax.lang.model.type.DeclaredType)191 ArrayList (java.util.ArrayList)169 Test (org.junit.Test)153 AnnotationMirror (javax.lang.model.element.AnnotationMirror)92 Types (javax.lang.model.util.Types)77 List (java.util.List)69 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)64 Elements (javax.lang.model.util.Elements)61 Map (java.util.Map)60 HashSet (java.util.HashSet)59 ArrayCodeTypeMirror (com.oracle.truffle.dsl.processor.java.model.CodeTypeMirror.ArrayCodeTypeMirror)50 ArrayType (javax.lang.model.type.ArrayType)50 ExecutableType (javax.lang.model.type.ExecutableType)48 MethodSpec (com.squareup.javapoet.MethodSpec)46 Set (java.util.Set)45