phodal / chapi

CHAPI (Common Hierarchical Abstract Parser and Information Converter) streamlines code analysis by converting diverse language source code into a unified abstract model, simplifying cross-language development. Chapi 是一个通用层次抽象解析器与信息转换器,它可以将不同编程语言的源代码转换为统一的层次抽象模型。
https://chapi.phodal.com/
Mozilla Public License 2.0
270 stars 44 forks source link

How to add comments from java codebase that exists at class variable and function level #25

Closed JayGhiya closed 6 months ago

JayGhiya commented 6 months ago

Is there a roadmap to modify existing code container to add that sry not a kotlin person otherwise would have contributed

phodal commented 6 months ago

in current design, the Content field is for full function code which with comments, you maybe try this. Then parse it in your code.

for class level:

https://github.com/phodal/chapi/blob/39562227fda0cc7ae66fa767ccbdf99843108cba/chapi-domain/src/main/kotlin/chapi/domain/core/CodeDataStruct.kt#L66

for function level:

https://github.com/phodal/chapi/blob/39562227fda0cc7ae66fa767ccbdf99843108cba/chapi-domain/src/main/kotlin/chapi/domain/core/CodeFunction.kt#L47

phodal commented 6 months ago

Here is a example: https://github.com/unit-mesh/unit-gen/blob/master/code-quality/src/main/kotlin/cc/unitmesh/quality/comment/CodeComment.kt

JayGhiya commented 6 months ago

hey @phodal this is great so the spec covers the comments . so i just did parsing for example class and functions with comments. looks like content at codeFunction and CodeDataStruct does not autofill content as of now. Is this already on roadmap to do the same? So as of now the best strategy would be to use https://javaparser.org/ based on spec of chapi to fetch comments regarding class and functions and fill the content. is that right?

phodal commented 6 months ago

Not sure about javaparser, the design princinple of Chapi is to support multi-languages, like: https://github.com/archguard/archguard/tree/master/analyser_sourcecode

Here is othr example to fill with content:

https://github.com/archguard/archguard/blob/049f3cc8f2c0e2c34e65bb0049f645caa5be9bf8/analyser_sourcecode/lang_java/src/main/kotlin/org/archguard/scanner/analyser/JavaAnalyser.kt#L45-L56