Search code examples
javaeclipse-pluginsyntax-highlightingeclipse-cdthighlight

Get highlighted variable -Eclipse


I am implementing an Eclipse plugin for C programmers. I can't find a way to get the variable that the user already highlited.(The user will highlight a variable in the editor and I need to know which variable it is/variable's name/location of this variable in the editor, like line number..) Can anyone help to achieve that ?


Solution

  • Well after searching in some links, I achvieved that by using the ISelectionProvider and ITextSelection Interfaces. Here a code to get the name of the highlighted variable :

    ISelectionProvider selProvider = textEditor.getSelectionProvider();
                ITextSelection txtSel = (ITextSelection) selProvider.getSelection();
                String varName = txtSel.getText();