Example usage for javax.lang.model.type DeclaredType toString

List of usage examples for javax.lang.model.type DeclaredType toString

Introduction

In this page you can find the example usage for javax.lang.model.type DeclaredType toString.

Prototype

String toString();

Source Link

Document

Returns an informative string representation of this type.

Usage

From source file:org.mule.devkit.utils.NameUtils.java

public String generateClassNameInPackage(Element element, String className) {
    Element enclosingElement = element.getEnclosingElement();
    String packageName;//from w w  w.j ava2  s.c o m
    if (enclosingElement.getKind() == ElementKind.CLASS) {
        packageName = getPackageName(getBinaryName((TypeElement) enclosingElement));
    } else if (enclosingElement.getEnclosingElement() != null) {
        TypeElement parentClass = ElementFilter.typesIn(Arrays.asList(enclosingElement.getEnclosingElement()))
                .get(0);
        packageName = getPackageName(getBinaryName(parentClass));
    } else {
        // inner enum or parametrized type
        DeclaredType declaredType = (DeclaredType) element.asType();
        packageName = getPackageName(declaredType.toString());
    }
    return packageName + "." + className;
}

From source file:org.netbeans.jpa.modeler.spec.extend.MultiRelationAttribute.java

@Override
public void loadAttribute(EntityMappings entityMappings, Element element, VariableElement variableElement,
        AnnotationMirror relationAnnotationMirror) {
    super.loadAttribute(entityMappings, element, variableElement, relationAnnotationMirror);

    AnnotationMirror orderByMirror = JavaSourceParserUtil.findAnnotation(element, "javax.persistence.OrderBy");
    if (orderByMirror != null) {
        Object value = JavaSourceParserUtil.findAnnotationValue(orderByMirror, "value");
        this.orderBy = value == null ? StringUtils.EMPTY : value.toString();
    }/*from   ww  w  . ja va2  s.  c o m*/

    this.mappedBy = (String) JavaSourceParserUtil.findAnnotationValue(relationAnnotationMirror, "mappedBy");
    this.collectionType = ((DeclaredType) variableElement.asType()).asElement().toString();
    Class collectionTypeClass = null;
    try {
        collectionTypeClass = Class.forName(this.collectionType);
    } catch (ClassNotFoundException ex) {
    }
    boolean mapKeyExist = collectionTypeClass != null && Map.class.isAssignableFrom(collectionTypeClass);

    DeclaredType declaredType = (DeclaredType) JavaSourceParserUtil
            .findAnnotationValue(relationAnnotationMirror, "targetEntity");
    if (declaredType == null) {
        if (variableElement.asType() instanceof ErrorType) { //variable => "<any>"
            throw new TypeNotPresentException(this.name + " type not found", null);
        }
        declaredType = (DeclaredType) ((DeclaredType) variableElement.asType()).getTypeArguments()
                .get(mapKeyExist ? 1 : 0);
    }
    this.targetEntity = declaredType.asElement().getSimpleName().toString();

    if (mapKeyExist) {
        this.mapKey = new MapKey().load(element, null);
        this.mapKeyType = this.mapKey != null ? MapKeyType.EXT : MapKeyType.NEW;

        DeclaredType keyDeclaredType = MapKeyClass.getDeclaredType(element);
        if (keyDeclaredType == null) {
            keyDeclaredType = (DeclaredType) ((DeclaredType) variableElement.asType()).getTypeArguments()
                    .get(0);
        }
        if (isEmbeddableClass(keyDeclaredType.asElement())) {
            loadEmbeddableClass(entityMappings, element, variableElement, keyDeclaredType);
            this.mapKeyAttributeType = getSimpleClassName(keyDeclaredType.toString());
        } else if (isEntityClass(keyDeclaredType.asElement())) {
            loadEntityClass(entityMappings, element, variableElement, keyDeclaredType);
            this.mapKeyAttributeType = getSimpleClassName(keyDeclaredType.toString());
        } else {
            this.mapKeyAttributeType = keyDeclaredType.toString();
        }

        this.mapKeyColumn = new Column().load(element,
                JavaSourceParserUtil.findAnnotation(element, MAP_KEY_COLUMN_FQN));
        this.mapKeyTemporal = TemporalType.load(element,
                JavaSourceParserUtil.findAnnotation(element, MAP_KEY_TEMPORAL_FQN));
        this.mapKeyEnumerated = EnumType.load(element,
                JavaSourceParserUtil.findAnnotation(element, MAP_KEY_ENUMERATED_FQN));

        AnnotationMirror joinColumnsAnnotationMirror = JavaSourceParserUtil.findAnnotation(element,
                "javax.persistence.MapKeyJoinColumns");
        if (joinColumnsAnnotationMirror != null) {
            List joinColumnsAnnot = (List) JavaSourceParserUtil.findAnnotationValue(joinColumnsAnnotationMirror,
                    "value");
            if (joinColumnsAnnot != null) {
                for (Object joinColumnObj : joinColumnsAnnot) {
                    this.getMapKeyJoinColumn()
                            .add(new JoinColumn().load(element, (AnnotationMirror) joinColumnObj));
                }
            }
        } else {
            AnnotationMirror joinColumnAnnotationMirror = JavaSourceParserUtil.findAnnotation(element,
                    "javax.persistence.MapKeyJoinColumn");
            if (joinColumnAnnotationMirror != null) {
                this.getMapKeyJoinColumn().add(new JoinColumn().load(element, joinColumnAnnotationMirror));
            }
        }

        this.mapKeyForeignKey = ForeignKey.load(element, null);
        this.getMapKeyAttributeOverride().addAll(AttributeOverride.load(element));

    }
}