private Type asGeneric(Type type) { if (type.getParameters().size() == 0) { int count = type.getJavaClass().getTypeParameters().length; if (count > 0) { return new SimpleType(type, new Type[count]); } } return type; }
private void addSupertypeFields(EntityType model, Map<String, EntityType> superTypes, Set<EntityType> handled) { if (handled.add(model)) { for (Supertype supertype : model.getSuperTypes()) { EntityType entityType = superTypes.get(supertype.getType().getFullName()); if (entityType == null) { if (supertype.getType().getPackageName().startsWith("java.")) { // skip internal supertypes continue; } // FIXME this misses the generics Class<?> cl = supertype.getType().getJavaClass(); typeFactory.addEmbeddableType(cl); entityType = createEntityType(cl, new HashMap<Class<?>, EntityType>()); addProperties(cl, entityType); } addSupertypeFields(entityType, superTypes, handled); supertype.setEntityType(entityType); model.include(supertype); } } }
@Test public void generics_wildcard() throws SecurityException, NoSuchFieldException { Field field = DefaultQueryMetadata.class.getDeclaredField("exprInJoins"); Type type = factory.get(field.getType(), field.getGenericType()); assertEquals(TypeCategory.SET, type.getCategory()); Type parameter = type.getParameters().get(0); assertEquals(Expression.class, parameter.getJavaClass()); parameter = parameter.getParameters().get(0); assertEquals(TypeExtends.class, parameter.getClass()); assertNull(((TypeExtends) parameter).getVarName()); }
@Override public Class<?> getJavaClass() { return type.getJavaClass(); }
private void register(UID uid, Type type) { if (usePrimitives && Primitives.isWrapperType(type.getJavaClass())) { String name = Primitives.unwrap(type.getJavaClass()).getName(); type = new SimpleType(type.getCategory(), "java.lang." + name, "java.lang", name, true, true); } datatypeToType.put(uid, type); }
@Override public Class<?> getJavaClass() { if (javaClass == null) { String className; if (packageName.length() > 0) { className = packageName + "." + localName.replace('.', '$'); } else { className = localName.replace('.', '$'); } try { if (className.endsWith("[]")) { Class<?> component = getComponentType().getJavaClass(); javaClass = Array.newInstance(component, 0).getClass(); } else if (PRIMITIVES.containsKey(className)) { javaClass = PRIMITIVES.get(className); } else { javaClass = Class.forName(className); } } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } return javaClass; }
protected EntityType createEntityType(Type type, Map<Class<?>, EntityType> types) { Class<?> key = type.getJavaClass(); if (allTypes.containsKey(key)) { return allTypes.get(key); } else { EntityType entityType = new EntityType(type, variableNameFunction); typeMappings.register(entityType, queryTypeFactory.create(entityType)); Class<?> superClass = key.getSuperclass(); if (entityType.getSuperType() == null && superClass != null && !superClass.equals(Object.class)) { entityType.addSupertype(new Supertype(typeFactory.get(superClass, key.getGenericSuperclass()))); } types.put(key, entityType); allTypes.put(key, entityType); return entityType; } }
protected EntityType createEntityType(Type type, Map<Class<?>, EntityType> types) { Class<?> key = type.getJavaClass(); if (allTypes.containsKey(key)) { return allTypes.get(key); } else { EntityType entityType = new EntityType(type, variableNameFunction); registerConfig(entityType); typeMappings.register(entityType, queryTypeFactory.create(entityType)); Class<?> superClass = key.getSuperclass(); if (entityType.getSuperType() == null && superClass != null && !superClass.equals(Object.class)) { entityType.addSupertype(new Supertype(typeFactory.get(superClass, key.getGenericSuperclass()))); } types.put(key, entityType); allTypes.put(key, entityType); return entityType; } }
private void addSupertypeFields(EntityType model, Map<Class<?>, EntityType> superTypes, Set<EntityType> handled) { if (handled.add(model)) { for (Supertype supertype : model.getSuperTypes()) { EntityType entityType = superTypes.get(supertype.getType().getJavaClass()); if (entityType != null) { addSupertypeFields(entityType, superTypes, handled); supertype.setEntityType(entityType); model.include(supertype); } } } }
private void addSupertypeFields(EntityType model, Map<Class<?>, EntityType> superTypes, Set<EntityType> handled) { if (handled.add(model)) { for (Supertype supertype : model.getSuperTypes()) { EntityType entityType = superTypes.get(supertype.getType().getJavaClass()); if (entityType != null) { addSupertypeFields(entityType, superTypes, handled); supertype.setEntityType(entityType); model.include(supertype); } } } }
for (Map.Entry<Class<?>, EntityType> entry : allTypes.entrySet()) { EntityType entityType = entry.getValue(); if (entityType.getSuperType() != null && !allTypes.containsKey(entityType.getSuperType().getType().getJavaClass())) { additions.add(entityType.getSuperType());
for (Map.Entry<Class<?>, EntityType> entry : allTypes.entrySet()) { EntityType entityType = entry.getValue(); if (entityType.getSuperType() != null && !allTypes.containsKey(entityType.getSuperType().getType().getJavaClass())) { additions.add(entityType.getSuperType());
@Test public void Generics_Wildcard() throws SecurityException, NoSuchFieldException { Field field = DefaultQueryMetadata.class.getDeclaredField("exprInJoins"); Type type = factory.get(field.getType(), field.getGenericType()); assertEquals(TypeCategory.SET, type.getCategory()); Type parameter = type.getParameters().get(0); assertEquals(Expression.class, parameter.getJavaClass()); parameter = parameter.getParameters().get(0); assertEquals(TypeExtends.class, parameter.getClass()); assertNull(((TypeExtends)parameter).getVarName()); }
@Test public void generics_wildcard() throws SecurityException, NoSuchFieldException { Field field = DefaultQueryMetadata.class.getDeclaredField("exprInJoins"); Type type = factory.get(field.getType(), field.getGenericType()); assertEquals(TypeCategory.SET, type.getCategory()); Type parameter = type.getParameters().get(0); assertEquals(Expression.class, parameter.getJavaClass()); parameter = parameter.getParameters().get(0); assertEquals(TypeExtends.class, parameter.getClass()); assertNull(((TypeExtends) parameter).getVarName()); }