mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-30 21:08:30 +08:00
Changed "for (v <- coll) {...}" into "coll foreach {v => ...}" and some for-loops into .map(...).
This commit is contained in:
parent
3e4a102bf0
commit
35cf7d52c7
@ -21,7 +21,7 @@ class ScalaBeanSerializer extends Serializer {
|
||||
val javadocSuffix = " is a Querydsl bean type";
|
||||
|
||||
def serialize(model: EntityType, serializerConfig: SerializerConfig, writer: CodeWriter) {
|
||||
val simpleName: String = model.getSimpleName;
|
||||
val simpleName = model.getSimpleName;
|
||||
|
||||
// package
|
||||
if (!model.getPackageName.isEmpty()){
|
||||
@ -29,7 +29,7 @@ class ScalaBeanSerializer extends Serializer {
|
||||
}
|
||||
|
||||
// imports
|
||||
var importedClasses: Set[String] = getAnnotationTypes(model);
|
||||
val importedClasses = getAnnotationTypes(model);
|
||||
importedClasses.add("scala.reflect.BeanProperty");
|
||||
if (model.hasLists()){
|
||||
importedClasses.add(classOf[List[_]].getName);
|
||||
@ -44,37 +44,28 @@ class ScalaBeanSerializer extends Serializer {
|
||||
writer.javadoc(simpleName + javadocSuffix);
|
||||
|
||||
// header
|
||||
for (annotation <- model.getAnnotations){
|
||||
writer.annotation(annotation);
|
||||
}
|
||||
model.getAnnotations.foreach(writer.annotation(_));
|
||||
|
||||
writer.beginClass(model);
|
||||
|
||||
// properties
|
||||
for (property <- model.getProperties()){
|
||||
property.getAnnotations.foreach( {writer.annotation(_);} )
|
||||
model.getProperties foreach { property =>
|
||||
property.getAnnotations.foreach(writer.annotation(_))
|
||||
if (javaBeanSupport){
|
||||
writer.line("@BeanProperty");
|
||||
}
|
||||
writer.publicField(property.getType(), property.getEscapedName, "_");
|
||||
}
|
||||
|
||||
|
||||
writer.end();
|
||||
}
|
||||
|
||||
def getAnnotationTypes(model: EntityType): Set[String] = {
|
||||
var imports = new HashSet[String]();
|
||||
// for (annotation <- model.getAnnotations){
|
||||
// imports.add(annotation.annotationType.getName);
|
||||
// }
|
||||
imports.addAll(model.getAnnotations.map(_.annotationType.getName))
|
||||
// flatMap flattens the results of the map-function.
|
||||
// E.g. List(List(1,2,3), List(4,5,6)).flatMap(_.map(_*3)) ends up as List(3, 6, 9, 12, 15, 18).
|
||||
imports.addAll(model.getProperties.flatMap(_.getAnnotations.map(_.annotationType.getName)))
|
||||
|
||||
// for (property <- model.getProperties; annotation <- property.getAnnotations) {
|
||||
// imports.add(annotation.annotationType.getName);
|
||||
// }
|
||||
imports;
|
||||
}
|
||||
|
||||
|
||||
@ -88,7 +88,7 @@ class ScalaMetaDataSerializer(val namePrefix: String, val namingStrategy: Naming
|
||||
}
|
||||
|
||||
def serializeProperties(model: EntityType, writer: CodeWriter, properties: Collection[Property]){
|
||||
for (property <- properties){
|
||||
properties foreach { property =>
|
||||
val methodName: String = property.getType.getCategory match {
|
||||
case COMPARABLE => "createComparable";
|
||||
case BOOLEAN => "createBoolean";
|
||||
@ -112,28 +112,19 @@ class ScalaMetaDataSerializer(val namePrefix: String, val namingStrategy: Naming
|
||||
}
|
||||
|
||||
def serializePrimaryKeys(model: EntityType, writer: CodeWriter, primaryKeys: Collection[PrimaryKeyData]) {
|
||||
for (primaryKey <- primaryKeys){
|
||||
primaryKeys foreach { primaryKey =>
|
||||
val fieldName = namingStrategy.getPropertyNameForPrimaryKey(primaryKey.getName(), model);
|
||||
val value = new StringBuilder("createPrimaryKey(");
|
||||
// var first = true;
|
||||
// for (column <- primaryKey.getColumns()){
|
||||
// if (!first){
|
||||
// value.append(", ");
|
||||
// }
|
||||
// value.append(namingStrategy.getPropertyName(column, namePrefix, model));
|
||||
// first = false;
|
||||
// }
|
||||
value.append(primaryKey.getColumns().map({ column =>
|
||||
namingStrategy.getPropertyName(column, namePrefix, model)
|
||||
}).mkString(", "));
|
||||
|
||||
value.append(")");
|
||||
writer.publicFinal(new ClassType(classOf[PrimaryKey[_]], model), fieldName, value.toString);
|
||||
}
|
||||
}
|
||||
|
||||
def serializeForeignKeys(model: EntityType, writer: CodeWriter, foreignKeys: Collection[_ <: KeyData] , inverse: Boolean){
|
||||
for (foreignKey <- foreignKeys){
|
||||
foreignKeys foreach { foreignKey =>
|
||||
var fieldName: String = null;
|
||||
if (inverse){
|
||||
fieldName = namingStrategy.getPropertyNameForInverseForeignKey(foreignKey.getName, model);
|
||||
@ -177,10 +168,8 @@ class ScalaMetaDataSerializer(val namePrefix: String, val namingStrategy: Naming
|
||||
}
|
||||
|
||||
def getAnnotationTypes(model: EntityType): Set[String] = {
|
||||
var imports = new HashSet[String]();
|
||||
for (annotation <- model.getAnnotations){
|
||||
imports.add(annotation.annotationType.getName);
|
||||
}
|
||||
val imports = new HashSet[String]();
|
||||
imports.addAll(model.getAnnotations.map(_.annotationType.getName))
|
||||
imports;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user