package org.treeleafj.xdoc.resolver.sun.converter;

import com.sun.javadoc.ParamTag;
import org.treeleafj.xdoc.tag.DocTag;
import org.treeleafj.xdoc.tag.ParamTagImpl;

/**
 * Created by leaf on 2017/3/4.
 */
public class ParamTagConverter implements SunTagConverter<ParamTag> {

    @Override
    public DocTag converter(ParamTag o) {

        //解析 "@param user :username 用户名|必填" 这种注释
        boolean require = false;
        String paramDesc = o.parameterComment();
        if (paramDesc.contains("|")) {
            int endIndex = paramDesc.lastIndexOf("|必填");
            require = endIndex > 0;
            if (require) {
                paramDesc = paramDesc.substring(0, endIndex);
            }
        }

        String paramName = o.parameterName();
        if (paramDesc.startsWith(":")) {
            int index = paramDesc.indexOf(" ");
            if (index > 0) {
                paramName = paramDesc.substring(1, index);
                paramDesc = paramDesc.substring(index + 1);
            }
        }
        return new ParamTagImpl(o.name(), paramName, paramDesc, require);
    }
}

@@ -74,24 +74,69 @@
 c.ParamTag;%0A
+import org.apache.commons.lang3.StringUtils;%0A
 import org.t
@@ -778,16 +778,42 @@
 mName = 
+StringUtils.defaultString(
 o.parame
@@ -821,16 +821,17 @@
 erName()
+)
 ;%0A      

修复@param没写描述导致null的问题