运行Eclipse插件 [英] Running an Eclipse Plugin

查看:199
本文介绍了运行Eclipse插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在资源[1]下运行插件项目: http://www.eclipse.org/articles/article.php?file=Article-JavaCodeManipulation%5FAST/index.html

How do I run the plugin project under Resources [1] here: http://www.eclipse.org/articles/article.php?file=Article-JavaCodeManipulation%5FAST/index.html

如果我没有错,项目起点就是这里
public class ASTArticleActionDelegate实现IObjectActionDelegate - > public void run(IAction action)

If I am not wrong, the project starting point is here public class ASTArticleActionDelegate implements IObjectActionDelegate -> public void run(IAction action)

public void run(IAction action) {
    if (selection instanceof IStructuredSelection) {
        ICompilationUnit lwUnit = (ICompilationUnit) ((IStructuredSelection) selection).getFirstElement();
        createActionExecutable(action.getId()).run(lwUnit);
    }
}

我知道我应该将其作为Eclipse应用程序运行,但是我该怎么办才能看到sth?我只看到一个Eclipse应用程序启动,没有别的,没有按钮或任何东西!

I know I should run it as an Eclipse Application, but what should I do after that to see sth? I only see an Eclipse application started, and nothing else, no button or anything!

我搜索IObjectActionDelegate,它似乎与上下文菜单有关,这是我应该看到sth当我右键单击sth(IStructuredSelection - tree结构体?)?但我看到上下文菜单没有区别! :'(

I search for "IObjectActionDelegate" and it seems like it has sth to do with context menu, which is i should see sth when I right click on sth (IStructuredSelection - tree structure?)? But I see no difference in the context menu! :'(

只需让我知道一个方法来看这个项目正在运行的例子,以便我可以使用它。

Just let me know an example of a way to see that this project is running, so that I would be able to use it.

请帮助,谢谢!

推荐答案

正确的方式来测试这个AST项目示例 net.sourceforge.earticleast.app_1.0.0。 zip_1.0.0.zip )是:

The proper way to test this AST project example (net.sourceforge.earticleast.app_1.0.0.zip_1.0.0.zip) is to:


  • 解压缩该包

  • 导入当前eclipse工作区内的该包中的项目

  • 右键单击项目,然后选择调试为> Eclipse应用程序

(注意Debug As,可以在第一个eclipse实例中设置断点)

(Note the "Debug As", to be able to set breakpoint within your first eclipse instance)

一旦第二次eclipse启动,您可以:

Once the second eclipse is launched, you can:


  • 转到Help / Anout Eclipse SDK,点击安装详细信息,单击插件,并在顶部看到插件抽象语法树文章,应用程序插件示例,id net.sourceforge.earticleast.app

  • 导入任何项目该第二个eclipse实例的新工作区(您可以例如重新导入 net.sourceforge.earticleast.app 项目!)

  • 右键单击任何类,并在上下文菜单中查看自定义条目: Ast文章:移动声明(用于检测矛盾的变量声明并将其移动到他们正确的地方)

  • go to Help/Anout Eclipse SDK, click on "installation details", click "Plugins" and see right at the top the plugin "Abstract Syntax Tree Article, Example Application Plugin", id "net.sourceforge.earticleast.app"
  • Import any project in that new workspace of that second eclipse instance (you can for instance re-importe the net.sourceforge.earticleast.app project!)
  • right-click on any class and see a custom entry in the contextual menu: "Ast article: Move Declaration" (the action to detect contradicting variable declarations and to move them to their correct place)

所以现在几乎所有的一切都到位来测试这些AST操纵。

So now almost everything is in place to test those AST manipulation.

最后一件事:创建一个可以突出显示这些变量声明重写的Java单元编译。

One last thing: create a Java Unit compilation able to highlights those variable declarations rewrites.

在导入的项目(无论是什么)中创建一个包 test ,与类:

Create in your imported project (whatever it is) a package test, with the class:

package test;

public class Test {

    static {
        int i = 2;
        System.out.println("test");
        System.out.println(i);
    }

}

右键单击该类,选择 Ast文章:移动声明:看到源被即时重写为:

Right-click on that class and select "Ast article: Move Declaration": see the source being instantly rewritten as:

package test;

public class Test {

    static {
        System.out.println("test");
        int i = 2;
        System.out.println(i);
    }

}

从日食的第一个实例您可以在以下位置设置一些断点:

From the first instance of the eclipse, you can set up some breakpoints in:


  • ASTArticleMoveVariableDeclaration:run() / li>
  • AbstractManipulator:manipulate(最终的CompilationUnit单元,Collection< VariableBindingManager>经理)

  • ASTArticleMoveVariableDeclaration:run()
  • AbstractManipulator:manipulate(final CompilationUnit unit, Collection<VariableBindingManager> managers)

查看魔术发生的地方。

其他移动声明案例为:

static {
    int i = 2;
    System.out.println("test");
    try
    {
        System.out.println(i);          
    }
    catch(Exception e)
    {
        System.out.println(i);          
    }
}

被改写为:

static {
    System.out.println("test");
    int i = 2;
    try
    {
        System.out.println(i);          
    }
    catch(Exception e)
    {
        System.out.println(i);          
    }
}

最后,有一个更先进的举动是:

Finally, there is a more advanced move which is:

package test;

public class Test {

    static {
        int i = 2;
        i = 3;
        System.out.println(i);
    }

}

package test;

public class Test {

    static {
        i = 3;
        int i = 3;
        System.out.println(i);
    }

}

' int i = 2 '已正确删除。但是,请注意剩下的' i = 3 ':这是因为新的声明节点' int i = 3 在之后添加 i = 3 '而不是替换它。

'int i = 2' has been correctly removed. However, note the 'i = 3' which is left: that is because the new declaration node 'int i = 3 is added after 'i = 3' instead of replacing it.

之后一些调试,结果是 ASTRewriteBasedManipulator:addNewVariableDeclaration()忘记删除初始化程序' i = 3 '它是应该用声明 int i = 3 '替换。

After some debugging, it turns out ASTRewriteBasedManipulator:addNewVariableDeclaration() forgets to remove the initializer 'i=3' which it is supposed to replaced with the declaration 'int i = 3'.

只需在此方法的末尾添加:

Just add at the end of this method:

 rewrite.remove(manager.getInitializer().getParent().getParent(), null);

,你很好去。

这篇关于运行Eclipse插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆