diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMultiDefNode.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMultiDefNode.java index 5358756520b..5c6f414962a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMultiDefNode.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHMultiDefNode.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.cdt.internal.ui.callhierarchy; +import java.util.Objects; + import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ITranslationUnit; @@ -63,6 +65,6 @@ public class CHMultiDefNode extends CHNode { return false; final CHMultiDefNode rhs = (CHMultiDefNode) o; - return CoreUtility.safeEquals(getOneRepresentedDeclaration(), rhs.getOneRepresentedDeclaration()); + return Objects.equals(getOneRepresentedDeclaration(), rhs.getOneRepresentedDeclaration()); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHNode.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHNode.java index 4be662972ec..c60dba50cc6 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHNode.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHNode.java @@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.ui.callhierarchy; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Objects; import org.eclipse.core.runtime.IAdaptable; @@ -83,7 +84,7 @@ public class CHNode implements IAdaptable { return false; } - return CoreUtility.safeEquals(fRepresentedDecl, rhs.fRepresentedDecl); + return Objects.equals(fRepresentedDecl, rhs.fRepresentedDecl); } private boolean computeIsRecursive(CHNode parent, ICElement decl) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHViewPart.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHViewPart.java index 172953b27fb..34a937d3aaf 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHViewPart.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHViewPart.java @@ -77,7 +77,6 @@ import org.eclipse.cdt.internal.ui.IContextMenuConstants; import org.eclipse.cdt.internal.ui.actions.CopyTreeAction; import org.eclipse.cdt.internal.ui.editor.ICEditorActionDefinitionIds; import org.eclipse.cdt.internal.ui.search.actions.SelectionSearchGroup; -import org.eclipse.cdt.internal.ui.util.CoreUtility; import org.eclipse.cdt.internal.ui.util.Messages; import org.eclipse.cdt.internal.ui.viewsupport.AdaptingSelectionProvider; import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels; @@ -480,7 +479,7 @@ public class CHViewPart extends ViewPart { CHNode n2= (CHNode) e2; int offset1= n1.getFirstReferenceOffset(); int offset2= n2.getFirstReferenceOffset(); - return CoreUtility.compare(offset1, offset2); + return Integer.compare(offset1, offset2); } }; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBFile.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBFile.java index 8faf1a4193a..1f832835dfd 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBFile.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBFile.java @@ -12,6 +12,8 @@ package org.eclipse.cdt.internal.ui.includebrowser; +import java.util.Objects; + import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; @@ -60,17 +62,17 @@ public class IBFile { public boolean equals(Object obj) { if (obj instanceof IBFile) { IBFile file = (IBFile) obj; - return (CoreUtility.safeEquals(fLocation, file.fLocation) && - CoreUtility.safeEquals(fTU, file.fTU)); + return (Objects.equals(fLocation, file.fLocation) && + Objects.equals(fTU, file.fTU)); } return super.equals(obj); } @Override public int hashCode() { - return CoreUtility.safeHashcode(fLocation) - + 31* (CoreUtility.safeHashcode(fTU) - + 31* CoreUtility.safeHashcode(fName)); + return Objects.hashCode(fLocation) + + 31* (Objects.hashCode(fTU) + + 31* Objects.hashCode(fName)); } public ITranslationUnit getTranslationUnit() { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBNode.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBNode.java index d9cd1e4675f..524cfb65a68 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBNode.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBNode.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.cdt.internal.ui.includebrowser; +import java.util.Objects; + import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IPath; @@ -80,7 +82,7 @@ public class IBNode implements IAdaptable { return false; } - return CoreUtility.safeEquals(fRepresentedFile, rhs.fRepresentedFile); + return Objects.equals(fRepresentedFile, rhs.fRepresentedFile); } private boolean computeIsRecursive(IBNode parent, IIndexFileLocation ifl) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/THNode.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/THNode.java index 335fee77453..4cd9b6b767e 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/THNode.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/typehierarchy/THNode.java @@ -14,6 +14,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.Objects; import org.eclipse.core.runtime.IAdaptable; @@ -66,7 +67,7 @@ public class THNode implements IAdaptable { return false; } - return CoreUtility.safeEquals(fElement, rhs.fElement); + return Objects.equals(fElement, rhs.fElement); } /** diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/CoreUtility.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/CoreUtility.java index 952d7eed3e1..8bc1e330f17 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/CoreUtility.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/CoreUtility.java @@ -21,36 +21,33 @@ import org.eclipse.swt.custom.BusyIndicator; import org.osgi.framework.Bundle; public class CoreUtility { - /** * Creates a folder and all parent folders if not existing. * Project must exist. - * org.eclipse.ui.dialogs.ContainerGenerator is too heavy + * {@link org.eclipse.ui.dialogs.ContainerGenerator} is too heavy * (creates a runnable) */ public static void createFolder(IFolder folder, boolean force, boolean local, IProgressMonitor monitor) throws CoreException { if (!folder.exists()) { IContainer parent= folder.getParent(); if (parent instanceof IFolder) { - createFolder((IFolder)parent, force, local, null); + createFolder((IFolder) parent, force, local, null); } folder.create(force, local, monitor); } } /** - * Creates an extension. If the extension plugin has not - * been loaded a busy cursor will be activated during the duration of - * the load. + * Creates an extension. If the extension plugin has not been loaded, + * a busy cursor will be activated during the duration of the load. * * @param element the config element defining the extension * @param classAttribute the name of the attribute carrying the class * @return the extension object */ public static Object createExtension(final IConfigurationElement element, final String classAttribute) throws CoreException { - // If plugin has been loaded create extension. + // If plugin has been loaded, create extension. // Otherwise, show busy cursor then create extension. - String id= element.getContributor().getName(); Bundle bundle = Platform.getBundle(id); if(bundle.getState() == org.osgi.framework.Bundle.ACTIVE) { @@ -72,38 +69,5 @@ public class CoreUtility { throw exc[0]; return ret[0]; } - - /** - * Calls equals after checking for nulls - */ - public static boolean safeEquals(Object lhs, Object rhs) { - if (lhs==rhs) { - return true; - } - if (lhs == null || rhs == null) { - return false; - } - return lhs.equals(rhs); - } - - /** - * Calls hashCode after checking for null - */ - public static int safeHashcode(Object o) { - return o == null ? 0 : o.hashCode(); - } - - /** - * Comparse two integers. - */ - public static int compare(int lhs, int rhs) { - if (lhs < rhs) { - return -1; - } - if (lhs > rhs) { - return 1; - } - return 0; - } }