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