Using the Eclipse AST

后端 未结 2 1778
一整个雨季
一整个雨季 2021-02-03 14:10

I have recently come into the need of modifying some Java code (adding methods, changing the signatures of some fields and removing methods) and I think that all of this can be

2条回答
  •  南旧
    南旧 (楼主)
    2021-02-03 14:44

    You can do this with Eclipse by calling APIs that let you manipulate the ASTs.

    Or you can apply program transformations to achieve your effect in way that doesn't depend on the microscopic details of the AST.

    As an example you might write the following program transformation:

    add_int_parameter(p:parameter_list, i: identifier): parameters -> parameters
      " \p " -> " \p , int \i";
    

    to add an integer parameter with an arbitrary name to a parameter list. This achieves the same effect as a whole set of API calls but it is a lot more readable because it is in the surface syntax of your language (in this case, Java).

    Our DMS Software Reengineering Toolkit can accept such program transformations and apply them to many languages, including Java.

提交回复
热议问题