Eclipse plugin: TextSelection cannot be resolved


I am trying to develop my first plugin.
The plugin must manage the contents of the selected text in the active text editor.

I started with the "hello world" example from the "Cheat sheet", which worked perfectly.
When I tried to change, I found that the project did not recognize many types.

I added the following libraries to the project path library:

  • org.eclipse.jface.text_3.5.1.r351_v20090708-0800.jar
  • org.eclipse.text_3.5.0.v20090513-2000.jar
  • org.eclipse.ui.editors_3. 5.0.v20090527-2000.jar

Now the code compiles.

  • ISelection iSelection = null;
  • IEditorSite iEditorSite = window.getActivePage().getActiveEditor().getEditorSite();
  • if (iEditorSite != null) {
  • ISelectionProvider iSelectionProvider = iEditorSite.getSelectionProvider();
  • if (iSelectionProvider != null)
  •   {
  •    iSelection = iSelectionProvider.getSelection();
  •    selectedText = ((ITextSelection)iSelection).getText();
  •   }
  • }

The problem is on line 08. Although eclipse recognizes the ITextSelection interface, at runtime I get I can not allow a type exception.

:

org.eclipse.jface.text

+3

Source: https://habr.com/ru/post/1720070/


All Articles