From 0d5ba083d76a92939fe4fc1ccdc6aafdc6658a5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Westk=C3=A4mper?= Date: Wed, 1 Oct 2014 22:52:05 +0300 Subject: [PATCH 1/2] Remove validation in EntitySerializer --- .../query/codegen/EntitySerializer.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/querydsl-codegen/src/main/java/com/mysema/query/codegen/EntitySerializer.java b/querydsl-codegen/src/main/java/com/mysema/query/codegen/EntitySerializer.java index d4ed16c3e..b06b8ebf9 100644 --- a/querydsl-codegen/src/main/java/com/mysema/query/codegen/EntitySerializer.java +++ b/querydsl-codegen/src/main/java/com/mysema/query/codegen/EntitySerializer.java @@ -13,6 +13,13 @@ */ package com.mysema.query.codegen; +import javax.annotation.Generated; +import javax.inject.Inject; +import javax.inject.Named; +import java.io.IOException; +import java.lang.annotation.Annotation; +import java.util.*; + import com.google.common.base.Function; import com.google.common.base.Joiner; import com.google.common.collect.Lists; @@ -23,14 +30,6 @@ import com.mysema.query.types.*; import com.mysema.query.types.expr.ComparableExpression; import com.mysema.query.types.expr.SimpleExpression; import com.mysema.query.types.path.*; - -import javax.annotation.Generated; -import javax.inject.Inject; -import javax.inject.Named; -import java.io.IOException; -import java.lang.annotation.Annotation; -import java.util.*; - import static com.mysema.codegen.Symbols.*; /** @@ -221,10 +220,7 @@ public class EntitySerializer implements Serializer { protected void initEntityFields(CodeWriter writer, SerializerConfig config, EntityType model) throws IOException { Supertype superType = model.getSuperType(); - if (superType != null && superType.getEntityType() == null) { - throw new IllegalStateException("No entity type for " + superType.getType().getFullName()); - } - if (superType != null && superType.getEntityType().hasEntityFields()) { + if (superType != null && superType.getEntityType() != null && superType.getEntityType().hasEntityFields()) { Type superQueryType = typeMappings.getPathType(superType.getEntityType(), model, false); writer.line("this._super = new " + writer.getRawName(superQueryType) + "(type, metadata, inits);"); } From a3fa506a11c96261dd6f43b430ec97a5ff2ce0fc Mon Sep 17 00:00:00 2001 From: Ruben Dijkstra Date: Thu, 2 Oct 2014 20:21:20 +0200 Subject: [PATCH 2/2] Break up the if into two ifs This to keep the statement within reasonable margin of 'the guide' and aid IDEs in the validity of the nullcheck --- .../java/com/mysema/query/codegen/EntitySerializer.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/querydsl-codegen/src/main/java/com/mysema/query/codegen/EntitySerializer.java b/querydsl-codegen/src/main/java/com/mysema/query/codegen/EntitySerializer.java index b06b8ebf9..d30818bf5 100644 --- a/querydsl-codegen/src/main/java/com/mysema/query/codegen/EntitySerializer.java +++ b/querydsl-codegen/src/main/java/com/mysema/query/codegen/EntitySerializer.java @@ -220,9 +220,12 @@ public class EntitySerializer implements Serializer { protected void initEntityFields(CodeWriter writer, SerializerConfig config, EntityType model) throws IOException { Supertype superType = model.getSuperType(); - if (superType != null && superType.getEntityType() != null && superType.getEntityType().hasEntityFields()) { - Type superQueryType = typeMappings.getPathType(superType.getEntityType(), model, false); - writer.line("this._super = new " + writer.getRawName(superQueryType) + "(type, metadata, inits);"); + if (superType != null) { + EntityType entityType = superType.getEntityType(); + if (entityType != null && entityType.hasEntityFields()) { + Type superQueryType = typeMappings.getPathType(entityType, model, false); + writer.line("this._super = new " + writer.getRawName(superQueryType) + "(type, metadata, inits);"); + } } for (Property field : model.getProperties()) {