我目前正在參加一個項目管理課程,教授給了這個任務,以便在所有情況下以編程方式比較兩個.java文件的方法和字段。 我不認爲這是真的可以做但也許我錯了!是否有可能在所有情況下比較兩個.java文件的方法和字段?
分配規格爲如下(其極其曖昧,我知道)
In this assignment, you are required to write a comparison tool for two
versions of a Java source file.
Your program takes as input two .java files representing those two versions
and reports the following atomic changes:
1. AM: Add a new method
2. DM: Delete a method
3. CM: Change the body of a method (note: you need to handle the case where a method is
relocated within the body of its class)
4. AF: Add a field
5. DF: Delete a field
6. CFI: Change the definition of an instance field initializer (including (i) adding an initialization to a
field, (ii) deleting an initialization of a field, (iii) making changes to the initialized value of a field,
and (iv) making changes to a field modifier, e.g., private to public)
所以,這就是我與工作,我的方法是使用反射,因爲它可以讓你做的一切,但檢測的差異方法體。
我曾考慮過可以創建解析器的想法,但這看起來很荒謬,特別是對於項目管理中的3學分的本科課程。像BeyondCompare這樣的工具不會列出更改的方法或字段,只是不同的行不符合要求。
我轉過這份工作,幾乎整個班都失敗了,原因是「我們的代碼不適用於沒有給出外部依賴性的java文件,或者是不同項目中的java文件」 - 這是完全正確的但我也在想,不可能做到。
我想明確一個具體的答案,爲什麼這實際上不可能做或學習新的東西,爲什麼這是可能的,所以任何洞察力將是偉大的。
絕對不是不可能的。看看https://github.com/javaparser/javaparser。看起來你可以解析2個java文件並查找更改。 –
感謝您的鏈接! – Shaun314