Skip to content

Commit

Permalink
Merge pull request #802 from shalousun/master
Browse files Browse the repository at this point in the history
Optimize: Optimize the repetitive code in RPC and Javadoc document ge…
  • Loading branch information
shalousun authored Jun 4, 2024
2 parents eab97b3 + b03a3af commit 652c70e
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 718 deletions.
254 changes: 2 additions & 252 deletions src/main/java/com/ly/doc/model/RpcJavaMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,261 +20,11 @@
*/
package com.ly.doc.model;

import com.ly.doc.utils.ParamUtil;
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaMethod;
import com.thoughtworks.qdox.model.JavaType;

import java.util.List;
import java.util.Map;

/**
* for rpc
*
* @author yu 2020/1/29.
*/
public class RpcJavaMethod implements IMethod {

/**
* java method
*/
private JavaMethod javaMethod;

/**
* methodId handled by md5
*/
private String methodId;

/**
* method name
*/
private String name;

/**
* method order
*/
private int order;


/**
* method description
*/
private String desc;

/**
* method definition
*/
private String methodDefinition;

/**
* escape method definition
*/
private String escapeMethodDefinition;

/**
* detailed introduction of the method
*/
private String detail;

/**
* method describe
*/
private String throwsInfo;

/**
* return class Info
*/
private String returnClassInfo;

/**
* http request params
*/
private List<ApiParam> requestParams;

/**
* http request author
*/
private String author;

/**
* http response params
*/
private List<ApiParam> responseParams;

/**
* method deprecated
*/
private boolean deprecated;

private Map<String, JavaType> actualTypesMap;


private String version;

public String getVersion() {
return version;
}

public RpcJavaMethod setVersion(String version) {
this.version = version;
return this;
}

public static RpcJavaMethod builder() {
return new RpcJavaMethod();
}

public JavaMethod getJavaMethod() {
return javaMethod;
}

public RpcJavaMethod setJavaMethod(JavaMethod javaMethod) {
this.javaMethod = javaMethod;
return this;
}

public String getMethodId() {
return methodId;
}

public RpcJavaMethod setMethodId(String methodId) {
this.methodId = methodId;
return this;
}

public String getName() {
return name;
}

public RpcJavaMethod setName(String name) {
this.name = name;
return this;
}

public int getOrder() {
return order;
}

public RpcJavaMethod setOrder(int order) {
this.order = order;
return this;
}

public String getDesc() {
return desc;
}

public RpcJavaMethod setDesc(String desc) {
this.desc = desc;
return this;
}

public String getDetail() {
return detail;
}

public RpcJavaMethod setDetail(String detail) {
this.detail = detail;
return this;
}

public String getThrowsInfo() {
return throwsInfo;
}

public RpcJavaMethod setThrowsInfo(String throwsInfo) {
this.throwsInfo = throwsInfo;
return this;
}

public String getReturnClassInfo() {
return returnClassInfo;
}

public RpcJavaMethod setReturnClassInfo(String returnClassInfo) {
this.returnClassInfo = returnClassInfo;
return this;
}

public String getAuthor() {
return author;
}

public RpcJavaMethod setAuthor(String author) {
this.author = author;
return this;
}

public List<ApiParam> getResponseParams() {
return responseParams;
}

public RpcJavaMethod setResponseParams(List<ApiParam> responseParams) {
this.responseParams = responseParams;
return this;
}

public boolean isDeprecated() {
return deprecated;
}

public RpcJavaMethod setDeprecated(boolean deprecated) {
this.deprecated = deprecated;
return this;
}

public List<ApiParam> getRequestParams() {
return requestParams;
}

public RpcJavaMethod setRequestParams(List<ApiParam> requestParams) {
this.requestParams = requestParams;
return this;
}

public String getMethodDefinition() {
return methodDefinition;
}

public RpcJavaMethod setMethodDefinition(String methodDefinition) {
this.methodDefinition = methodDefinition;
return this;
}

public String getEscapeMethodDefinition() {
return escapeMethodDefinition;
}

public RpcJavaMethod setEscapeMethodDefinition(String escapeMethodDefinition) {
this.escapeMethodDefinition = escapeMethodDefinition;
return this;
}

public Map<String, JavaType> getActualTypesMap() {
return actualTypesMap;
}

public RpcJavaMethod setActualTypesMap(Map<String, JavaType> actualTypesMap) {
this.actualTypesMap = actualTypesMap;
return this;
}

@Override
public JavaClass getDeclaringClass() {
return this.javaMethod.getDeclaringClass();
}

@Override
public String getMethodName() {
return this.name;
}

@Override
public List<String> getArgsClasses() {
return ParamUtil.extractQualifiedName(this.requestParams);
}
public class RpcJavaMethod extends JavadocJavaMethod {

@Override
public List<String> getReturnClasses() {
return ParamUtil.extractQualifiedName(this.responseParams);
}
}
22 changes: 22 additions & 0 deletions src/main/java/com/ly/doc/template/IDocBuildBaseTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package com.ly.doc.template;

import com.ly.doc.builder.ProjectDocConfigBuilder;
import com.ly.doc.constants.DocTags;
import com.ly.doc.constants.TornaConstants;
import com.ly.doc.helper.DocBuildHelper;
import com.ly.doc.model.ApiConfig;
Expand All @@ -34,6 +35,7 @@
import com.power.common.util.CollectionUtil;
import com.power.common.util.StringUtil;
import com.thoughtworks.qdox.JavaProjectBuilder;
import com.thoughtworks.qdox.model.DocletTag;
import com.thoughtworks.qdox.model.JavaClass;

import java.util.*;
Expand Down Expand Up @@ -196,6 +198,26 @@ default boolean isEntryPoint(JavaProjectBuilder javaProjectBuilder, String javaC
return isEntryPoint(javaClass, registeredAnnotations());
}

default boolean skipClass( ApiConfig apiConfig ,JavaClass javaClass, FrameworkAnnotations frameworkAnnotations) {
if (StringUtil.isNotEmpty(apiConfig.getPackageFilters())) {
// from smart config
if (!DocUtil.isMatch(apiConfig.getPackageFilters(), javaClass)) {
return true;
}
}
if (StringUtil.isNotEmpty(apiConfig.getPackageExcludeFilters())) {
if (DocUtil.isMatch(apiConfig.getPackageExcludeFilters(), javaClass)) {
return true;
}
}
// from tag
DocletTag ignoreTag = javaClass.getTagByName(DocTags.IGNORE);
if (!isEntryPoint(javaClass, frameworkAnnotations) || Objects.nonNull(ignoreTag)) {
return true;
}
return false;
}

/**
* is entry point
*
Expand Down
Loading

0 comments on commit 652c70e

Please sign in to comment.