All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.thrift.service.perstruct.bean.decorator.class.vm Maven / Gradle / Ivy

There is a newer version: 3.5.0
Show newest version
#parse("${include}/header.include.vm")
#parse("${include}/generic.include.vm")
#parse("thrift/include/decorator.include.vm")
#if(!$sourceinfo.bean)
#set($codewriter.saveCurrentFile = false)
#stop
#end
#set ( $baseClass = $sourceinfo.baseClass)
#set ( $className ="${baseClass.simpleName}" )
#set ( $fields         = $TOOL.sortByName($sourceinfo.getFieldDescriptors()) )
#set ( $pkg = ${sourceinfo.decoratorPackage})
$codewriter.setCurrentJavaFilename("$pkg", "${className}.java")
${sourceinfo.removeDecorateTypesFromImports()}
## 读取源码注释
## 默认#set语句不允许设置null,所以这里要通过#if判断来将$classDoc设置为空
#if($JavadocReader.read(${baseClass}))
#set ($classDoc    = $JavadocReader.read(${baseClass}))
#else
#set ($classDoc    = "")
#end
package $pkg;
#outputImports()
import com.facebook.swift.codec.ThriftStruct;
import com.facebook.swift.codec.ThriftField;
import com.facebook.swift.codec.ThriftField.Requiredness;
#importCodegen()
#if ($sourceinfo.needTransformer)
import com.gitee.l0km.xthrift.thrift.TypeTransformer;
#end
/**
#if(${classDoc.getClassComment()})
${classDoc.getClassComment(false,true,true)}
 * ========================================
#end * decorator pattern 装饰者模式代理{@link #typeName(${baseClass})}
* 代理对象必须有默认构造方法,必须是普通类型,不可以有@ThriftStruct注释
* 转发所有{@link #typeName(${baseClass})}get/set方法到{@link ${esc.hash}delegate()}指定的实例,
* $GENERAED_BY
* */ @ThriftStruct public final class ${className} implements ThriftDecorator<#typeName(${baseClass})> { private final #typeName(${baseClass}) delegate; public ${className}(){ this(new #typeName(${baseClass})()); } public ${className}(#typeName(${baseClass}) delegate) { if(null == delegate){ throw new NullPointerException("delegate is null"); } // 检查被装饰类是否有@ThriftStruct注释 if(delegate.getClass().isAnnotationPresent(ThriftStruct.class)){ throw new IllegalArgumentException( String.format("NOT ALLOW %s have @ThriftStruct annotation",delegate.getClass().getName())); } this.delegate = delegate; } /** * 返回被装饰的{@link #typeName(${baseClass})}实例 */ @Override public #typeName(${baseClass}) delegate() { return delegate; } @Override public int hashCode() { return delegate().hashCode(); } @Override public boolean equals(Object obj) { return delegate().equals(obj); } @Override public String toString() { return delegate().toString(); } #foreach ($field in $fields) #set($propertyType = $field.propertyType) #if($propertyType.primitive) #set ($requireness = 'Requiredness.REQUIRED' ) #else #set ($requireness = 'Requiredness.OPTIONAL' ) #end #set ($readMethod = $field.readMethod) $!{classDoc.getMethodComment($readMethod)}## @ThriftField(value = $velocityCount,name = "$schemainfo.escapeField($field.name)",requiredness=$requireness) #renderCodegen($field) public $sourceinfo.toThriftType($readMethod.genericReturnType) ${readMethod.name}(){ return #returnValue($readMethod.genericReturnType,"delegate().${readMethod.name}()"); } #set ($writeMethod = $field.writeMethod) $!{classDoc.getMethodComment($writeMethod)}## @ThriftField public void ${writeMethod.name}($sourceinfo.toThriftType($readMethod.genericReturnType) $field.name){ delegate().${writeMethod.name}(#setValue($readMethod.genericReturnType,"$field.name")); } #end##foreach }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy