-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support generated java comments by solidity devdoc. (#39)
Co-authored-by: dwzhan <[email protected]>
- Loading branch information
1 parent
df1bdf0
commit 842e38f
Showing
14 changed files
with
943 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.fisco.bcos.codegen.v2.utils; | ||
|
||
import java.util.Map; | ||
|
||
public class Devdoc { | ||
private String details; | ||
private Map<String, Method> methods; | ||
|
||
public String getDetails() { | ||
return details; | ||
} | ||
|
||
public void setDetails(String details) { | ||
this.details = details; | ||
} | ||
|
||
public Map<String, Method> getMethods() { | ||
return methods; | ||
} | ||
|
||
public void setMethods(Map<String, Method> methods) { | ||
this.methods = methods; | ||
} | ||
|
||
public static class Method { | ||
private String details; | ||
private Map<String, String> params; | ||
private Map<String, String> returns; | ||
|
||
public String getDetails() { | ||
return details; | ||
} | ||
|
||
public void setDetails(String details) { | ||
this.details = details; | ||
} | ||
|
||
public Map<String, String> getParams() { | ||
return params; | ||
} | ||
|
||
public void setParams(Map<String, String> params) { | ||
this.params = params; | ||
} | ||
|
||
public Map<String, String> getReturns() { | ||
return returns; | ||
} | ||
|
||
public void setReturns(Map<String, String> returns) { | ||
this.returns = returns; | ||
} | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/main/java/org/fisco/bcos/codegen/v2/utils/DocUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.fisco.bcos.codegen.v2.utils; | ||
|
||
import com.squareup.javapoet.MethodSpec; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
import org.fisco.bcos.codegen.v2.exceptions.CodeGenException; | ||
import org.fisco.bcos.sdk.abi.wrapper.ABIDefinition; | ||
import org.fisco.bcos.sdk.transaction.tools.JsonUtils; | ||
import org.fisco.bcos.sdk.utils.StringUtils; | ||
|
||
public class DocUtils { | ||
|
||
public static Devdoc.Method getMethod(Devdoc devdoc, ABIDefinition functionDefinition) { | ||
if (devdoc != null && devdoc.getMethods() != null) { | ||
return devdoc.getMethods().get(functionDefinition.getMethodSignatureAsString()); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public static void addMethodComments(Devdoc.Method method, MethodSpec.Builder methodBuilder) { | ||
if (method == null) { | ||
return; | ||
} | ||
|
||
// add comments for method | ||
if (!StringUtils.isEmpty(method.getDetails())) { | ||
methodBuilder.addJavadoc("$L \n", method.getDetails()); | ||
} | ||
} | ||
|
||
public static void addParamsComments(Devdoc.Method method, MethodSpec.Builder methodBuilder) { | ||
if (method == null) { | ||
return; | ||
} | ||
|
||
// add comments for params | ||
Map<String, String> params = method.getParams(); | ||
if (params != null) { | ||
for (String p : params.keySet()) { | ||
if (!StringUtils.isEmpty(params.get(p))) { | ||
methodBuilder.addJavadoc("@param $N $L \n", p, params.get(p)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static void addReturnsComments( | ||
String comments, Devdoc.Method method, MethodSpec.Builder methodBuilder) { | ||
if (method == null) { | ||
return; | ||
} | ||
|
||
// add comments for returns | ||
Map<String, String> returns = method.getReturns(); | ||
if (returns != null) { | ||
for (String r : returns.keySet()) { | ||
if (!StringUtils.isEmpty(returns.get(r))) { | ||
methodBuilder.addJavadoc("$L $N $L \n", comments, r, returns.get(r)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static Devdoc convertDevDoc(File devdocFile) throws CodeGenException, IOException { | ||
if (devdocFile != null && devdocFile.exists()) { | ||
byte[] devdocBytes = CodeGenUtils.readBytes(devdocFile); | ||
return JsonUtils.fromJson(new String(devdocBytes), Devdoc.class); | ||
} else { | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.fisco.bcos.codegen.v3.utils; | ||
|
||
import java.util.Map; | ||
|
||
public class Devdoc { | ||
private String details; | ||
private Map<String, Method> methods; | ||
|
||
public String getDetails() { | ||
return details; | ||
} | ||
|
||
public void setDetails(String details) { | ||
this.details = details; | ||
} | ||
|
||
public Map<String, Method> getMethods() { | ||
return methods; | ||
} | ||
|
||
public void setMethods(Map<String, Method> methods) { | ||
this.methods = methods; | ||
} | ||
|
||
public static class Method { | ||
private String details; | ||
private Map<String, String> params; | ||
private Map<String, String> returns; | ||
|
||
public String getDetails() { | ||
return details; | ||
} | ||
|
||
public void setDetails(String details) { | ||
this.details = details; | ||
} | ||
|
||
public Map<String, String> getParams() { | ||
return params; | ||
} | ||
|
||
public void setParams(Map<String, String> params) { | ||
this.params = params; | ||
} | ||
|
||
public Map<String, String> getReturns() { | ||
return returns; | ||
} | ||
|
||
public void setReturns(Map<String, String> returns) { | ||
this.returns = returns; | ||
} | ||
} | ||
} |
Oops, something went wrong.