idea去除sonarlint扫描Date的问题

idea去除sonarlint扫描Date的问题

  • 重写get和set方法
    • get设置
    • set设置
  • 删除正则
    • 验证

重写get和set方法

设置idea的get和set方法

get设置

#if($field.modifierStatic)
static ##
#end
#if($field.date)
$field.type ##
#set($name = $StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project))))
#if ($field.boolean && $field.primitive)
is##
#else
get##
#end
${name}() {
if(this.$field.name == null){
return null;
}
return ($field.type) this. $field.name .clone();
}
#else
public void delete_get_method_##
$field.name (){}
#end

set设置

#set($paramName = $helper.getParamName($field, $project))
#if($field.modifierStatic)
static ##
#end
#if($field.date)
void set$StringUtil.capitalizeWithJavaBeanConvention($StringUtil.sanitizeJavaIdentifier($helper.getPropertyName($field, $project)))($field.type $paramName) {
#if ($field.name == $paramName)
    #if (!$field.modifierStatic)
    ##
    #else
        $classname.##
    #end
#end
if($paramName == null){
this.##
$field.name = null;
return;
}
this.##
$field.name = ($field.type)##
$paramName##
.clone();
}
#else
public void delete_set_method_##
$field.name (){}
#end

删除正则

\n +public void delete_(set|get)_method_[A-Za-z0-9]+\(\) \{\n +\}\n

验证

idea去除sonarlint扫描Date的问题_第1张图片
idea去除sonarlint扫描Date的问题_第2张图片
idea去除sonarlint扫描Date的问题_第3张图片

public class TestGetSet {
    private Date date;
    private Timestamp timestamp;
    private String name;
    private Integer count;

    public Date getDate() {
        if (this.date == null) {
            return null;
        }
        return (Date) this.date.clone();
    }

    public void setDate(Date date) {
        if (date == null) {
            this.date = null;
            return;
        }
        this.date = (Date) date.clone();
    }

    public Timestamp getTimestamp() {
        if (this.timestamp == null) {
            return null;
        }
        return (Timestamp) this.timestamp.clone();
    }

    public void setTimestamp(Timestamp timestamp) {
        if (timestamp == null) {
            this.timestamp = null;
            return;
        }
        this.timestamp = (Timestamp) timestamp.clone();
    }
}

你可能感兴趣的:(java)