我有一個eclipse插件,它提供了一個菜單項,可以選擇該菜單項以在當前活動的文件上運行命令。如果當前活動文件有任何錯誤(如「問題」視圖中報告),我希望插件顯示一條警告消息,類似於當您嘗試運行帶有錯誤的Java項目時Eclipse的行爲。執行操作前檢查項目錯誤
1
A
回答
1
我知道這是一個老問題,但我找到了一個類似於所提出的解決方案。做你所描述的代碼是org.eclipse.debug.core.model.LaunchConfigurationDelegate
。它檢查項目是否有錯誤,並在需要時顯示對話框。下面是相關的代碼,從Eclipse的月神:
/**
* Returns whether the given project contains any problem markers of the
* specified severity.
*
* @param proj the project to search
* @return whether the given project contains any problems that should
* stop it from launching
* @throws CoreException if an error occurs while searching for
* problem markers
*/
protected boolean existsProblems(IProject proj) throws CoreException {
IMarker[] markers = proj.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
if (markers.length > 0) {
for (int i = 0; i < markers.length; i++) {
if (isLaunchProblem(markers[i])) {
return true;
}
}
}
return false;
}
/**
* Returns whether the given problem should potentially abort the launch.
* By default if the problem has an error severity, the problem is considered
* a potential launch problem. Subclasses may override to specialize error
* detection.
*
* @param problemMarker candidate problem
* @return whether the given problem should potentially abort the launch
* @throws CoreException if any exceptions occur while accessing marker attributes
*/
protected boolean isLaunchProblem(IMarker problemMarker) throws CoreException {
Integer severity = (Integer)problemMarker.getAttribute(IMarker.SEVERITY);
if (severity != null) {
return severity.intValue() >= IMarker.SEVERITY_ERROR;
}
return false;
}
相同的代碼可以在任何IResource
,而不是一個IProject
運行。
我設法很容易地找到它,方法是在顯示對話框時暫停調試器,並在相關類上設置斷點並從那裏追溯。
0
錯誤通常保存爲資源上的IMarkers(您的情況爲IFile),因此您可以在IFile中查詢您正在查找的標記。
您需要在查找之前知道標記的類型(通過調試並獲取所有當前標記,或者通過查看在文件的驗證過程中貢獻它們的代碼)。
希望有所幫助。
相關問題
- 1. Eclipse JMeter v3.1項目執行錯誤「檢查JMeterHome和庫」
- 2. 對項目集合執行操作
- 3. 在執行操作前檢查PHP中的重定向
- 4. 檢查在執行操作前是否已登錄
- 5. 執行前綴操作符++
- 6. 查詢執行錯誤檢查
- 7. 發生錯誤時執行操作RxJava
- 8. 根據錯誤執行操作
- 9. fio錯誤檢查寫操作
- 10. 執行前檢查條件
- 11. 編譯XNA項目時請求的操作無法執行錯誤
- 12. 操作錯誤:在查詢目標-C
- 13. 從查詢訪問調用宏(打開表單)運行時錯誤'2486':您目前無法執行此操作
- 14. TFS檢查政策強制執行工作項目,但也允許非工作項目相關檢查
- 15. Xcode錯誤啓動可執行項目
- 16. 執行項目後Eclipse中的錯誤
- 17. 編譯sencha項目檢查錯誤
- 18. 如何在執行集合操作之前檢查查詢中的結果?
- 19. 不允許子操作執行重定向操作錯誤
- 20. SQLGrammarException:無法執行本機批量操作查詢錯誤
- 21. 執行查詢時在JOIN操作中的語法錯誤
- 22. 查詢操作中的BigQuery錯誤:找不到項目ID
- 23. 檢查長度時執行速度很差執行錯誤
- 24. MVC複選框列表 - 項目後錯誤地檢查項目
- 25. 當按鈕執行檢查操作時,更改不起作用
- 26. 在symfony2中執行操作之前
- 27. 保存前執行操作(`on_pre_save`)
- 28. ASP.NET MVC 2如何在執行操作之前檢查用戶的權限?
- 29. 如何在執行操作前檢查所有方法是否正確
- 30. 在執行網絡操作之前,我應該檢查網絡狀態嗎?