AST tool in JDT

xiaoxiao2021-03-05  28

JDT as a Java development tool for Eclipse, providing a Java source file, compiled as an AST (Abstract Syntax Tree) of the intermediate code, can modify the code at a higher level

JDT as a Java development tool for Eclipse, providing a Java source file, compiled as an AST (Abstract Syntax Tree) of the intermediate code, can modify the code at a higher level

For example, Refactor in Eclipse can highly intelligently modify the code. We can also use AST to dynamically generate code or modify the code. The main process is entered:

1. Get the Java source file or his corresponding compirationuint (CU), then set by AST.SETSource (), then create an AST tree, return root node, Astnode.

2. Use the ASTREWRITE to modify the source file and save the results in the TextEditor object.

3. Use the Apply () method to implement these modifications.

The above method is to describe the modification, which is that he does not modify directly on the AST tree, but using the API interface of the ASTREWRITER, record the modified part, and finally ().

Another one is to modify directly. .

转载请注明原文地址:https://www.9cbs.com/read-33533.html

New Post(0)