--- a/java.project/nbproject/project.xml Tue Jan 13 15:00:23 2009 +0100 +++ a/java.project/nbproject/project.xml Tue Jan 13 20:08:22 2009 +0300 @@ -246,7 +246,7 @@ 3 - 3.3 + 3.20 --- a/java.project/src/org/netbeans/spi/java/project/support/ui/PackageRootNode.java Tue Jan 13 15:00:23 2009 +0100 +++ a/java.project/src/org/netbeans/spi/java/project/support/ui/PackageRootNode.java Tue Jan 13 20:08:22 2009 +0300 @@ -91,6 +91,7 @@ import org.openide.util.lookup.ProxyLookup; import org.openidex.search.SearchInfo; import org.openidex.search.SearchInfoFactory; +import org.openidex.search.Utils; /** Node displaying a packages in given SourceGroup * @author Petr Hrebejk @@ -449,7 +450,7 @@ return new AlwaysSearchableSearchInfo(i); } - private static final class AlwaysSearchableSearchInfo implements SearchInfo { + private static final class AlwaysSearchableSearchInfo implements SearchInfo.Files { private final SearchInfo delegate; @@ -464,7 +465,10 @@ public Iterator objectsToSearch() { return delegate.objectsToSearch(); } - + + public Iterator filesToSearch() { + return Utils.getFileObjectsIterator(delegate); + } } } --- a/o.openidex.util/apichanges.xml Tue Jan 13 15:00:23 2009 +0100 +++ a/o.openidex.util/apichanges.xml Tue Jan 13 20:08:22 2009 +0300 @@ -105,7 +105,46 @@ - + + + Added utility class Utils + + + + + +

+ Class Utils made public with one public static method + getFileObjectsIterator(SearchInfo si). This utility + method returns Iterator of FileObjects + for the provided SearchInfo. This change simplifies + the work with SearchInfo implementations. +

+
+ +
+ + + + Added interface SearchInfo.Files + + + + + +

+ Added SearchInfo.Files interface which extends + SearchInfo interface. It adds method + filesToSearch() to provide FileObjects + which should be searched. This change allows to operate FileObjects + in the search mechanism instead of DataObjects and + as a result improves search performance. +

+
+ + +
+ Added method createCompoundSearchInfo(...) --- a/o.openidex.util/manifest.mf Tue Jan 13 15:00:23 2009 +0100 +++ a/o.openidex.util/manifest.mf Tue Jan 13 20:08:22 2009 +0300 @@ -1,5 +1,5 @@ Manifest-Version: 1.0 OpenIDE-Module: org.openidex.util/3 OpenIDE-Module-Localizing-Bundle: org/openidex/resources/Bundle.properties -OpenIDE-Module-Specification-Version: 3.16 +OpenIDE-Module-Specification-Version: 3.20 AutoUpdate-Essential-Module: true --- a/o.openidex.util/src/org/openidex/search/CompoundSearchInfo.java Tue Jan 13 15:00:23 2009 +0100 +++ a/o.openidex.util/src/org/openidex/search/CompoundSearchInfo.java Tue Jan 13 20:08:22 2009 +0300 @@ -45,13 +45,14 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; +import org.openide.filesystems.FileObject; import org.openide.loaders.DataObject; /** * * @author Marian Petras */ -class CompoundSearchInfo implements SearchInfo { +class CompoundSearchInfo implements SearchInfo.Files { /** */ private final SearchInfo[] elements; @@ -88,8 +89,14 @@ /** */ public Iterator objectsToSearch() { + return Utils.toDataObjectIterator(filesToSearch()); + } + + /** + */ + public Iterator filesToSearch() { if (elements == null) { - return Collections.emptyList().iterator(); + return Collections.emptyList().iterator(); } List searchableElements = new ArrayList(elements.length); --- a/o.openidex.util/src/org/openidex/search/CompoundSearchIterator.java Tue Jan 13 15:00:23 2009 +0100 +++ a/o.openidex.util/src/org/openidex/search/CompoundSearchIterator.java Tue Jan 13 20:08:22 2009 +0300 @@ -43,22 +43,22 @@ import java.util.Iterator; import java.util.NoSuchElementException; -import org.openide.loaders.DataObject; +import org.openide.filesystems.FileObject; /** * * @author Marian Petras */ -class CompoundSearchIterator implements Iterator { +class CompoundSearchIterator implements Iterator { /** */ private final SearchInfo[] elements; /** */ private int elementIndex; /** */ - private Iterator elementIterator; + private Iterator elementIterator; /** */ - private DataObject nextObject; + private FileObject nextObject; /** */ private boolean upToDate; @@ -80,7 +80,7 @@ upToDate = true; //hasNext() returns always false } else { this.elements = elements; - elementIterator = elements[elementIndex = 0].objectsToSearch(); + elementIterator = Utils.getFileObjectsIterator(elements[elementIndex = 0]); upToDate = false; } } @@ -96,7 +96,7 @@ /** */ - public DataObject next() { + public FileObject next() { if (!hasNext()) { throw new NoSuchElementException(); } @@ -117,7 +117,7 @@ break; } - elementIterator = elements[elementIndex].objectsToSearch(); + elementIterator = Utils.getFileObjectsIterator(elements[elementIndex]); } if (elementIndex < elements.length) { --- a/o.openidex.util/src/org/openidex/search/SearchInfo.java Tue Jan 13 15:00:23 2009 +0100 +++ a/o.openidex.util/src/org/openidex/search/SearchInfo.java Tue Jan 13 20:08:22 2009 +0300 @@ -42,6 +42,7 @@ package org.openidex.search; import java.util.Iterator; +import org.openide.filesystems.FileObject; import org.openide.loaders.DataObject; /** @@ -97,5 +98,25 @@ * to be searched */ public Iterator objectsToSearch(); - + + /** + * Additionally defines which FileObjects should be searched. + * + * @since org.openidex.util/3 3.20 + * @author kaktus + */ + public interface Files extends SearchInfo{ + + /** + * Specifies which FileObjects should be searched. + * The returned Iterator needn't implement method + * {@link java.util.Iterator#remove remove()} (i.e. it may throw + * UnsupportedOperationException instead of actual + * implementation). + * + * @return iterator which iterates over FileObjects + * to be searched + */ + public Iterator filesToSearch(); + } } --- a/o.openidex.util/src/org/openidex/search/SimpleSearchInfo.java Tue Jan 13 15:00:23 2009 +0100 +++ a/o.openidex.util/src/org/openidex/search/SimpleSearchInfo.java Tue Jan 13 20:08:22 2009 +0300 @@ -52,7 +52,7 @@ * * @author Marian Petras */ -class SimpleSearchInfo implements SearchInfo { +class SimpleSearchInfo implements SearchInfo.Files { /** * Empty search info object. @@ -61,13 +61,17 @@ * (returned by method * {@link SearchInfo#objectsToSearch objectsToSearch()}) has no elements. */ - static final SearchInfo EMPTY_SEARCH_INFO - = new SearchInfo() { + static final SearchInfo.Files EMPTY_SEARCH_INFO + = new SearchInfo.Files() { public boolean canSearch() { return true; } public Iterator objectsToSearch() { return Collections.emptyList().iterator(); + } + + public Iterator filesToSearch() { + return Collections.emptyList().iterator(); } }; @@ -112,6 +116,12 @@ /** */ public Iterator objectsToSearch() { + return Utils.toDataObjectIterator(filesToSearch()); + } + + /** + */ + public Iterator filesToSearch() { return new SimpleSearchIterator(rootFolder, recursive, filters != null ? Arrays.asList(filters) --- a/o.openidex.util/src/org/openidex/search/SimpleSearchIterator.java Tue Jan 13 15:00:23 2009 +0100 +++ a/o.openidex.util/src/org/openidex/search/SimpleSearchIterator.java Tue Jan 13 20:08:22 2009 +0300 @@ -48,16 +48,15 @@ import java.util.NoSuchElementException; import org.openide.filesystems.FileObject; import org.openide.loaders.DataFolder; -import org.openide.loaders.DataObject; /** * * @author Marian Petras */ -class SimpleSearchIterator implements Iterator { +class SimpleSearchIterator implements Iterator { /** current enumeration of children */ - private Enumeration childrenEnum; + private Enumeration childrenEnum; /** * filters to be applied on the current enumeration of children * ({@link #childrenEnum}) @@ -70,8 +69,8 @@ /** */ private final boolean recursive; /** stack of the ancestor folders' children enumerations */ - private final List> enums - = new ArrayList>(); //unsynced stack + private final List> enums + = new ArrayList>(); //unsynced stack /** * stack of filter lists to be applied on children of the ancestor folders * ({@link #enums}) @@ -84,14 +83,14 @@ * DataObject to be returned the next time method * {@link #next()} is called */ - private DataObject nextObject; + private FileObject nextObject; /** */ SimpleSearchIterator(DataFolder folder, boolean recursive, List filters) { - this.childrenEnum = folder.children(false); + this.childrenEnum = folder.getPrimaryFile().getChildren(false); this.recursive = recursive; this.filters = (filters != null) ? new ArrayList(filters) : null; @@ -108,7 +107,7 @@ /** */ - public DataObject next() { + public FileObject next() { if (!hasNext()) { throw new NoSuchElementException(); } @@ -124,8 +123,7 @@ assert childrenEnum != null; do { if (childrenEnum.hasMoreElements()) { - DataObject dataObject = childrenEnum.nextElement(); - FileObject file = dataObject.getPrimaryFile(); + FileObject file = childrenEnum.nextElement(); if (file.isFolder()) { if (!recursive) { continue; @@ -147,13 +145,13 @@ filterLists.add(null); } enums.add(childrenEnum); - childrenEnum = ((DataFolder) dataObject).children(false); + childrenEnum = file.getChildren(false); } else { if ((filters != null) && !checkFileFilters(file)) { continue; } - nextObject = dataObject; + nextObject = file; break; } } else { --- a/o.openidex.util/src/org/openidex/search/SubnodesSearchInfo.java Tue Jan 13 15:00:23 2009 +0100 +++ a/o.openidex.util/src/org/openidex/search/SubnodesSearchInfo.java Tue Jan 13 20:08:22 2009 +0300 @@ -45,6 +45,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; +import org.openide.filesystems.FileObject; import org.openide.loaders.DataObject; import org.openide.nodes.Node; @@ -52,7 +53,7 @@ * * @author Marian Petras */ -final class SubnodesSearchInfo implements SearchInfo { +final class SubnodesSearchInfo implements SearchInfo.Files { /** */ private final Node node; @@ -80,9 +81,15 @@ /** */ public Iterator objectsToSearch() { + return Utils.toDataObjectIterator(filesToSearch()); + } + + /** + */ + public Iterator filesToSearch() { final Node[] nodes = node.getChildren().getNodes(true); if (nodes.length == 0) { - return SimpleSearchInfo.EMPTY_SEARCH_INFO.objectsToSearch(); + return SimpleSearchInfo.EMPTY_SEARCH_INFO.filesToSearch(); } List searchInfoElements = new ArrayList(nodes.length); @@ -96,9 +103,9 @@ final int size = searchInfoElements.size(); switch (size) { case 0: - return Collections.emptyList().iterator(); + return Collections.emptyList().iterator(); case 1: - return searchInfoElements.get(0).objectsToSearch(); + return Utils.getFileObjectsIterator(searchInfoElements.get(0)); default: return new CompoundSearchIterator( searchInfoElements.toArray(new SearchInfo[size])); --- a/o.openidex.util/src/org/openidex/search/Utils.java Tue Jan 13 15:00:23 2009 +0100 +++ a/o.openidex.util/src/org/openidex/search/Utils.java Tue Jan 13 20:08:22 2009 +0300 @@ -41,14 +41,23 @@ package org.openidex.search; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import org.openide.filesystems.FileObject; import org.openide.loaders.DataFolder; +import org.openide.loaders.DataObject; +import org.openide.loaders.DataObjectNotFoundException; import org.openide.nodes.Node; -/** - * - * @author Marian Petras - */ -final class Utils { + /** ++ * Search API utility class. + * ++ * @since org.openidex.util/3 3.20 + * @author Marian Petras ++ * @author cactus + */ +public final class Utils { /** */ @@ -71,5 +80,36 @@ SearchInfoFactory.VISIBILITY_FILTER }); } } - + + /** + * Returns Iterator of FileObject's for the provided SearchInfo. + * If provided SearchInfo object is implementation of SearchInfo.Files interface + * then the result of method SearchInfo.Files.filesToSearch is returned. Otherwise the objects + * are getting from the SearchInfo.objectsToSearch method. + * + * @param si SearchInfo object to return the iterator for + * @return iterator which iterates over FileObjects + * @since org.openidex.util/3 3.20 + */ + public static Iterator getFileObjectsIterator(SearchInfo si){ + if (si instanceof SearchInfo.Files){ + return ((SearchInfo.Files)si).filesToSearch(); + }else{ + Set set = new HashSet(); + for(Iterator iter = si.objectsToSearch(); iter.hasNext();){ + set.add(iter.next().getPrimaryFile()); + } + return set.iterator(); + } + } + + static Iterator toDataObjectIterator(Iterator itFO){ + Set set = new HashSet(); + while(itFO.hasNext()){ + try { + set.add(DataObject.find(itFO.next())); + } catch (DataObjectNotFoundException ex){} + } + return set.iterator(); + } } --- a/projectui/nbproject/project.xml Tue Jan 13 15:00:23 2009 +0100 +++ a/projectui/nbproject/project.xml Tue Jan 13 20:08:22 2009 +0300 @@ -211,7 +211,7 @@ 3 - 3.3 + 3.20 --- a/projectui/src/org/netbeans/modules/project/ui/ProjectsRootNode.java Tue Jan 13 15:00:23 2009 +0100 +++ a/projectui/src/org/netbeans/modules/project/ui/ProjectsRootNode.java Tue Jan 13 20:08:22 2009 +0300 @@ -97,6 +97,7 @@ import org.openidex.search.FileObjectFilter; import org.openidex.search.SearchInfo; import org.openidex.search.SearchInfoFactory; +import org.openidex.search.Utils; /** Root node for list of open projects */ @@ -734,7 +735,7 @@ return new AlwaysSearchableSearchInfo(p); } - private static final class AlwaysSearchableSearchInfo implements SearchInfo { + private static final class AlwaysSearchableSearchInfo implements SearchInfo.Files { private final SearchInfo delegate; @@ -762,7 +763,10 @@ public Iterator objectsToSearch() { return delegate.objectsToSearch(); } + + public Iterator filesToSearch() { + return Utils.getFileObjectsIterator(delegate); + } } - } --- a/utilities.project/src/org/netbeans/modules/search/project/SearchScopeMainProject.java Tue Jan 13 15:00:23 2009 +0100 +++ a/utilities.project/src/org/netbeans/modules/search/project/SearchScopeMainProject.java Tue Jan 13 20:08:22 2009 +0300 @@ -42,7 +42,6 @@ package org.netbeans.modules.search.project; import org.netbeans.api.project.Project; -import org.netbeans.api.project.ui.OpenProjects; import org.netbeans.api.project.ui.OpenProjects; import org.openide.util.NbBundle; import org.openidex.search.SearchInfo; --- a/utilities/nbproject/project.xml Tue Jan 13 15:00:23 2009 +0100 +++ a/utilities/nbproject/project.xml Tue Jan 13 20:08:22 2009 +0300 @@ -183,7 +183,7 @@ 3 - 3.3 + 3.20 --- a/utilities/src/org/netbeans/modules/search/BasicSearchCriteria.java Tue Jan 13 15:00:23 2009 +0100 +++ a/utilities/src/org/netbeans/modules/search/BasicSearchCriteria.java Tue Jan 13 20:08:22 2009 +0300 @@ -561,13 +561,16 @@ * criteria, {@code false} otherwise */ boolean matches(DataObject dataObj) { + return matches(dataObj.getPrimaryFile()); + } + + boolean matches(FileObject fileObj) { lastCharset = null; - if (!dataObj.isValid()) { + if (!fileObj.isValid()) { return false; } - FileObject fileObj = dataObj.getPrimaryFile(); if (fileObj.isFolder() || !fileObj.isValid() || (isFullText() && !isTextFile(fileObj))) { return false; } @@ -580,7 +583,7 @@ /* Check the file's content: */ if (textPatternValid - && !checkFileContent(fileObj, dataObj)) { + && !checkFileContent(fileObj)) { return false; } @@ -635,14 +638,14 @@ * Checks whether the file's content matches the text pattern. * * @param fileObj file whose content is to be checked - * @param dataObj {@code DataObject} corresponding to the file * @return {@code true} if the file contains at least one substring * matching the pattern, {@code false} otherwise */ - private boolean checkFileContent(FileObject fileObj, DataObject dataObj) { + private boolean checkFileContent(FileObject fileObj) { boolean firstMatch = true; SearchPattern searchPattern = null; ArrayList txtDetails = null; + DataObject dObj = null; LineNumberReader reader = null; try { @@ -656,8 +659,9 @@ searchPattern = createSearchPattern(); txtDetails = new ArrayList(5); firstMatch = false; + dObj = DataObject.find(fileObj); } - TextDetail det = new TextDetail(dataObj, searchPattern); + TextDetail det = new TextDetail(dObj, searchPattern); det.setLine(reader.getLineNumber()); det.setLineText(line); int start = matcher.start(); @@ -669,7 +673,7 @@ } if (txtDetails != null) { txtDetails.trimToSize(); - getDetailsMap().put(dataObj, txtDetails); + getDetailsMap().put(dObj, txtDetails); return true; } else { return false; --- a/utilities/src/org/netbeans/modules/search/SpecialSearchGroup.java Tue Jan 13 15:00:23 2009 +0100 +++ a/utilities/src/org/netbeans/modules/search/SpecialSearchGroup.java Tue Jan 13 20:08:22 2009 +0300 @@ -45,8 +45,13 @@ import java.util.Collection; import java.util.Iterator; import java.util.LinkedList; +import org.openide.filesystems.FileObject; import org.openide.loaders.DataObject; import org.openidex.search.DataObjectSearchGroup; +import org.openide.loaders.DataObjectNotFoundException; +import org.openide.util.Exceptions; +import org.openidex.search.FileObjectSearchGroup; +import org.openidex.search.SearchInfo; import org.openidex.search.SearchType; /** @@ -54,7 +59,7 @@ * @author Marian Petras * @author kaktus */ -final class SpecialSearchGroup extends DataObjectSearchGroup { +final class SpecialSearchGroup extends FileObjectSearchGroup { final BasicSearchCriteria basicCriteria; final boolean hasExtraSearchTypes; @@ -86,11 +91,21 @@ @Override protected void prepareSearch(){ searchItems = new LinkedList(); - for (Iterator j = searchScope.getSearchInfo().objectsToSearch(); j.hasNext(); ) { - if (stopped) { - return; + SearchInfo sInfo = searchScope.getSearchInfo(); + if (sInfo instanceof SearchInfo.Files){ + for (Iterator j = ((SearchInfo.Files)sInfo).filesToSearch(); j.hasNext(); ) { + if (stopped) { + return; + } + searchItems.add(j.next()); } - searchItems.add(j.next()); + } else { + for (Iterator j = sInfo.objectsToSearch(); j.hasNext(); ) { + if (stopped) { + return; + } + searchItems.add(j.next()); + } } } @@ -102,7 +117,7 @@ if (stopped) { return; } - processSearchObject(/*DataObject*/ searchItems.poll()); + processSearchObject(searchItems.poll()); notifyProgress(index++); } } @@ -122,9 +137,20 @@ protected void processSearchObject(Object searchObject) { if (!hasExtraSearchTypes) { assert basicCriteria != null; - DataObject dataObj = (DataObject) searchObject; - if (basicCriteria.matches(dataObj)) { - notifyMatchingObjectFound(dataObj); + if (searchObject instanceof DataObject){ + DataObject dataObj = (DataObject) searchObject; + if (basicCriteria.matches(dataObj)) { + notifyMatchingObjectFound(dataObj); + } + } else if (searchObject instanceof FileObject){ + FileObject fileObj = (FileObject) searchObject; + if (basicCriteria.matches(fileObj)) { + try { + notifyMatchingObjectFound(DataObject.find(fileObj)); + } catch (DataObjectNotFoundException ex) { + Exceptions.printStackTrace(ex); + } + } } return; }