From 65936fefd334f463517d43161fb1eeed10ceead6 Mon Sep 17 00:00:00 2001 From: Nikita Akilov Date: Tue, 22 Sep 2020 13:22:40 +0300 Subject: [PATCH] #9765 codestyle fixes --- .../actions/NavigatorHandlerObjectDelete.java | 13 +++--- .../actions/NavigatorObjectsDeleter.java | 43 ++++++++++--------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/plugins/org.jkiss.dbeaver.ui.navigator/src/org/jkiss/dbeaver/ui/navigator/actions/NavigatorHandlerObjectDelete.java b/plugins/org.jkiss.dbeaver.ui.navigator/src/org/jkiss/dbeaver/ui/navigator/actions/NavigatorHandlerObjectDelete.java index b7bf35ae1c..2396d31e0d 100644 --- a/plugins/org.jkiss.dbeaver.ui.navigator/src/org/jkiss/dbeaver/ui/navigator/actions/NavigatorHandlerObjectDelete.java +++ b/plugins/org.jkiss.dbeaver.ui.navigator/src/org/jkiss/dbeaver/ui/navigator/actions/NavigatorHandlerObjectDelete.java @@ -43,7 +43,6 @@ import org.jkiss.utils.CommonUtils; import java.util.*; import java.util.List; -@SuppressWarnings({"rawtypes"}) public class NavigatorHandlerObjectDelete extends NavigatorHandlerObjectBase implements IElementUpdater { @Override public Object execute(final ExecutionEvent event) throws ExecutionException { @@ -52,14 +51,14 @@ public class NavigatorHandlerObjectDelete extends NavigatorHandlerObjectBase imp return null; } final IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); - final List selectedObjects = ((IStructuredSelection)selection).toList(); + @SuppressWarnings("unchecked") final List selectedObjects = ((IStructuredSelection) selection).toList(); final NavigatorObjectsDeleter deleter = NavigatorObjectsDeleter.of(selectedObjects, window); makeDeletionAttempt(window, selectedObjects, deleter); return null; } - private void makeDeletionAttempt(final IWorkbenchWindow window, final List selectedObjects, final NavigatorObjectsDeleter deleter) { - if (deleter.areSomeNodesFromDifferentDataSources()) { + private void makeDeletionAttempt(final IWorkbenchWindow window, final List selectedObjects, final NavigatorObjectsDeleter deleter) { + if (deleter.hasNodesFromDifferentDataSources()) { // attempt to delete database nodes from different databases DBWorkbench.getPlatformUI(). showError( @@ -89,7 +88,7 @@ public class NavigatorHandlerObjectDelete extends NavigatorHandlerObjectBase imp } private static class ConfirmationDialog extends MessageDialog { - private final List selectedObjects; + private final List selectedObjects; private final boolean showCascade; @@ -98,7 +97,7 @@ public class NavigatorHandlerObjectDelete extends NavigatorHandlerObjectBase imp private boolean cascadeCheck; private ConfirmationDialog(final Shell shell, final String title, final String message, - final List selectedObjects, final boolean showCascade, final boolean showViewScript) { + final List selectedObjects, final boolean showCascade, final boolean showViewScript) { super( shell, title, @@ -113,7 +112,7 @@ public class NavigatorHandlerObjectDelete extends NavigatorHandlerObjectBase imp this.showViewScript = showViewScript; } - static ConfirmationDialog of(final Shell shell, final List selectedObjects, + static ConfirmationDialog of(final Shell shell, final List selectedObjects, final boolean showCascade, final boolean showViewScript) { if (selectedObjects.size() > 1) { return new ConfirmationDialog( diff --git a/plugins/org.jkiss.dbeaver.ui.navigator/src/org/jkiss/dbeaver/ui/navigator/actions/NavigatorObjectsDeleter.java b/plugins/org.jkiss.dbeaver.ui.navigator/src/org/jkiss/dbeaver/ui/navigator/actions/NavigatorObjectsDeleter.java index 6d0541abc0..c09d9a5cb0 100644 --- a/plugins/org.jkiss.dbeaver.ui.navigator/src/org/jkiss/dbeaver/ui/navigator/actions/NavigatorObjectsDeleter.java +++ b/plugins/org.jkiss.dbeaver.ui.navigator/src/org/jkiss/dbeaver/ui/navigator/actions/NavigatorObjectsDeleter.java @@ -35,7 +35,6 @@ import org.jkiss.dbeaver.ui.internal.UINavigatorMessages; import java.lang.reflect.InvocationTargetException; import java.util.*; -@SuppressWarnings({"rawtypes", "unchecked"}) class NavigatorObjectsDeleter { private static final Log log = Log.getLog(NavigatorObjectsDeleter.class); @@ -56,7 +55,7 @@ class NavigatorObjectsDeleter { /** * A list containing objects to delete. */ - private final List selection; + private final List selection; /** * {@code true} if 'Cascade delete' button should be shown @@ -71,25 +70,26 @@ class NavigatorObjectsDeleter { /** * {@code true} in case of attempt to delete database nodes which belong to different data sources */ - private final boolean areSomeNodesFromDifferentDataSources; + private final boolean hasNodesFromDifferentDataSources; - private @Nullable DBECommandContext commandContext; + @Nullable + private DBECommandContext commandContext; private boolean checkCascade = false; - private NavigatorObjectsDeleter(final List selection, final IWorkbenchWindow window, - final boolean areSomeNodesFromDifferentDataSources, final boolean showCascade, + private NavigatorObjectsDeleter(final List selection, final IWorkbenchWindow window, + final boolean hasNodesFromDifferentDataSources, final boolean showCascade, final boolean showViewScript) { this.selection = selection; this.window = window; - this.areSomeNodesFromDifferentDataSources = areSomeNodesFromDifferentDataSources; + this.hasNodesFromDifferentDataSources = hasNodesFromDifferentDataSources; this.showCascade = showCascade; this.showViewScript = showViewScript; } - static NavigatorObjectsDeleter of(final List selection, final IWorkbenchWindow window) { + static NavigatorObjectsDeleter of(final List selection, final IWorkbenchWindow window) { DBPDataSource dataSource = null; - boolean areSomeNodesFromDifferentDataSources = false; + boolean hasNodesFromDifferentDataSources = false; boolean showCascade = false; boolean showViewScript = false; for (Object obj: selection) { @@ -101,7 +101,7 @@ class NavigatorObjectsDeleter { if (dataSource == null) { dataSource = currentDatasource; } else if (!dataSource.equals(currentDatasource)) { - areSomeNodesFromDifferentDataSources = true; + hasNodesFromDifferentDataSources = true; } if (!(node.getParentNode() instanceof DBNContainer)) { continue; @@ -110,7 +110,8 @@ class NavigatorObjectsDeleter { if (object == null) { continue; } - final DBEObjectMaker objectMaker = DBWorkbench.getPlatform().getEditorsRegistry().getObjectManager(object.getClass(), DBEObjectMaker.class); + @SuppressWarnings("rawtypes") final DBEObjectMaker objectMaker = + DBWorkbench.getPlatform().getEditorsRegistry().getObjectManager(object.getClass(), DBEObjectMaker.class); if (objectMaker == null) { continue; } @@ -130,11 +131,11 @@ class NavigatorObjectsDeleter { showViewScript = true; } } - return new NavigatorObjectsDeleter(selection, window, areSomeNodesFromDifferentDataSources, showCascade, showViewScript); + return new NavigatorObjectsDeleter(selection, window, hasNodesFromDifferentDataSources, showCascade, showViewScript); } - boolean areSomeNodesFromDifferentDataSources() { - return areSomeNodesFromDifferentDataSources; + boolean hasNodesFromDifferentDataSources() { + return hasNodesFromDifferentDataSources; } public boolean getShowCascade() { @@ -196,7 +197,8 @@ class NavigatorObjectsDeleter { if (object == null) { throw new DBException("Can't delete node with null object"); } - final DBEObjectMaker objectMaker = DBWorkbench.getPlatform().getEditorsRegistry().getObjectManager(object.getClass(), DBEObjectMaker.class); + @SuppressWarnings("rawtypes") final DBEObjectMaker objectMaker = + DBWorkbench.getPlatform().getEditorsRegistry().getObjectManager(object.getClass(), DBEObjectMaker.class); if (objectMaker == null) { throw new DBException("Object maker not found for type '" + object.getClass().getName() + "'"); //$NON-NLS-2$ } @@ -218,7 +220,7 @@ class NavigatorObjectsDeleter { // try to find corresponding command context // and execute command within it } - Map deleteOptions = Collections.EMPTY_MAP; + @SuppressWarnings("unchecked") Map deleteOptions = Collections.EMPTY_MAP; if (checkCascade && supportsCascade) { deleteOptions = OPTIONS_CASCADE; } @@ -258,6 +260,7 @@ class NavigatorObjectsDeleter { UIServiceSQL serviceSQL = DBWorkbench.getService(UIServiceSQL.class); if (serviceSQL != null) { result = serviceSQL.openSQLViewer( + //command context is not null because sql is not empty, see appendSQL() commandContext.getExecutionContext(), UINavigatorMessages.actions_navigator_delete_script, UIIcon.SQL_PREVIEW, @@ -291,12 +294,12 @@ class NavigatorObjectsDeleter { if (!(node.getParentNode() instanceof DBNContainer)) { return; } - // Try to delete object using object manager final DBSObject object = node.getObject(); if (object == null) { return; } - final DBEObjectMaker objectMaker = DBWorkbench.getPlatform().getEditorsRegistry().getObjectManager(object.getClass(), DBEObjectMaker.class); + @SuppressWarnings("rawtypes") final DBEObjectMaker objectMaker = + DBWorkbench.getPlatform().getEditorsRegistry().getObjectManager(object.getClass(), DBEObjectMaker.class); if (objectMaker == null) { return; } @@ -333,11 +336,11 @@ class NavigatorObjectsDeleter { } final StringBuilder script = new StringBuilder(); final DBECommandContext commandContext = commandTarget.getContext(); - final Collection commands = commandContext.getFinalCommands(); + final @SuppressWarnings("rawtypes") Collection commands = commandContext.getFinalCommands(); try { UIUtils.runInProgressService(monitor -> { try { - for (DBECommand command : commands) { + for(@SuppressWarnings("rawtypes") DBECommand command : commands) { final DBEPersistAction[] persistActions = command.getPersistActions(monitor, commandContext.getExecutionContext(), deleteOptions); script.append( SQLUtils.generateScript(commandContext.getExecutionContext().getDataSource(), -- GitLab