• <small id='Hd4W9'></small><noframes id='Hd4W9'>

    <i id='Hd4W9'><tr id='Hd4W9'><dt id='Hd4W9'><q id='Hd4W9'><span id='Hd4W9'><b id='Hd4W9'><form id='Hd4W9'><ins id='Hd4W9'></ins><ul id='Hd4W9'></ul><sub id='Hd4W9'></sub></form><legend id='Hd4W9'></legend><bdo id='Hd4W9'><pre id='Hd4W9'><center id='Hd4W9'></center></pre></bdo></b><th id='Hd4W9'></th></span></q></dt></tr></i><div id='Hd4W9'><tfoot id='Hd4W9'></tfoot><dl id='Hd4W9'><fieldset id='Hd4W9'></fieldset></dl></div>

      <legend id='Hd4W9'><style id='Hd4W9'><dir id='Hd4W9'><q id='Hd4W9'></q></dir></style></legend>

        • <bdo id='Hd4W9'></bdo><ul id='Hd4W9'></ul>

        <tfoot id='Hd4W9'></tfoot>

        如何在 Eclipse 中获取选定的代码?

        How can I get the selected code in Eclipse?(如何在 Eclipse 中获取选定的代码?)
          <tbody id='VroGt'></tbody>

                <i id='VroGt'><tr id='VroGt'><dt id='VroGt'><q id='VroGt'><span id='VroGt'><b id='VroGt'><form id='VroGt'><ins id='VroGt'></ins><ul id='VroGt'></ul><sub id='VroGt'></sub></form><legend id='VroGt'></legend><bdo id='VroGt'><pre id='VroGt'><center id='VroGt'></center></pre></bdo></b><th id='VroGt'></th></span></q></dt></tr></i><div id='VroGt'><tfoot id='VroGt'></tfoot><dl id='VroGt'><fieldset id='VroGt'></fieldset></dl></div>
              1. <small id='VroGt'></small><noframes id='VroGt'>

                <tfoot id='VroGt'></tfoot><legend id='VroGt'><style id='VroGt'><dir id='VroGt'><q id='VroGt'></q></dir></style></legend>
                  <bdo id='VroGt'></bdo><ul id='VroGt'></ul>
                • 本文介绍了如何在 Eclipse 中获取选定的代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  对于我的插件,我正在尝试访问 CompilationUnitEditor 中的选定代码.因此,我向上下文菜单添加了一个贡献并使用以下代码:

                  For my plugin I'm trying to access the selected code in a CompilationUnitEditor. Therefore I added a contribution to the context menu and use following code:

                  public class ContextMenuHandler implements IEditorActionDelegate {
                  
                      private IEditorPart editorPart;
                  
                      @Override
                      public void setActiveEditor(IAction action, IEditorPart editorPart) {
                          this.editorPart = editorPart;
                      }
                  
                      @Override
                      public void run(IAction action) {
                          JavaUI.getEditorInputJavaElement(editorPart.getEditorInput());
                      }
                  
                      @Override
                      public void selectionChanged(IAction action, ISelection selection) {
                          if (selection instanceof TextSelection) {
                              TextSelection text = (TextSelection) selection;
                              System.out.println("Text: " + text.getText());
                          } else {
                              System.out.println(selection);
                          }
                      }
                  
                  }
                  

                  现在的问题是方法 selectionChanged(...) 仅在我真正选择某些内容时才被调用,以便我可以复制/粘贴它.但我想访问像这样突出显示的代码元素(这里我想获取IEditorPart")

                  Now the problem is that the method selectionChanged(...) is only called when i really select something so that I could copy/paste it. But I want to access the Code elements that are highlighted like this (here I would like to get the "IEditorPart")

                  不幸的是,我不知道我应该寻找什么.

                  Unfortunately, I have no idea what I should look for.

                  推荐答案

                  使用其他答案的输入,我最终得到了以下解决方案:

                  Using the inputs from the other answers, I ended up with the following solution:

                  @Override
                  public void setActiveEditor(IAction action, IEditorPart editorPart) {
                      ((CompilationUnitEditor) editorPart).getViewer().addTextListener(new ITextListener() {
                  
                          @Override
                          public void textChanged(TextEvent event) {
                              selectedText = event.getText();
                          }
                      });
                  
                  }
                  

                  这篇关于如何在 Eclipse 中获取选定的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)

                • <i id='plFsS'><tr id='plFsS'><dt id='plFsS'><q id='plFsS'><span id='plFsS'><b id='plFsS'><form id='plFsS'><ins id='plFsS'></ins><ul id='plFsS'></ul><sub id='plFsS'></sub></form><legend id='plFsS'></legend><bdo id='plFsS'><pre id='plFsS'><center id='plFsS'></center></pre></bdo></b><th id='plFsS'></th></span></q></dt></tr></i><div id='plFsS'><tfoot id='plFsS'></tfoot><dl id='plFsS'><fieldset id='plFsS'></fieldset></dl></div>

                      <small id='plFsS'></small><noframes id='plFsS'>

                        • <tfoot id='plFsS'></tfoot>
                          <legend id='plFsS'><style id='plFsS'><dir id='plFsS'><q id='plFsS'></q></dir></style></legend>
                            <tbody id='plFsS'></tbody>
                            <bdo id='plFsS'></bdo><ul id='plFsS'></ul>