Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove useless cast in CreateStubsAction #1963

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2024 IBM Corporation and others.
* Copyright (c) 2005, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -54,7 +54,7 @@
*/
public final class CreateStubsAction implements IObjectActionDelegate {

private static final String[] DEFAULT_PACKAGES= new String[] {
private static final String[] DEFAULT_PACKAGES= {
"java.beans",
"java.io",
"java.lang",
Expand Down Expand Up @@ -128,19 +128,18 @@ private void fail(String msg) {
@Override
public void run(IAction action) {
ISelection selection= fTargetPart.getSite().getSelectionProvider().getSelection();
if (!(selection instanceof IStructuredSelection)) {
if (!(selection instanceof IStructuredSelection structuredSelection)) {
fail("Select packages to create stubs."); //$NON-NLS-1$
return;
}
final IStructuredSelection structuredSelection= (IStructuredSelection) selection;

Shell shell= fTargetPart.getSite().getShell();
String initialValue= JavaTestPlugin.getDefault().getDialogSettings().get(SETTINGS_ID_STUBS_PROJECT);
if (initialValue == null)
initialValue = "stubs"; //$NON-NLS-1$
final InputDialog inputDialog= new InputDialog(shell, CREATE_STUBS_DIALOG_TITLE, "Target project name:", initialValue, newText -> {
IStatus status = ResourcesPlugin.getWorkspace().validateName(newText, IResource.PROJECT);
return status.isOK() ? null : (String) status.getMessage();
return status.isOK() ? null : status.getMessage();
});
if (inputDialog.open() != Window.OK)
return;
Expand All @@ -161,10 +160,9 @@ public void run(IAction action) {

boolean checkCompletionOfDefaultPackages= false;
for (Object sel : structuredSelection.toList()) {
if (sel instanceof IPackageFragment) {
packageFragments.add((IPackageFragment) sel);
} else if (sel instanceof IPackageFragmentRoot) {
IPackageFragmentRoot root = (IPackageFragmentRoot) sel;
if (sel instanceof IPackageFragment packageFragment) {
packageFragments.add(packageFragment);
} else if (sel instanceof IPackageFragmentRoot root) {
for (Iterator<String> iter= defaultPackages.iterator(); iter.hasNext();) {
String packName= iter.next();
IPackageFragment packageFragment = root.getPackageFragment(packName);
Expand Down Expand Up @@ -195,10 +193,8 @@ public void run(IAction action) {
MessageDialog.openInformation(fTargetPart.getSite().getShell(), CREATE_STUBS_DIALOG_TITLE, message.toString());
} catch (InterruptedException e) {
// Do not log
} catch (InvocationTargetException e) {
} catch (InvocationTargetException|CoreException e) {
JavaTestPlugin.log(e);
} catch (CoreException exception) {
JavaTestPlugin.log(exception);
}
}

Expand Down
Loading