1 11 package org.eclipse.jdt.internal.ui.search; 12 13 import org.eclipse.core.resources.IWorkspace; 14 import org.eclipse.core.runtime.CoreException; 15 import org.eclipse.core.runtime.IProgressMonitor; 16 import org.eclipse.jdt.core.IJavaElement; 17 import org.eclipse.jdt.core.IMethod; 18 import org.eclipse.jdt.core.search.IJavaSearchConstants; 19 import org.eclipse.jdt.core.search.IJavaSearchScope; 20 import org.eclipse.jdt.core.search.SearchEngine; 21 import org.eclipse.jdt.internal.ui.JavaPluginImages; 22 import org.eclipse.jface.resource.ImageDescriptor; 23 import org.eclipse.ui.actions.WorkspaceModifyOperation; 24 25 public class JavaSearchOperation extends WorkspaceModifyOperation { 26 27 private IWorkspace fWorkspace; 28 private IJavaElement fElementPattern; 29 private int fLimitTo; 30 private String fStringPattern; 31 private boolean fIsCaseSensitive; 32 private int fSearchFor; 33 private IJavaSearchScope fScope; 34 private String fScopeDescription; 35 private JavaSearchResultCollector fCollector; 36 37 protected JavaSearchOperation( 38 IWorkspace workspace, 39 int limitTo, 40 IJavaSearchScope scope, 41 String scopeDescription, 42 JavaSearchResultCollector collector) { 43 super(null); 44 fWorkspace= workspace; 45 fLimitTo= limitTo; 46 fScope= scope; 47 fScopeDescription= scopeDescription; 48 fCollector= collector; 49 fCollector.setOperation(this); 50 } 51 52 public JavaSearchOperation( 53 IWorkspace workspace, 54 IJavaElement pattern, 55 int limitTo, 56 IJavaSearchScope scope, 57 String scopeDescription, 58 JavaSearchResultCollector collector) { 59 this(workspace, limitTo, scope, scopeDescription, collector); 60 fElementPattern= pattern; 61 } 62 63 public JavaSearchOperation( 64 IWorkspace workspace, 65 String pattern, 66 boolean caseSensitive, 67 int searchFor, 68 int limitTo, 69 IJavaSearchScope scope, 70 String scopeDescription, 71 JavaSearchResultCollector collector) { 72 this(workspace, limitTo, scope, scopeDescription, collector); 73 fStringPattern= pattern; 74 fIsCaseSensitive= caseSensitive; 75 fSearchFor= searchFor; 76 } 77 78 protected void execute(IProgressMonitor monitor) throws CoreException { 79 fCollector.setProgressMonitor(monitor); 80 81 SearchEngine engine; 83 if (true) { 84 engine= new SearchEngine(); 85 } 86 87 if (fElementPattern != null) 88 engine.search(fWorkspace, fElementPattern, fLimitTo, fScope, fCollector); 89 else 90 engine.search(fWorkspace, SearchEngine.createSearchPattern(fStringPattern, fSearchFor, fLimitTo, fIsCaseSensitive), fScope, fCollector); 91 } 92 93 String getSingularLabel() { 94 String desc= null; 95 if (fElementPattern != null) { 96 if (fLimitTo == IJavaSearchConstants.REFERENCES 97 && fElementPattern.getElementType() == IJavaElement.METHOD) 98 desc= PrettySignature.getUnqualifiedMethodSignature((IMethod)fElementPattern); 99 else 100 desc= fElementPattern.getElementName(); 101 if ("".equals(desc) && fElementPattern.getElementType() == IJavaElement.PACKAGE_FRAGMENT) desc= SearchMessages.getString("JavaSearchOperation.default_package"); } 104 else 105 desc= fStringPattern; 106 107 String [] args= new String [] {desc, fScopeDescription}; switch (fLimitTo) { 109 case IJavaSearchConstants.IMPLEMENTORS: 110 return SearchMessages.getFormattedString("JavaSearchOperation.singularImplementorsPostfix", args); case IJavaSearchConstants.DECLARATIONS: 112 return SearchMessages.getFormattedString("JavaSearchOperation.singularDeclarationsPostfix", args); case IJavaSearchConstants.REFERENCES: 114 return SearchMessages.getFormattedString("JavaSearchOperation.singularReferencesPostfix", args); case IJavaSearchConstants.ALL_OCCURRENCES: 116 return SearchMessages.getFormattedString("JavaSearchOperation.singularOccurrencesPostfix", args); case IJavaSearchConstants.READ_ACCESSES: 118 return SearchMessages.getFormattedString("JavaSearchOperation.singularReadReferencesPostfix", args); case IJavaSearchConstants.WRITE_ACCESSES: 120 return SearchMessages.getFormattedString("JavaSearchOperation.singularWriteReferencesPostfix", args); default: 122 return SearchMessages.getFormattedString("JavaSearchOperation.singularOccurrencesPostfix", args); } 124 } 125 126 String getPluralLabelPattern() { 127 String desc= null; 128 if (fElementPattern != null) { 129 if (fLimitTo == IJavaSearchConstants.REFERENCES 130 && fElementPattern.getElementType() == IJavaElement.METHOD) 131 desc= PrettySignature.getUnqualifiedMethodSignature((IMethod)fElementPattern); 132 else 133 desc= fElementPattern.getElementName(); 134 if ("".equals(desc) && fElementPattern.getElementType() == IJavaElement.PACKAGE_FRAGMENT) desc= SearchMessages.getString("JavaSearchOperation.default_package"); } 137 else 138 desc= fStringPattern; 139 140 String [] args= new String [] {desc, "{0}", fScopeDescription}; switch (fLimitTo) { 142 case IJavaSearchConstants.IMPLEMENTORS: 143 return SearchMessages.getFormattedString("JavaSearchOperation.pluralImplementorsPostfix", args); case IJavaSearchConstants.DECLARATIONS: 145 return SearchMessages.getFormattedString("JavaSearchOperation.pluralDeclarationsPostfix", args); case IJavaSearchConstants.REFERENCES: 147 return SearchMessages.getFormattedString("JavaSearchOperation.pluralReferencesPostfix", args); case IJavaSearchConstants.ALL_OCCURRENCES: 149 return SearchMessages.getFormattedString("JavaSearchOperation.pluralOccurrencesPostfix", args); case IJavaSearchConstants.READ_ACCESSES: 151 return SearchMessages.getFormattedString("JavaSearchOperation.pluralReadReferencesPostfix", args); case IJavaSearchConstants.WRITE_ACCESSES: 153 return SearchMessages.getFormattedString("JavaSearchOperation.pluralWriteReferencesPostfix", args); default: 155 return SearchMessages.getFormattedString("JavaSearchOperation.pluralOccurrencesPostfix", args); } 157 } 158 159 ImageDescriptor getImageDescriptor() { 160 if (fLimitTo == IJavaSearchConstants.IMPLEMENTORS || fLimitTo == IJavaSearchConstants.DECLARATIONS) 161 return JavaPluginImages.DESC_OBJS_SEARCH_DECL; 162 else 163 return JavaPluginImages.DESC_OBJS_SEARCH_REF; 164 } 165 } 166 | Popular Tags |