Skip to content

Commit

Permalink
Remove useless cast in CreateStubsAction
Browse files Browse the repository at this point in the history
While in the class also:
* use pattern matching
* create arrays with curly
* multi-catch

This useless cast is catched by javac but not by ecj.
  • Loading branch information
akurtakov committed Jan 22, 2025
1 parent 013e35b commit ad0816f
Showing 1 changed file with 8 additions and 12 deletions.
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

0 comments on commit ad0816f

Please sign in to comment.