Package com.mysema.codegen.model

Examples of com.mysema.codegen.model.Type


                            handleProperty(entityType, pc.getMappedClass(), (org.hibernate.mapping.Property) properties.next());
                        }
                    } else {
                        String name = component.getNodeName();
                        Class<?> clazz = component.getType().getReturnedClass();
                        Type propertyType = getType(pc.getMappedClass(), clazz, name);
                        AnnotatedElement annotated = getAnnotatedElement(pc.getMappedClass(), name);
                        Property property = createProperty(entityType, name, propertyType, annotated);
                        entityType.addProperty(property);
                        // handle component properties
                        EntityType embeddedType = createEmbeddableType(propertyType);
View Full Code Here


        try {
            clazz = p.getType().getReturnedClass();
        } catch (MappingException e) {
            // ignore
        }
        Type propertyType = getType(cl, clazz, p.getName());
        try {
            propertyType = getPropertyType(p, propertyType);
        } catch (MappingException e) {
            // ignore
        }

        AnnotatedElement annotated = getAnnotatedElement(cl, p.getName());
        propertyType = getTypeOverride(propertyType, annotated);
        if (propertyType == null) {
            return;
        }

        if (p.isComposite()) {
            EntityType embeddedType = createEmbeddableType(propertyType);
            Iterator<?> properties = ((Component)p.getValue()).getPropertyIterator();
            while (properties.hasNext()) {
                handleProperty(embeddedType, embeddedType.getJavaClass(), (org.hibernate.mapping.Property)properties.next());
            }
            propertyType = embeddedType;
        } else if (propertyType.getCategory() == TypeCategory.ENTITY || p.getValue() instanceof ManyToOne) {
            propertyType = createEntityType(propertyType);
        } else if (propertyType.getCategory() == TypeCategory.CUSTOM) {
            propertyType = createEmbeddableType(propertyType);
        } else if (p.getValue() instanceof org.hibernate.mapping.Collection) {
            org.hibernate.mapping.Collection collection = (org.hibernate.mapping.Collection)p.getValue();
            if (collection.getElement() instanceof OneToMany) {
                String entityName = ((OneToMany)collection.getElement()).getReferencedEntityName();
                if (entityName != null) {
                    if (collection.isMap()) {
                        Type keyType = typeFactory.get(Class.forName(propertyType.getParameters().get(0).getFullName()));
                        Type valueType = typeFactory.get(Class.forName(entityName));
                        propertyType = new SimpleType(propertyType,
                                normalize(propertyType.getParameters().get(0), keyType),
                                normalize(propertyType.getParameters().get(1), valueType));
                    } else {
                        Type componentType = typeFactory.get(Class.forName(entityName));
                        propertyType = new SimpleType(propertyType,
                                normalize(propertyType.getParameters().get(0), componentType));
                    }
                }
            } else if (collection.getElement() instanceof Component) {
View Full Code Here

        try {
            clazz = p.getJavaType();
        } catch (MappingException e) {
            // ignore
        }
        Type propertyType = getType(cl, clazz, p.getName());

        AnnotatedElement annotated = getAnnotatedElement(cl, p.getName());
        propertyType = getTypeOverride(propertyType, annotated);
        if (propertyType == null) {
            return;
        }

        if (p.isCollection()) {
            if (p instanceof MapAttribute) {
                MapAttribute<?,?,?> map = (MapAttribute<?,?,?>)p;
                Type keyType = typeFactory.get(map.getKeyJavaType());
                Type valueType = typeFactory.get(map.getElementType().getJavaType());
                valueType = getPropertyType(p, valueType);
                propertyType = new SimpleType(propertyType,
                        normalize(propertyType.getParameters().get(0), keyType),
                        normalize(propertyType.getParameters().get(1), valueType));
            } else {
                Type valueType = typeFactory.get(((PluralAttribute<?,?,?>)p).getElementType().getJavaType());
                valueType = getPropertyType(p, valueType);
                propertyType = new SimpleType(propertyType,
                        normalize(propertyType.getParameters().get(0), valueType));
            }
        } else {
View Full Code Here

        if (entityType.getSuperType() != null) {
            superTypes.push(entityType.getSuperType().getType());
        }

        while (!superTypes.isEmpty()) {
            Type superType = superTypes.pop();
            if (!context.allTypes.containsKey(superType.getFullName())) {
                TypeElement typeElement = processingEnv.getElementUtils().getTypeElement(superType.getFullName());
                if (conf.isStrictMode() && !TypeUtils.hasAnnotationOfType(typeElement, conf.getEntityAnnotations())) {
                    continue;
                }
                if (typeElement == null) {
                    throw new IllegalStateException("Found no type for " + superType.getFullName());
                }
                EntityType superEntityType = elementHandler.handleEntityType(typeElement);
                if (superEntityType.getSuperType() != null) {
                    superTypes.push(superEntityType.getSuperType().getType());
                }
                context.allTypes.put(superType.getFullName(), superEntityType);
            }
        }

    }
View Full Code Here

        for (Element delegateMethod : delegateMethods) {
            ExecutableElement method = (ExecutableElement)delegateMethod;
            Element element = delegateMethod.getEnclosingElement();
            String name = method.getSimpleName().toString();
            Type delegateType = typeFactory.getType(element.asType(), true);
            Type returnType = typeFactory.getType(method.getReturnType(), true);
            List<Parameter> parameters = elementHandler.transformParams(method.getParameters());
            // remove first element
            parameters = parameters.subList(1, parameters.size());

            EntityType entityType = null;
View Full Code Here

    }

    private void serialize(Serializer serializer, Collection<EntityType> models) {
        for (EntityType model : models) {
            try {
                Type type = conf.getTypeMappings().getPathType(model, model, true);
                String packageName = type.getPackageName();
                String className = !packageName.isEmpty() ? (packageName + "." + type.getSimpleName()) : type.getSimpleName();

                // skip if type is excluded class or in excluded package
                if (conf.isExcludedPackage(model.getPackageName()) || conf.isExcludedClass(model.getFullName())) {
                    continue;
                }
View Full Code Here

    }

    private void serialize(Map<Class<?>, EntityType> types, Serializer serializer) throws IOException {
        for (EntityType entityType : types.values()) {
            if (serialized.add(entityType)) {
                Type type = typeMappings.getPathType(entityType, entityType, true);
                String packageName = type.getPackageName();
                String className = packageName.length() > 0 ? (packageName + "." + type.getSimpleName()) : type.getSimpleName();
                write(serializer, className.replace('.', '/') + ".java", entityType);
            }
        }
    }
View Full Code Here


    private Property toProperty(EntityType entityType, String name, TypeMirror type,
            Annotations annotations) {
        // type
        Type propertyType = typeFactory.getType(type, true);
        if (annotations.isAnnotationPresent(QueryType.class)) {
            PropertyType propertyTypeAnn = annotations.getAnnotation(QueryType.class).value();
            if (propertyTypeAnn != PropertyType.NONE) {
                TypeCategory typeCategory = TypeCategory.valueOf(annotations.getAnnotation(QueryType.class).value().name());
                if (typeCategory == null) {
                    return null;
                }
                propertyType = propertyType.as(typeCategory);
            } else {
                return null;
            }
        }
View Full Code Here

        return new Property(entityType, name, propertyType, inits);
    }


    public EntityType handleProjectionType(TypeElement e) {
        Type c = typeFactory.getType(e.asType(), true);
        EntityType entityType = new EntityType(c.as(TypeCategory.ENTITY));
        typeMappings.register(entityType, queryTypeFactory.create(entityType));
        List<? extends Element> elements = e.getEnclosedElements();
        handleConstructors(entityType, elements);
        return entityType;
    }
View Full Code Here

    }

    @Test
    public void Generics_WildCard() throws SecurityException, NoSuchFieldException{
        Field field = getClass().getDeclaredField("field");
        Type type = factory.get(field.getType(), field.getGenericType());
        assertEquals(1, type.getParameters().size());
        assertEquals(TypeExtends.class, type.getParameters().get(0).getClass());
//        assertNull(type.getParameters().get(0));
    }
View Full Code Here

TOP

Related Classes of com.mysema.codegen.model.Type

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.