ph-dev-tools
Version:
Development Tools for PHibernate
47 lines (38 loc) • 1.63 kB
text/typescript
import {QEntityBuilder} from "./QEntityBuilder";
import {PropertyDocEntry} from "../../parser/DocEntry";
import {
QBuilder, getPropertyFieldType, getPropertyFieldInterface, getPropertyFieldClass,
getPropertyTypedOperationInterface, getPropertyJSONOperationInterface
} from "./../QBuilder";
import {FieldType} from "querydsl-typescript/lib/index";
/**
* Created by Papa on 4/25/2016.
*/
export class QPropertyBuilder implements QBuilder {
constructor(
private parentBuilder:QEntityBuilder, //
public propertyDocEntry:PropertyDocEntry //
) {
}
build():string {
let prop = this.propertyDocEntry;
let clazz = this.parentBuilder.entity.docEntry.name;
let qClazz = `Q${clazz}`;
let name = prop.name;
let fieldClass = getPropertyFieldClass(prop);
let type = `${fieldClass}<${qClazz}>`;
return `${name} = new ${type}(this, ${qClazz}, '${clazz}', '${name}');`;
}
buildInterfaceDefinition():string {
let prop = this.propertyDocEntry;
let name = prop.name;
// let clazz = this.parentBuilder.entity.docEntry.name;
let fieldInterface = getPropertyFieldInterface(prop);
// let typedOperationInterface = `${getPropertyTypedOperationInterface(prop)}<I${clazz}>`;
let typedOperationInterface = getPropertyTypedOperationInterface(prop);
// let jsonOperationInterface = `${getPropertyJSONOperationInterface(prop)}<I${clazz}>`;
let jsonOperationInterface = getPropertyJSONOperationInterface(prop);
let type = `${fieldInterface}<any>`;
return `${name}?: ${type} | ${typedOperationInterface} | ${jsonOperationInterface} | ${prop.primitive};`;
}
}