diff options
author | Markus Keller | 2015-11-30 19:23:22 +0000 |
---|---|---|
committer | Markus Keller | 2015-12-01 12:59:16 +0000 |
commit | 96da92a20589d62dad534245c5d9c4d45618ee95 (patch) | |
tree | db7f27dc0839db136db463ad28a7e763a6a07a91 /org.eclipse.search | |
parent | 0bbe21e0e553957dd09eda0b29e8c77a98f38048 (diff) | |
download | eclipse.platform.text-96da92a20589d62dad534245c5d9c4d45618ee95.tar.gz eclipse.platform.text-96da92a20589d62dad534245c5d9c4d45618ee95.tar.xz eclipse.platform.text-96da92a20589d62dad534245c5d9c4d45618ee95.zip |
Bug 478673: generify codeI20151201-1100I20151201-0800
Diffstat (limited to 'org.eclipse.search')
57 files changed, 606 insertions, 611 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()][]); } } diff --git a/org.eclipse.search/search/org/eclipse/search/internal/core/text/FileNamePatternSearchScope.java b/org.eclipse.search/search/org/eclipse/search/internal/core/text/FileNamePatternSearchScope.java index dd01d712e76..f55b7e00e4f 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/core/text/FileNamePatternSearchScope.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/core/text/FileNamePatternSearchScope.java @@ -44,7 +44,7 @@ public class FileNamePatternSearchScope extends TextSearchScope { private final String fDescription; private final IResource[] fRootElements; - private final Set fFileNamePatterns; + private final Set<String> fFileNamePatterns; private Matcher fFileNameMatcher; private boolean fVisitDerived; @@ -53,7 +53,7 @@ public class FileNamePatternSearchScope extends TextSearchScope { Assert.isNotNull(description); fDescription= description; fRootElements= resources; - fFileNamePatterns= new HashSet(3); + fFileNamePatterns= new HashSet<>(3); fFileNameMatcher= null; fVisitDerived= visitDerived; } @@ -119,7 +119,7 @@ public class FileNamePatternSearchScope extends TextSearchScope { if (fFileNamePatterns.isEmpty()) { pattern= Pattern.compile(".*"); //$NON-NLS-1$ } else { - String[] patternStrings= (String[]) fFileNamePatterns.toArray(new String[fFileNamePatterns.size()]); + String[] patternStrings= fFileNamePatterns.toArray(new String[fFileNamePatterns.size()]); pattern= PatternConstructor.createPattern(patternStrings, IS_CASE_SENSITIVE_FILESYSTEM); } fFileNameMatcher= pattern.matcher(""); //$NON-NLS-1$ @@ -141,7 +141,7 @@ public class FileNamePatternSearchScope extends TextSearchScope { * @return the description of the scope */ public String getFileNamePatternDescription() { - String[] ext= (String[]) fFileNamePatterns.toArray(new String[fFileNamePatterns.size()]); + String[] ext= fFileNamePatterns.toArray(new String[fFileNamePatterns.size()]); Arrays.sort(ext); StringBuffer buf= new StringBuffer(); for (int i= 0; i < ext.length; i++) { @@ -155,21 +155,21 @@ public class FileNamePatternSearchScope 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 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/search/org/eclipse/search/internal/core/text/FilesOfScopeCalculator.java b/org.eclipse.search/search/org/eclipse/search/internal/core/text/FilesOfScopeCalculator.java index 4f9eea1a77f..b4b2ec1c7ac 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/core/text/FilesOfScopeCalculator.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/core/text/FilesOfScopeCalculator.java @@ -26,7 +26,7 @@ public class FilesOfScopeCalculator implements IResourceProxyVisitor { private final TextSearchScope fScope; private final MultiStatus fStatus; - private ArrayList fFiles; + private ArrayList<IResource> fFiles; public FilesOfScopeCalculator(TextSearchScope scope, MultiStatus status) { fScope= scope; @@ -44,7 +44,7 @@ public class FilesOfScopeCalculator implements IResourceProxyVisitor { } public IFile[] process() { - fFiles= new ArrayList(); + fFiles= new ArrayList<>(); try { IResource[] roots= fScope.getRoots(); for (int i= 0; i < roots.length; i++) { @@ -58,7 +58,7 @@ public class FilesOfScopeCalculator implements IResourceProxyVisitor { fStatus.add(ex.getStatus()); } } - return (IFile[]) fFiles.toArray(new IFile[fFiles.size()]); + return fFiles.toArray(new IFile[fFiles.size()]); } finally { fFiles= null; } diff --git a/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchEngineRegistry.java b/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchEngineRegistry.java index 82476a46060..20ab53caaf3 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchEngineRegistry.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchEngineRegistry.java @@ -100,7 +100,7 @@ public class TextSearchEngineRegistry { } public String[][] getAvailableEngines() { - ArrayList res= new ArrayList(); + ArrayList<String[]> res= new ArrayList<>(); res.add(new String[] { SearchMessages.TextSearchEngineRegistry_defaulttextsearch_label, "" }); //$NON-NLS-1$ IConfigurationElement[] extensions= Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_POINT_ID); @@ -110,6 +110,6 @@ public class TextSearchEngineRegistry { 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()][]); } } diff --git a/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchVisitor.java b/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchVisitor.java index b50496b8980..8942085da61 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchVisitor.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/core/text/TextSearchVisitor.java @@ -142,7 +142,7 @@ public class TextSearchVisitor { private final IFile[] fFiles; private final int fBegin; private final int fEnd; - private final Map fDocumentsInEditors; + private final Map<IFile, IDocument> fDocumentsInEditors; private ReusableMatchAccess fReusableMatchAccess; private IProgressMonitor fMonitor; @@ -154,7 +154,7 @@ public class TextSearchVisitor { * @param end one past the last element in the array to process * @param documentsInEditors a map from IFile to IDocument for all open, dirty editors */ - public TextSearchJob(IFile[] files, int begin, int end, Map documentsInEditors) { + public TextSearchJob(IFile[] files, int begin, int end, Map<IFile, IDocument> documentsInEditors) { super(files[begin].getName()); setSystem(true); fFiles = files; @@ -185,7 +185,7 @@ public class TextSearchVisitor { return fMonitor; } - public Map getDocumentsInEditors() { + public Map<IFile, IDocument> getDocumentsInEditors() { return fDocumentsInEditors; } @@ -281,7 +281,7 @@ public class TextSearchVisitor { monitorUpdateJob.schedule(); try { fCollector.beginReporting(); - Map documentsInEditors= PlatformUI.isWorkbenchRunning() ? evalNonFileBufferDocuments() : Collections.EMPTY_MAP; + Map<IFile, IDocument> documentsInEditors= PlatformUI.isWorkbenchRunning() ? evalNonFileBufferDocuments() : Collections.emptyMap(); int filesPerJob = (files.length + jobCount - 1) / jobCount; for (int first= 0; first < files.length; first += filesPerJob) { int end= Math.min(files.length, first + filesPerJob); @@ -324,8 +324,8 @@ public class TextSearchVisitor { * * @return a map from IFile to IDocument for all open, dirty editors */ - private Map evalNonFileBufferDocuments() { - Map result= new HashMap(); + private Map<IFile, IDocument> evalNonFileBufferDocuments() { + Map<IFile, IDocument> result= new HashMap<>(); IWorkbench workbench= SearchPlugin.getDefault().getWorkbench(); IWorkbenchWindow[] windows= workbench.getWorkbenchWindows(); for (int i= 0; i < windows.length; i++) { @@ -343,7 +343,7 @@ public class TextSearchVisitor { return result; } - private void evaluateTextEditor(Map result, IEditorPart ep) { + private void evaluateTextEditor(Map<IFile, IDocument> result, IEditorPart ep) { IEditorInput input= ep.getEditorInput(); if (input instanceof IFileEditorInput) { IFile file= ((IFileEditorInput) input).getFile(); @@ -497,8 +497,8 @@ public class TextSearchVisitor { return message; } - private IDocument getOpenDocument(IFile file, Map documentsInEditors) { - IDocument document= (IDocument)documentsInEditors.get(file); + private IDocument getOpenDocument(IFile file, Map<IFile, IDocument> documentsInEditors) { + IDocument document= documentsInEditors.get(file); if (document == null) { ITextFileBufferManager bufferManager= FileBuffers.getTextFileBufferManager(); ITextFileBuffer textFileBuffer= bufferManager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE); diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/CopyToClipboardAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/CopyToClipboardAction.java index 696ad75105d..31b56c3278a 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/CopyToClipboardAction.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/CopyToClipboardAction.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 @@ -109,7 +109,7 @@ public class CopyToClipboardAction extends Action { IBaseLabelProvider labelProvider= fViewer.getLabelProvider(); String lineDelim= System.getProperty("line.separator"); //$NON-NLS-1$ StringBuffer buf= new StringBuffer(); - Iterator iter= getSelection(); + Iterator<?> iter= getSelection(); while (iter.hasNext()) { if (buf.length() > 0) { buf.append(lineDelim); @@ -141,11 +141,11 @@ public class CopyToClipboardAction extends Action { } } - private Iterator getSelection() { + private Iterator<?> getSelection() { ISelection s= fViewer.getSelection(); if (s instanceof IStructuredSelection) return ((IStructuredSelection)s).iterator(); - return Collections.EMPTY_LIST.iterator(); + return Collections.emptyList().iterator(); } private void copyToClipboard(Clipboard clipboard, String str, Shell shell) { diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/OpenSearchDialogPageAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/OpenSearchDialogPageAction.java index 8740ee84117..068992c47ac 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/OpenSearchDialogPageAction.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/OpenSearchDialogPageAction.java @@ -75,10 +75,10 @@ public class OpenSearchDialogPageAction implements IWorkbenchWindowPulldownDeleg } private void fillMenu(final Menu localMenu) { - List pageDescriptors= SearchPlugin.getDefault().getSearchPageDescriptors(); + List<SearchPageDescriptor> pageDescriptors= SearchPlugin.getDefault().getSearchPageDescriptors(); int accelerator= 1; - for (Iterator iter= pageDescriptors.iterator(); iter.hasNext();) { - SearchPageDescriptor desc= (SearchPageDescriptor) iter.next(); + for (Iterator<SearchPageDescriptor> iter= pageDescriptors.iterator(); iter.hasNext();) { + SearchPageDescriptor desc= iter.next(); if (!WorkbenchActivityHelper.filterItem(desc) && desc.isEnabled()) { SearchPageAction action= new SearchPageAction(fWorkbenchWindow, desc); addToMenu(localMenu, action, accelerator++); diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/RemovePotentialMatchesAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/RemovePotentialMatchesAction.java index e30dfd45a52..0d1622be627 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/RemovePotentialMatchesAction.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/RemovePotentialMatchesAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 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 @@ -78,18 +78,18 @@ class RemovePotentialMatchesAction extends Action { if (size <= 0) return null; - ArrayList markers= new ArrayList(size * 3); - Iterator iter= selection.iterator(); + ArrayList<IMarker> markers= new ArrayList<>(size * 3); + Iterator<?> iter= selection.iterator(); while (iter.hasNext()) { SearchResultViewEntry entry= (SearchResultViewEntry)iter.next(); - Iterator entryIter= entry.getMarkers().iterator(); + Iterator<IMarker> entryIter= entry.getMarkers().iterator(); while (entryIter.hasNext()) { - IMarker marker= (IMarker)entryIter.next(); + IMarker marker= entryIter.next(); if (marker.getAttribute(SearchUI.POTENTIAL_MATCH, false)) markers.add(marker); } } - return (IMarker[])markers.toArray(new IMarker[markers.size()]); + return markers.toArray(new IMarker[markers.size()]); } private boolean usePluralLabel() { @@ -104,12 +104,12 @@ class RemovePotentialMatchesAction extends Action { return false; int markerCount= 0; - Iterator iter= selection.iterator(); + Iterator<?> iter= selection.iterator(); while (iter.hasNext()) { SearchResultViewEntry entry= (SearchResultViewEntry)iter.next(); - Iterator entryIter= entry.getMarkers().iterator(); + Iterator<IMarker> entryIter= entry.getMarkers().iterator(); while (entryIter.hasNext()) { - IMarker marker= (IMarker)entryIter.next(); + IMarker marker= entryIter.next(); if (marker.getAttribute(SearchUI.POTENTIAL_MATCH, false)) { markerCount++; } diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/RemoveResultAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/RemoveResultAction.java index c60a0aaa4af..996f7bc994f 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/RemoveResultAction.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/RemoveResultAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 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 @@ -73,15 +73,15 @@ class RemoveResultAction extends Action { int size= selection.size(); if (size <= 0) return null; - ArrayList markers= new ArrayList(size * 3); + ArrayList<IMarker> markers= new ArrayList<>(size * 3); int markerCount= 0; - Iterator iter= selection.iterator(); + Iterator<?> iter= selection.iterator(); while (iter.hasNext()) { SearchResultViewEntry entry= (SearchResultViewEntry)iter.next(); markerCount += entry.getMatchCount(); markers.addAll(entry.getMarkers()); } - return (IMarker[])markers.toArray(new IMarker[markerCount]); + return markers.toArray(new IMarker[markerCount]); } private boolean usePluralLabel() { diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/ResourceToItemsMapper.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/ResourceToItemsMapper.java index 0546843fff7..8e74e8a6e9e 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/ResourceToItemsMapper.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/ResourceToItemsMapper.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 @@ -37,15 +37,15 @@ class ResourceToItemsMapper { private static final int NUMBER_LIST_REUSE= 10; - // map from resource to item - private HashMap fResourceToItem; - private Stack fReuseLists; + // map from IResource to Item | List<Item> + private HashMap<IResource, Object> fResourceToItem; + private Stack<List<Item>> fReuseLists; private ContentViewer fContentViewer; public ResourceToItemsMapper(ContentViewer viewer) { - fResourceToItem= new HashMap(); - fReuseLists= new Stack(); + fResourceToItem= new HashMap<>(); + fReuseLists= new Stack<>(); fContentViewer= viewer; } @@ -61,9 +61,10 @@ class ResourceToItemsMapper { } else if (obj instanceof Item) { updateItem((Item) obj); } else { // List of Items - List list= (List) obj; + @SuppressWarnings("unchecked") + List<Item> list= (List<Item>) obj; for (int k= 0; k < list.size(); k++) { - updateItem((Item) list.get(k)); + updateItem(list.get(k)); } } } @@ -101,13 +102,14 @@ class ResourceToItemsMapper { fResourceToItem.put(resource, item); } else if (existingMapping instanceof Item) { if (existingMapping != item) { - List list= getNewList(); - list.add(existingMapping); + List<Item> list= getNewList(); + list.add((Item) existingMapping); list.add(item); fResourceToItem.put(resource, list); } } else { // List - List list= (List) existingMapping; + @SuppressWarnings("unchecked") + List<Item> list= (List<Item>) existingMapping; if (!list.contains(item)) { list.add(item); } @@ -129,7 +131,8 @@ class ResourceToItemsMapper { } else if (existingMapping instanceof Item) { fResourceToItem.remove(resource); } else { // List - List list= (List) existingMapping; + @SuppressWarnings("unchecked") + List<Item> list= (List<Item>) existingMapping; list.remove(item); if (list.isEmpty()) { fResourceToItem.remove(list); @@ -139,14 +142,14 @@ class ResourceToItemsMapper { } } - private List getNewList() { + private List<Item> getNewList() { if (!fReuseLists.isEmpty()) { - return (List) fReuseLists.pop(); + return fReuseLists.pop(); } - return new ArrayList(2); + return new ArrayList<>(2); } - private void releaseList(List list) { + private void releaseList(List<Item> list) { if (fReuseLists.size() < NUMBER_LIST_REUSE) { fReuseLists.push(list); } diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/ScopePart.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/ScopePart.java index 279e9710635..5596d58cb8a 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/ScopePart.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/ScopePart.java @@ -125,7 +125,7 @@ public class ScopePart { IWorkingSetManager workingSetManager= PlatformUI.getWorkbench().getWorkingSetManager(); if (lruWorkingSetNames != null) { - Set existingWorkingSets= new HashSet(lruWorkingSetNames.length); + Set<IWorkingSet> existingWorkingSets= new HashSet<>(lruWorkingSetNames.length); for (int i= 0; i < lruWorkingSetNames.length; i++) { IWorkingSet workingSet= getWorkingSet(workingSetManager, lruWorkingSetNames[i]); if (workingSet != null) { @@ -133,7 +133,7 @@ public class ScopePart { } } if (!existingWorkingSets.isEmpty()) { - return (IWorkingSet[]) existingWorkingSets.toArray(new IWorkingSet[existingWorkingSets.size()]); + return existingWorkingSets.toArray(new IWorkingSet[existingWorkingSets.size()]); } } else { // Backward compatibility @@ -230,7 +230,7 @@ public class ScopePart { Assert.isNotNull(workingSets); setSelectedScope(ISearchPageContainer.WORKING_SET_SCOPE); fWorkingSets= null; - Set existingWorkingSets= new HashSet(workingSets.length); + Set<IWorkingSet> existingWorkingSets= new HashSet<>(workingSets.length); for (int i= 0; i < workingSets.length; i++) { String name= workingSets[i].getName(); IWorkingSet workingSet= PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSet(name); @@ -238,7 +238,7 @@ public class ScopePart { existingWorkingSets.add(workingSet); } if (!existingWorkingSets.isEmpty()) - fWorkingSets= (IWorkingSet[]) existingWorkingSets.toArray(new IWorkingSet[existingWorkingSets.size()]); + fWorkingSets= existingWorkingSets.toArray(new IWorkingSet[existingWorkingSets.size()]); saveState(); diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/Search.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/Search.java index e9c4d970b20..2796e550555 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/Search.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/Search.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 @@ -42,7 +42,7 @@ public class Search extends Object { private ImageDescriptor fImageDescriptor; private ILabelProvider fLabelProvider; private ISelection fSelection; - private ArrayList fResults; + private ArrayList<SearchResultViewEntry> fResults; private IAction fGotoMarkerAction; private IContextMenuContributor fContextMenuContributor; private IActionGroupFactory fActionGroupFactory; @@ -125,15 +125,15 @@ public class Search extends Object { int getItemCount() { int count= 0; - Iterator iter= getResults().iterator(); + Iterator<SearchResultViewEntry> iter= getResults().iterator(); while (iter.hasNext()) count += ((ISearchResultViewEntry)iter.next()).getMatchCount(); return count; } - List getResults() { + List<SearchResultViewEntry> getResults() { if (fResults == null) - return new ArrayList(); + return new ArrayList<>(); return fResults; } @@ -161,9 +161,9 @@ public class Search extends Object { } void backupMarkers() { - Iterator iter= getResults().iterator(); + Iterator<SearchResultViewEntry> iter= getResults().iterator(); while (iter.hasNext()) { - ((SearchResultViewEntry)iter.next()).backupMarkers(); + iter.next().backupMarkers(); } } @@ -195,7 +195,7 @@ public class Search extends Object { fResults= null; } - void setResults(ArrayList results) { + void setResults(ArrayList<SearchResultViewEntry> results) { Assert.isNotNull(results); fResults= results; } diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchDialog.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchDialog.java index dabc2c4ac46..bde9ccc084d 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchDialog.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchDialog.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 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 @@ -143,7 +143,7 @@ public class SearchDialog extends ExtendedDialogWindow implements ISearchPageCon private String fInitialPageId; private int fCurrentIndex; - private List fDescriptors; + private List<SearchPageDescriptor> fDescriptors; private Point fMinSize; private ScopePart[] fScopeParts; private boolean fLastEnableState; @@ -197,8 +197,8 @@ public class SearchDialog extends ExtendedDialogWindow implements ISearchPageCon return new String[] { name }; } } else if (selection instanceof IStructuredSelection) { - HashSet res= new HashSet(); - for (Iterator iter= ((IStructuredSelection) selection).iterator(); iter.hasNext();) { + HashSet<String> res= new HashSet<>(); + for (Iterator<?> iter= ((IStructuredSelection) selection).iterator(); iter.hasNext();) { Object curr= iter.next(); if (curr instanceof IWorkingSet) { IWorkingSet workingSet= (IWorkingSet) curr; @@ -227,7 +227,7 @@ public class SearchDialog extends ExtendedDialogWindow implements ISearchPageCon } } if (!res.isEmpty()) { - return (String[]) res.toArray(new String[res.size()]); + return res.toArray(new String[res.size()]); } } return new String[0]; @@ -307,10 +307,10 @@ public class SearchDialog extends ExtendedDialogWindow implements ISearchPageCon } private void handleCustomizePressed() { - List input= SearchPlugin.getDefault().getSearchPageDescriptors(); + List<SearchPageDescriptor> input= SearchPlugin.getDefault().getSearchPageDescriptors(); input= filterByActivities(input); - final ArrayList createdImages= new ArrayList(input.size()); + final ArrayList<Image> createdImages= new ArrayList<>(input.size()); ILabelProvider labelProvider= new LabelProvider() { @Override public String getText(Object element) { @@ -393,10 +393,10 @@ public class SearchDialog extends ExtendedDialogWindow implements ISearchPageCon destroyImages(createdImages); } - private List filterByActivities(List input) { - ArrayList filteredList= new ArrayList(input.size()); - for (Iterator descriptors= input.iterator(); descriptors.hasNext();) { - SearchPageDescriptor descriptor= (SearchPageDescriptor) descriptors.next(); + private List<SearchPageDescriptor> filterByActivities(List<SearchPageDescriptor> input) { + ArrayList<SearchPageDescriptor> filteredList= new ArrayList<>(input.size()); + for (Iterator<SearchPageDescriptor> descriptors= input.iterator(); descriptors.hasNext();) { + SearchPageDescriptor descriptor= descriptors.next(); if (!WorkbenchActivityHelper.filterItem(descriptor)) filteredList.add(descriptor); @@ -404,10 +404,10 @@ public class SearchDialog extends ExtendedDialogWindow implements ISearchPageCon return filteredList; } - private void destroyImages(List images) { - Iterator iter= images.iterator(); + private void destroyImages(List<Image> images) { + Iterator<Image> iter= images.iterator(); while (iter.hasNext()) { - Image image= (Image)iter.next(); + Image image= iter.next(); if (image != null && !image.isDisposed()) image.dispose(); } @@ -544,7 +544,7 @@ public class SearchDialog extends ExtendedDialogWindow implements ISearchPageCon } private SearchPageDescriptor getDescriptorAt(int index) { - return (SearchPageDescriptor) fDescriptors.get(index); + return fDescriptors.get(index); } private Point getMinSize() { @@ -616,7 +616,7 @@ public class SearchDialog extends ExtendedDialogWindow implements ISearchPageCon int level= ISearchPageScoreComputer.LOWEST; int size= fDescriptors.size(); for (int i= 0; i < size; i++) { - SearchPageDescriptor descriptor= (SearchPageDescriptor) fDescriptors.get(i); + SearchPageDescriptor descriptor= fDescriptors.get(i); if (fInitialPageId != null && fInitialPageId.equals(descriptor.getId())) return i; @@ -834,7 +834,7 @@ public class SearchDialog extends ExtendedDialogWindow implements ISearchPageCon @Override public boolean close() { for (int i= 0; i < fDescriptors.size(); i++) { - SearchPageDescriptor desc= (SearchPageDescriptor) fDescriptors.get(i); + SearchPageDescriptor desc= fDescriptors.get(i); desc.dispose(); } return super.close(); diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchDropDownAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchDropDownAction.java index 1fe05775b1c..ac1fe2f1b6f 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchDropDownAction.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchDropDownAction.java @@ -59,11 +59,11 @@ class SearchDropDownAction extends Action implements IMenuCreator { fMenu= new Menu(parent); boolean checkedOne= false; - Iterator iter= SearchManager.getDefault().getPreviousSearches().iterator(); + Iterator<Search> iter= SearchManager.getDefault().getPreviousSearches().iterator(); Search selected= SearchManager.getDefault().getCurrentSearch(); int i= 0; while (iter.hasNext() && i++ < RESULTS_IN_DROP_DOWN) { - Search search= (Search)iter.next(); + Search search= iter.next(); ShowSearchAction action= new ShowSearchAction(search); action.setChecked(search.equals(selected)); if (search.equals(selected)) diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchManager.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchManager.java index 253bf416ebc..0eb749fcc08 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchManager.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchManager.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 @@ -58,8 +58,8 @@ public class SearchManager implements IResourceChangeListener { SearchPlugin.getWorkspace().addResourceChangeListener(this); } - private HashSet fListeners= new HashSet(); - private LinkedList fPreviousSearches= new LinkedList(); + private HashSet<SearchResultViewer> fListeners= new HashSet<>(); + private LinkedList<Search> fPreviousSearches= new LinkedList<>(); private boolean fIsRemoveAll= false; public static synchronized SearchManager getDefault() { @@ -76,17 +76,17 @@ public class SearchManager implements IResourceChangeListener { * Returns the list with previous searches (ISearch). * @return previous searches */ - LinkedList getPreviousSearches() { + LinkedList<Search> getPreviousSearches() { return fPreviousSearches; } /** * Returns the list with current (last) results * @return the current results */ - ArrayList getCurrentResults() { + ArrayList<SearchResultViewEntry> getCurrentResults() { if (fCurrentSearch == null) - return new ArrayList(0); - return (ArrayList)fCurrentSearch.getResults(); + return new ArrayList<>(0); + return (ArrayList<SearchResultViewEntry>)fCurrentSearch.getResults(); } public Search getCurrentSearch() { @@ -118,13 +118,13 @@ public class SearchManager implements IResourceChangeListener { } // clear searches - fPreviousSearches= new LinkedList(); + fPreviousSearches= new LinkedList<>(); fCurrentSearch= null; // update viewers - Iterator iter= fListeners.iterator(); + Iterator<SearchResultViewer> iter= fListeners.iterator(); while (iter.hasNext()) { - SearchResultViewer viewer= (SearchResultViewer)iter.next(); + SearchResultViewer viewer= iter.next(); handleAllSearchesRemoved(viewer); } } @@ -177,15 +177,15 @@ public class SearchManager implements IResourceChangeListener { monitor.worked(10); // add search markers - Iterator iter= getCurrentResults().iterator(); - ArrayList emptyEntries= new ArrayList(10); + Iterator<SearchResultViewEntry> iter= getCurrentResults().iterator(); + ArrayList<SearchResultViewEntry> emptyEntries= new ArrayList<>(10); boolean filesChanged= false; boolean filesDeleted= false; IGroupByKeyComputer groupByKeyComputer= getCurrentSearch().getGroupByKeyComputer(); while (iter.hasNext()) { monitor.worked(1); - SearchResultViewEntry entry= (SearchResultViewEntry)iter.next(); - Iterator attrPerMarkerIter= entry.getAttributesPerMarker().iterator(); + SearchResultViewEntry entry= iter.next(); + Iterator<Map<String, Object>> attrPerMarkerIter= entry.getAttributesPerMarker().iterator(); entry.clearMarkerList(); if (entry.getResource() == null || !entry.getResource().exists()) { emptyEntries.add(entry); @@ -201,7 +201,7 @@ public class SearchManager implements IResourceChangeListener { continue; } try { - newMarker.setAttributes((Map)attrPerMarkerIter.next()); + newMarker.setAttributes(attrPerMarkerIter.next()); if (groupByKeyComputer !=null && groupByKeyComputer.computeGroupByKey(newMarker) == null) { filesDeleted= true; newMarker.delete(); @@ -246,11 +246,11 @@ public class SearchManager implements IResourceChangeListener { } // update viewers - iter= fListeners.iterator(); + Iterator<SearchResultViewer> iter2= fListeners.iterator(); if (display != null && !display.isDisposed()) { final Viewer visibleViewer= ((SearchResultView)SearchUI.getSearchResultView()).getViewer(); - while (iter.hasNext()) { - final SearchResultViewer viewer= (SearchResultViewer)iter.next(); + while (iter2.hasNext()) { + final SearchResultViewer viewer= iter2.next(); display.syncExec(new Runnable() { @Override public void run() { @@ -296,12 +296,12 @@ public class SearchManager implements IResourceChangeListener { SearchPlugin.getWorkspace().removeResourceChangeListener(this); // Clear the viewers - Iterator iter= fListeners.iterator(); + Iterator<SearchResultViewer> iter= fListeners.iterator(); Display display= getDisplay(); if (display != null && !display.isDisposed()) { final Viewer visibleViewer= ((SearchResultView)SearchUI.getSearchResultView()).getViewer(); while (iter.hasNext()) { - final SearchResultViewer viewer= (SearchResultViewer)iter.next(); + final SearchResultViewer viewer= iter.next(); display.syncExec(new Runnable() { @Override public void run() { @@ -330,7 +330,7 @@ public class SearchManager implements IResourceChangeListener { } } - void searchFinished(ArrayList results) { + void searchFinished(ArrayList<SearchResultViewEntry> results) { Assert.isNotNull(results); getCurrentSearch().setResults(results); @@ -369,9 +369,9 @@ public class SearchManager implements IResourceChangeListener { return; } - Iterator iter= fListeners.iterator(); + Iterator<SearchResultViewer> iter= fListeners.iterator(); while (iter.hasNext()) - ((SearchResultViewer)iter.next()).getControl().setRedraw(false); + iter.next().getControl().setRedraw(false); for (int i=0; i < markerDeltas.length; i++) { handleSearchMarkerChanged(markerDeltas[i]); @@ -379,7 +379,7 @@ public class SearchManager implements IResourceChangeListener { iter= fListeners.iterator(); while (iter.hasNext()) - ((SearchResultViewer)iter.next()).getControl().setRedraw(true); + iter.next().getControl().setRedraw(true); } @@ -395,15 +395,15 @@ public class SearchManager implements IResourceChangeListener { private void handleRemoveAll() { if (fCurrentSearch != null) fCurrentSearch.removeResults(); - Iterator iter= fListeners.iterator(); + Iterator<SearchResultViewer> iter= fListeners.iterator(); while (iter.hasNext()) - ((SearchResultViewer)iter.next()).handleRemoveAll(); + iter.next().handleRemoveAll(); } private void handleNewSearchResult() { - Iterator iter= fListeners.iterator(); + Iterator<SearchResultViewer> iter= fListeners.iterator(); while (iter.hasNext()) { - SearchResultViewer viewer= (SearchResultViewer)iter.next(); + SearchResultViewer viewer= iter.next(); viewer.setInput(getCurrentResults()); } } @@ -423,14 +423,14 @@ public class SearchManager implements IResourceChangeListener { entry.remove(marker); if (entry.getMatchCount() == 0) { getCurrentResults().remove(entry); - Iterator iter= fListeners.iterator(); + Iterator<SearchResultViewer> iter= fListeners.iterator(); while (iter.hasNext()) - ((SearchResultViewer)iter.next()).handleRemoveMatch(entry); + iter.next().handleRemoveMatch(entry); } else { - Iterator iter= fListeners.iterator(); + Iterator<SearchResultViewer> iter= fListeners.iterator(); while (iter.hasNext()) - ((SearchResultViewer)iter.next()).handleUpdateMatch(entry, true); + iter.next().handleUpdateMatch(entry, true); } } } @@ -438,16 +438,16 @@ public class SearchManager implements IResourceChangeListener { private void handleUpdateMatch(IMarker marker) { SearchResultViewEntry entry= findEntry(marker); if (entry != null) { - Iterator iter= fListeners.iterator(); + Iterator<SearchResultViewer> iter= fListeners.iterator(); while (iter.hasNext()) - ((SearchResultViewer)iter.next()).handleUpdateMatch(entry, false); + iter.next().handleUpdateMatch(entry, false); } } private SearchResultViewEntry findEntry(IMarker marker) { - Iterator entries= getCurrentResults().iterator(); + Iterator<SearchResultViewEntry> entries= getCurrentResults().iterator(); while (entries.hasNext()) { - SearchResultViewEntry entry= (SearchResultViewEntry)entries.next(); + SearchResultViewEntry entry= entries.next(); if (entry.contains(marker)) return entry; } @@ -479,9 +479,9 @@ public class SearchManager implements IResourceChangeListener { if (getCurrentSearch() != null) { handleSearchMarkersChanged(markerDeltas); // update title and actions - Iterator iter= fListeners.iterator(); + Iterator<SearchResultViewer> iter= fListeners.iterator(); while (iter.hasNext()) { - SearchResultViewer viewer= (SearchResultViewer)iter.next(); + SearchResultViewer viewer= iter.next(); viewer.enableActions(); viewer.updateTitle(); } @@ -495,7 +495,7 @@ public class SearchManager implements IResourceChangeListener { * @return the display */ private Display getDisplay() { - Iterator iter= fListeners.iterator(); + Iterator<SearchResultViewer> iter= fListeners.iterator(); while (iter.hasNext()) { Control control= ((Viewer)iter.next()).getControl(); if (control != null && !control.isDisposed()) { diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPageDescriptor.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPageDescriptor.java index 36c2dfa2300..3c59e8b5d72 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPageDescriptor.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPageDescriptor.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 @@ -47,7 +47,7 @@ import org.eclipse.search.ui.ISearchPageScoreComputer; /** * Proxy that represents a search page. */ -class SearchPageDescriptor implements IPluginContribution, Comparable { +class SearchPageDescriptor implements IPluginContribution, Comparable<SearchPageDescriptor> { public final static String PAGE_TAG= "page"; //$NON-NLS-1$ private final static String ID_ATTRIBUTE= "id"; //$NON-NLS-1$ @@ -69,7 +69,7 @@ class SearchPageDescriptor implements IPluginContribution, Comparable { private final static String STORE_ENABLED_PAGE_IDS= SECTION_ID + ".enabledPageIds"; //$NON-NLS-1$ private final static String STORE_PROCESSED_PAGE_IDS= SECTION_ID + ".processedPageIds"; //$NON-NLS-1$ - private static List fgEnabledPageIds; + private static List<String> fgEnabledPageIds; private static class ExtensionScorePair { public String extension; @@ -81,7 +81,7 @@ class SearchPageDescriptor implements IPluginContribution, Comparable { } private IConfigurationElement fElement; - private List fExtensionScorePairs; + private List<ExtensionScorePair> fExtensionScorePairs; private int fWildcardScore= ISearchPageScoreComputer.UNKNOWN; private ISearchPage fCreatedPage; @@ -232,7 +232,7 @@ class SearchPageDescriptor implements IPluginContribution, Comparable { } static void setEnabled(Object[] enabledDescriptors) { - fgEnabledPageIds= new ArrayList(5); + fgEnabledPageIds= new ArrayList<>(5); for (int i= 0; i < enabledDescriptors.length; i++) { if (enabledDescriptors[i] instanceof SearchPageDescriptor) fgEnabledPageIds.add(((SearchPageDescriptor)enabledDescriptors[i]).getId()); @@ -240,28 +240,28 @@ class SearchPageDescriptor implements IPluginContribution, Comparable { storeEnabledPageIds(); } - private static List getEnabledPageIds() { + private static List<String> getEnabledPageIds() { if (fgEnabledPageIds == null) { - List descriptors= SearchPlugin.getDefault().getSearchPageDescriptors(); + List<SearchPageDescriptor> descriptors= SearchPlugin.getDefault().getSearchPageDescriptors(); String[] enabledPageIds= getDialogSettings().getArray(STORE_ENABLED_PAGE_IDS); if (enabledPageIds == null) - fgEnabledPageIds= new ArrayList(descriptors.size()); + fgEnabledPageIds= new ArrayList<>(descriptors.size()); else - fgEnabledPageIds= new ArrayList(Arrays.asList(enabledPageIds)); + fgEnabledPageIds= new ArrayList<>(Arrays.asList(enabledPageIds)); - List processedPageIds; + List<String> processedPageIds; String[] processedPageIdsArr= getDialogSettings().getArray(STORE_PROCESSED_PAGE_IDS); if (processedPageIdsArr == null) - processedPageIds= new ArrayList(descriptors.size()); + processedPageIds= new ArrayList<>(descriptors.size()); else - processedPageIds= new ArrayList(Arrays.asList(processedPageIdsArr)); + processedPageIds= new ArrayList<>(Arrays.asList(processedPageIdsArr)); // Enable pages based on contribution - Iterator iter= descriptors.iterator(); + Iterator<SearchPageDescriptor> iter= descriptors.iterator(); while (iter.hasNext()) { - SearchPageDescriptor desc= (SearchPageDescriptor)iter.next(); + SearchPageDescriptor desc= iter.next(); if (processedPageIds.contains(desc.getId())) continue; @@ -270,14 +270,14 @@ class SearchPageDescriptor implements IPluginContribution, Comparable { fgEnabledPageIds.add(desc.getId()); } - getDialogSettings().put(STORE_PROCESSED_PAGE_IDS, (String[])processedPageIds.toArray(new String[processedPageIds.size()])); + getDialogSettings().put(STORE_PROCESSED_PAGE_IDS, processedPageIds.toArray(new String[processedPageIds.size()])); storeEnabledPageIds(); } return fgEnabledPageIds; } private static void storeEnabledPageIds() { - getDialogSettings().put(STORE_ENABLED_PAGE_IDS, (String[])fgEnabledPageIds.toArray(new String[fgEnabledPageIds.size()])); + getDialogSettings().put(STORE_ENABLED_PAGE_IDS, fgEnabledPageIds.toArray(new String[fgEnabledPageIds.size()])); } private static IDialogSettings getDialogSettings() { @@ -289,15 +289,12 @@ class SearchPageDescriptor implements IPluginContribution, Comparable { return section; } - /* - * Implements a method from IComparable - */ @Override - public int compareTo(Object o) { + public int compareTo(SearchPageDescriptor o) { int myPos= getTabPosition(); - int objsPos= ((SearchPageDescriptor)o).getTabPosition(); + int objsPos= o.getTabPosition(); if (myPos == Integer.MAX_VALUE && objsPos == Integer.MAX_VALUE || myPos == objsPos) - return getLabel().compareTo(((SearchPageDescriptor)o).getLabel()); + return getLabel().compareTo(o.getLabel()); return myPos - objsPos; } @@ -338,7 +335,7 @@ class SearchPageDescriptor implements IPluginContribution, Comparable { int size= fExtensionScorePairs.size(); for (int i= 0; i < size; i++) { - ExtensionScorePair p= (ExtensionScorePair)fExtensionScorePairs.get(i); + ExtensionScorePair p= fExtensionScorePairs.get(i); if (extension.equals(p.extension)) return p.score; } @@ -347,7 +344,7 @@ class SearchPageDescriptor implements IPluginContribution, Comparable { } private void readExtensionScorePairs() { - fExtensionScorePairs= new ArrayList(3); + fExtensionScorePairs= new ArrayList<>(3); String content= fElement.getAttribute(EXTENSIONS_ATTRIBUTE); if (content == null) return; diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPlugin.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPlugin.java index 538a67eccfc..3702c32cb06 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPlugin.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPlugin.java @@ -85,8 +85,8 @@ public class SearchPlugin extends AbstractUIPlugin { private static SearchPlugin fgSearchPlugin; - private List fPageDescriptors; - private List fSorterDescriptors; + private List<SearchPageDescriptor> fPageDescriptors; + private List<SorterDescriptor> fSorterDescriptors; private TextSearchEngineRegistry fTextSearchEngineRegistry; private TextSearchQueryProviderRegistry fTextSearchQueryProviderRegistry; @@ -226,7 +226,7 @@ public class SearchPlugin extends AbstractUIPlugin { /** * @return Returns all search pages contributed to the workbench. */ - public List getSearchPageDescriptors() { + public List<SearchPageDescriptor> getSearchPageDescriptors() { if (fPageDescriptors == null) { IConfigurationElement[] elements= Platform.getExtensionRegistry().getConfigurationElementsFor(NewSearchUI.PLUGIN_ID, SEARCH_PAGE_EXTENSION_POINT); fPageDescriptors= createSearchPageDescriptors(elements); @@ -238,11 +238,11 @@ public class SearchPlugin extends AbstractUIPlugin { * @param pageId the page id or <code>null</code> * @return all descriptors of the enabled search pages, plus the descriptor for the given page id */ - public List getEnabledSearchPageDescriptors(String pageId) { - Iterator iter= getSearchPageDescriptors().iterator(); - List enabledDescriptors= new ArrayList(5); + public List<SearchPageDescriptor> getEnabledSearchPageDescriptors(String pageId) { + Iterator<SearchPageDescriptor> iter= getSearchPageDescriptors().iterator(); + List<SearchPageDescriptor> enabledDescriptors= new ArrayList<>(5); while (iter.hasNext()) { - SearchPageDescriptor desc= (SearchPageDescriptor)iter.next(); + SearchPageDescriptor desc= iter.next(); if (desc.isEnabled() || desc.getId().equals(pageId)) enabledDescriptors.add(desc); } @@ -261,9 +261,9 @@ public class SearchPlugin extends AbstractUIPlugin { Search currentSearch= SearchManager.getDefault().getCurrentSearch(); if (currentSearch != null) { String pageId= currentSearch.getPageId(); - Iterator iter= getSearchPageDescriptors().iterator(); + Iterator<SearchPageDescriptor> iter= getSearchPageDescriptors().iterator(); while (iter.hasNext()) { - SearchPageDescriptor desc= (SearchPageDescriptor)iter.next(); + SearchPageDescriptor desc= iter.next(); if (desc.getId().equals(pageId)) { String helpId= desc.getSearchViewHelpContextId(); if (helpId == null) @@ -280,8 +280,8 @@ public class SearchPlugin extends AbstractUIPlugin { * @param elements the configuration elements * @return the created SearchPageDescriptor */ - private List createSearchPageDescriptors(IConfigurationElement[] elements) { - List result= new ArrayList(5); + private List<SearchPageDescriptor> createSearchPageDescriptors(IConfigurationElement[] elements) { + List<SearchPageDescriptor> result= new ArrayList<>(5); for (int i= 0; i < elements.length; i++) { IConfigurationElement element= elements[i]; if (SearchPageDescriptor.PAGE_TAG.equals(element.getName())) { @@ -296,7 +296,7 @@ public class SearchPlugin extends AbstractUIPlugin { /** * @return Returns all sorters contributed to the workbench. */ - public List getSorterDescriptors() { + public List<SorterDescriptor> getSorterDescriptors() { if (fSorterDescriptors == null) { IConfigurationElement[] elements= Platform.getExtensionRegistry().getConfigurationElementsFor(NewSearchUI.PLUGIN_ID, SORTER_EXTENSION_POINT); fSorterDescriptors= createSorterDescriptors(elements); @@ -324,8 +324,8 @@ public class SearchPlugin extends AbstractUIPlugin { * @param elements the configuration elements * @return the created SorterDescriptor */ - private List createSorterDescriptors(IConfigurationElement[] elements) { - List result= new ArrayList(5); + private List<SorterDescriptor> createSorterDescriptors(IConfigurationElement[] elements) { + List<SorterDescriptor> result= new ArrayList<>(5); for (int i= 0; i < elements.length; i++) { IConfigurationElement element= elements[i]; if (SorterDescriptor.SORTER_TAG.equals(element.getName())) diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPreferencePage.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPreferencePage.java index 01c47faadfb..716c1321b24 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPreferencePage.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchPreferencePage.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 @@ -59,15 +59,12 @@ public class SearchPreferencePage extends FieldEditorPreferencePage implements I private BooleanFieldEditor fIgnorePotentialMatchesCheckbox; - private static class PerspectiveDescriptorComparator implements Comparator { + private static class PerspectiveDescriptorComparator implements Comparator<IPerspectiveDescriptor> { @Override - public int compare(Object o1, Object o2) { - if (o1 instanceof IPerspectiveDescriptor && o2 instanceof IPerspectiveDescriptor) { - String id1= ((IPerspectiveDescriptor)o1).getLabel(); - String id2= ((IPerspectiveDescriptor)o2).getLabel(); - return Collator.getInstance().compare(id1, id2); - } - return 0; + public int compare(IPerspectiveDescriptor o1, IPerspectiveDescriptor o2) { + String id1= o1.getLabel(); + String id2= o2.getLabel(); + return Collator.getInstance().compare(id1, id2); } } diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultView.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultView.java index 953f26e6984..f05bdcf7259 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultView.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultView.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 @@ -57,10 +57,10 @@ import org.eclipse.search.ui.ISearchResultView; public class SearchResultView extends ViewPart implements ISearchResultView { - private static Map fgLabelProviders= new HashMap(5); + private static Map<String, ILabelProvider> fgLabelProviders= new HashMap<>(5); private SearchResultViewer fViewer; - private Map fResponse; + private Map<Object, SearchResultViewEntry> fResponse; private IMemento fMemento; private IPropertyChangeListener fPropertyChangeListener; private CellEditorActionHandler fCellEditorActionHandler; @@ -183,7 +183,7 @@ public class SearchResultView extends ViewPart implements ISearchResultView { ILabelProvider getLabelProvider(String pageId) { if (pageId != null) - return (ILabelProvider)fgLabelProviders.get(pageId); + return fgLabelProviders.get(pageId); return null; } @@ -245,10 +245,10 @@ public class SearchResultView extends ViewPart implements ISearchResultView { Assert.isNotNull(pluralLabelPattern); Assert.isNotNull(gotoAction); - fResponse= new HashMap(500); + fResponse= new HashMap<>(500); setGotoMarkerAction(gotoAction); - ILabelProvider oldLabelProvider= (ILabelProvider)fgLabelProviders.get(pageId); + ILabelProvider oldLabelProvider= fgLabelProviders.get(pageId); if (oldLabelProvider != null) oldLabelProvider.dispose(); fgLabelProviders.put(pageId, labelProvider); @@ -301,10 +301,10 @@ public class SearchResultView extends ViewPart implements ISearchResultView { Assert.isNotNull(pluralLabelPattern); Assert.isNotNull(gotoAction); - fResponse= new HashMap(500); + fResponse= new HashMap<>(500); setGotoMarkerAction(gotoAction); - ILabelProvider oldLabelProvider= (ILabelProvider)fgLabelProviders.get(pageId); + ILabelProvider oldLabelProvider= fgLabelProviders.get(pageId); if (oldLabelProvider != null) oldLabelProvider.dispose(); fgLabelProviders.put(pageId, labelProvider); @@ -327,7 +327,7 @@ public class SearchResultView extends ViewPart implements ISearchResultView { */ @Override public void addMatch(String description, Object groupByKey, IResource resource, IMarker marker) { - SearchResultViewEntry entry= (SearchResultViewEntry)fResponse.get(groupByKey); + SearchResultViewEntry entry= fResponse.get(groupByKey); if (entry == null) { entry= new SearchResultViewEntry(groupByKey, resource); fResponse.put(groupByKey, entry); @@ -341,7 +341,7 @@ public class SearchResultView extends ViewPart implements ISearchResultView { */ @Override public void searchFinished() { - SearchManager.getDefault().searchFinished(new ArrayList(fResponse.values())); + SearchManager.getDefault().searchFinished(new ArrayList<>(fResponse.values())); fResponse= null; } } diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewEntry.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewEntry.java index 5e73850e8a2..485f60bd8e1 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewEntry.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewEntry.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 @@ -34,8 +34,8 @@ public class SearchResultViewEntry extends PlatformObject implements ISearchResu private Object fGroupByKey= null; private IResource fResource= null; private IMarker fMarker= null; - private ArrayList fMarkers= null; - private ArrayList fAttributes; + private ArrayList<IMarker> fMarkers= null; + private ArrayList<Map<String, Object>> fAttributes; private int fSelectedMarkerIndex; private long fModificationStamp= IResource.NULL_STAMP; private String fMarkerType; @@ -77,9 +77,9 @@ public class SearchResultViewEntry extends PlatformObject implements ISearchResu return false; } - List getAttributesPerMarker() { + List<Map<String, Object>> getAttributesPerMarker() { if (fAttributes == null) - return new ArrayList(0); + return new ArrayList<>(0); return fAttributes; } @@ -109,7 +109,7 @@ public class SearchResultViewEntry extends PlatformObject implements ISearchResu return; } if (fMarkers == null) { - fMarkers= new ArrayList(10); + fMarkers= new ArrayList<>(10); addByStartpos(fMarkers, fMarker); } addByStartpos(fMarkers, marker); @@ -125,15 +125,15 @@ public class SearchResultViewEntry extends PlatformObject implements ISearchResu if (fMarkers == null && fMarker == null) return null; if (fMarkers != null && fSelectedMarkerIndex >= 0) - return (IMarker)fMarkers.get(fSelectedMarkerIndex); + return fMarkers.get(fSelectedMarkerIndex); return fMarker; } - public List getMarkers() { + public List<IMarker> getMarkers() { if (fMarkers == null && fMarker == null) - return new ArrayList(0); + return new ArrayList<>(0); else if (fMarkers == null && fMarker != null) { - List markers= new ArrayList(1); + List<IMarker> markers= new ArrayList<>(1); markers.add(fMarker); return markers; } @@ -165,7 +165,7 @@ public class SearchResultViewEntry extends PlatformObject implements ISearchResu else { fMarkers.remove(marker); if (fMarkers.size() == 1) { - fMarker= (IMarker)fMarkers.get(0); + fMarker= fMarkers.get(0); fMarkers= null; } } @@ -174,12 +174,12 @@ public class SearchResultViewEntry extends PlatformObject implements ISearchResu void backupMarkers() { if (fResource != null) fModificationStamp= fResource.getModificationStamp(); - List markers= getMarkers(); - fAttributes= new ArrayList(markers.size()); - Iterator iter= markers.iterator(); + List<IMarker> markers= getMarkers(); + fAttributes= new ArrayList<>(markers.size()); + Iterator<IMarker> iter= markers.iterator(); while (iter.hasNext()) { - IMarker marker= (IMarker)iter.next(); - Map attributes= null; + IMarker marker= iter.next(); + Map<String, Object> attributes= null; try { attributes= marker.getAttributes(); } catch (CoreException ex) { @@ -190,11 +190,11 @@ public class SearchResultViewEntry extends PlatformObject implements ISearchResu } } - private void addByStartpos(ArrayList markers, IMarker marker) { + private void addByStartpos(ArrayList<IMarker> markers, IMarker marker) { int startPos= marker.getAttribute(IMarker.CHAR_START, -1); int i= 0; int markerCount= markers.size(); - while (i < markerCount && startPos >= ((IMarker)markers.get(i)).getAttribute(IMarker.CHAR_START, -1)) + while (i < markerCount && startPos >= markers.get(i).getAttribute(IMarker.CHAR_START, -1)) i++; markers.add(i, marker); if (i == 0) @@ -202,7 +202,7 @@ public class SearchResultViewEntry extends PlatformObject implements ISearchResu } @Override - public Object getAdapter(Class adapter) { + public <T> T getAdapter(Class<T> adapter) { return super.getAdapter(adapter); } } diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewEntryAdapterFactory.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewEntryAdapterFactory.java index 7151156a8bd..b122d1628b9 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewEntryAdapterFactory.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewEntryAdapterFactory.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 @@ -27,23 +27,24 @@ import org.eclipse.search.ui.ISearchResultViewEntry; @Deprecated public class SearchResultViewEntryAdapterFactory implements IAdapterFactory { - private static Class[] PROPERTIES= new Class[] { + private static Class<?>[] PROPERTIES= new Class[] { IResource.class, IMarker.class, }; @Override - public Class[] getAdapterList() { + public Class<?>[] getAdapterList() { return PROPERTIES; } + @SuppressWarnings("unchecked") @Override - public Object getAdapter(Object element, Class key) { + public <T> T getAdapter(Object element, Class<T> key) { ISearchResultViewEntry entry= (ISearchResultViewEntry) element; if (IMarker.class.equals(key)) { - return entry.getSelectedMarker(); + return (T) entry.getSelectedMarker(); } if (IResource.class.equals(key)) { IResource resource= entry.getResource(); @@ -54,7 +55,7 @@ public class SearchResultViewEntryAdapterFactory implements IAdapterFactory { */ int type= resource.getType(); if (type != IResource.PROJECT && type != IResource.ROOT) - return resource; + return (T) resource; } return null; } diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewer.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewer.java index aa53a3c97bb..4af2237ee0f 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewer.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchResultViewer.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 @@ -347,7 +347,7 @@ public class SearchResultViewer extends TableViewer { if (getSelectedEntriesCount() == 0) return false; - Iterator iter= Collections.EMPTY_LIST.iterator(); + Iterator<?> iter= Collections.emptyList().iterator(); ISelection selection= getSelection(); if (selection instanceof IStructuredSelection) iter= ((IStructuredSelection)selection).iterator(); @@ -677,7 +677,7 @@ public class SearchResultViewer extends TableViewer { protected void handleLabelProviderChanged(LabelProviderChangedEvent event) { Object[] changed= event.getElements(); if (changed != null && !fResourceToItemsMapper.isEmpty()) { - ArrayList others= new ArrayList(changed.length); + ArrayList<Object> others= new ArrayList<>(changed.length); for (int i= 0; i < changed.length; i++) { Object curr= changed[i]; if (curr instanceof IResource) diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SelectAllAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SelectAllAction.java index 1b4be53d703..1e497535be0 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SelectAllAction.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/SelectAllAction.java @@ -44,7 +44,7 @@ public class SelectAllAction extends Action { fViewer= viewer; } - private void collectExpandedAndVisible(TreeItem[] items, List result) { + private void collectExpandedAndVisible(TreeItem[] items, List<TreeItem> result) { for (int i= 0; i < items.length; i++) { TreeItem item= items[i]; result.add(item); @@ -63,10 +63,10 @@ public class SelectAllAction extends Action { return; } if (fViewer instanceof TreeViewer) { - ArrayList allVisible= new ArrayList(); + ArrayList<TreeItem> allVisible= new ArrayList<>(); Tree tree= ((TreeViewer) fViewer).getTree(); collectExpandedAndVisible(tree.getItems(), allVisible); - tree.setSelection((TreeItem[]) allVisible.toArray(new TreeItem[allVisible.size()])); + tree.setSelection(allVisible.toArray(new TreeItem[allVisible.size()])); } else if (fViewer instanceof TableViewer) { ((TableViewer) fViewer).getTable().selectAll(); // force viewer selection change diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/ShowSearchesAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/ShowSearchesAction.java index 10ee4dd15e5..4c504e5e774 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/ShowSearchesAction.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/ShowSearchesAction.java @@ -36,7 +36,7 @@ class ShowSearchesAction extends Action { private static final class SearchesLabelProvider extends LabelProvider { - private ArrayList fImages= new ArrayList(); + private ArrayList<Image> fImages= new ArrayList<>(); @Override public String getText(Object element) { @@ -61,9 +61,9 @@ class ShowSearchesAction extends Action { @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; } @@ -85,7 +85,7 @@ class ShowSearchesAction extends Action { } public void run(boolean showAll) { - Iterator iter= SearchManager.getDefault().getPreviousSearches().iterator(); + Iterator<Search> iter= SearchManager.getDefault().getPreviousSearches().iterator(); int cutOffSize; if (showAll) cutOffSize= 0; @@ -94,10 +94,10 @@ class ShowSearchesAction extends Action { int size= SearchManager.getDefault().getPreviousSearches().size() - cutOffSize; Search selectedSearch= SearchManager.getDefault().getCurrentSearch(); Action selectedAction = null; - ArrayList input= new ArrayList(size); + ArrayList<Action> input= new ArrayList<>(size); int i= 0; while (iter.hasNext()) { - Search search= (Search)iter.next(); + Search search= iter.next(); if (i++ < cutOffSize) continue; Action action= new ShowSearchAction(search); @@ -132,7 +132,7 @@ class ShowSearchesAction extends Action { dlg.setInitialSelections(selected); } if (dlg.open() == Window.OK) { - List result= Arrays.asList(dlg.getResult()); + List<Object> result= Arrays.asList(dlg.getResult()); if (result != null && result.size() == 1) { ((ShowSearchAction)result.get(0)).run(); } diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SortDropDownAction.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SortDropDownAction.java index 8e973814622..0130c9cc70c 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SortDropDownAction.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/SortDropDownAction.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 @@ -13,6 +13,7 @@ package org.eclipse.search.internal.ui; import java.util.HashMap; import java.util.Iterator; import java.util.Map; +import java.util.Map.Entry; import org.eclipse.swt.custom.BusyIndicator; import org.eclipse.swt.widgets.Control; @@ -40,12 +41,12 @@ class SortDropDownAction extends Action implements IMenuCreator { private static final String TAG_PAGE_ID= "pageId"; //$NON-NLS-1$ private static final String TAG_SORTER_ID= "sorterId"; //$NON-NLS-1$ - private static Map fgLastCheckedForType= new HashMap(5); + private static Map<String, SorterDescriptor> fgLastCheckedForType= new HashMap<>(5); private SearchResultViewer fViewer; private String fPageId; private Menu fMenu; - private Map fLastCheckedForType; + private Map<String, SorterDescriptor> fLastCheckedForType; public SortDropDownAction(SearchResultViewer viewer) { super(SearchMessages.SortDropDownAction_label); @@ -53,7 +54,7 @@ class SortDropDownAction extends Action implements IMenuCreator { fViewer= viewer; setToolTipText(SearchMessages.SortDropDownAction_tooltip); setMenuCreator(this); - fLastCheckedForType= new HashMap(5); + fLastCheckedForType= new HashMap<>(5); } @Override @@ -70,9 +71,9 @@ class SortDropDownAction extends Action implements IMenuCreator { void setPageId(String pageId) { fPageId= pageId; - SorterDescriptor sorterDesc= (SorterDescriptor)fLastCheckedForType.get(pageId); + SorterDescriptor sorterDesc= fLastCheckedForType.get(pageId); if (sorterDesc == null) - sorterDesc= (SorterDescriptor)fgLastCheckedForType.get(pageId); + sorterDesc= fgLastCheckedForType.get(pageId); if (sorterDesc == null) sorterDesc= findSorter(fPageId); if (sorterDesc != null) { @@ -90,7 +91,7 @@ class SortDropDownAction extends Action implements IMenuCreator { fMenu= new Menu(parent); - Iterator iter= SearchPlugin.getDefault().getSorterDescriptors().iterator(); + Iterator<SorterDescriptor> iter= SearchPlugin.getDefault().getSorterDescriptors().iterator(); while (iter.hasNext()) { Object value= fLastCheckedForType.get(fPageId); final String checkedId; @@ -99,7 +100,7 @@ class SortDropDownAction extends Action implements IMenuCreator { else checkedId= ""; //$NON-NLS-1$ - final SorterDescriptor sorterDesc= (SorterDescriptor) iter.next(); + final SorterDescriptor sorterDesc= iter.next(); if (!sorterDesc.getPageId().equals(fPageId) && !sorterDesc.getPageId().equals("*")) //$NON-NLS-1$ continue; final ViewerSorter sorter= sorterDesc.createObject(); @@ -139,9 +140,9 @@ class SortDropDownAction extends Action implements IMenuCreator { } private SorterDescriptor findSorter(String pageId) { - Iterator iter= SearchPlugin.getDefault().getSorterDescriptors().iterator(); + Iterator<SorterDescriptor> iter= SearchPlugin.getDefault().getSorterDescriptors().iterator(); while (iter.hasNext()) { - SorterDescriptor sorterDesc= (SorterDescriptor)iter.next(); + SorterDescriptor sorterDesc= iter.next(); if (sorterDesc.getPageId().equals(pageId) || sorterDesc.getPageId().equals("*")) //$NON-NLS-1$ return sorterDesc; } @@ -149,9 +150,9 @@ class SortDropDownAction extends Action implements IMenuCreator { } private SorterDescriptor getSorter(String sorterId) { - Iterator iter= SearchPlugin.getDefault().getSorterDescriptors().iterator(); + Iterator<SorterDescriptor> iter= SearchPlugin.getDefault().getSorterDescriptors().iterator(); while (iter.hasNext()) { - SorterDescriptor sorterDesc= (SorterDescriptor)iter.next(); + SorterDescriptor sorterDesc= iter.next(); if (sorterDesc.getId().equals(sorterId)) return sorterDesc; } @@ -184,7 +185,7 @@ class SortDropDownAction extends Action implements IMenuCreator { restoreState(memento, fgLastCheckedForType, TAG_DEFAULT_SORTERS); } - private void restoreState(IMemento memento, Map map, String mapName) { + private void restoreState(IMemento memento, Map<String, SorterDescriptor> map, String mapName) { memento= memento.getChild(mapName); if (memento == null) return; @@ -203,22 +204,22 @@ class SortDropDownAction extends Action implements IMenuCreator { saveState(memento, fLastCheckedForType, TAG_SORTERS); } - private void saveState(IMemento memento, Map map, String mapName) { - Iterator iter= map.entrySet().iterator(); + private void saveState(IMemento memento, Map<String, SorterDescriptor> map, String mapName) { + Iterator<Entry<String, SorterDescriptor>> iter= map.entrySet().iterator(); memento= memento.createChild(mapName); while (iter.hasNext()) { IMemento mementoElement= memento.createChild(TAG_ELEMENT); - Map.Entry entry= (Map.Entry)iter.next(); - mementoElement.putString(TAG_PAGE_ID, (String)entry.getKey()); - mementoElement.putString(TAG_SORTER_ID, ((SorterDescriptor)entry.getValue()).getId()); + Entry<String, SorterDescriptor> entry= iter.next(); + mementoElement.putString(TAG_PAGE_ID, entry.getKey()); + mementoElement.putString(TAG_SORTER_ID, entry.getValue().getId()); } } int getSorterCount() { int count= 0; - Iterator iter= SearchPlugin.getDefault().getSorterDescriptors().iterator(); + Iterator<SorterDescriptor> iter= SearchPlugin.getDefault().getSorterDescriptors().iterator(); while (iter.hasNext()) { - SorterDescriptor sorterDesc= (SorterDescriptor)iter.next(); + SorterDescriptor sorterDesc= iter.next(); if (sorterDesc.getPageId().equals(fPageId) || sorterDesc.getPageId().equals("*")) //$NON-NLS-1$ count++; } diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/WorkingSetComparator.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/WorkingSetComparator.java index 9fbc46976b7..075c3511a60 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/WorkingSetComparator.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/WorkingSetComparator.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 @@ -16,21 +16,14 @@ import com.ibm.icu.text.Collator; import org.eclipse.ui.IWorkingSet; -public class WorkingSetComparator implements Comparator { +public class WorkingSetComparator implements Comparator<IWorkingSet> { private Collator fCollator= Collator.getInstance(); @Override - public int compare(Object o1, Object o2) { - String name1= null; - String name2= null; - - if (o1 instanceof IWorkingSet) - name1= ((IWorkingSet)o1).getLabel(); - - if (o2 instanceof IWorkingSet) - name2= ((IWorkingSet)o2).getLabel(); - + public int compare(IWorkingSet o1, IWorkingSet o2) { + String name1= o1.getLabel(); + String name2= o2.getLabel(); return fCollator.compare(name1, name2); } } diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/EditorOpener.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/EditorOpener.java index 8b0744b8259..f907e685d61 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/EditorOpener.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/EditorOpener.java @@ -127,7 +127,7 @@ public class EditorOpener { IMarker marker= null; try { marker= file.createMarker(NewSearchUI.SEARCH_MARKER); - HashMap attributes= new HashMap(4); + HashMap<String, Integer> attributes= new HashMap<>(4); attributes.put(IMarker.CHAR_START, new Integer(offset)); attributes.put(IMarker.CHAR_END, new Integer(offset + length)); marker.setAttributes(attributes); diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileLabelProvider.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileLabelProvider.java index 6d90937d259..797e7f7a278 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileLabelProvider.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileLabelProvider.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 @@ -21,11 +21,11 @@ import org.eclipse.swt.graphics.Image; import org.eclipse.core.resources.IResource; +import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; import org.eclipse.jface.viewers.ILabelProviderListener; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.StyledCellLabelProvider; import org.eclipse.jface.viewers.StyledString; -import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider; import org.eclipse.ui.model.WorkbenchLabelProvider; @@ -48,7 +48,7 @@ public class FileLabelProvider extends LabelProvider implements IStyledLabelProv private final WorkbenchLabelProvider fLabelProvider; private final AbstractTextSearchViewPage fPage; - private final Comparator fMatchComparator; + private final Comparator<FileMatch> fMatchComparator; private final Image fLineMatchImage; @@ -59,10 +59,10 @@ public class FileLabelProvider extends LabelProvider implements IStyledLabelProv fOrder= orderFlag; fPage= page; fLineMatchImage= SearchPluginImages.get(SearchPluginImages.IMG_OBJ_TEXT_SEARCH_LINE); - fMatchComparator= new Comparator() { + fMatchComparator= new Comparator<FileMatch>() { @Override - public int compare(Object o1, Object o2) { - return ((FileMatch) o1).getOriginalOffset() - ((FileMatch) o2).getOriginalOffset(); + public int compare(FileMatch o1, FileMatch o2) { + return o1.getOriginalOffset() - o2.getOriginalOffset(); } }; } @@ -116,7 +116,7 @@ public class FileLabelProvider extends LabelProvider implements IStyledLabelProv StyledString str= new StyledString(lineNumberString, StyledString.QUALIFIER_STYLER); - Match[] matches= lineElement.getMatches(fPage.getInput()); + FileMatch[] matches= lineElement.getMatches(fPage.getInput()); Arrays.sort(matches, fMatchComparator); String content= lineElement.getContents(); @@ -127,7 +127,7 @@ public class FileLabelProvider extends LabelProvider implements IStyledLabelProv int charsToCut= getCharsToCut(length, matches); // number of characters to leave away if the line is too long for (int i= 0; i < matches.length; i++) { - FileMatch match= (FileMatch) matches[i]; + FileMatch match= matches[i]; int start= Math.max(match.getOriginalOffset() - lineElement.getOffset(), 0); // append gap between last match and the new one if (pos < start) { diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchPage.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchPage.java index a40dcf2e78e..55d54928f5b 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchPage.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchPage.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 @@ -104,7 +104,9 @@ public class FileSearchPage extends AbstractTextSearchViewPage implements IAdapt name1 = "";//$NON-NLS-1$ if (name2 == null) name2 = "";//$NON-NLS-1$ - return getComparator().compare(name1, name2); + @SuppressWarnings("unchecked") + int result= getComparator().compare(name1, name2); + return result; } } @@ -308,10 +310,11 @@ public class FileSearchPage extends AbstractTextSearchViewPage implements IAdapt memento.putInteger(KEY_LIMIT, getElementLimit().intValue()); } + @SuppressWarnings("unchecked") @Override - public Object getAdapter(Class adapter) { + public <T> T getAdapter(Class<T> adapter) { if (IShowInTargetList.class.equals(adapter)) { - return SHOW_IN_TARGET_LIST; + return (T) SHOW_IN_TARGET_LIST; } if (adapter == IShowInSource.class) { @@ -322,8 +325,8 @@ public class FileSearchPage extends AbstractTextSearchViewPage implements IAdapt ISelection selection= selectionProvider.getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection= ((StructuredSelection)selection); - final Set newSelection= new HashSet(structuredSelection.size()); - Iterator iter= structuredSelection.iterator(); + final Set<Object> newSelection= new HashSet<>(structuredSelection.size()); + Iterator<?> iter= structuredSelection.iterator(); while (iter.hasNext()) { Object element= iter.next(); if (element instanceof LineElement) @@ -331,10 +334,10 @@ public class FileSearchPage extends AbstractTextSearchViewPage implements IAdapt newSelection.add(element); } - return new IShowInSource() { + return (T) new IShowInSource() { @Override public ShowInContext getShowInContext() { - return new ShowInContext(null, new StructuredSelection(new ArrayList(newSelection))); + return new ShowInContext(null, new StructuredSelection(new ArrayList<>(newSelection))); } }; } @@ -395,7 +398,7 @@ public class FileSearchPage extends AbstractTextSearchViewPage implements IAdapt } @Override - protected void evaluateChangedElements(Match[] matches, Set changedElements) { + protected void evaluateChangedElements(Match[] matches, Set<Object> changedElements) { if (showLineMatches()) { for (int i = 0; i < matches.length; i++) { changedElements.add(((FileMatch) matches[i]).getLineElement()); diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchQuery.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchQuery.java index 04328300593..1b47a288596 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchQuery.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchQuery.java @@ -52,7 +52,7 @@ public class FileSearchQuery implements ISearchQuery { private final boolean fSearchInBinaries; private final boolean fIsLightweightAutoRefresh; - private Map fCachedMatches; // map of IFile -> ArrayList of FileMatches + private Map<IFile, ArrayList<FileMatch>> fCachedMatches; private Object fLock= new Object(); private TextSearchResultCollector(AbstractTextSearchResult result, boolean isFileSearchOnly, boolean searchInBinaries) { @@ -89,7 +89,7 @@ public class FileSearchQuery implements ISearchQuery { @Override public boolean acceptPatternMatch(TextSearchMatchAccess matchRequestor) throws CoreException { - ArrayList matches; + ArrayList<FileMatch> matches; synchronized(fLock) { // fCachedMatches is set to null when the caller invokes endReporting(), // indicating that no further results are desired/expected, so discard @@ -97,7 +97,7 @@ public class FileSearchQuery implements ISearchQuery { if (fCachedMatches == null) { return false; } - matches= (ArrayList) fCachedMatches.get(matchRequestor.getFile()); + matches= fCachedMatches.get(matchRequestor.getFile()); } int matchOffset= matchRequestor.getMatchOffset(); @@ -120,9 +120,9 @@ public class FileSearchQuery implements ISearchQuery { if (fCachedMatches == null) { return false; } - matches= (ArrayList) fCachedMatches.get(matchRequestor.getFile()); + matches= fCachedMatches.get(matchRequestor.getFile()); if (matches == null) { - matches= new ArrayList(); + matches= new ArrayList<>(); fCachedMatches.put(matchRequestor.getFile(), matches); } matches.add(fileMatch); @@ -131,13 +131,13 @@ public class FileSearchQuery implements ISearchQuery { return true; } - private LineElement getLineElement(int offset, TextSearchMatchAccess matchRequestor, ArrayList matches) { + private LineElement getLineElement(int offset, TextSearchMatchAccess matchRequestor, ArrayList<FileMatch> matches) { int lineNumber= 1; int lineStart= 0; if (matches != null) { // match on same line as last? - FileMatch last= (FileMatch) matches.get(matches.size() - 1); + FileMatch last= matches.get(matches.size() - 1); LineElement lineElement= last.getLineElement(); if (lineElement.contains(offset)) { return lineElement; @@ -188,7 +188,7 @@ public class FileSearchQuery implements ISearchQuery { @Override public void beginReporting() { - fCachedMatches= new HashMap(); + fCachedMatches= new HashMap<>(); } @Override @@ -202,10 +202,10 @@ public class FileSearchQuery implements ISearchQuery { private void flushMatches() { synchronized (fLock) { if (fCachedMatches != null && !fCachedMatches.isEmpty()) { - Iterator it = fCachedMatches.values().iterator(); + Iterator<ArrayList<FileMatch>> it = fCachedMatches.values().iterator(); while(it.hasNext()) { - ArrayList matches= (ArrayList) it.next(); - fResult.addMatches((Match[]) matches.toArray(new Match[matches.size()])); + ArrayList<FileMatch> matches= it.next(); + fResult.addMatches(matches.toArray(new Match[matches.size()])); } fCachedMatches.clear(); } diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileTreeContentProvider.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileTreeContentProvider.java index d891cd5e2e7..8ee249cb20e 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileTreeContentProvider.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileTreeContentProvider.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 @@ -36,7 +36,7 @@ public class FileTreeContentProvider implements ITreeContentProvider, IFileSearc private AbstractTextSearchResult fResult; private FileSearchPage fPage; private AbstractTreeViewer fTreeViewer; - private Map fChildrenMap; + private Map<Object, Set<Object>> fChildrenMap; FileTreeContentProvider(FileSearchPage page, AbstractTreeViewer viewer) { fPage= page; @@ -73,7 +73,7 @@ public class FileTreeContentProvider implements ITreeContentProvider, IFileSearc private synchronized void initialize(AbstractTextSearchResult result) { fResult= result; - fChildrenMap= new HashMap(); + fChildrenMap= new HashMap<>(); boolean showLineMatches= !((FileSearchQuery) fResult.getQuery()).isFileNameSearch(); if (result != null) { @@ -120,16 +120,16 @@ public class FileTreeContentProvider implements ITreeContentProvider, IFileSearc */ private boolean insertChild(Object parent, Object child) { - Set children= (Set) fChildrenMap.get(parent); + Set<Object> children= fChildrenMap.get(parent); if (children == null) { - children= new HashSet(); + children= new HashSet<>(); fChildrenMap.put(parent, children); } return children.add(child); } private boolean hasChild(Object parent, Object child) { - Set children= (Set) fChildrenMap.get(parent); + Set<Object> children= fChildrenMap.get(parent); return children != null && children.contains(child); } @@ -170,7 +170,7 @@ public class FileTreeContentProvider implements ITreeContentProvider, IFileSearc private void removeFromSiblings(Object element, Object parent) { - Set siblings= (Set) fChildrenMap.get(parent); + Set<Object> siblings= fChildrenMap.get(parent); if (siblings != null) { siblings.remove(element); } @@ -178,7 +178,7 @@ public class FileTreeContentProvider implements ITreeContentProvider, IFileSearc @Override public Object[] getChildren(Object parentElement) { - Set children= (Set) fChildrenMap.get(parentElement); + Set<Object> children= fChildrenMap.get(parentElement); if (children == null) return EMPTY_ARR; return children.toArray(); diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/LineElement.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/LineElement.java index 7d0e0c1019e..cb9c0d2ff16 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/LineElement.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/LineElement.java @@ -62,7 +62,7 @@ public class LineElement { } public FileMatch[] getMatches(AbstractTextSearchResult result) { - ArrayList res= new ArrayList(); + ArrayList<FileMatch> res= new ArrayList<>(); Match[] matches= result.getMatches(fParent); for (int i= 0; i < matches.length; i++) { FileMatch curr= (FileMatch) matches[i]; @@ -70,7 +70,7 @@ public class LineElement { res.add(curr); } } - return (FileMatch[]) res.toArray(new FileMatch[res.size()]); + return res.toArray(new FileMatch[res.size()]); } public int getNumberOfMatches(AbstractTextSearchResult result) { diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceConfigurationPage.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceConfigurationPage.java index 838c4a6828e..ee0710c580a 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceConfigurationPage.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceConfigurationPage.java @@ -196,7 +196,7 @@ public class ReplaceConfigurationPage extends UserInputWizardPage { private void storeSettings() { String[] items= fTextField.getItems(); - ArrayList history= new ArrayList(); + ArrayList<String> history= new ArrayList<>(); history.add(fTextField.getText()); int historySize= Math.min(items.length, 6); for (int i= 0; i < historySize; i++) { @@ -206,7 +206,7 @@ public class ReplaceConfigurationPage extends UserInputWizardPage { } } IDialogSettings settings= SearchPlugin.getDefault().getDialogSettings().addNewSection(SETTINGS_GROUP); - settings.put(SETTINGS_REPLACE_WITH, (String[]) history.toArray(new String[history.size()])); + settings.put(SETTINGS_REPLACE_WITH, history.toArray(new String[history.size()])); } diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceRefactoring.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceRefactoring.java index 67bde0296be..c8d7bcee13c 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceRefactoring.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceRefactoring.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 IBM Corporation and others. + * Copyright (c) 2007, 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 @@ -19,6 +19,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; @@ -87,16 +88,16 @@ public class ReplaceRefactoring extends Refactoring { private MatchGroup[] fMatchGroups; private Match[] fMatches; - private Map/*<URI,ArrayList<Match>*/ fIgnoredMatches; + private Map<URI, ArrayList<FileMatch>> fIgnoredMatches; private final FileSearchResult fResult; private final boolean fIsRemove; - public SearchResultUpdateChange(FileSearchResult result, MatchGroup[] matchGroups, Map ignoredMatches) { + public SearchResultUpdateChange(FileSearchResult result, MatchGroup[] matchGroups, Map<URI, ArrayList<FileMatch>> ignoredMatches) { this(result, null, ignoredMatches, true); fMatchGroups= matchGroups; } - private SearchResultUpdateChange(FileSearchResult result, Match[] matches, Map ignoredMatches, boolean isRemove) { + private SearchResultUpdateChange(FileSearchResult result, Match[] matches, Map<URI, ArrayList<FileMatch>> ignoredMatches, boolean isRemove) { fResult= result; fMatches= matches; fIgnoredMatches= ignoredMatches; @@ -124,7 +125,7 @@ public class ReplaceRefactoring extends Refactoring { private Match[] getMatches() { if (fMatches == null) { - ArrayList matches= new ArrayList(); + ArrayList<FileMatch> matches= new ArrayList<>(); for (int i= 0; i < fMatchGroups.length; i++) { MatchGroup curr= fMatchGroups[i]; if (curr.group.isEnabled()) { @@ -138,13 +139,13 @@ public class ReplaceRefactoring extends Refactoring { IFile file= match.getFile(); URI uri= file.getLocationURI(); if (uri != null) { - ArrayList ignoredMatches= (ArrayList)fIgnoredMatches.get(uri); + ArrayList<FileMatch> ignoredMatches= fIgnoredMatches.get(uri); if (ignoredMatches != null) matches.addAll(ignoredMatches); } } } - fMatches= (Match[]) matches.toArray(new Match[matches.size()]); + fMatches= matches.toArray(new Match[matches.size()]); fMatchGroups= null; } return fMatches; @@ -168,13 +169,13 @@ public class ReplaceRefactoring extends Refactoring { private final FileSearchResult fResult; private final Object[] fSelection; - private final HashMap/*<IFile,Set<Match>*/ fMatches; + private final HashMap<IFile, Set<FileMatch>> fMatches; /** Map that keeps already collected locations. */ - private final Map/*<URI,IFile>*/fAlreadyCollected; + private final Map<URI, IFile> fAlreadyCollected; /** Map that keeps ignored matches (can be null). */ - private Map/*<URI,ArrayList<Match>*/ fIgnoredMatches; + private Map<URI, ArrayList<FileMatch>> fIgnoredMatches; private String fReplaceString; @@ -186,8 +187,8 @@ public class ReplaceRefactoring extends Refactoring { fResult= result; fSelection= selection; - fMatches= new HashMap(); - fAlreadyCollected= new HashMap(selection != null ? selection.length : result.getElements().length); + fMatches= new HashMap<>(); + fAlreadyCollected= new HashMap<>(selection != null ? selection.length : result.getElements().length); fReplaceString= null; } @@ -244,7 +245,7 @@ public class ReplaceRefactoring extends Refactoring { } else if (object instanceof IFile) { Match[] matches= fResult.getMatches(object); if (matches.length > 0) { - Collection bucket= null; + Collection<FileMatch> bucket= null; for (int i= 0; i < matches.length; i++) { FileMatch fileMatch= (FileMatch) matches[i]; if (isMatchToBeIncluded(fileMatch)) { @@ -264,8 +265,8 @@ public class ReplaceRefactoring extends Refactoring { public int getNumberOfMatches() { int count= 0; - for (Iterator iterator= fMatches.values().iterator(); iterator.hasNext();) { - Collection bucket= (Collection) iterator.next(); + for (Iterator<Set<FileMatch>> iterator= fMatches.values().iterator(); iterator.hasNext();) { + Set<FileMatch> bucket= iterator.next(); count += bucket.size(); } return count; @@ -289,17 +290,17 @@ public class ReplaceRefactoring extends Refactoring { if (uri == null) return true; - for (Iterator iter= fAlreadyCollected.keySet().iterator(); iter.hasNext();) { - if (URIUtil.equals((URI)iter.next(), uri)) { + for (Iterator<URI> iter= fAlreadyCollected.keySet().iterator(); iter.hasNext();) { + if (URIUtil.equals(iter.next(), uri)) { if (file.equals(fAlreadyCollected.get(uri))) return true; // another FileMatch for an IFile which already had matches if (fIgnoredMatches == null) - fIgnoredMatches= new HashMap(); + fIgnoredMatches= new HashMap<>(); - ArrayList matches= (ArrayList)fIgnoredMatches.get(uri); + ArrayList<FileMatch> matches= fIgnoredMatches.get(uri); if (matches == null) { - matches= new ArrayList(); + matches= new ArrayList<>(); fIgnoredMatches.put(uri, matches); } matches.add(match); @@ -312,13 +313,13 @@ public class ReplaceRefactoring extends Refactoring { return true; } - private Collection getBucket(IFile file) { - Collection col= (Collection) fMatches.get(file); - if (col == null) { - col= new HashSet(); - fMatches.put(file, col); + private Set<FileMatch> getBucket(IFile file) { + Set<FileMatch> set= fMatches.get(file); + if (set == null) { + set= new HashSet<>(); + fMatches.put(file, set); } - return col; + return set; } @Override @@ -335,14 +336,14 @@ public class ReplaceRefactoring extends Refactoring { RefactoringStatus resultingStatus= new RefactoringStatus(); - Collection allFilesSet= fMatches.keySet(); - IFile[] allFiles= (IFile[]) allFilesSet.toArray(new IFile[allFilesSet.size()]); - Arrays.sort(allFiles, new Comparator() { + Collection<IFile> allFilesSet= fMatches.keySet(); + IFile[] allFiles= allFilesSet.toArray(new IFile[allFilesSet.size()]); + Arrays.sort(allFiles, new Comparator<IFile>() { private Collator fCollator= Collator.getInstance(); @Override - public int compare(Object o1, Object o2) { - String p1= ((IFile) o1).getFullPath().toString(); - String p2= ((IFile) o2).getFullPath().toString(); + public int compare(IFile o1, IFile o2) { + String p1= o1.getFullPath().toString(); + String p2= o2.getFullPath().toString(); return fCollator.compare(p1, p2); } }); @@ -354,12 +355,12 @@ public class ReplaceRefactoring extends Refactoring { CompositeChange compositeChange= new CompositeChange(SearchMessages.ReplaceRefactoring_composite_change_name); compositeChange.markAsSynthetic(); - ArrayList matchGroups= new ArrayList(); + ArrayList<MatchGroup> matchGroups= new ArrayList<>(); boolean hasChanges= false; try { for (int i= 0; i < allFiles.length; i++) { IFile file= allFiles[i]; - Collection bucket= (Collection) fMatches.get(file); + Set<FileMatch> bucket= fMatches.get(file); if (!bucket.isEmpty()) { try { TextChange change= createFileChange(file, pattern, bucket, resultingStatus, matchGroups); @@ -381,20 +382,20 @@ public class ReplaceRefactoring extends Refactoring { return RefactoringStatus.createFatalErrorStatus(SearchMessages.ReplaceRefactoring_error_no_changes); } - compositeChange.add(new SearchResultUpdateChange(fResult, (MatchGroup[])matchGroups.toArray(new MatchGroup[matchGroups.size()]), fIgnoredMatches)); + compositeChange.add(new SearchResultUpdateChange(fResult, matchGroups.toArray(new MatchGroup[matchGroups.size()]), fIgnoredMatches)); fChange= compositeChange; return resultingStatus; } private void checkFilesToBeChanged(IFile[] filesToBeChanged, RefactoringStatus resultingStatus) throws CoreException { - ArrayList readOnly= new ArrayList(); + ArrayList<IFile> readOnly= new ArrayList<>(); for (int i= 0; i < filesToBeChanged.length; i++) { IFile file= filesToBeChanged[i]; if (file.isReadOnly()) readOnly.add(file); } - IFile[] readOnlyFiles= (IFile[]) readOnly.toArray(new IFile[readOnly.size()]); + IFile[] readOnlyFiles= readOnly.toArray(new IFile[readOnly.size()]); IStatus status= ResourcesPlugin.getWorkspace().validateEdit(readOnlyFiles, getValidationContext()); if (status.getSeverity() == IStatus.CANCEL) { @@ -407,7 +408,7 @@ public class ReplaceRefactoring extends Refactoring { resultingStatus.merge(ResourceChangeChecker.checkFilesToBeChanged(filesToBeChanged, null)); } - private TextChange createFileChange(IFile file, Pattern pattern, Collection/*FileMatch*/ matches, RefactoringStatus resultingStatus, Collection matchGroups) throws PatternSyntaxException, CoreException { + private TextChange createFileChange(IFile file, Pattern pattern, Set<FileMatch> matches, RefactoringStatus resultingStatus, Collection<MatchGroup> matchGroups) throws PatternSyntaxException, CoreException { PositionTracker tracker= InternalSearchUI.getInstance().getPositionTracker(); TextFileChange change= new TextFileChange(Messages.format(SearchMessages.ReplaceRefactoring_group_label_change_for_file, file.getName()), file); @@ -424,8 +425,8 @@ public class ReplaceRefactoring extends Refactoring { IDocument document= textFileBuffer.getDocument(); String lineDelimiter= TextUtilities.getDefaultLineDelimiter(document); - for (Iterator iterator= matches.iterator(); iterator.hasNext();) { - FileMatch match= (FileMatch) iterator.next(); + for (Iterator<FileMatch> iterator= matches.iterator(); iterator.hasNext();) { + FileMatch match= iterator.next(); int offset= match.getOffset(); int length= match.getLength(); Position currentPosition= tracker.getCurrentPosition(match); diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchPage.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchPage.java index 039f1128bfb..5d81904ee4f 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchPage.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/TextSearchPage.java @@ -112,7 +112,7 @@ public class TextSearchPage extends DialogPage implements ISearchPage, IReplaceP */ private static final String STORE_EXTENSIONS= "EXTENSIONS"; //$NON-NLS-1$ - private List fPreviousSearchPatterns= new ArrayList(HISTORY_SIZE); + private List<SearchPatternData> fPreviousSearchPatterns= new ArrayList<>(HISTORY_SIZE); private boolean fFirstTime= true; private boolean fIsCaseSensitive; @@ -336,10 +336,10 @@ public class TextSearchPage extends DialogPage implements ISearchPage, IReplaceP } private FileTextSearchScope getSelectedResourcesScope() { - HashSet resources= new HashSet(); + HashSet<IResource> resources= new HashSet<>(); ISelection sel= getContainer().getSelection(); if (sel instanceof IStructuredSelection && !sel.isEmpty()) { - Iterator iter= ((IStructuredSelection) sel).iterator(); + Iterator<?> iter= ((IStructuredSelection) sel).iterator(); while (iter.hasNext()) { Object curr= iter.next(); if (curr instanceof IWorkingSet) { @@ -368,7 +368,7 @@ public class TextSearchPage extends DialogPage implements ISearchPage, IReplaceP } else if (getContainer().getActiveEditorInput() != null) { resources.add(getContainer().getActiveEditorInput().getAdapter(IFile.class)); } - IResource[] arr= (IResource[]) resources.toArray(new IResource[resources.size()]); + IResource[] arr= resources.toArray(new IResource[resources.size()]); return FileTextSearchScope.newSearchScope(arr, getExtensions(), fSearchDerived); } @@ -389,8 +389,8 @@ public class TextSearchPage extends DialogPage implements ISearchPage, IReplaceP private SearchPatternData findInPrevious(String pattern) { - for (Iterator iter= fPreviousSearchPatterns.iterator(); iter.hasNext();) { - SearchPatternData element= (SearchPatternData) iter.next(); + for (Iterator<SearchPatternData> iter= fPreviousSearchPatterns.iterator(); iter.hasNext();) { + SearchPatternData element= iter.next(); if (pattern.equals(element.textPattern)) { return element; } @@ -421,22 +421,22 @@ public class TextSearchPage extends DialogPage implements ISearchPage, IReplaceP } private String[] getPreviousExtensionsOldStyle() { - List extensions= new ArrayList(fPreviousSearchPatterns.size()); + List<String> extensions= new ArrayList<>(fPreviousSearchPatterns.size()); int size= fPreviousSearchPatterns.size(); for (int i= 0; i < size; i++) { - SearchPatternData data= (SearchPatternData)fPreviousSearchPatterns.get(i); + SearchPatternData data= fPreviousSearchPatterns.get(i); String text= FileTypeEditor.typesToString(data.fileNamePatterns); if (!extensions.contains(text)) extensions.add(text); } - return (String[])extensions.toArray(new String[extensions.size()]); + return extensions.toArray(new String[extensions.size()]); } private String[] getPreviousSearchPatterns() { int size= fPreviousSearchPatterns.size(); String [] patterns= new String[size]; for (int i= 0; i < size; i++) - patterns[i]= ((SearchPatternData) fPreviousSearchPatterns.get(i)).textPattern; + patterns[i]= fPreviousSearchPatterns.get(i).textPattern; return patterns; } @@ -632,7 +632,7 @@ public class TextSearchPage extends DialogPage implements ISearchPage, IReplaceP if (selectionIndex < 0 || selectionIndex >= fPreviousSearchPatterns.size()) return; - SearchPatternData patternData= (SearchPatternData) fPreviousSearchPatterns.get(selectionIndex); + SearchPatternData patternData= fPreviousSearchPatterns.get(selectionIndex); if (!fPattern.getText().equals(patternData.textPattern)) return; fIsCaseSensitiveCheckbox.setSelection(patternData.isCaseSensitive); @@ -852,7 +852,7 @@ public class TextSearchPage extends DialogPage implements ISearchPage, IReplaceP // ignore } - Set previousExtensions= new LinkedHashSet(HISTORY_SIZE); + Set<String> previousExtensions= new LinkedHashSet<>(HISTORY_SIZE); IDialogSettings extensionsSettings= s.getSection(STORE_EXTENSIONS); if (extensionsSettings != null) { for (int i= 0; i < HISTORY_SIZE; i++) { @@ -883,13 +883,13 @@ public class TextSearchPage extends DialogPage implements ISearchPage, IReplaceP s.put(STORE_HISTORY_SIZE, historySize); for (int i= 0; i < historySize; i++) { IDialogSettings histSettings= s.addNewSection(STORE_HISTORY + i); - SearchPatternData data= ((SearchPatternData) fPreviousSearchPatterns.get(i)); + SearchPatternData data= fPreviousSearchPatterns.get(i); data.store(histSettings); } IDialogSettings extensionsSettings= s.addNewSection(STORE_EXTENSIONS); extensionsSettings.put(Integer.toString(0), fExtensions.getText()); - Set extensions= new HashSet(HISTORY_SIZE); + Set<String> extensions= new HashSet<>(HISTORY_SIZE); extensions.add(fExtensions.getText()); int length= Math.min(fExtensions.getItemCount(), HISTORY_SIZE - 1); int j= 1; diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/ExtendedDialogWindow.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/util/ExtendedDialogWindow.java index c479282aaa0..70819f64665 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/ExtendedDialogWindow.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/util/ExtendedDialogWindow.java @@ -47,7 +47,7 @@ public abstract class ExtendedDialogWindow extends TrayDialog implements IRunnab private Control fContents; private Button fCancelButton; - private List fActionButtons; + private List<Button> fActionButtons; // The number of long running operation executed from the dialog. private long fActiveRunningOperations; @@ -60,7 +60,7 @@ public abstract class ExtendedDialogWindow extends TrayDialog implements IRunnab public ExtendedDialogWindow(Shell shell) { super(shell); - fActionButtons= new ArrayList(); + fActionButtons= new ArrayList<>(); } @Override @@ -174,8 +174,8 @@ public abstract class ExtendedDialogWindow extends TrayDialog implements IRunnab * @param state The new state */ public void setPerformActionEnabled(boolean state) { - for (Iterator buttons = fActionButtons.iterator(); buttons.hasNext(); ) { - Button element = (Button) buttons.next(); + for (Iterator<Button> buttons = fActionButtons.iterator(); buttons.hasNext(); ) { + Button element = buttons.next(); element.setEnabled(state); } } @@ -211,7 +211,7 @@ public abstract class ExtendedDialogWindow extends TrayDialog implements IRunnab * @return The saved UI state. */ protected synchronized Object aboutToStart(boolean enableCancelButton) { - HashMap savedState= null; + HashMap<Object, Object> savedState= null; Shell shell= getShell(); if (shell != null) { Display d= shell.getDisplay(); @@ -257,7 +257,8 @@ public abstract class ExtendedDialogWindow extends TrayDialog implements IRunnab fProgressMonitorPart.removeFromCancelComponent(fCancelButton); } - HashMap state= (HashMap)savedState; + @SuppressWarnings("unchecked") + HashMap<Object, Object> state= (HashMap<Object, Object>)savedState; restoreUIState(state); setDisplayCursor(shell.getDisplay(), null); @@ -276,10 +277,10 @@ public abstract class ExtendedDialogWindow extends TrayDialog implements IRunnab //---- UI state save and restoring --------------------------------------------- - private void restoreUIState(HashMap state) { + private void restoreUIState(HashMap<Object, Object> state) { restoreEnableState(fCancelButton, state); - for (Iterator actionButtons = fActionButtons.iterator(); actionButtons.hasNext(); ) { - Button button = (Button) actionButtons.next(); + for (Iterator<Button> actionButtons = fActionButtons.iterator(); actionButtons.hasNext(); ) { + Button button = actionButtons.next(); restoreEnableState(button, state); } ControlEnableState pageState= (ControlEnableState)state.get("tabForm"); //$NON-NLS-1$ @@ -289,7 +290,7 @@ public abstract class ExtendedDialogWindow extends TrayDialog implements IRunnab /* * Restores the enable state of the given control. */ - protected void restoreEnableState(Control w, HashMap h) { + protected void restoreEnableState(Control w, HashMap<Object, Object> h) { if (!w.isDisposed()) { Boolean b= (Boolean)h.get(w); if (b != null) @@ -297,11 +298,11 @@ public abstract class ExtendedDialogWindow extends TrayDialog implements IRunnab } } - private HashMap saveUIState(boolean keepCancelEnabled) { - HashMap savedState= new HashMap(10); + private HashMap<Object, Object> saveUIState(boolean keepCancelEnabled) { + HashMap<Object, Object> savedState= new HashMap<>(10); saveEnableStateAndSet(fCancelButton, savedState, keepCancelEnabled); - for (Iterator actionButtons = fActionButtons.iterator(); actionButtons.hasNext(); ) { - Button button = (Button) actionButtons.next(); + for (Iterator<Button> actionButtons = fActionButtons.iterator(); actionButtons.hasNext(); ) { + Button button = actionButtons.next(); saveEnableStateAndSet(button, savedState, false); } savedState.put("tabForm", ControlEnableState.disable(fContents)); //$NON-NLS-1$ @@ -309,7 +310,7 @@ public abstract class ExtendedDialogWindow extends TrayDialog implements IRunnab return savedState; } - private void saveEnableStateAndSet(Control w, HashMap h, boolean enabled) { + private void saveEnableStateAndSet(Control w, HashMap<Object, Object> h, boolean enabled) { if (!w.isDisposed()) { h.put(w, Boolean.valueOf(w.isEnabled())); w.setEnabled(enabled); diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/FileLabelProvider.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/util/FileLabelProvider.java index 9c7418971d8..91bae8fe13a 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/FileLabelProvider.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/util/FileLabelProvider.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 @@ -45,7 +45,7 @@ public class FileLabelProvider extends LabelProvider { private ILabelDecorator fDecorator; private int fOrder; - private String[] fArgs= new String[2]; + private Object[] fArgs= new String[2]; public FileLabelProvider(int orderFlag) { fDecorator= PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator(); diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/FileTypeEditor.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/util/FileTypeEditor.java index e5fb3e9cacc..f8cd8e8928e 100644 --- a/org.eclipse.search/search/org/eclipse/search/internal/ui/util/FileTypeEditor.java +++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/util/FileTypeEditor.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,11 +38,8 @@ public class FileTypeEditor extends SelectionAdapter implements DisposeListener private final static String TYPE_DELIMITER= SearchMessages.FileTypeEditor_typeDelimiter; public final static String FILE_PATTERN_NEGATOR= "!"; //$NON-NLS-1$ - private static final Comparator FILE_TYPES_COMPARATOR= new Comparator() { + private static final Comparator<String> FILE_TYPES_COMPARATOR= new Comparator<String>() { @Override - public int compare(Object o1, Object o2) { - return compare((String) o1, (String) o2); - } public int compare(String fp1, String fp2) { boolean isNegative1= fp1.startsWith(FILE_PATTERN_NEGATOR); boolean isNegative2= fp2.startsWith(FILE_PATTERN_NEGATOR); @@ -78,14 +75,14 @@ public class FileTypeEditor extends SelectionAdapter implements DisposeListener } public String[] getFileTypes() { - Set result= new HashSet(); + Set<String> result= new HashSet<>(); StringTokenizer tokenizer= new StringTokenizer(fTextField.getText(), TYPE_DELIMITER); while (tokenizer.hasMoreTokens()) { String currentExtension= tokenizer.nextToken().trim(); result.add(currentExtension); } - return (String[]) result.toArray(new String[result.size()]); + return result.toArray(new String[result.size()]); } public void setFileTypes(String[] types) { @@ -96,7 +93,7 @@ public class FileTypeEditor extends SelectionAdapter implements DisposeListener TypeFilteringDialog dialog= new TypeFilteringDialog(fTextField.getShell(), Arrays.asList(getFileTypes())); if (dialog.open() == Window.OK) { Object[] result= dialog.getResult(); - HashSet patterns= new HashSet(); + HashSet<String> patterns= new HashSet<>(); boolean starIncluded= false; for (int i= 0; i < result.length; i++) { String curr= result[i].toString(); @@ -109,7 +106,7 @@ public class FileTypeEditor extends SelectionAdapter implements DisposeListener if (patterns.isEmpty() && starIncluded) { // remove star when other file extensions active patterns.add("*"); //$NON-NLS-1$ } - String[] filePatterns= (String[]) patterns.toArray(new String[patterns.size()]); + String[] filePatterns= patterns.toArray(new String[patterns.size()]); Arrays.sort(filePatterns); setFileTypes(filePatterns); } |