From 9f2a9d2fb6a39c9e7b82eac18746ec17de6d8148 Mon Sep 17 00:00:00 2001 From: Alexander Kurtakov Date: Wed, 7 Feb 2018 18:42:21 +0200 Subject: Bug 530854 - Move away of methods deprecated in Java 9 Number constructors and Class.newInstance. Some small cleanups (generification, lambdas) in surrounding code. Change-Id: I62bab4119a98a7b5df560b8c9247f79fdfa8da03 Signed-off-by: Alexander Kurtakov --- .../compare/internal/DocLineComparator.java | 4 +-- .../eclipse/core/internal/net/ProxyManager.java | 4 +-- .../team/internal/ccvs/ui/CVSHistoryPage.java | 4 +-- .../team/internal/ccvs/ui/CVSPreferencesPage.java | 18 +++++------ .../internal/ccvs/ui/SelectionPropertyTester.java | 12 ++----- .../mapping/IgnoreLeadingPathSegmentsAction.java | 30 +++++++----------- .../compare/examples/xml/XMLStructureViewer.java | 37 ++++++---------------- .../eclipse/compare/tests/TextMergeViewerTest.java | 16 +++------- 8 files changed, 44 insertions(+), 81 deletions(-) diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/DocLineComparator.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/DocLineComparator.java index 5b417a4ba..9bb2fadce 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/DocLineComparator.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/DocLineComparator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2018 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 @@ -207,7 +207,7 @@ public class DocLineComparator implements ITokenComparator { if (fCompareFilters != null && fCompareFilters.length > 0) { if (fCompareFilterCache != null && other.fCompareFilterCache != null) { - extracts[0] = (String) fCompareFilterCache.get(new Integer( + extracts[0] = (String) fCompareFilterCache.get(Integer.valueOf( thisIndex)); if (extracts[0] == null) { extracts[0] = Utilities.applyCompareFilters( diff --git a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxyManager.java b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxyManager.java index 234a32907..f8fd8deb5 100644 --- a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxyManager.java +++ b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxyManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2017 IBM Corporation and others. + * Copyright (c) 2007, 2018 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 @@ -60,7 +60,7 @@ public class ProxyManager implements IProxyService, IPreferenceChangeListener { private ProxyManager() { try { nativeProxyProvider = (AbstractProxyProvider) Class.forName( - "org.eclipse.core.net.ProxyProvider").newInstance(); //$NON-NLS-1$ + "org.eclipse.core.net.ProxyProvider").getDeclaredConstructor().newInstance(); //$NON-NLS-1$ } catch (ClassNotFoundException e) { // no class found } catch (Exception e) { diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSHistoryPage.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSHistoryPage.java index b28aa9c58..7808d2645 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSHistoryPage.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSHistoryPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2012 IBM Corporation and others. + * Copyright (c) 2006, 2018 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 @@ -2133,7 +2133,7 @@ public class CVSHistoryPage extends HistoryPage implements IAdaptable, IHistoryC if (historyPageSite instanceof WorkbenchHistoryPageSite){ IWorkbenchPart part = ((WorkbenchHistoryPageSite) historyPageSite).getPart(); if (part instanceof GenericHistoryView){ - String revisions = NLS.bind(CVSUIMessages.CVSHistoryPage_FilterOnMessage, new Object[]{Integer.valueOf(historyFilter.getMatchCount()),new Integer(before)}); + String revisions = NLS.bind(CVSUIMessages.CVSHistoryPage_FilterOnMessage, new Object[]{Integer.valueOf(historyFilter.getMatchCount()),Integer.valueOf(before)}); String old = getName(); description = NLS.bind(CVSUIMessages.CVSHistoryPage_FilterDescription, new Object[]{file.getName(), revisions}); CVSHistoryPage.this.firePropertyChange(CVSHistoryPage.this, P_NAME, old, getName()); diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSPreferencesPage.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSPreferencesPage.java index 15a095d22..c428985d1 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSPreferencesPage.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSPreferencesPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2018 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 @@ -292,19 +292,17 @@ public class CVSPreferencesPage extends PreferencePage implements IWorkbenchPref fFields= new ArrayList(); final KSubstOption[] options = KSubstOption.getAllKSubstOptions(); - final ArrayList KSUBST_MODES= new ArrayList(); + final ArrayList KSUBST_MODES= new ArrayList<>(); for (int i = 0; i < options.length; i++) { final KSubstOption option = options[i]; if (!option.isBinary()) { KSUBST_MODES.add(option); } } - Collections.sort(KSUBST_MODES, new Comparator() { - public int compare(Object a, Object b) { - final String aKey = ((KSubstOption) a).getLongDisplayText(); - final String bKey = ((KSubstOption) b).getLongDisplayText(); - return aKey.compareTo(bKey); - } + Collections.sort(KSUBST_MODES, (a, b) -> { + final String aKey = a.getLongDisplayText(); + final String bKey = b.getLongDisplayText(); + return aKey.compareTo(bKey); }); KSUBST_LABELS= new String[KSUBST_MODES.size()]; @@ -462,7 +460,7 @@ public class CVSPreferencesPage extends PreferencePage implements IWorkbenchPref CVSUIMessages.CVSPreferencesPage_26, IHelpContextIds.PREF_QUIET, new String [] { CVSUIMessages.CVSPreferencesPage_27, CVSUIMessages.CVSPreferencesPage_28, CVSUIMessages.CVSPreferencesPage_29 }, // - new Integer [] { Integer.valueOf(0), new Integer(1), new Integer(2)}); + new Integer [] { Integer.valueOf(0), Integer.valueOf(1), Integer.valueOf(2)}); quietnessCombo.getCombo().addSelectionListener(new SelectionListener() { public void widgetSelected(SelectionEvent e) { @@ -531,7 +529,7 @@ public class CVSPreferencesPage extends PreferencePage implements IWorkbenchPref CVSUIMessages.CVSPreferencesPage_41, IHelpContextIds.PREF_SAVE_DIRTY_EDITORS, YES_NO_PROMPT, - new Integer [] { Integer.valueOf(ICVSUIConstants.OPTION_AUTOMATIC), new Integer(ICVSUIConstants.OPTION_NEVER), new Integer(ICVSUIConstants.OPTION_PROMPT)}); + new Integer [] { Integer.valueOf(ICVSUIConstants.OPTION_AUTOMATIC), Integer.valueOf(ICVSUIConstants.OPTION_NEVER), Integer.valueOf(ICVSUIConstants.OPTION_PROMPT)}); new StringRadioButtons( composite, diff --git a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/SelectionPropertyTester.java b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/SelectionPropertyTester.java index 2b97b5f52..e85c9e011 100644 --- a/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/SelectionPropertyTester.java +++ b/bundles/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/SelectionPropertyTester.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2018 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 @@ -29,12 +29,6 @@ public class SelectionPropertyTester extends PropertyTester { // TODO Auto-generated constructor stub } - /* - * (non-Javadoc) - * - * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, - * java.lang.String, java.lang.Object[], java.lang.Object) - */ public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { @@ -62,8 +56,8 @@ public class SelectionPropertyTester extends PropertyTester { Object invoke; try { - Class clazz = Class.forName((String) args[0]); - Object instance = clazz.newInstance(); + Class clazz = Class.forName((String) args[0]); + Object instance = clazz.getDeclaredConstructor().newInstance(); // Field fld = clazz.getDeclaredField(SELECTION_FIELDNAME); // fld.set(instance, (ISelection) receiver); diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/IgnoreLeadingPathSegmentsAction.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/IgnoreLeadingPathSegmentsAction.java index f1865ad4e..56e749652 100644 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/IgnoreLeadingPathSegmentsAction.java +++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/mapping/IgnoreLeadingPathSegmentsAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 IBM Corporation and others. + * Copyright (c) 2010, 2018 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 @@ -11,7 +11,6 @@ package org.eclipse.team.internal.ui.mapping; import org.eclipse.jface.action.Action; -import org.eclipse.jface.dialogs.IInputValidator; import org.eclipse.jface.dialogs.InputDialog; import org.eclipse.jface.window.Window; import org.eclipse.osgi.util.NLS; @@ -49,23 +48,18 @@ public class IgnoreLeadingPathSegmentsAction extends Action { int oldValue = subscriber.getPatcher().getStripPrefixSegments(); maxValue = subscriber.getPatcher().calculatePrefixSegmentCount() - 1; - InputDialog dlg = new InputDialog( - Display.getCurrent().getActiveShell(), - TeamUIMessages.IgnoreLeadingPathSegmentsDialog_title, NLS.bind( - TeamUIMessages.IgnoreLeadingPathSegmentsDialog_message, - Integer.valueOf(maxValue)), new Integer(oldValue) - .toString(), new IInputValidator() { - @Override - public String isValid(String input) { - try { - int i = Integer.parseInt(input); - if (i < 0 || i > maxValue) - return TeamUIMessages.IgnoreLeadingPathSegmentsDialog_numberOutOfRange; - } catch (NumberFormatException x) { - return TeamUIMessages.IgnoreLeadingPathSegmentsDialog_notANumber; - } - return null; + InputDialog dlg = new InputDialog(Display.getCurrent().getActiveShell(), + TeamUIMessages.IgnoreLeadingPathSegmentsDialog_title, + NLS.bind(TeamUIMessages.IgnoreLeadingPathSegmentsDialog_message, Integer.valueOf(maxValue)), + Integer.valueOf(oldValue).toString(), input -> { + try { + int i = Integer.parseInt(input); + if (i < 0 || i > maxValue) + return TeamUIMessages.IgnoreLeadingPathSegmentsDialog_numberOutOfRange; + } catch (NumberFormatException x) { + return TeamUIMessages.IgnoreLeadingPathSegmentsDialog_notANumber; } + return null; }); if (dlg.open() == Window.OK) { diff --git a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLStructureViewer.java b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLStructureViewer.java index cf3613fd1..e792a4d76 100644 --- a/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLStructureViewer.java +++ b/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/XMLStructureViewer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2018 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 @@ -101,15 +101,10 @@ public class XMLStructureViewer extends StructureDiffViewer { final ArrayList originalTree= new ArrayList( Arrays.asList(parent.getChildren())); - Arrays.sort(elements, new Comparator() { - @Override - public int compare(Object a, Object b) { - return XMLSorter.this.compare( - (DiffNode) a, - (DiffNode) b, - originalTree); - } - }); + Arrays.sort(elements, (a, b) -> XMLSorter.this.compare( + (DiffNode) a, + (DiffNode) b, + originalTree)); return; } } @@ -325,11 +320,7 @@ public class XMLStructureViewer extends StructureDiffViewer { action.setEnabled(false); } else { String oldId= (String) idmapHM.get(signature); - if (oldId - .startsWith( - (new Character(XMLStructureCreator - .ID_TYPE_BODY)) - .toString())) + if (oldId.startsWith((Character.valueOf(XMLStructureCreator.ID_TYPE_BODY)).toString())) oldId= oldId.substring(1); action.setText(MessageFormat.format("{0} {1}", XMLCompareMessages.XMLStructureViewer_action_setId_text2, oldId)); //$NON-NLS-1$ action.setEnabled(true); @@ -440,19 +431,11 @@ public class XMLStructureViewer extends StructureDiffViewer { XMLNode textNode= (XMLNode) fDiffNode.getId(); XMLNode idelem= textNode.getParent(); XMLNode elem= idelem.getParent(); - String signature= - elem.getSignature().substring( - 0, - elem.getSignature().indexOf( - XMLStructureCreator.SIGN_ELEMENT)); + String signature = elem.getSignature().substring(0, + elem.getSignature().indexOf(XMLStructureCreator.SIGN_ELEMENT)); String idname= idelem.getOrigId(); - idname= - idname.substring( - 0, - idname.indexOf(XMLStructureCreator.ID_SEPARATOR)); - idname= - Character.valueOf(XMLStructureCreator.ID_TYPE_BODY) - + idname; + idname = idname.substring(0, idname.indexOf(XMLStructureCreator.ID_SEPARATOR)); + idname = Character.valueOf(XMLStructureCreator.ID_TYPE_BODY) + idname; idmapHM.put(signature, idname); XMLPlugin.getDefault().setIdMaps( fIdMaps, diff --git a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/TextMergeViewerTest.java b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/TextMergeViewerTest.java index 9cd4cfd39..0779899d1 100644 --- a/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/TextMergeViewerTest.java +++ b/tests/org.eclipse.compare.tests/src/org/eclipse/compare/tests/TextMergeViewerTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2015 IBM Corporation and others. + * Copyright (c) 2006, 2018 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 @@ -235,11 +235,7 @@ public class TextMergeViewerTest extends TestCase { } protected void saveViewerContents() { - try { - viewer.save(new NullProgressMonitor()); - } catch (CoreException e) { - throw new WrappedException(e); - } + viewer.flush(new NullProgressMonitor()); } protected IDocument getDocument(boolean left) { @@ -404,7 +400,7 @@ public class TextMergeViewerTest extends TestCase { IMergeViewerTestAdapter ta = (IMergeViewerTestAdapter) adapter; assertEquals(ta.getChangesCount(), 1); - Map filters = new HashMap(); + Map filters = new HashMap<>(); filters.put("filter.id", new ICompareFilter() { public void setInput(Object input, Object ancestor, Object left, Object right) { @@ -423,15 +419,13 @@ public class TextMergeViewerTest extends TestCase { if (thisContributor.equals(Character.valueOf('L'))) { assertEquals(thisLine, leftString); - assertEquals(otherContributor, new Character( - 'R')); + assertEquals(otherContributor, Character.valueOf('R')); assertEquals(otherLine, rightString); } else { assertEquals(thisContributor, Character.valueOf('R')); assertEquals(thisLine, rightString); - assertEquals(otherContributor, new Character( - 'L')); + assertEquals(otherContributor, Character.valueOf('L')); assertEquals(otherLine, leftString); } -- cgit v1.2.3