use of com.sun.codemodel.JMethod in project rest.li by linkedin.
the class JavaDataTemplateGenerator method overrideCopierMethod.
private static void overrideCopierMethod(JDefinedClass templateClass, String methodName) {
final JMethod copierMethod = templateClass.method(JMod.PUBLIC, templateClass, methodName);
copierMethod.annotate(Override.class);
copierMethod._throws(CloneNotSupportedException.class);
copierMethod.body()._return(JExpr.cast(templateClass, JExpr._super().invoke(methodName)));
}
use of com.sun.codemodel.JMethod in project rest.li by linkedin.
the class JavaDataTemplateGenerator method generatePathSpecMethodsForCollection.
private void generatePathSpecMethodsForCollection(JDefinedClass templateClass, DataSchema schema, JClass childClass, String wildcardMethodName) throws JClassAlreadyExistsException {
if (hasNestedFields(schema)) {
final JDefinedClass fieldsNestedClass = generatePathSpecNestedClass(templateClass);
final JClass itemsFieldType = getCodeModel().ref(childClass.fullName() + ".Fields");
final JMethod constantField = fieldsNestedClass.method(JMod.PUBLIC, itemsFieldType, wildcardMethodName);
constantField.body()._return(JExpr._new(itemsFieldType).arg(JExpr.invoke("getPathComponents")).arg(_pathSpecClass.staticRef("WILDCARD")));
}
}
use of com.sun.codemodel.JMethod in project rest.li by linkedin.
the class JavaDataTemplateGenerator method generatePathSpecMethodsForRecord.
private void generatePathSpecMethodsForRecord(List<RecordTemplateSpec.Field> fieldSpecs, JDefinedClass templateClass) throws JClassAlreadyExistsException {
final JDefinedClass fieldsNestedClass = generatePathSpecNestedClass(templateClass);
for (RecordTemplateSpec.Field field : fieldSpecs) {
JClass fieldsRefType = _pathSpecClass;
if (hasNestedFields(field.getSchemaField().getType())) {
final JClass fieldType = generate(field.getType());
fieldsRefType = getCodeModel().ref(fieldType.fullName() + ".Fields");
}
final JMethod constantField = fieldsNestedClass.method(JMod.PUBLIC, fieldsRefType, escapeReserved(field.getSchemaField().getName()));
constantField.body()._return(JExpr._new(fieldsRefType).arg(JExpr.invoke("getPathComponents")).arg(field.getSchemaField().getName()));
if (!field.getSchemaField().getDoc().isEmpty()) {
constantField.javadoc().append(field.getSchemaField().getDoc());
}
setDeprecatedAnnotationAndJavadoc(constantField, field.getSchemaField());
}
final JVar staticFields = templateClass.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, fieldsNestedClass, "_fields").init(JExpr._new(fieldsNestedClass));
final JMethod staticFieldsAccessor = templateClass.method(JMod.PUBLIC | JMod.STATIC, fieldsNestedClass, "fields");
staticFieldsAccessor.body()._return(staticFields);
}
use of com.sun.codemodel.JMethod in project rest.li by linkedin.
the class JavaDataTemplateGenerator method generateUnion.
protected void generateUnion(JDefinedClass unionClass, UnionTemplateSpec unionSpec) throws JClassAlreadyExistsException {
extendUnionBaseClass(unionClass);
final JVar schemaField = generateSchemaField(unionClass, unionSpec.getSchema());
generateConstructorWithNoArg(unionClass, schemaField, _dataMapClass);
generateConstructorWithObjectArg(unionClass, schemaField);
for (UnionTemplateSpec.Member member : unionSpec.getMembers()) {
if (member.getClassTemplateSpec() != null) {
generateUnionMemberAccessors(unionClass, member, generate(member.getClassTemplateSpec()), generate(member.getDataClass()), schemaField);
}
}
unionSpec.getMembers().stream().map(UnionTemplateSpec.Member::getCustomInfo).distinct().forEach(customInfo -> generateCustomClassInitialization(unionClass, customInfo));
if (_pathSpecMethods) {
generatePathSpecMethodsForUnion(unionSpec, unionClass);
}
if (_copierMethods) {
generateCopierMethods(unionClass);
}
if (unionSpec.getTyperefClass() != null) {
final TyperefTemplateSpec typerefClassSpec = unionSpec.getTyperefClass();
final JDefinedClass typerefInfoClass = unionClass._class(getJModValue(typerefClassSpec.getModifiers()), escapeReserved(typerefClassSpec.getClassName()));
generateTyperef(typerefInfoClass, typerefClassSpec);
final JFieldVar typerefInfoField = unionClass.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, TyperefInfo.class, DataTemplateUtil.TYPEREFINFO_FIELD_NAME);
typerefInfoField.init(JExpr._new(typerefInfoClass));
unionClass._implements(HasTyperefInfo.class);
final JMethod typerefInfoMethod = unionClass.method(JMod.PUBLIC, TyperefInfo.class, "typerefInfo");
typerefInfoMethod.body()._return(typerefInfoField);
}
}
use of com.sun.codemodel.JMethod in project rest.li by linkedin.
the class JavaDataTemplateGenerator method generateConstructorWithInitialCapacity.
private void generateConstructorWithInitialCapacity(JDefinedClass cls, JClass elementClass) {
final JMethod argConstructor = cls.constructor(JMod.PUBLIC);
final JVar initialCapacity = argConstructor.param(getCodeModel().INT, "initialCapacity");
argConstructor.body().invoke(THIS).arg(JExpr._new(elementClass).arg(initialCapacity));
}
Aggregations