I have done a plugin in eclipse helios for parsing (AST) and comparing code. First I parse the code and keep the MethodDeclaration node. Then I select a method from the code to compare with the methods of the node.
I save the code in SelectedText selectedText and the node in MethodDeclaration method.
How can I compare this two variables to know if they are holding the same code??? I have done the next code but it doesn’t work:
for (MethodDeclaration method : visitor.getMethods()) {
if(selectedText.getSelectedText().equals(method.toString())){
MessageDialog.openInformation(shell, "COMPARISON", "GOOD");
}
}
You need to parse the selected code into an AST as well; otherwise simple differences in white space like
a=0anda = 0would be different.Look at the source code for the Java editor, it should be possible to ask it for the AST node of the currently selected method.