1 11 package org.eclipse.jdt.internal.corext.refactoring; 12 13 import java.util.ArrayList ; 14 import java.util.Arrays ; 15 import java.util.HashSet ; 16 import java.util.List ; 17 import java.util.Set ; 18 19 import org.eclipse.core.runtime.Assert; 20 21 import org.eclipse.core.resources.IResource; 22 23 import org.eclipse.jdt.core.ICompilationUnit; 24 import org.eclipse.jdt.core.IJavaElement; 25 import org.eclipse.jdt.core.search.SearchMatch; 26 27 import org.eclipse.jdt.internal.corext.util.SearchUtils; 28 29 public class SearchResultGroup { 30 31 private final IResource fResouce; 32 private final List fSearchMatches; 33 34 public SearchResultGroup(IResource res, SearchMatch[] matches){ 35 Assert.isNotNull(matches); 36 fResouce= res; 37 fSearchMatches= new ArrayList (Arrays.asList(matches)); 38 } 39 40 public void add(SearchMatch match) { 41 Assert.isNotNull(match); 42 fSearchMatches.add(match); 43 } 44 45 public IResource getResource() { 46 return fResouce; 47 } 48 49 public SearchMatch[] getSearchResults() { 50 return (SearchMatch[]) fSearchMatches.toArray(new SearchMatch[fSearchMatches.size()]); 51 } 52 53 public static IResource[] getResources(SearchResultGroup[] searchResultGroups){ 54 Set resourceSet= new HashSet (searchResultGroups.length); 55 for (int i= 0; i < searchResultGroups.length; i++) { 56 resourceSet.add(searchResultGroups[i].getResource()); 57 } 58 return (IResource[]) resourceSet.toArray(new IResource[resourceSet.size()]); 59 } 60 61 public ICompilationUnit getCompilationUnit(){ 62 if (getSearchResults() == null || getSearchResults().length == 0) 63 return null; 64 return SearchUtils.getCompilationUnit(getSearchResults()[0]); 65 } 66 67 public String toString() { 68 StringBuffer buf= new StringBuffer (fResouce.getFullPath().toString()); 69 buf.append('\n'); 70 for (int i= 0; i < fSearchMatches.size(); i++) { 71 SearchMatch match= (SearchMatch) fSearchMatches.get(i); 72 buf.append(" ").append(match.getOffset()).append(", ").append(match.getLength()); buf.append(match.getAccuracy() == SearchMatch.A_ACCURATE ? "; acc" : "; inacc"); if (match.isInsideDocComment()) 75 buf.append("; inDoc"); if (match.getElement() instanceof IJavaElement) 77 buf.append("; in: ").append(((IJavaElement) match.getElement()).getElementName()); buf.append('\n'); 79 } 80 return buf.toString(); 81 } 82 } 83 | Popular Tags |