我需要通过(迭代)ISearchResult 以便比较 Eclipse 搜索的结果

I need to go through (iterate) ISearchResult so as to compare the results of eclipse search

我有一个 IsearchResult 对象,我需要遍历(迭代)它以便比较每个结果。

e.g. I look for (ctrl+H) add method.

and then I have this results' list

我需要遍历此列表(它存储在 ISearchResult 对象中)并比较查询的每个结果。

我有这个代码。

NewSearchUI.addQueryListener(new IQueryListener() {

            @Override
            public void queryStarting(ISearchQuery query) {
                System.out.println("query start " + query);

            }

            @Override
            public void queryRemoved(ISearchQuery query) {
            }

            @Override
            public void queryFinished(ISearchQuery query) {
                System.out.println("query finished " + query);
                System.out.println("result " + query.getSearchResult().getLabel());
                query.getSearchResult().addListener(new ISearchResultListener() {

                    @Override
                    public void searchResultChanged(SearchResultEvent e) {
                    }
                });
            }

            @Override
            public void queryAdded(ISearchQuery query) {
            }

我需要遍历结果列表并比较或提取每个结果的信息。

您不能迭代结果。

您必须在 queryStarting 方法中添加 ISearchResultListener 并保存在 searchResultChanged 调用中提供给您的结果。

NewSearchUI.addQueryListener(new IQueryListener() {

        @Override
        public void queryStarting(ISearchQuery query) {
            System.out.println("query start " + query);

            // Starting listening to the search query

            query.getSearchResult().addListener(new ISearchResultListener() {

                @Override
                public void searchResultChanged(SearchResultEvent e) {
                   // TODO save the results as they appear
                }
            });

        }

        @Override
        public void queryRemoved(ISearchQuery query) {
        }

        @Override
        public void queryFinished(ISearchQuery query) {
            System.out.println("query finished " + query);
            System.out.println("result " + query.getSearchResult().getLabel());
        }

        @Override
        public void queryAdded(ISearchQuery query) {
        }