Search in sources :

Example 26 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 27 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 28 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)

Example 29 with TypeMirror

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

the class XmlMetaEntity method getType.

/**
	 * Returns the entity type for a property.
	 *
	 * @param propertyName The property name
	 * @param explicitTargetEntity The explicitly specified target entity type or {@code null}.
	 * @param expectedElementKind Determines property vs field access type
	 *
	 * @return The entity type for this property  or {@code null} if the property with the name and the matching access
	 *         type does not exist.
	 */
private String getType(String propertyName, String explicitTargetEntity, ElementKind expectedElementKind) {
    for (Element elem : element.getEnclosedElements()) {
        if (!expectedElementKind.equals(elem.getKind())) {
            continue;
        }
        TypeMirror mirror;
        String name = elem.getSimpleName().toString();
        if (ElementKind.METHOD.equals(elem.getKind())) {
            name = StringUtil.getPropertyName(name);
            mirror = ((ExecutableElement) elem).getReturnType();
        } else {
            mirror = elem.asType();
        }
        if (name == null || !name.equals(propertyName)) {
            continue;
        }
        if (explicitTargetEntity != null) {
            // TODO should there be a check of the target entity class and if it is loadable?
            return explicitTargetEntity;
        }
        switch(mirror.getKind()) {
            case INT:
                {
                    return "java.lang.Integer";
                }
            case LONG:
                {
                    return "java.lang.Long";
                }
            case BOOLEAN:
                {
                    return "java.lang.Boolean";
                }
            case BYTE:
                {
                    return "java.lang.Byte";
                }
            case SHORT:
                {
                    return "java.lang.Short";
                }
            case CHAR:
                {
                    return "java.lang.Char";
                }
            case FLOAT:
                {
                    return "java.lang.Float";
                }
            case DOUBLE:
                {
                    return "java.lang.Double";
                }
            case DECLARED:
                {
                    return mirror.toString();
                }
            case TYPEVAR:
                {
                    return mirror.toString();
                }
            default:
                {
                }
        }
    }
    context.logMessage(Diagnostic.Kind.WARNING, "Unable to determine type for property " + propertyName + " of class " + getQualifiedName() + " using access type " + accessTypeInfo.getDefaultAccessType());
    return null;
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element)

Example 30 with TypeMirror

use of javax.lang.model.type.TypeMirror in project neo4j by neo4j.

the class ServiceProcessor method process.

@SuppressWarnings("unchecked")
@Override
protected void process(TypeElement annotationType, Element annotated, AnnotationMirror annotation, Map<? extends ExecutableElement, ? extends AnnotationValue> values) throws IOException {
    for (AnnotationValue o : (List<? extends AnnotationValue>) values.values().iterator().next().getValue()) {
        TypeMirror service = (TypeMirror) o.getValue();
        addTo(((TypeElement) annotated).getQualifiedName().toString(), "META-INF", "services", service.toString());
    }
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) AnnotationValue(javax.lang.model.element.AnnotationValue) List(java.util.List)

Aggregations

TypeMirror (javax.lang.model.type.TypeMirror)475 TypeElement (javax.lang.model.element.TypeElement)197 ExecutableElement (javax.lang.model.element.ExecutableElement)105 Test (org.junit.Test)90 VariableElement (javax.lang.model.element.VariableElement)88 DeclaredType (javax.lang.model.type.DeclaredType)76 Element (javax.lang.model.element.Element)61 ArrayList (java.util.ArrayList)36 Expression (com.google.devtools.j2objc.ast.Expression)32 PrefixExpression (com.google.devtools.j2objc.ast.PrefixExpression)28 Elements (javax.lang.model.util.Elements)28 FunctionInvocation (com.google.devtools.j2objc.ast.FunctionInvocation)24 AbstractJClass (com.helger.jcodemodel.AbstractJClass)24 List (java.util.List)23 Types (javax.lang.model.util.Types)22 InfixExpression (com.google.devtools.j2objc.ast.InfixExpression)21 TypeParameterElement (javax.lang.model.element.TypeParameterElement)21 ArrayType (javax.lang.model.type.ArrayType)21 FunctionElement (com.google.devtools.j2objc.types.FunctionElement)20 IJExpression (com.helger.jcodemodel.IJExpression)20