标题翻译
Tool is delaying output in eclipse plugin developemnt
问题
我正在为 Eclipse 开发插件。它将运行我的 Clang 工具。在 Clang 工具中,我正在编写一个简单的 Pass,以检查每个 case 和 default 语句是否都有 break 语句。
我正在使用进程构建器运行我的 Clang 工具。
我正在使用 Job API 来运行我的工具,并使用 Display 类来打印错误。
当我运行我的插件时,我遇到了一些问题。
假设我注释了其中一个 case 或 default 语句的 break 语句,它应该在控制台中打印错误,指出每个 case 和 default 语句都必须有 break 语句。
但实际上,只有在我键入其他内容、空格,或者尝试取消注释后,它才会打印错误信息。
同样地,当我取消注释时,它不应该打印错误,但实际上它会打印错误,但当我再次键入内容、空格或尝试注释时,错误消息就会消失。
以下是我的代码链接:
https://github.com/sunilsarode/eclipse_plugin/blob/master/ccchecker/src/ccchecker/handlers/SampleHandler.java
下面的图片显示了第一个 case 在我正在开发插件的 Eclipse 控制台上没有打印错误。
[![在此输入图片描述][1]][1]
而这张图片显示了第二个 case 在我正在开发插件的 Eclipse 控制台上打印了错误。
[![在此输入图片描述][2]][2]
对此有什么帮助吗?
**编辑:**
我希望我的插件在控制台视图上输出一些内容(而不是在开发控制台上),或者在文本编辑器的边线上显示一些点状的东西,当我点击或悬停在那个点上时,我希望显示一个带有错误消息的弹出窗口。
我尝试通过使用此链接创建控制台来在控制台视图上打印消息 https://wiki.eclipse.org/FAQ_How_do_I_write_to_the_console_from_a_plug-in%3F
它有效,但新的问题是,我从文本编辑器失去了焦点,转而到了我创建的控制台,因此我无法测试我在问题中提到的问题。
抱歉,我期望的可能太多了。
下面的图片显示了文本编辑器失去焦点,转而到了控制台视图,而你提到的按钮不在控制台视图上,但在我编写代码的 Eclipse 控制台上是有的。
[![在此输入图片描述][3]][3]
[1]: https://i.stack.imgur.com/9X3p0.png
[2]: https://i.stack.imgur.com/AFEuS.png
[3]: https://i.stack.imgur.com/Jn4zq.png
英文翻译
I am developing plugin for eclipse. It will run my clang tool. In clang tool i am writing simple pass to check that every case and default statement must have the break statement.
I am running my clang tool using process builder.
I am using job API to run my tool and Display class to print the error.
when i run my plugin i am facing some issue.
Let say i commented my break statement of one of the case or default statement , it should print error in console that every case and default statement must have the break statement.
it is printing error after i type something else or some space or trying to uncomment after my comment .
similarly when i do uncomment , it should not print the error , but it is printing , but again when i type something or some space or trying to comment , error disappear.
following is the link of my code
following image show the first case not printing error on my eclipse console on which i am developing a plugin .
and this shows that second case printing error on my eclipse console on which i am developing a plugin .
any help in this ?
EDIT:
I want my plugin-in to output something on console view (not on development console ) or some dot kind of thing on the gutter of the text editor and when i click or hover on that dot , i want to show some popup with error message.
I tried to print message on console view by crating console using this link https://wiki.eclipse.org/FAQ_How_do_I_write_to_the_console_from_a_plug-in%3F
it works , but new problem is , i lost focus from text editor to console that i have created and because of this i am unable to test the problem i mentioned in question.
sorry too much i am expecting.
Following image show that text editor lost its focus to console view and the button you have mentioned is not there at console view but it is there at console of eclipse on which i am writing a code.
答案1
得分: 0
以下是翻译好的内容:
在按下 Ctrl+s 键时,以下的 keypress 方法和 addKeyListener 方法无法正常工作。为了触发保存事件,我们必须使用 ICommandService 与 save 命令。
((StyledText) editor.getAdapter(Control.class)).addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent keyEvent) {
if (((keyEvent.stateMask & SWT.CTRL) == SWT.CTRL) && (keyEvent.keyCode == 's')) {
// System.out.println("From Display I am the Key down !!" + keyEvent.keyCode);
Job job = new Job("My job") {
@Override
protected IStatus run(IProgressMonitor arg0) {
// TODO Auto-generated method stub
StringBuilder builder = runCCChecker(path);
syncWithUi(builder);
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
}
}
@Override
public void keyReleased(KeyEvent arg0) {
}
});
为了在每一行显示警告,我正在使用 IMarker 接口。
为了仅在我触发保存命令的 Eclipse 编辑器的当前活动文件上运行我的工具,我正在使用 IPartService 服务。
以下是我的代码链接:
它工作得很好。如果有人发现任何问题,请告诉我。
英文翻译
Following keypress method and addKeyListener is not working when i press the Ctrl+s. In order to get the save event we have to use the ICommandService with save command.
((StyledText) editor.getAdapter(Control.class)).addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent keyEvent) {
if (((keyEvent.stateMask & SWT.CTRL) == SWT.CTRL) && (keyEvent.keyCode == 's')) {
// System.out.println("From Display I am the Key down !!" + keyEvent.keyCode);
Job job = new Job("My job") {
@Override
protected IStatus run(IProgressMonitor arg0) {
// TODO Auto-generated method stub
StringBuilder builder = runCCChecker(path);
syncWithUi(builder);
return Status.OK_STATUS;
}
};
job.setUser(true);
job.schedule();
}
}
@Override
public void keyReleased(KeyEvent arg0) {
}
});
In order to show the warning at each line I am using IMarker interface.
In order to run my tool only on current active file of eclipse editor on which I am firing save command , I am using IPartService service.
following is the link of my code
It is working fine. If anybody find any issue please let me know.
专注分享java语言的经验与见解,让所有开发者获益!
评论