Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2010 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2016 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
Lines 9-14
Link Here
|
9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.jdt.internal.ui.search; |
11 |
package org.eclipse.jdt.internal.ui.search; |
|
|
12 |
|
13 |
import java.util.ArrayList; |
14 |
import java.util.List; |
12 |
|
15 |
|
13 |
import org.eclipse.core.runtime.CoreException; |
16 |
import org.eclipse.core.runtime.CoreException; |
14 |
import org.eclipse.core.runtime.IProgressMonitor; |
17 |
import org.eclipse.core.runtime.IProgressMonitor; |
Lines 55-67
Link Here
|
55 |
private static final String PERF_SEARCH_PARTICIPANT= "org.eclipse.jdt.ui/perf/search/participants"; //$NON-NLS-1$ |
58 |
private static final String PERF_SEARCH_PARTICIPANT= "org.eclipse.jdt.ui/perf/search/participants"; //$NON-NLS-1$ |
56 |
|
59 |
|
57 |
private ISearchResult fResult; |
60 |
private ISearchResult fResult; |
58 |
private final QuerySpecification fPatternData; |
61 |
private final List<QuerySpecification> fPatternDataList; |
59 |
|
62 |
|
60 |
public JavaSearchQuery(QuerySpecification data) { |
63 |
public JavaSearchQuery(QuerySpecification data) { |
61 |
if (data == null) { |
64 |
if (data == null) { |
62 |
throw new IllegalArgumentException("data must not be null"); //$NON-NLS-1$ |
65 |
throw new IllegalArgumentException("data must not be null"); //$NON-NLS-1$ |
63 |
} |
66 |
} |
64 |
fPatternData= data; |
67 |
fPatternDataList= new ArrayList<>(); |
|
|
68 |
fPatternDataList.add(data); |
69 |
} |
70 |
|
71 |
public JavaSearchQuery(List<QuerySpecification> dataList) { |
72 |
if (dataList == null) { |
73 |
throw new IllegalArgumentException("data must not be null"); //$NON-NLS-1$ |
74 |
} |
75 |
fPatternDataList= dataList; |
65 |
} |
76 |
} |
66 |
|
77 |
|
67 |
private static class SearchRequestor implements ISearchRequestor { |
78 |
private static class SearchRequestor implements ISearchRequestor { |
Lines 93-99
Link Here
|
93 |
try { |
104 |
try { |
94 |
|
105 |
|
95 |
int totalTicks= 1000; |
106 |
int totalTicks= 1000; |
96 |
IProject[] projects= JavaSearchScopeFactory.getInstance().getProjects(fPatternData.getScope()); |
107 |
IProject[] projects= JavaSearchScopeFactory.getInstance().getProjects(getPatternData().getScope()); |
97 |
final SearchParticipantRecord[] participantDescriptors= SearchParticipantsExtensionPoint.getInstance().getSearchParticipants(projects); |
108 |
final SearchParticipantRecord[] participantDescriptors= SearchParticipantsExtensionPoint.getInstance().getSearchParticipants(projects); |
98 |
final int[] ticks= new int[participantDescriptors.length]; |
109 |
final int[] ticks= new int[participantDescriptors.length]; |
99 |
for (int i= 0; i < participantDescriptors.length; i++) { |
110 |
for (int i= 0; i < participantDescriptors.length; i++) { |
Lines 108-114
Link Here
|
108 |
|
119 |
|
109 |
@Override |
120 |
@Override |
110 |
public void run() throws Exception { |
121 |
public void run() throws Exception { |
111 |
ticks[iPrime]= participantDescriptors[iPrime].getParticipant().estimateTicks(fPatternData); |
122 |
for (QuerySpecification querySpecification : fPatternDataList) { |
|
|
123 |
ticks[iPrime]+= participantDescriptors[iPrime].getParticipant().estimateTicks(querySpecification); |
124 |
} |
112 |
} |
125 |
} |
113 |
}; |
126 |
}; |
114 |
|
127 |
|
Lines 116-138
Link Here
|
116 |
totalTicks+= ticks[i]; |
129 |
totalTicks+= ticks[i]; |
117 |
} |
130 |
} |
118 |
|
131 |
|
119 |
SearchPattern pattern; |
132 |
SearchPattern pattern= null; |
120 |
String stringPattern; |
133 |
String stringPattern= null; |
121 |
|
134 |
|
122 |
if (fPatternData instanceof ElementQuerySpecification) { |
135 |
if (fPatternDataList.size() == 1) { |
123 |
IJavaElement element= ((ElementQuerySpecification) fPatternData).getElement(); |
136 |
if (getPatternData() instanceof ElementQuerySpecification) { |
124 |
stringPattern= JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT); |
137 |
IJavaElement element= ((ElementQuerySpecification) getPatternData()).getElement(); |
125 |
if (!element.exists()) { |
138 |
stringPattern= JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT); |
126 |
return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(SearchMessages.JavaSearchQuery_error_element_does_not_exist, stringPattern), null); |
139 |
if (!element.exists()) { |
|
|
140 |
return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(SearchMessages.JavaSearchQuery_error_element_does_not_exist, stringPattern), null); |
141 |
} |
142 |
pattern= SearchPattern.createPattern(element, getPatternData().getLimitTo(), SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE); |
143 |
} else if (getPatternData() instanceof PatternQuerySpecification) { |
144 |
PatternQuerySpecification patternSpec= (PatternQuerySpecification) getPatternData(); |
145 |
stringPattern= patternSpec.getPattern(); |
146 |
int matchMode= getMatchMode(stringPattern) | SearchPattern.R_ERASURE_MATCH; |
147 |
if (patternSpec.isCaseSensitive()) |
148 |
matchMode|= SearchPattern.R_CASE_SENSITIVE; |
149 |
pattern= SearchPattern.createPattern(patternSpec.getPattern(), patternSpec.getSearchFor(), patternSpec.getLimitTo(), matchMode); |
127 |
} |
150 |
} |
128 |
pattern= SearchPattern.createPattern(element, fPatternData.getLimitTo(), SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE); |
|
|
129 |
} else { |
151 |
} else { |
130 |
PatternQuerySpecification patternSpec = (PatternQuerySpecification) fPatternData; |
152 |
for (QuerySpecification querySpecification : fPatternDataList) { |
131 |
stringPattern= patternSpec.getPattern(); |
153 |
if (!(querySpecification instanceof ElementQuerySpecification)) |
132 |
int matchMode= getMatchMode(stringPattern) | SearchPattern.R_ERASURE_MATCH; |
154 |
break; |
133 |
if (patternSpec.isCaseSensitive()) |
155 |
IJavaElement element= ((ElementQuerySpecification) querySpecification).getElement(); |
134 |
matchMode |= SearchPattern.R_CASE_SENSITIVE; |
156 |
stringPattern= JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT); |
135 |
pattern= SearchPattern.createPattern(patternSpec.getPattern(), patternSpec.getSearchFor(), patternSpec.getLimitTo(), matchMode); |
157 |
if (!element.exists()) { |
|
|
158 |
return new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, Messages.format(SearchMessages.JavaSearchQuery_error_element_does_not_exist, stringPattern), null); |
159 |
} |
160 |
SearchPattern elementPattern= SearchPattern.createPattern(element, getPatternData().getLimitTo(), SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE); |
161 |
if (pattern == null) { |
162 |
pattern= elementPattern; |
163 |
} else { |
164 |
pattern= SearchPattern.createOrPattern(pattern, elementPattern); |
165 |
} |
166 |
} |
136 |
} |
167 |
} |
137 |
|
168 |
|
138 |
if (pattern == null) { |
169 |
if (pattern == null) { |
Lines 145-151
Link Here
|
145 |
NewSearchResultCollector collector= new NewSearchResultCollector(textResult, ignorePotentials); |
176 |
NewSearchResultCollector collector= new NewSearchResultCollector(textResult, ignorePotentials); |
146 |
|
177 |
|
147 |
|
178 |
|
148 |
engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, fPatternData.getScope(), collector, mainSearchPM); |
179 |
engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, getPatternData().getScope(), collector, mainSearchPM); |
149 |
for (int i= 0; i < participantDescriptors.length; i++) { |
180 |
for (int i= 0; i < participantDescriptors.length; i++) { |
150 |
final ISearchRequestor requestor= new SearchRequestor(participantDescriptors[i].getParticipant(), textResult); |
181 |
final ISearchRequestor requestor= new SearchRequestor(participantDescriptors[i].getParticipant(), textResult); |
151 |
final IProgressMonitor participantPM= new SubProgressMonitor(monitor, ticks[i]); |
182 |
final IProgressMonitor participantPM= new SubProgressMonitor(monitor, ticks[i]); |
Lines 167-173
Link Here
|
167 |
final PerformanceStats stats= PerformanceStats.getStats(PERF_SEARCH_PARTICIPANT, participant); |
198 |
final PerformanceStats stats= PerformanceStats.getStats(PERF_SEARCH_PARTICIPANT, participant); |
168 |
stats.startRun(); |
199 |
stats.startRun(); |
169 |
|
200 |
|
170 |
participant.search(requestor, fPatternData, participantPM); |
201 |
for (QuerySpecification querySpecification : fPatternDataList) { |
|
|
202 |
participant.search(requestor, querySpecification, participantPM); |
203 |
} |
171 |
|
204 |
|
172 |
stats.endRun(); |
205 |
stats.endRun(); |
173 |
} |
206 |
} |
Lines 200-206
Link Here
|
200 |
public String getResultLabel(int nMatches) { |
233 |
public String getResultLabel(int nMatches) { |
201 |
int limitTo= getMaskedLimitTo(); |
234 |
int limitTo= getMaskedLimitTo(); |
202 |
if (nMatches == 1) { |
235 |
if (nMatches == 1) { |
203 |
String[] args= { getSearchPatternDescription(), fPatternData.getScopeDescription() }; |
236 |
String[] args= { getSearchPatternDescription(), getPatternData().getScopeDescription() }; |
204 |
switch (limitTo) { |
237 |
switch (limitTo) { |
205 |
case IJavaSearchConstants.IMPLEMENTORS: |
238 |
case IJavaSearchConstants.IMPLEMENTORS: |
206 |
return Messages.format(SearchMessages.JavaSearchOperation_singularImplementorsPostfix, args); |
239 |
return Messages.format(SearchMessages.JavaSearchOperation_singularImplementorsPostfix, args); |
Lines 219-225
Link Here
|
219 |
return Messages.format(SearchMessages.JavaSearchQuery_singularReferencesWithMatchLocations, new Object[] { args[0], args[1], matchLocations }); |
252 |
return Messages.format(SearchMessages.JavaSearchQuery_singularReferencesWithMatchLocations, new Object[] { args[0], args[1], matchLocations }); |
220 |
} |
253 |
} |
221 |
} else { |
254 |
} else { |
222 |
Object[] args= { getSearchPatternDescription(), new Integer(nMatches), fPatternData.getScopeDescription() }; |
255 |
Object[] args= { getSearchPatternDescription(), new Integer(nMatches), getPatternData().getScopeDescription() }; |
223 |
switch (limitTo) { |
256 |
switch (limitTo) { |
224 |
case IJavaSearchConstants.IMPLEMENTORS: |
257 |
case IJavaSearchConstants.IMPLEMENTORS: |
225 |
return Messages.format(SearchMessages.JavaSearchOperation_pluralImplementorsPostfix, args); |
258 |
return Messages.format(SearchMessages.JavaSearchOperation_pluralImplementorsPostfix, args); |
Lines 241-256
Link Here
|
241 |
} |
274 |
} |
242 |
|
275 |
|
243 |
private String getSearchPatternDescription() { |
276 |
private String getSearchPatternDescription() { |
244 |
if (fPatternData instanceof ElementQuerySpecification) { |
277 |
if (fPatternDataList.size() == 1) { |
245 |
IJavaElement element= ((ElementQuerySpecification) fPatternData).getElement(); |
278 |
if (getPatternData() instanceof ElementQuerySpecification) { |
246 |
return JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT |
279 |
IJavaElement element= ((ElementQuerySpecification) getPatternData()).getElement(); |
247 |
| JavaElementLabels.ALL_FULLY_QUALIFIED | JavaElementLabels.USE_RESOLVED | JavaElementLabels.P_COMPRESSED); |
280 |
return JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT |
|
|
281 |
| JavaElementLabels.ALL_FULLY_QUALIFIED | JavaElementLabels.USE_RESOLVED | JavaElementLabels.P_COMPRESSED); |
282 |
} else if (getPatternData() instanceof PatternQuerySpecification) { |
283 |
return BasicElementLabels.getFilePattern(((PatternQuerySpecification) getPatternData()).getPattern()); |
284 |
} |
285 |
} else { |
286 |
StringBuilder description= new StringBuilder(); |
287 |
for (int i= 0; i < fPatternDataList.size(); i++) { |
288 |
QuerySpecification querySpecification= fPatternDataList.get(i); |
289 |
if (!(querySpecification instanceof ElementQuerySpecification)) { |
290 |
return new String(""); //$NON-NLS-1$ |
291 |
} |
292 |
IJavaElement element= ((ElementQuerySpecification) querySpecification).getElement(); |
293 |
if (description.length() != 0 && i < (fPatternDataList.size() - 1)) { |
294 |
description.append(", "); //$NON-NLS-1$ |
295 |
} else if (description.length() > 0) { |
296 |
description.append(" " + SearchMessages.JavaSearchQuery_multi_selection_search_and + " "); //$NON-NLS-1$//$NON-NLS-2$ |
297 |
} |
298 |
description.append(JavaElementLabels.getElementLabel(element, JavaElementLabels.ALL_DEFAULT |
299 |
| JavaElementLabels.ALL_FULLY_QUALIFIED | JavaElementLabels.USE_RESOLVED | JavaElementLabels.P_COMPRESSED)); |
300 |
} |
301 |
return description.toString(); |
248 |
} |
302 |
} |
249 |
return BasicElementLabels.getFilePattern(((PatternQuerySpecification) fPatternData).getPattern()); |
303 |
return new String(""); //$NON-NLS-1$ |
250 |
} |
304 |
} |
251 |
|
305 |
|
252 |
private int getMaskedLimitTo() { |
306 |
private int getMaskedLimitTo() { |
253 |
return fPatternData.getLimitTo() & ~(IJavaSearchConstants.IGNORE_RETURN_TYPE | IJavaSearchConstants.IGNORE_DECLARING_TYPE); |
307 |
return getPatternData().getLimitTo() & ~(IJavaSearchConstants.IGNORE_RETURN_TYPE | IJavaSearchConstants.IGNORE_DECLARING_TYPE); |
254 |
} |
308 |
} |
255 |
|
309 |
|
256 |
ImageDescriptor getImageDescriptor() { |
310 |
ImageDescriptor getImageDescriptor() { |
Lines 281-287
Link Here
|
281 |
return fResult; |
335 |
return fResult; |
282 |
} |
336 |
} |
283 |
|
337 |
|
284 |
QuerySpecification getSpecification() { |
338 |
private QuerySpecification getPatternData() { |
285 |
return fPatternData; |
339 |
return fPatternDataList.get(0); |
|
|
340 |
} |
341 |
|
342 |
List<QuerySpecification> getSpecification() { |
343 |
return fPatternDataList; |
286 |
} |
344 |
} |
287 |
} |
345 |
} |