deep-code-search icon indicating copy to clipboard operation
deep-code-search copied to clipboard

How to parse the Java code?

Open KidOfJealous opened this issue 6 years ago • 3 comments

I tried some methods but the results are a little different. For example, when I get method o.m(), I do not know how to get the Class of o and add O.m to the API Sequence.

KidOfJealous avatar Dec 04 '18 12:12 KidOfJealous

you can use eclipse JDT to parse the AST. The AST contains class names of each method invocation. You can find JDT through maven. There are also python libraries for parsing Java code such as https://github.com/c2nes/javalang

guxd avatar Dec 05 '18 15:12 guxd

@guxd I am working on the data pre-processing of extracting method, description, API sequence, tokens using python library - https://github.com/c2nes/javalang. Regarding extracting token, I need to transform AST to java code at first, then transform the code to tokens. Do you have any idea of transforming AST nodes to java code, currently I haven't find suitable solutions. I want to ask if you have any idea, because you are experts in such fields.

Thanks a lot

ttbuffey avatar Apr 30 '19 06:04 ttbuffey

https://github.com/mast-group/codemining-core/blob/master/src/main/java/codemining/java/tokenizers/JavaTokenizer.java

guxd avatar Apr 30 '19 20:04 guxd