diff options
Diffstat (limited to 'org.eclipse.search/new search')
20 files changed, 236 insertions, 235 deletions
diff --git a/org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchResult.java b/org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchResult.java index fbd75957f9b..f4ba3d60c6c 100644 --- a/org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchResult.java +++ b/org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchResult.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -33,8 +33,8 @@ public abstract class AbstractTextSearchResult implements ISearchResult { private static final Match[] EMPTY_ARRAY= new Match[0]; - private final Map fElementsToMatches; - private final List fListeners; + private final Map<Object, List<Match>> fElementsToMatches; + private final List<ISearchResultListener> fListeners; private final MatchEvent fMatchEvent; private MatchFilter[] fMatchFilters; @@ -43,8 +43,8 @@ public abstract class AbstractTextSearchResult implements ISearchResult { * Constructs a new <code>AbstractTextSearchResult</code> */ protected AbstractTextSearchResult() { - fElementsToMatches= new HashMap(); - fListeners= new ArrayList(); + fElementsToMatches= new HashMap<>(); + fListeners= new ArrayList<>(); fMatchEvent= new MatchEvent(this); fMatchFilters= null; // filtering disabled by default @@ -60,9 +60,9 @@ public abstract class AbstractTextSearchResult implements ISearchResult { */ public Match[] getMatches(Object element) { synchronized (fElementsToMatches) { - List matches= (List) fElementsToMatches.get(element); + List<Match> matches= fElementsToMatches.get(element); if (matches != null) - return (Match[]) matches.toArray(new Match[matches.size()]); + return matches.toArray(new Match[matches.size()]); return EMPTY_ARRAY; } } @@ -94,7 +94,7 @@ public abstract class AbstractTextSearchResult implements ISearchResult { * @param matches the matches to add */ public void addMatches(Match[] matches) { - Collection reallyAdded= new ArrayList(); + Collection<Match> reallyAdded= new ArrayList<>(); synchronized (fElementsToMatches) { for (int i = 0; i < matches.length; i++) { if (doAddMatch(matches[i])) @@ -111,9 +111,9 @@ public abstract class AbstractTextSearchResult implements ISearchResult { return fMatchEvent; } - private MatchEvent getSearchResultEvent(Collection matches, int eventKind) { + private MatchEvent getSearchResultEvent(Collection<Match> matches, int eventKind) { fMatchEvent.setKind(eventKind); - Match[] matchArray= (Match[]) matches.toArray(new Match[matches.size()]); + Match[] matchArray= matches.toArray(new Match[matches.size()]); fMatchEvent.setMatches(matchArray); return fMatchEvent; } @@ -121,9 +121,9 @@ public abstract class AbstractTextSearchResult implements ISearchResult { private boolean doAddMatch(Match match) { updateFilterState(match); - List matches= (List) fElementsToMatches.get(match.getElement()); + List<Match> matches= fElementsToMatches.get(match.getElement()); if (matches == null) { - matches= new ArrayList(); + matches= new ArrayList<>(); fElementsToMatches.put(match.getElement(), matches); matches.add(match); return true; @@ -135,17 +135,17 @@ public abstract class AbstractTextSearchResult implements ISearchResult { return false; } - private static void insertSorted(List matches, Match match) { + private static void insertSorted(List<Match> matches, Match match) { int insertIndex= getInsertIndex(matches, match); matches.add(insertIndex, match); } - private static int getInsertIndex(List matches, Match match) { + private static int getInsertIndex(List<Match> matches, Match match) { int count= matches.size(); int min = 0, max = count - 1; while (min <= max) { int mid = (min + max) / 2; - Match data = (Match) matches.get(mid); + Match data = matches.get(mid); int compare = compare(match, data); if (compare > 0) max = mid - 1; @@ -206,7 +206,7 @@ public abstract class AbstractTextSearchResult implements ISearchResult { * @param matches the matches to remove */ public void removeMatches(Match[] matches) { - Collection existing= new ArrayList(); + Collection<Match> existing= new ArrayList<>(); synchronized (fElementsToMatches) { for (int i = 0; i < matches.length; i++) { if (doRemoveMatch(matches[i])) @@ -220,7 +220,7 @@ public abstract class AbstractTextSearchResult implements ISearchResult { private boolean doRemoveMatch(Match match) { boolean existed= false; - List matches= (List) fElementsToMatches.get(match.getElement()); + List<Match> matches= fElementsToMatches.get(match.getElement()); if (matches != null) { existed= matches.remove(match); if (matches.isEmpty()) @@ -252,19 +252,19 @@ public abstract class AbstractTextSearchResult implements ISearchResult { * @see ISearchResultListener */ protected void fireChange(SearchResultEvent e) { - HashSet copiedListeners= new HashSet(); + HashSet<ISearchResultListener> copiedListeners= new HashSet<>(); synchronized (fListeners) { copiedListeners.addAll(fListeners); } - Iterator listeners= copiedListeners.iterator(); + Iterator<ISearchResultListener> listeners= copiedListeners.iterator(); while (listeners.hasNext()) { - ((ISearchResultListener) listeners.next()).searchResultChanged(e); + listeners.next().searchResultChanged(e); } } private void updateFilterStateForAllMatches() { boolean disableFiltering= getActiveMatchFilters() == null; - ArrayList changed= new ArrayList(); + ArrayList<Match> changed= new ArrayList<>(); Object[] elements= getElements(); for (int i= 0; i < elements.length; i++) { Match[] matches= getMatches(elements[i]); @@ -274,7 +274,7 @@ public abstract class AbstractTextSearchResult implements ISearchResult { } } } - Match[] allChanges= (Match[]) changed.toArray(new Match[changed.size()]); + Match[] allChanges= changed.toArray(new Match[changed.size()]); fireChange(new FilterUpdateEvent(this, allChanges, getActiveMatchFilters())); } @@ -307,8 +307,8 @@ public abstract class AbstractTextSearchResult implements ISearchResult { public int getMatchCount() { int count= 0; synchronized (fElementsToMatches) { - for (Iterator elements= fElementsToMatches.values().iterator(); elements.hasNext();) { - List element= (List) elements.next(); + for (Iterator<List<Match>> elements= fElementsToMatches.values().iterator(); elements.hasNext();) { + List<Match> element= elements.next(); if (element != null) count+= element.size(); } @@ -325,7 +325,7 @@ public abstract class AbstractTextSearchResult implements ISearchResult { * @return the number of matches reported against the element */ public int getMatchCount(Object element) { - List matches= (List) fElementsToMatches.get(element); + List<Match> matches= fElementsToMatches.get(element); if (matches != null) return matches.size(); return 0; diff --git a/org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchViewPage.java b/org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchViewPage.java index f7578dddcfe..dfda8772022 100644 --- a/org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchViewPage.java +++ b/org.eclipse.search/new search/org/eclipse/search/ui/text/AbstractTextSearchViewPage.java @@ -174,7 +174,7 @@ public abstract class AbstractTextSearchViewPage extends Page implements ISearch } private class SelectionProviderAdapter implements ISelectionProvider, ISelectionChangedListener { - private ArrayList fListeners= new ArrayList(5); + private ArrayList<ISelectionChangedListener> fListeners= new ArrayList<>(5); @Override public void addSelectionChangedListener(ISelectionChangedListener listener) { @@ -200,8 +200,8 @@ public abstract class AbstractTextSearchViewPage extends Page implements ISearch public void selectionChanged(SelectionChangedEvent event) { // forward to my listeners SelectionChangedEvent wrappedEvent= new SelectionChangedEvent(this, event.getSelection()); - for (Iterator listeners= fListeners.iterator(); listeners.hasNext();) { - ISelectionChangedListener listener= (ISelectionChangedListener) listeners.next(); + for (Iterator<ISelectionChangedListener> listeners= fListeners.iterator(); listeners.hasNext();) { + ISelectionChangedListener listener= listeners.next(); listener.selectionChanged(wrappedEvent); } } @@ -223,7 +223,7 @@ public abstract class AbstractTextSearchViewPage extends Page implements ISearch private PageBook fPagebook; private boolean fIsBusyShown; private ISearchResultViewPart fViewPart; - private Set fBatchedUpdates; + private Set<Object> fBatchedUpdates; private boolean fBatchedClearAll; private ISearchResultListener fListener; @@ -296,7 +296,7 @@ public abstract class AbstractTextSearchViewPage extends Page implements ISearch fSelectAllAction= new SelectAllAction(); createLayoutActions(); - fBatchedUpdates = new HashSet(); + fBatchedUpdates = new HashSet<>(); fBatchedClearAll= false; fListener = new ISearchResultListener() { @@ -1240,7 +1240,7 @@ public abstract class AbstractTextSearchViewPage extends Page implements ISearch * @param changedElements the set that collects the elements to change. Clients should only add elements to the set. * @since 3.4 */ - protected void evaluateChangedElements(Match[] matches, Set changedElements) { + protected void evaluateChangedElements(Match[] matches, Set<Object> changedElements) { for (int i = 0; i < matches.length; i++) { changedElements.add(matches[i].getElement()); } @@ -1357,7 +1357,7 @@ public abstract class AbstractTextSearchViewPage extends Page implements ISearch StructuredViewer viewer = getViewer(); IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); - HashSet set = new HashSet(); + HashSet<Match> set = new HashSet<>(); if (viewer instanceof TreeViewer) { ITreeContentProvider cp = (ITreeContentProvider) viewer.getContentProvider(); collectAllMatchesBelow(result, set, cp, selection.toArray()); @@ -1371,7 +1371,7 @@ public abstract class AbstractTextSearchViewPage extends Page implements ISearch result.removeMatches(matches); } - private void collectAllMatches(HashSet set, Object[] elements) { + private void collectAllMatches(HashSet<Match> set, Object[] elements) { for (int j = 0; j < elements.length; j++) { Match[] matches = getDisplayedMatches(elements[j]); for (int i = 0; i < matches.length; i++) { @@ -1380,7 +1380,7 @@ public abstract class AbstractTextSearchViewPage extends Page implements ISearch } } - private void collectAllMatchesBelow(AbstractTextSearchResult result, Set set, ITreeContentProvider cp, Object[] elements) { + private void collectAllMatchesBelow(AbstractTextSearchResult result, Set<Match> set, ITreeContentProvider cp, Object[] elements) { for (int j = 0; j < elements.length; j++) { Match[] matches = getDisplayedMatches(elements[j]); for (int i = 0; i < matches.length; i++) { diff --git a/org.eclipse.search/new search/org/eclipse/search/ui/text/FileTextSearchScope.java b/org.eclipse.search/new search/org/eclipse/search/ui/text/FileTextSearchScope.java index 9ace3c800e8..da2462f3d99 100644 --- a/org.eclipse.search/new search/org/eclipse/search/ui/text/FileTextSearchScope.java +++ b/org.eclipse.search/new search/org/eclipse/search/ui/text/FileTextSearchScope.java @@ -240,7 +240,7 @@ public final class FileTextSearchScope extends TextSearchScope { if (fileNamePatterns == null || fileNamePatterns.length == 0) { return null; } - ArrayList patterns= new ArrayList(); + ArrayList<String> patterns= new ArrayList<>(); for (int i= 0; i < fileNamePatterns.length; i++) { String pattern= fFileNamePatterns[i]; if (negativeMatcher == pattern.startsWith(FileTypeEditor.FILE_PATTERN_NEGATOR)) { @@ -253,7 +253,7 @@ public final class FileTextSearchScope extends TextSearchScope { } } if (!patterns.isEmpty()) { - String[] patternArray= (String[]) patterns.toArray(new String[patterns.size()]); + String[] patternArray= patterns.toArray(new String[patterns.size()]); Pattern pattern= PatternConstructor.createPattern(patternArray, IS_CASE_SENSITIVE_FILESYSTEM); return pattern.matcher(""); //$NON-NLS-1$ } @@ -261,16 +261,16 @@ public final class FileTextSearchScope extends TextSearchScope { } private static IResource[] removeRedundantEntries(IResource[] elements, boolean includeDerived) { - ArrayList res= new ArrayList(); + ArrayList<IResource> res= new ArrayList<>(); for (int i= 0; i < elements.length; i++) { IResource curr= elements[i]; addToList(res, curr, includeDerived); } - return (IResource[])res.toArray(new IResource[res.size()]); + return res.toArray(new IResource[res.size()]); } private static IResource[] convertToResources(IWorkingSet[] workingSets, boolean includeDerived) { - ArrayList res= new ArrayList(); + ArrayList<IResource> res= new ArrayList<>(); for (int i= 0; i < workingSets.length; i++) { IWorkingSet workingSet= workingSets[i]; if (workingSet.isAggregateWorkingSet() && workingSet.isEmpty()) { @@ -284,16 +284,16 @@ public final class FileTextSearchScope extends TextSearchScope { } } } - return (IResource[]) res.toArray(new IResource[res.size()]); + return res.toArray(new IResource[res.size()]); } - private static void addToList(ArrayList res, IResource curr, boolean includeDerived) { + private static void addToList(ArrayList<IResource> res, IResource curr, boolean includeDerived) { if (!includeDerived && curr.isDerived(IResource.CHECK_ANCESTORS)) { return; } IPath currPath= curr.getFullPath(); for (int k= res.size() - 1; k >= 0 ; k--) { - IResource other= (IResource) res.get(k); + IResource other= res.get(k); IPath otherPath= other.getFullPath(); if (otherPath.isPrefixOf(currPath)) { return; diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/InternalSearchUI.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/InternalSearchUI.java index 04e885b3d42..99ac2018bee 100644 --- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/InternalSearchUI.java +++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/InternalSearchUI.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -46,7 +46,7 @@ public class InternalSearchUI { private static InternalSearchUI fgInstance; // contains all running jobs - private HashMap fSearchJobs; + private HashMap<ISearchQuery, SearchJobRecord> fSearchJobs; private QueryManager fSearchResultsManager; private PositionTracker fPositionTracker; @@ -123,7 +123,7 @@ public class InternalSearchUI { */ public InternalSearchUI() { fgInstance= this; - fSearchJobs= new HashMap(); + fSearchJobs= new HashMap<>(); fSearchResultsManager= new QueryManager(); fPositionTracker= new PositionTracker(); @@ -186,7 +186,7 @@ public class InternalSearchUI { } public boolean isQueryRunning(ISearchQuery query) { - SearchJobRecord sjr= (SearchJobRecord) fSearchJobs.get(query); + SearchJobRecord sjr= fSearchJobs.get(query); return sjr != null && sjr.isRunning; } @@ -253,9 +253,9 @@ public class InternalSearchUI { } private void doShutdown() { - Iterator jobRecs= fSearchJobs.values().iterator(); + Iterator<SearchJobRecord> jobRecs= fSearchJobs.values().iterator(); while (jobRecs.hasNext()) { - SearchJobRecord element= (SearchJobRecord) jobRecs.next(); + SearchJobRecord element= jobRecs.next(); if (element.job != null) element.job.cancel(); } @@ -266,7 +266,7 @@ public class InternalSearchUI { } public void cancelSearch(ISearchQuery job) { - SearchJobRecord rec= (SearchJobRecord) fSearchJobs.get(job); + SearchJobRecord rec= fSearchJobs.get(job); if (rec != null && rec.job != null) rec.job.cancel(); } @@ -332,8 +332,8 @@ public class InternalSearchUI { } public void removeAllQueries() { - for (Iterator queries= fSearchJobs.keySet().iterator(); queries.hasNext();) { - ISearchQuery query= (ISearchQuery) queries.next(); + for (Iterator<ISearchQuery> queries= fSearchJobs.keySet().iterator(); queries.hasNext();) { + ISearchQuery query= queries.next(); cancelSearch(query); } fSearchJobs.clear(); diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/MatchFilterAction.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/MatchFilterAction.java index 63c78167762..27978fe4b22 100644 --- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/MatchFilterAction.java +++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/MatchFilterAction.java @@ -41,7 +41,7 @@ public class MatchFilterAction extends Action implements IUpdate { if (input == null) { return; } - ArrayList newFilters= new ArrayList(); + ArrayList<MatchFilter> newFilters= new ArrayList<>(); MatchFilter[] activeMatchFilters= input.getActiveMatchFilters(); if (activeMatchFilters == null) { return; @@ -56,7 +56,7 @@ public class MatchFilterAction extends Action implements IUpdate { if (newState) { newFilters.add(fFilter); } - input.setActiveMatchFilters((MatchFilter[]) newFilters.toArray(new MatchFilter[newFilters.size()])); + input.setActiveMatchFilters(newFilters.toArray(new MatchFilter[newFilters.size()])); } public MatchFilter getFilter() { diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/QueryManager.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/QueryManager.java index 673e1f94ea1..1bed6493e09 100644 --- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/QueryManager.java +++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/QueryManager.java @@ -21,14 +21,14 @@ import org.eclipse.search.ui.IQueryListener; import org.eclipse.search.ui.ISearchQuery; class QueryManager { - private List fQueries; - private List fListeners; + private List<ISearchQuery> fQueries; + private List<IQueryListener> fListeners; public QueryManager() { super(); // an ArrayList should be plenty fast enough (few searches). - fListeners= new ArrayList(); - fQueries= new LinkedList(); + fListeners= new ArrayList<>(); + fQueries= new LinkedList<>(); } public boolean hasQueries() { @@ -50,7 +50,7 @@ class QueryManager { */ public ISearchQuery[] getQueries() { synchronized (this) { - return (ISearchQuery[]) fQueries.toArray(new ISearchQuery[fQueries.size()]); + return fQueries.toArray(new ISearchQuery[fQueries.size()]); } } @@ -83,60 +83,60 @@ class QueryManager { } public void fireAdded(ISearchQuery query) { - Set copiedListeners= new HashSet(); + Set<IQueryListener> copiedListeners= new HashSet<>(); synchronized (fListeners) { copiedListeners.addAll(fListeners); } - Iterator listeners= copiedListeners.iterator(); + Iterator<IQueryListener> listeners= copiedListeners.iterator(); while (listeners.hasNext()) { - IQueryListener l= (IQueryListener) listeners.next(); + IQueryListener l= listeners.next(); l.queryAdded(query); } } public void fireRemoved(ISearchQuery query) { - Set copiedListeners= new HashSet(); + Set<IQueryListener> copiedListeners= new HashSet<>(); synchronized (fListeners) { copiedListeners.addAll(fListeners); } - Iterator listeners= copiedListeners.iterator(); + Iterator<IQueryListener> listeners= copiedListeners.iterator(); while (listeners.hasNext()) { - IQueryListener l= (IQueryListener) listeners.next(); + IQueryListener l= listeners.next(); l.queryRemoved(query); } } public void fireStarting(ISearchQuery query) { - Set copiedListeners= new HashSet(); + Set<IQueryListener> copiedListeners= new HashSet<>(); synchronized (fListeners) { copiedListeners.addAll(fListeners); } - Iterator listeners= copiedListeners.iterator(); + Iterator<IQueryListener> listeners= copiedListeners.iterator(); while (listeners.hasNext()) { - IQueryListener l= (IQueryListener) listeners.next(); + IQueryListener l= listeners.next(); l.queryStarting(query); } } public void fireFinished(ISearchQuery query) { - Set copiedListeners= new HashSet(); + Set<IQueryListener> copiedListeners= new HashSet<>(); synchronized (fListeners) { copiedListeners.addAll(fListeners); } - Iterator listeners= copiedListeners.iterator(); + Iterator<IQueryListener> listeners= copiedListeners.iterator(); while (listeners.hasNext()) { - IQueryListener l= (IQueryListener) listeners.next(); + IQueryListener l= listeners.next(); l.queryFinished(query); } } public void removeAll() { synchronized (this) { - List old= fQueries; - fQueries= new LinkedList(); - Iterator iter= old.iterator(); + List<ISearchQuery> old= fQueries; + fQueries= new LinkedList<>(); + Iterator<ISearchQuery> iter= old.iterator(); while (iter.hasNext()) { - ISearchQuery element= (ISearchQuery) iter.next(); + ISearchQuery element= iter.next(); fireRemoved(element); } } diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchHistoryDropDownAction.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchHistoryDropDownAction.java index 7b695e09266..45924a447ff 100644 --- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchHistoryDropDownAction.java +++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchHistoryDropDownAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -38,7 +38,7 @@ class SearchHistoryDropDownAction extends Action implements IMenuCreator { String label= escapeAmp(search.getLabel()); if (InternalSearchUI.getInstance().isQueryRunning(search.getQuery())) - label= MessageFormat.format(SearchMessages.SearchDropDownAction_running_message, new String[] { label }); + label= MessageFormat.format(SearchMessages.SearchDropDownAction_running_message, new Object[] { label }); // fix for bug 38049 if (label.indexOf('@') >= 0) label+= '@'; diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchHistorySelectionDialog.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchHistorySelectionDialog.java index aa6a69aadbc..9d7e59cd4b9 100644 --- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchHistorySelectionDialog.java +++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchHistorySelectionDialog.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -67,8 +67,8 @@ public class SearchHistorySelectionDialog extends SelectionDialog { private static final int REMOVE_ID= IDialogConstants.CLIENT_ID+1; private static final int WIDTH_IN_CHARACTERS= 55; - private List fInput; - private final List fRemovedEntries; + private List<ISearchResult> fInput; + private final List<ISearchResult> fRemovedEntries; private TableViewer fViewer; private Button fRemoveButton; @@ -82,10 +82,10 @@ public class SearchHistorySelectionDialog extends SelectionDialog { private int fHistorySize; private Text fHistorySizeTextField; - private final List fCurrentList; - private final List fCurrentRemoves; + private final List<ISearchResult> fCurrentList; + private final List<ISearchResult> fCurrentRemoves; - public HistoryConfigurationDialog(Shell parent, List currentList, List removedEntries) { + public HistoryConfigurationDialog(Shell parent, List<ISearchResult> currentList, List<ISearchResult> removedEntries) { super(parent); fCurrentList= currentList; fCurrentRemoves= removedEntries; @@ -186,7 +186,7 @@ public class SearchHistorySelectionDialog extends SelectionDialog { private static final class SearchesLabelProvider extends LabelProvider { - private ArrayList fImages= new ArrayList(); + private ArrayList<Image> fImages= new ArrayList<>(); @Override public String getText(Object element) { @@ -208,20 +208,20 @@ public class SearchHistorySelectionDialog extends SelectionDialog { @Override public void dispose() { - Iterator iter= fImages.iterator(); + Iterator<Image> iter= fImages.iterator(); while (iter.hasNext()) - ((Image)iter.next()).dispose(); + iter.next().dispose(); fImages= null; } } - public SearchHistorySelectionDialog(Shell parent, List input) { + public SearchHistorySelectionDialog(Shell parent, List<ISearchResult> input) { super(parent); setTitle(SearchMessages.SearchesDialog_title); setMessage(SearchMessages.SearchesDialog_message); fInput= input; - fRemovedEntries= new ArrayList(); + fRemovedEntries= new ArrayList<>(); setHelpAvailable(false); } @@ -273,7 +273,7 @@ public class SearchHistorySelectionDialog extends SelectionDialog { public void create() { super.create(); - List initialSelection= getInitialElementSelections(); + List<?> initialSelection= getInitialElementSelections(); if (initialSelection != null) fViewer.setSelection(new StructuredSelection(initialSelection)); @@ -388,9 +388,9 @@ public class SearchHistorySelectionDialog extends SelectionDialog { protected void buttonPressed(int buttonId) { if (buttonId == REMOVE_ID) { IStructuredSelection selection= (IStructuredSelection) fViewer.getSelection(); - Iterator searchResults= selection.iterator(); + Iterator<?> searchResults= selection.iterator(); while (searchResults.hasNext()) { - Object curr= searchResults.next(); + ISearchResult curr= (ISearchResult) searchResults.next(); fRemovedEntries.add(curr); fInput.remove(curr); fViewer.remove(curr); @@ -418,8 +418,8 @@ public class SearchHistorySelectionDialog extends SelectionDialog { setResult(((IStructuredSelection) fViewer.getSelection()).toList()); // remove queries - for (Iterator iter= fRemovedEntries.iterator(); iter.hasNext();) { - ISearchResult result= (ISearchResult) iter.next(); + for (Iterator<ISearchResult> iter= fRemovedEntries.iterator(); iter.hasNext();) { + ISearchResult result= iter.next(); ISearchQuery query= result.getQuery(); if (query != null) { // must not be null: invalid implementation of a search query InternalSearchUI.getInstance().removeQuery(query); diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchPageRegistry.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchPageRegistry.java index 821322c02a9..0eb8fc7c25b 100644 --- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchPageRegistry.java +++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchPageRegistry.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -35,13 +35,13 @@ public class SearchPageRegistry { public static final String ATTRIB_HELP_CONTEXT= "helpContextId"; //$NON-NLS-1$ - private final Map fResultClassNameToExtension; - private final Map fExtensionToInstance; + private final Map<String, IConfigurationElement> fResultClassNameToExtension; + private final Map<IConfigurationElement, ISearchResultPage> fExtensionToInstance; private final IConfigurationElement[] fExtensions; public SearchPageRegistry() { - fExtensionToInstance= new HashMap(); - fResultClassNameToExtension= new HashMap(); + fExtensionToInstance= new HashMap<>(); + fResultClassNameToExtension= new HashMap<>(); fExtensions= Platform.getExtensionRegistry().getConfigurationElementsFor(ID_EXTENSION_POINT); for (int i= 0; i < fExtensions.length; i++) { fResultClassNameToExtension.put(fExtensions[i].getAttribute(ATTRIB_SEARCH_RESULT_CLASS), fExtensions[i]); @@ -49,7 +49,7 @@ public class SearchPageRegistry { } public ISearchResultPage findPageForSearchResult(ISearchResult result, boolean create) { - Class resultClass= result.getClass(); + Class<? extends ISearchResult> resultClass= result.getClass(); IConfigurationElement configElement= findConfigurationElement(resultClass); if (configElement != null) { return getSearchResultPage(configElement, create); @@ -82,7 +82,7 @@ public class SearchPageRegistry { } private ISearchResultPage getSearchResultPage(final IConfigurationElement configElement, boolean create) { - ISearchResultPage instance= (ISearchResultPage) fExtensionToInstance.get(configElement); + ISearchResultPage instance= fExtensionToInstance.get(configElement); if (instance == null && create) { final Object[] result= new Object[1]; @@ -117,13 +117,13 @@ public class SearchPageRegistry { return null; } - private IConfigurationElement findConfigurationElement(Class resultClass) { + private IConfigurationElement findConfigurationElement(Class<?> resultClass) { String className= resultClass.getName(); - IConfigurationElement configElement= (IConfigurationElement) fResultClassNameToExtension.get(className); + IConfigurationElement configElement= fResultClassNameToExtension.get(className); if (configElement != null) { return configElement; } - Class superclass= resultClass.getSuperclass(); + Class<?> superclass= resultClass.getSuperclass(); if (superclass != null) { IConfigurationElement foundExtension= findConfigurationElement(superclass); if (foundExtension != null) { @@ -132,7 +132,7 @@ public class SearchPageRegistry { } } - Class[] interfaces= resultClass.getInterfaces(); + Class<?>[] interfaces= resultClass.getInterfaces(); for (int i= 0; i < interfaces.length; i++) { IConfigurationElement foundExtension= findConfigurationElement(interfaces[i]); if (foundExtension != null) { diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchView.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchView.java index 51ac161063f..2d4bd7fbc0f 100644 --- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchView.java +++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchView.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2014 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -15,7 +15,7 @@ package org.eclipse.search2.internal.ui; import java.util.HashMap; import java.util.Iterator; -import java.util.Map; +import java.util.Map.Entry; import com.ibm.icu.text.MessageFormat; @@ -91,9 +91,9 @@ public class SearchView extends PageBookView implements ISearchResultViewPart, I private static final String MEMENTO_KEY_IS_PINNED= "isPinned"; //$NON-NLS-1$ private static final String MEMENTO_KEY_LAST_ACTIVATION= "org.eclipse.search.lastActivation"; //$NON-NLS-1$ private static final String MEMENTO_KEY_RESTORE= "org.eclipse.search.restore"; //$NON-NLS-1$ - private HashMap fPartsToPages; - private HashMap fPagesToParts; - private HashMap fSearchViewStates; + private HashMap<DummyPart, IPageBookViewPage> fPartsToPages; + private HashMap<ISearchResultPage, DummyPart> fPagesToParts; + private HashMap<ISearchResult, Object> fSearchViewStates; private SearchPageRegistry fSearchViewPageService; private SearchHistoryDropDownAction fSearchesDropDownAction; private ISearchResult fCurrentSearch; @@ -216,7 +216,7 @@ public class SearchView extends PageBookView implements ISearchResultViewPart, I @Override public void setFocus() {/*dummy*/} @Override - public Object getAdapter(Class adapter) { return null; } + public <T> T getAdapter(Class<T> adapter) { return null; } } static class EmptySearchView extends Page implements ISearchResultPage { @@ -312,10 +312,10 @@ public class SearchView extends PageBookView implements ISearchResultViewPart, I public SearchView() { super(); - fPartsToPages= new HashMap(); - fPagesToParts= new HashMap(); + fPartsToPages= new HashMap<>(); + fPagesToParts= new HashMap<>(); fSearchViewPageService= new SearchPageRegistry(); - fSearchViewStates= new HashMap(); + fSearchViewStates= new HashMap<>(); fIsPinned= false; } @@ -337,7 +337,7 @@ public class SearchView extends PageBookView implements ISearchResultViewPart, I @Override protected IPage createDefaultPage(PageBook book) { - IPageBookViewPage page= new EmptySearchView(); + ISearchResultPage page= new EmptySearchView(); page.createControl(book); initPage(page); DummyPart part= new DummyPart(getSite()); @@ -349,7 +349,7 @@ public class SearchView extends PageBookView implements ISearchResultViewPart, I @Override protected PageRec doCreatePage(IWorkbenchPart part) { - IPageBookViewPage page = (IPageBookViewPage) fPartsToPages.get(part); + IPageBookViewPage page = fPartsToPages.get(part); initPage(page); page.createControl(getPageBook()); PageRec rec = new PageRec(part, page); @@ -409,7 +409,7 @@ public class SearchView extends PageBookView implements ISearchResultViewPart, I if (page != null) { if (page != currentPage) { - DummyPart part= (DummyPart) fPagesToParts.get(page); + DummyPart part= fPagesToParts.get(page); if (part == null) { part= new DummyPart(getSite()); fPagesToParts.put(page, part); @@ -657,7 +657,7 @@ public class SearchView extends PageBookView implements ISearchResultViewPart, I if (result != null) { menuManager.appendToGroup(IContextMenuConstants.GROUP_SEARCH, fSearchAgainAction); // first check if we have a selection for the show in mechanism, bugzilla 127718 - IShowInSource showInSource= (IShowInSource) getAdapter(IShowInSource.class); + IShowInSource showInSource= getAdapter(IShowInSource.class); if (showInSource != null) { ShowInContext context= showInSource.getShowInContext(); if (context != null) { @@ -690,10 +690,10 @@ public class SearchView extends PageBookView implements ISearchResultViewPart, I @Override public void saveState(IMemento memento) { - for (Iterator iter= fPagesToParts.entrySet().iterator(); iter.hasNext();) { - Map.Entry entry= (Map.Entry) iter.next(); - ISearchResultPage page= (ISearchResultPage) entry.getKey(); - DummyPart part= (DummyPart) entry.getValue(); + for (Iterator<Entry<ISearchResultPage, DummyPart>> iter= fPagesToParts.entrySet().iterator(); iter.hasNext();) { + Entry<ISearchResultPage, DummyPart> entry= iter.next(); + ISearchResultPage page= entry.getKey(); + DummyPart part= entry.getValue(); IMemento child= memento.createChild(MEMENTO_TYPE, page.getID()); page.saveState(child); @@ -778,13 +778,14 @@ public class SearchView extends PageBookView implements ISearchResultViewPart, I getProgressService().warnOfContentChange(); } + @SuppressWarnings("unchecked") @Override - public Object getAdapter(Class adapter) { + public <T> T getAdapter(Class<T> adapter) { Object superAdapter= super.getAdapter(adapter); if (superAdapter != null) - return superAdapter; + return (T) superAdapter; if (adapter == IShowInSource.class) { - return new IShowInSource() { + return (T) new IShowInSource() { @Override public ShowInContext getShowInContext() { return new ShowInContext(null, getSelectionProvider().getSelection()); diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchViewManager.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchViewManager.java index e4d1e7f3b3a..0d0f7d3eab7 100644 --- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchViewManager.java +++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/SearchViewManager.java @@ -38,7 +38,7 @@ public class SearchViewManager { private IQueryListener fNewQueryListener; private int fViewCount= 0; - private LinkedList fLRUSearchViews; + private LinkedList<SearchView> fLRUSearchViews; public SearchViewManager(QueryManager queryManager) { @@ -60,7 +60,7 @@ public class SearchViewManager { queryManager.addQueryListener(fNewQueryListener); - fLRUSearchViews= new LinkedList(); + fLRUSearchViews= new LinkedList<>(); } @@ -71,7 +71,7 @@ public class SearchViewManager { protected boolean showNewSearchQuery(ISearchQuery query) { if (!fLRUSearchViews.isEmpty()) { - SearchView view= (SearchView) fLRUSearchViews.getFirst(); + SearchView view= fLRUSearchViews.getFirst(); view.showSearchResult(query.getSearchResult()); return true; } @@ -120,8 +120,8 @@ public class SearchViewManager { } public boolean isShown(ISearchQuery query) { - for (Iterator iter= fLRUSearchViews.iterator(); iter.hasNext();) { - SearchView view= (SearchView) iter.next(); + for (Iterator<SearchView> iter= fLRUSearchViews.iterator(); iter.hasNext();) { + SearchView view= iter.next(); ISearchResult currentSearchResult= view.getCurrentSearchResult(); if (currentSearchResult != null && query == currentSearchResult.getQuery()) { return true; @@ -142,8 +142,8 @@ public class SearchViewManager { private ISearchResultViewPart findLRUSearchResultView(IWorkbenchPage page, boolean avoidPinnedViews) { boolean viewFoundInPage= false; - for (Iterator iter= fLRUSearchViews.iterator(); iter.hasNext();) { - SearchView view= (SearchView) iter.next(); + for (Iterator<SearchView> iter= fLRUSearchViews.iterator(); iter.hasNext();) { + SearchView view= iter.next(); if (page.equals(view.getSite().getPage())) { if (!avoidPinnedViews || !view.isPinned()) { return view; diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/ShowSearchHistoryDialogAction.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/ShowSearchHistoryDialogAction.java index ca3d107fd62..bfee6fcfb19 100644 --- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/ShowSearchHistoryDialogAction.java +++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/ShowSearchHistoryDialogAction.java @@ -43,7 +43,7 @@ class ShowSearchHistoryDialogAction extends Action { public void run() { ISearchQuery[] queries= NewSearchUI.getQueries(); - ArrayList input= new ArrayList(); + ArrayList<ISearchResult> input= new ArrayList<>(); for (int j= 0; j < queries.length; j++) { ISearchResult search= queries[j].getSearchResult(); input.add(search); diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/AnnotationHighlighter.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/AnnotationHighlighter.java index 278661bc74a..954c1abc7c5 100644 --- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/AnnotationHighlighter.java +++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/AnnotationHighlighter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -41,17 +41,17 @@ import org.eclipse.search2.internal.ui.SearchMessages; public class AnnotationHighlighter extends Highlighter { private IAnnotationModel fModel; private IDocument fDocument; - private Map fMatchesToAnnotations; + private Map<Match, Annotation> fMatchesToAnnotations; public AnnotationHighlighter(IAnnotationModel model, IDocument document) { fModel= model; fDocument= document; - fMatchesToAnnotations= new HashMap(); + fMatchesToAnnotations= new HashMap<>(); } @Override public void addHighlights(Match[] matches) { - HashMap map= new HashMap(matches.length); + HashMap<Annotation, Position> map= new HashMap<>(matches.length); for (int i= 0; i < matches.length; i++) { int offset= matches[i].getOffset(); int length= matches[i].getLength(); @@ -95,9 +95,9 @@ public class AnnotationHighlighter extends Highlighter { @Override public void removeHighlights(Match[] matches) { - HashSet annotations= new HashSet(matches.length); + HashSet<Annotation> annotations= new HashSet<>(matches.length); for (int i= 0; i < matches.length; i++) { - Annotation annotation= (Annotation) fMatchesToAnnotations.remove(matches[i]); + Annotation annotation= fMatchesToAnnotations.remove(matches[i]); if (annotation != null) { annotations.add(annotation); } @@ -107,19 +107,19 @@ public class AnnotationHighlighter extends Highlighter { @Override public void removeAll() { - Collection matchSet= fMatchesToAnnotations.values(); + Collection<Annotation> matchSet= fMatchesToAnnotations.values(); removeAnnotations(matchSet); fMatchesToAnnotations.clear(); } - private void addAnnotations(Map annotationToPositionMap) { + private void addAnnotations(Map<Annotation, Position> annotationToPositionMap) { if (fModel instanceof IAnnotationModelExtension) { IAnnotationModelExtension ame= (IAnnotationModelExtension) fModel; ame.replaceAnnotations(new Annotation[0], annotationToPositionMap); } else { - for (Iterator elements= annotationToPositionMap.keySet().iterator(); elements.hasNext();) { - Annotation element= (Annotation) elements.next(); - Position p= (Position) annotationToPositionMap.get(element); + for (Iterator<Annotation> elements= annotationToPositionMap.keySet().iterator(); elements.hasNext();) { + Annotation element= elements.next(); + Position p= annotationToPositionMap.get(element); fModel.addAnnotation(element, p); } } @@ -132,14 +132,14 @@ public class AnnotationHighlighter extends Highlighter { * @param annotations A set containing the annotations to be removed. * @see Annotation */ - private void removeAnnotations(Collection annotations) { + private void removeAnnotations(Collection<Annotation> annotations) { if (fModel instanceof IAnnotationModelExtension) { IAnnotationModelExtension ame= (IAnnotationModelExtension) fModel; Annotation[] annotationArray= new Annotation[annotations.size()]; - ame.replaceAnnotations((Annotation[]) annotations.toArray(annotationArray), Collections.EMPTY_MAP); + ame.replaceAnnotations(annotations.toArray(annotationArray), Collections.emptyMap()); } else { - for (Iterator iter= annotations.iterator(); iter.hasNext();) { - Annotation element= (Annotation) iter.next(); + for (Iterator<Annotation> iter= annotations.iterator(); iter.hasNext();) { + Annotation element= iter.next(); fModel.removeAnnotation(element); } } @@ -152,8 +152,8 @@ public class AnnotationHighlighter extends Highlighter { ITextFileBuffer textBuffer= (ITextFileBuffer) buffer; if (fDocument != null && fDocument.equals(textBuffer.getDocument())) { - Set allMatches= fMatchesToAnnotations.keySet(); - Match[] matchesCopy= (Match[]) allMatches.toArray(new Match[allMatches.size()]); + Set<Match> allMatches= fMatchesToAnnotations.keySet(); + Match[] matchesCopy= allMatches.toArray(new Match[allMatches.size()]); removeAll(); addHighlights(matchesCopy); } diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/AnnotationManagers.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/AnnotationManagers.java index 15f69f08e18..1dc966b461e 100644 --- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/AnnotationManagers.java +++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/AnnotationManagers.java @@ -21,7 +21,7 @@ import org.eclipse.search.ui.text.AbstractTextSearchResult; public class AnnotationManagers { static { - fgManagerMap = new HashMap(); + fgManagerMap = new HashMap<>(); IWindowListener listener = new IWindowListener() { @Override public void windowActivated(IWorkbenchWindow window) { @@ -46,11 +46,11 @@ public class AnnotationManagers { PlatformUI.getWorkbench().addWindowListener(listener); } - private static HashMap fgManagerMap; + private static HashMap<IWorkbenchWindow, WindowAnnotationManager> fgManagerMap; private static void disposeAnnotationManager(IWorkbenchWindow window) { - WindowAnnotationManager mgr = (WindowAnnotationManager) fgManagerMap.remove(window); + WindowAnnotationManager mgr = fgManagerMap.remove(window); if (mgr != null) mgr.dispose(); } @@ -64,7 +64,7 @@ public class AnnotationManagers { } private static WindowAnnotationManager getWindowAnnotationManager(IWorkbenchWindow window) { - WindowAnnotationManager mgr= (WindowAnnotationManager) fgManagerMap.get(window); + WindowAnnotationManager mgr= fgManagerMap.get(window); if (mgr == null) { mgr= new WindowAnnotationManager(window); fgManagerMap.put(window, mgr); diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/EditorAccessHighlighter.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/EditorAccessHighlighter.java index 7312e2308ec..a2c665c87e9 100644 --- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/EditorAccessHighlighter.java +++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/EditorAccessHighlighter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -40,16 +40,16 @@ import org.eclipse.search2.internal.ui.SearchMessages; public class EditorAccessHighlighter extends Highlighter { private ISearchEditorAccess fEditorAcess; - private Map fMatchesToAnnotations; + private Map<Match, Annotation> fMatchesToAnnotations; public EditorAccessHighlighter(ISearchEditorAccess editorAccess) { fEditorAcess= editorAccess; - fMatchesToAnnotations= new HashMap(); + fMatchesToAnnotations= new HashMap<>(); } @Override public void addHighlights(Match[] matches) { - Map mapsByAnnotationModel= new HashMap(); + Map<IAnnotationModel, HashMap<Annotation, Position>> mapsByAnnotationModel= new HashMap<>(); for (int i= 0; i < matches.length; i++) { int offset= matches[i].getOffset(); int length= matches[i].getLength(); @@ -57,7 +57,7 @@ public class EditorAccessHighlighter extends Highlighter { try { Position position= createPosition(matches[i]); if (position != null) { - Map map= getMap(mapsByAnnotationModel, matches[i]); + Map<Annotation, Position> map= getMap(mapsByAnnotationModel, matches[i]); if (map != null) { Annotation annotation= matches[i].isFiltered() ? new Annotation(SearchPlugin.FILTERED_SEARCH_ANNOTATION_TYPE, true, null) @@ -71,9 +71,9 @@ public class EditorAccessHighlighter extends Highlighter { } } } - for (Iterator maps= mapsByAnnotationModel.keySet().iterator(); maps.hasNext();) { - IAnnotationModel model= (IAnnotationModel) maps.next(); - Map positionMap= (Map) mapsByAnnotationModel.get(model); + for (Iterator<IAnnotationModel> maps= mapsByAnnotationModel.keySet().iterator(); maps.hasNext();) { + IAnnotationModel model= maps.next(); + Map<Annotation, Position> positionMap= mapsByAnnotationModel.get(model); addAnnotations(model, positionMap); } @@ -98,25 +98,25 @@ public class EditorAccessHighlighter extends Highlighter { return position; } - private Map getMap(Map mapsByAnnotationModel, Match match) { + private Map<Annotation, Position> getMap(Map<IAnnotationModel, HashMap<Annotation, Position>> mapsByAnnotationModel, Match match) { IAnnotationModel model= fEditorAcess.getAnnotationModel(match); if (model == null) return null; - HashMap map= (HashMap) mapsByAnnotationModel.get(model); + HashMap<Annotation, Position> map= mapsByAnnotationModel.get(model); if (map == null) { - map= new HashMap(); + map= new HashMap<>(); mapsByAnnotationModel.put(model, map); } return map; } - private Set getSet(Map setsByAnnotationModel, Match match) { + private Set<Annotation> getSet(Map<IAnnotationModel, HashSet<Annotation>> setsByAnnotationModel, Match match) { IAnnotationModel model= fEditorAcess.getAnnotationModel(match); if (model == null) return null; - HashSet set= (HashSet) setsByAnnotationModel.get(model); + HashSet<Annotation> set= setsByAnnotationModel.get(model); if (set == null) { - set= new HashSet(); + set= new HashSet<>(); setsByAnnotationModel.put(model, set); } return set; @@ -124,32 +124,32 @@ public class EditorAccessHighlighter extends Highlighter { @Override public void removeHighlights(Match[] matches) { - Map setsByAnnotationModel= new HashMap(); + Map<IAnnotationModel, HashSet<Annotation>> setsByAnnotationModel= new HashMap<>(); for (int i= 0; i < matches.length; i++) { - Annotation annotation= (Annotation) fMatchesToAnnotations.remove(matches[i]); + Annotation annotation= fMatchesToAnnotations.remove(matches[i]); if (annotation != null) { - Set annotations= getSet(setsByAnnotationModel, matches[i]); + Set<Annotation> annotations= getSet(setsByAnnotationModel, matches[i]); if (annotations != null) annotations.add(annotation); } } - for (Iterator maps= setsByAnnotationModel.keySet().iterator(); maps.hasNext();) { - IAnnotationModel model= (IAnnotationModel) maps.next(); - Set set= (Set) setsByAnnotationModel.get(model); + for (Iterator<IAnnotationModel> maps= setsByAnnotationModel.keySet().iterator(); maps.hasNext();) { + IAnnotationModel model= maps.next(); + Set<Annotation> set= setsByAnnotationModel.get(model); removeAnnotations(model, set); } } - private void addAnnotations(IAnnotationModel model, Map annotationToPositionMap) { + private void addAnnotations(IAnnotationModel model, Map<Annotation, Position> annotationToPositionMap) { if (model instanceof IAnnotationModelExtension) { IAnnotationModelExtension ame= (IAnnotationModelExtension) model; ame.replaceAnnotations(new Annotation[0], annotationToPositionMap); } else { - for (Iterator elements= annotationToPositionMap.keySet().iterator(); elements.hasNext();) { - Annotation element= (Annotation) elements.next(); - Position p= (Position) annotationToPositionMap.get(element); + for (Iterator<Annotation> elements= annotationToPositionMap.keySet().iterator(); elements.hasNext();) { + Annotation element= elements.next(); + Position p= annotationToPositionMap.get(element); model.addAnnotation(element, p); } } @@ -162,14 +162,14 @@ public class EditorAccessHighlighter extends Highlighter { * @param annotations A set containing the annotations to be removed. * @see Annotation */ - private void removeAnnotations(IAnnotationModel model, Set annotations) { + private void removeAnnotations(IAnnotationModel model, Set<Annotation> annotations) { if (model instanceof IAnnotationModelExtension) { IAnnotationModelExtension ame= (IAnnotationModelExtension) model; Annotation[] annotationArray= new Annotation[annotations.size()]; - ame.replaceAnnotations((Annotation[]) annotations.toArray(annotationArray), Collections.EMPTY_MAP); + ame.replaceAnnotations(annotations.toArray(annotationArray), Collections.emptyMap()); } else { - for (Iterator iter= annotations.iterator(); iter.hasNext();) { - Annotation element= (Annotation) iter.next(); + for (Iterator<Annotation> iter= annotations.iterator(); iter.hasNext();) { + Annotation element= iter.next(); model.removeAnnotation(element); } } @@ -177,9 +177,9 @@ public class EditorAccessHighlighter extends Highlighter { @Override public void removeAll() { - Set matchSet= fMatchesToAnnotations.keySet(); + Set<Match> matchSet= fMatchesToAnnotations.keySet(); Match[] matches= new Match[matchSet.size()]; - removeHighlights((Match[]) matchSet.toArray(matches)); + removeHighlights(matchSet.toArray(matches)); } @Override @@ -188,8 +188,8 @@ public class EditorAccessHighlighter extends Highlighter { return; IDocument document= null; ITextFileBuffer textBuffer= (ITextFileBuffer) buffer; - for (Iterator matches = fMatchesToAnnotations.keySet().iterator(); matches.hasNext();) { - Match match = (Match) matches.next(); + for (Iterator<Match> matches = fMatchesToAnnotations.keySet().iterator(); matches.hasNext();) { + Match match = matches.next(); document= fEditorAcess.getDocument(match); if (document != null) break; diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/EditorAnnotationManager.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/EditorAnnotationManager.java index 00fa9f39323..30334152f93 100644 --- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/EditorAnnotationManager.java +++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/EditorAnnotationManager.java @@ -42,7 +42,7 @@ import org.eclipse.search.ui.text.RemoveAllEvent; public class EditorAnnotationManager implements ISearchResultListener { - private ArrayList fResults; + private ArrayList<AbstractTextSearchResult> fResults; private IEditorPart fEditor; private Highlighter fHighlighter; // initialized lazy @@ -57,7 +57,7 @@ public class EditorAnnotationManager implements ISearchResultListener { Assert.isNotNull(editorPart); fEditor= editorPart; fHighlighter= null; // lazy initialization - fResults= new ArrayList(3); + fResults= new ArrayList<>(3); } @@ -72,7 +72,7 @@ public class EditorAnnotationManager implements ISearchResultListener { fHighlighter.dispose(); for (int i= 0; i < fResults.size(); i++) { - ((AbstractTextSearchResult) fResults.get(i)).removeListener(this); + fResults.get(i).removeListener(this); } fResults.clear(); } @@ -86,20 +86,20 @@ public class EditorAnnotationManager implements ISearchResultListener { } for (int i= 0; i < fResults.size(); i++) { - AbstractTextSearchResult curr= (AbstractTextSearchResult) fResults.get(i); + AbstractTextSearchResult curr= fResults.get(i); addAnnotations(curr); } } - public synchronized void setSearchResults(List results) { + public synchronized void setSearchResults(List<AbstractTextSearchResult> results) { removeAllAnnotations(); for (int i= 0; i < fResults.size(); i++) { - ((AbstractTextSearchResult) fResults.get(i)).removeListener(this); + fResults.get(i).removeListener(this); } fResults.clear(); for (int i= 0; i < results.size(); i++) { - addSearchResult((AbstractTextSearchResult) results.get(i)); + addSearchResult(results.get(i)); } } @@ -154,18 +154,18 @@ public class EditorAnnotationManager implements ISearchResultListener { return adapter.isShownInEditor(matches[0], fEditor) ? matches : null; } - ArrayList matchesInEditor= null; // lazy initialization + ArrayList<Match> matchesInEditor= null; // lazy initialization for (int i= 0; i < matches.length; i++) { Match curr= matches[i]; if (adapter.isShownInEditor(curr, fEditor)) { if (matchesInEditor == null) { - matchesInEditor= new ArrayList(); + matchesInEditor= new ArrayList<>(); } matchesInEditor.add(curr); } } if (matchesInEditor != null) { - return (Match[]) matchesInEditor.toArray(new Match[matchesInEditor.size()]); + return matchesInEditor.toArray(new Match[matchesInEditor.size()]); } return null; } @@ -230,7 +230,7 @@ public class EditorAnnotationManager implements ISearchResultListener { removeAllAnnotations(); for (int i= 0; i < fResults.size(); i++) { - AbstractTextSearchResult curr= (AbstractTextSearchResult) fResults.get(i); + AbstractTextSearchResult curr= fResults.get(i); if (curr != result) { addAnnotations(curr); } diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/MarkerHighlighter.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/MarkerHighlighter.java index e4b1e81d20a..fab4562db97 100644 --- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/MarkerHighlighter.java +++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/MarkerHighlighter.java @@ -34,11 +34,11 @@ import org.eclipse.search2.internal.ui.InternalSearchUI; public class MarkerHighlighter extends Highlighter { private IFile fFile; - private Map fMatchesToAnnotations; + private Map<Match, IMarker> fMatchesToAnnotations; public MarkerHighlighter(IFile file) { fFile= file; - fMatchesToAnnotations= new HashMap(); + fMatchesToAnnotations= new HashMap<>(); } @Override @@ -74,7 +74,7 @@ public class MarkerHighlighter extends Highlighter { IMarker marker= match.isFiltered() ? fFile.createMarker(SearchPlugin.FILTERED_SEARCH_MARKER) : fFile.createMarker(NewSearchUI.SEARCH_MARKER); - HashMap attributes= new HashMap(4); + HashMap<String, Integer> attributes= new HashMap<>(4); if (match.getBaseUnit() == Match.UNIT_CHARACTER) { attributes.put(IMarker.CHAR_START, new Integer(position.getOffset())); attributes.put(IMarker.CHAR_END, new Integer(position.getOffset()+position.getLength())); @@ -88,7 +88,7 @@ public class MarkerHighlighter extends Highlighter { @Override public void removeHighlights(Match[] matches) { for (int i= 0; i < matches.length; i++) { - IMarker marker= (IMarker) fMatchesToAnnotations.remove(matches[i]); + IMarker marker= fMatchesToAnnotations.remove(matches[i]); if (marker != null) { try { marker.delete(); diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/PositionTracker.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/PositionTracker.java index 3a28913fcf4..b5ed04173a9 100644 --- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/PositionTracker.java +++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/PositionTracker.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2011 IBM Corporation and others. + * Copyright (c) 2000, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -48,9 +48,9 @@ import org.eclipse.search.ui.text.RemoveAllEvent; public class PositionTracker implements IQueryListener, ISearchResultListener, IFileBufferListener { - private Map fMatchesToPositions= new HashMap(); - private Map fMatchesToSearchResults= new HashMap(); - private Map fFileBuffersToMatches= new HashMap(); + private Map<Match, Position> fMatchesToPositions= new HashMap<>(); + private Map<Match, AbstractTextSearchResult> fMatchesToSearchResults= new HashMap<>(); + private Map<ITextFileBuffer, Set<Match>> fFileBuffersToMatches= new HashMap<>(); private interface IFileBufferMatchOperation { void run(ITextFileBuffer buffer, Match match); @@ -108,10 +108,10 @@ public class PositionTracker implements IQueryListener, ISearchResultListener, I } private void untrackAll(AbstractTextSearchResult result) { - Set matchSet= new HashSet(fMatchesToPositions.keySet()); - for (Iterator matches= matchSet.iterator(); matches.hasNext();) { - Match match= (Match) matches.next(); - AbstractTextSearchResult matchContainer= (AbstractTextSearchResult) fMatchesToSearchResults.get(match); + Set<Match> matchSet= new HashSet<>(fMatchesToPositions.keySet()); + for (Iterator<Match> matches= matchSet.iterator(); matches.hasNext();) { + Match match= matches.next(); + AbstractTextSearchResult matchContainer= fMatchesToSearchResults.get(match); if (result.equals(matchContainer)) { ITextFileBuffer fb= getTrackedFileBuffer(result, match.getElement()); if (fb != null) { @@ -122,7 +122,7 @@ public class PositionTracker implements IQueryListener, ISearchResultListener, I } private void untrackPosition(ITextFileBuffer fb, Match match) { - Position position= (Position) fMatchesToPositions.get(match); + Position position= fMatchesToPositions.get(match); if (position != null) { removeFileBufferMapping(fb, match); fMatchesToSearchResults.remove(match); @@ -168,16 +168,16 @@ public class PositionTracker implements IQueryListener, ISearchResultListener, I } private void addFileBufferMapping(ITextFileBuffer fb, Match match) { - Set matches= (Set) fFileBuffersToMatches.get(fb); + Set<Match> matches= fFileBuffersToMatches.get(fb); if (matches == null) { - matches= new HashSet(); + matches= new HashSet<>(); fFileBuffersToMatches.put(fb, matches); } matches.add(match); } private void removeFileBufferMapping(ITextFileBuffer fb, Match match) { - Set matches= (Set) fFileBuffersToMatches.get(fb); + Set<Match> matches= fFileBuffersToMatches.get(fb); if (matches != null) { matches.remove(match); if (matches.size() == 0) @@ -198,10 +198,10 @@ public class PositionTracker implements IQueryListener, ISearchResultListener, I } public Position getCurrentPosition(Match match) { - Position pos= (Position)fMatchesToPositions.get(match); + Position pos= fMatchesToPositions.get(match); if (pos == null) return pos; - AbstractTextSearchResult result= (AbstractTextSearchResult) fMatchesToSearchResults.get(match); + AbstractTextSearchResult result= fMatchesToSearchResults.get(match); if (match.getBaseUnit() == Match.UNIT_LINE && result != null) { ITextFileBuffer fb= getTrackedFileBuffer(result, match.getElement()); if (fb != null) { @@ -268,11 +268,11 @@ public class PositionTracker implements IQueryListener, ISearchResultListener, I private void doForExistingMatchesIn(IFileBuffer buffer, IFileBufferMatchOperation operation) { if (!(buffer instanceof ITextFileBuffer)) return; - Set matches= (Set) fFileBuffersToMatches.get(buffer); + Set<Match> matches= fFileBuffersToMatches.get(buffer); if (matches != null) { - Set matchSet= new HashSet(matches); - for (Iterator matchIterator= matchSet.iterator(); matchIterator.hasNext();) { - Match element= (Match) matchIterator.next(); + Set<Match> matchSet= new HashSet<>(matches); + for (Iterator<Match> matchIterator= matchSet.iterator(); matchIterator.hasNext();) { + Match element= matchIterator.next(); operation.run((ITextFileBuffer) buffer, element); } } @@ -303,7 +303,7 @@ public class PositionTracker implements IQueryListener, ISearchResultListener, I @Override public void run(ITextFileBuffer textBuffer, Match match) { trackCount[0]++; - AbstractTextSearchResult result= (AbstractTextSearchResult) fMatchesToSearchResults.get(match); + AbstractTextSearchResult result= fMatchesToSearchResults.get(match); untrackPosition(textBuffer, match); trackPosition(result, textBuffer, match); } @@ -324,10 +324,10 @@ public class PositionTracker implements IQueryListener, ISearchResultListener, I @Override public void run(ITextFileBuffer textBuffer, Match match) { trackCount[0]++; - Position pos= (Position) fMatchesToPositions.get(match); + Position pos= fMatchesToPositions.get(match); if (pos != null) { if (pos.isDeleted()) { - AbstractTextSearchResult result= (AbstractTextSearchResult) fMatchesToSearchResults.get(match); + AbstractTextSearchResult result= fMatchesToSearchResults.get(match); // might be that the containing element has been removed. if (result != null) { result.removeMatch(match); diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/WindowAnnotationManager.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/WindowAnnotationManager.java index a35c52d645e..65ff7f2cdc0 100644 --- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/WindowAnnotationManager.java +++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text/WindowAnnotationManager.java @@ -26,15 +26,15 @@ import org.eclipse.search.ui.text.AbstractTextSearchResult; public class WindowAnnotationManager { private IWorkbenchWindow fWindow; - private Map fAnnotationManagers; + private Map<IEditorPart, EditorAnnotationManager> fAnnotationManagers; private IPartListener2 fPartListener; - private ArrayList fSearchResults; + private ArrayList<AbstractTextSearchResult> fSearchResults; public WindowAnnotationManager(IWorkbenchWindow window) { fWindow = window; - fAnnotationManagers = new HashMap(); + fAnnotationManagers = new HashMap<>(); - fSearchResults= new ArrayList(); + fSearchResults= new ArrayList<>(); initEditors(); fPartListener= new IPartListener2() { @@ -83,7 +83,7 @@ public class WindowAnnotationManager { private void startHighlighting(IEditorPart editor) { if (editor == null) return; - EditorAnnotationManager mgr= (EditorAnnotationManager) fAnnotationManagers.get(editor); + EditorAnnotationManager mgr= fAnnotationManagers.get(editor); if (mgr == null) { mgr= new EditorAnnotationManager(editor); fAnnotationManagers.put(editor, mgr); @@ -94,7 +94,7 @@ public class WindowAnnotationManager { private void updateHighlighting(IEditorPart editor) { if (editor == null) return; - EditorAnnotationManager mgr= (EditorAnnotationManager) fAnnotationManagers.get(editor); + EditorAnnotationManager mgr= fAnnotationManagers.get(editor); if (mgr != null) { mgr.doEditorInputChanged(); } @@ -117,7 +117,7 @@ public class WindowAnnotationManager { private void stopHighlighting(IEditorPart editor) { if (editor == null) return; - EditorAnnotationManager mgr= (EditorAnnotationManager) fAnnotationManagers.remove(editor); + EditorAnnotationManager mgr= fAnnotationManagers.remove(editor); if (mgr != null) mgr.dispose(); } @@ -131,8 +131,8 @@ public class WindowAnnotationManager { void dispose() { fWindow.getPartService().removePartListener(fPartListener); - for (Iterator mgrs = fAnnotationManagers.values().iterator(); mgrs.hasNext();) { - EditorAnnotationManager mgr = (EditorAnnotationManager) mgrs.next(); + for (Iterator<EditorAnnotationManager> mgrs = fAnnotationManagers.values().iterator(); mgrs.hasNext();) { + EditorAnnotationManager mgr = mgrs.next(); mgr.dispose(); } fAnnotationManagers= null; @@ -142,8 +142,8 @@ public class WindowAnnotationManager { boolean alreadyShown= fSearchResults.contains(result); fSearchResults.add(result); if (!alreadyShown) { - for (Iterator mgrs = fAnnotationManagers.values().iterator(); mgrs.hasNext();) { - EditorAnnotationManager mgr = (EditorAnnotationManager) mgrs.next(); + for (Iterator<EditorAnnotationManager> mgrs = fAnnotationManagers.values().iterator(); mgrs.hasNext();) { + EditorAnnotationManager mgr = mgrs.next(); mgr.addSearchResult(result); } } @@ -153,8 +153,8 @@ public class WindowAnnotationManager { fSearchResults.remove(result); boolean stillShown= fSearchResults.contains(result); if (!stillShown) { - for (Iterator mgrs = fAnnotationManagers.values().iterator(); mgrs.hasNext();) { - EditorAnnotationManager mgr = (EditorAnnotationManager) mgrs.next(); + for (Iterator<EditorAnnotationManager> mgrs = fAnnotationManagers.values().iterator(); mgrs.hasNext();) { + EditorAnnotationManager mgr = mgrs.next(); mgr.removeSearchResult(result); } } diff --git a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text2/TextSearchQueryProviderRegistry.java b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text2/TextSearchQueryProviderRegistry.java index fe12c0aee1d..10f146c5aea 100644 --- a/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text2/TextSearchQueryProviderRegistry.java +++ b/org.eclipse.search/new search/org/eclipse/search2/internal/ui/text2/TextSearchQueryProviderRegistry.java @@ -91,7 +91,7 @@ public class TextSearchQueryProviderRegistry { } public String[][] getAvailableProviders() { - ArrayList res= new ArrayList(); + ArrayList<String[]> res= new ArrayList<>(); res.add(new String[] { SearchMessages.TextSearchQueryProviderRegistry_defaultProviderLabel, "" }); //$NON-NLS-1$ IConfigurationElement[] extensions= Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_POINT_ID); @@ -101,6 +101,6 @@ public class TextSearchQueryProviderRegistry { res.add(new String[] { engine.getAttribute(ATTRIB_LABEL), engine.getAttribute(ATTRIB_ID) }); } } - return (String[][]) res.toArray(new String[res.size()][]); + return res.toArray(new String[res.size()][]); } } |