From 5e9c23621c2ab956a8b1c490fd4cd8c7963df2b3 Mon Sep 17 00:00:00 2001 From: Alshama M S Date: Thu, 17 Aug 2023 13:16:39 +0530 Subject: [PATCH] Code Cleanup: Java 16 instanceof pattern matching in pde.ui --- .../pde/internal/ui/PDELabelProvider.java | 6 +- .../eclipse/pde/internal/ui/PDEPlugin.java | 9 +- .../OSGiAnnotationsASTVisitor.java | 3 +- .../pde/internal/ui/commands/CommandList.java | 6 +- .../ui/compare/ManifestStructureCreator.java | 3 +- .../AddActivationHeaderResolution.java | 3 +- .../AddActivationPolicyResolution.java | 3 +- .../AddAutomaticModuleResolution.java | 3 +- ...kageInternalDirectiveMarkerResolution.java | 3 +- .../AddExportPackageMarkerResolution.java | 3 +- .../AddNewExtensionPointResolution.java | 6 +- .../correction/AddNewExtensionResolution.java | 6 +- .../AddSingletonToSymbolicName.java | 3 +- .../correction/ChooseClassXMLResolution.java | 3 +- .../correction/CreateClassXMLResolution.java | 3 +- .../ui/correction/MultiFixResolution.java | 3 +- .../correction/RemoveNodeXMLResolution.java | 3 +- .../RemoveUnknownExecEnvironments.java | 3 +- .../ui/correction/ReplaceExecEnvironment.java | 3 +- ...supportedSingletonDirectiveResolution.java | 3 +- .../java/FindClassResolutionsOperation.java | 3 +- .../java/JavaResolutionFactory.java | 9 +- .../ui/dialogs/FeatureSelectionDialog.java | 12 +- .../ui/dialogs/PluginSelectionDialog.java | 9 +- .../internal/ui/editor/FormOutlinePage.java | 3 +- .../ui/editor/JarEntryEditorInput.java | 3 +- .../ui/editor/KeyValueSourcePage.java | 3 +- .../internal/ui/editor/ModelDataTransfer.java | 3 +- .../ui/editor/OpenManifestHandler.java | 3 +- .../pde/internal/ui/editor/PDEFormEditor.java | 27 ++--- .../ui/editor/PDEFormEditorContributor.java | 7 +- .../pde/internal/ui/editor/PDEFormPage.java | 12 +- .../ui/editor/PDEProjectionViewer.java | 3 +- .../pde/internal/ui/editor/PDESourcePage.java | 27 ++--- .../ui/editor/PDEStorageDocumentProvider.java | 6 +- .../actions/ToggleExpandStateAction.java | 6 +- .../editor/build/BuildHyperlinkDetector.java | 3 +- .../ui/editor/build/BuildOutlinePage.java | 3 +- .../ui/editor/build/BuildSourcePage.java | 3 +- .../ui/editor/build/BuildUndoManager.java | 3 +- .../ui/editor/build/RuntimeInfoSection.java | 3 +- .../editor/category/CategoryOutlinePage.java | 6 +- .../ui/editor/category/CategorySection.java | 30 ++--- .../editor/category/CategoryUndoManager.java | 12 +- .../ui/editor/category/IUDetailsSection.java | 3 +- .../ui/editor/category/SiteBundleAdapter.java | 3 +- .../SiteCategoryDefinitionAdapter.java | 3 +- .../editor/category/SiteFeatureAdapter.java | 3 +- .../TypePackageCompletionProcessor.java | 3 +- .../XMLElementProposalComputer.java | 6 +- .../contentassist/XMLInsertionComputer.java | 9 +- .../ui/editor/context/InputContext.java | 6 +- .../editor/context/InputContextManager.java | 3 +- .../context/XMLDocumentSetupParticpant.java | 3 +- .../ui/editor/context/XMLInputContext.java | 6 +- .../editor/feature/FeatureReferencePage.java | 9 +- .../ui/editor/feature/FeatureUndoManager.java | 3 +- .../feature/IncludedFeaturesSection.java | 3 +- .../ui/editor/feature/InfoSection.java | 6 +- .../editor/feature/OpenReferenceAction.java | 6 +- .../editor/feature/PluginDetailsSection.java | 3 +- .../ui/editor/feature/URLSection.java | 3 +- .../plugin/BundleHyperlinkDetector.java | 3 +- .../ui/editor/plugin/BundleInputContext.java | 3 +- .../ui/editor/plugin/BundleSourcePage.java | 6 +- .../plugin/DependencyManagementSection.java | 3 +- .../plugin/ExecutionEnvironmentSection.java | 3 +- .../editor/plugin/ExportPackageSection.java | 12 +- .../ExportPackageVisibilitySection.java | 3 +- .../editor/plugin/ExtensionPointDetails.java | 3 +- .../ui/editor/plugin/ExtensionsSection.java | 93 ++++++---------- .../editor/plugin/ImportPackageSection.java | 21 ++-- .../ui/editor/plugin/LibrarySection.java | 6 +- .../ui/editor/plugin/ManifestOutlinePage.java | 3 +- .../ui/editor/plugin/ManifestSourcePage.java | 3 +- .../ui/editor/plugin/MatchSection.java | 3 +- .../ui/editor/plugin/PluginInputContext.java | 3 +- .../plugin/PluginInputContextManager.java | 3 +- .../ui/editor/plugin/PluginUndoManager.java | 30 ++--- .../ui/editor/plugin/RequiresSection.java | 6 +- .../ui/editor/product/IntroSection.java | 3 +- .../ui/editor/product/JRESection.java | 3 +- .../internal/ui/editor/schema/DocSection.java | 3 +- .../ui/editor/schema/ElementSection.java | 12 +- ...ilteredSchemaAttributeSelectionDialog.java | 18 +-- .../ui/editor/schema/NewReferenceAction.java | 3 +- .../ui/editor/schema/SchemaEditor.java | 3 +- .../editor/schema/SchemaFormOutlinePage.java | 3 +- .../ui/editor/schema/SchemaFormPage.java | 3 +- .../SchemaIdentifierAttributeDetails.java | 3 +- .../editor/schema/SchemaIncludesSection.java | 4 +- .../ui/editor/schema/SchemaRearranger.java | 9 +- .../ui/editor/site/CategorySection.java | 9 +- .../ui/editor/site/SiteFeatureAdapter.java | 3 +- .../ui/editor/site/SiteOutlinePage.java | 6 +- .../ui/editor/site/SiteUndoManager.java | 12 +- .../editor/targetdefinition/TargetEditor.java | 3 +- .../ui/editor/text/AnnotationHover.java | 3 +- .../ui/editor/text/ManifestTextHover.java | 3 +- .../editor/text/PDEQuickAssistAssistant.java | 15 +-- .../ui/editor/text/TranslationHyperlink.java | 3 +- .../editor/text/XMLReconcilingStrategy.java | 6 +- .../ui/launcher/AbstractPluginBlock.java | 9 +- .../internal/ui/launcher/FeatureBlock.java | 30 ++--- .../launcher/LauncherUtilsStatusHandler.java | 3 +- .../internal/ui/launcher/OSGiBundleBlock.java | 3 +- .../pde/internal/ui/launcher/PluginBlock.java | 3 +- .../nls/ExternalizeStringsLabelProvider.java | 6 +- .../ui/nls/ExternalizeStringsOperation.java | 9 +- .../ui/nls/ExternalizeStringsWizardPage.java | 15 +-- .../GetNonExternalizedStringsOperation.java | 3 +- .../internal/ui/nls/ModelChangeElement.java | 24 ++-- .../internal/ui/nls/NLSFragmentGenerator.java | 3 +- .../internal/ui/parts/PluginVersionPart.java | 3 +- .../pde/internal/ui/preferences/BuildJob.java | 3 +- .../PDECompilersConfigurationBlock.java | 18 +-- .../preferences/ProjectSelectionDialog.java | 3 +- .../TargetPlatformPreferencePage.java | 3 +- .../ui/refactoring/BundleManifestChange.java | 6 +- .../CreateHeaderChangeOperation.java | 3 +- .../ManifestPackageMoveParticipant.java | 3 +- .../ManifestPackageRenameParticipant.java | 3 +- .../ManifestTypeMoveParticipant.java | 6 +- .../ManifestTypeRenameParticipant.java | 3 +- .../RenameExtensionPointProcessor.java | 6 +- .../ui/search/ClassSearchParticipant.java | 6 +- .../ui/search/ExtensionsPatternFilter.java | 3 +- .../ui/search/FindPluginReferencesAction.java | 3 +- .../ui/search/ManifestEditorOpener.java | 3 +- .../ui/search/PluginSearchActionGroup.java | 6 +- .../internal/ui/search/PluginSearchQuery.java | 6 +- .../ui/search/PluginSearchResultPage.java | 9 +- .../pde/internal/ui/search/SearchResult.java | 6 +- .../AddNewDependenciesOperation.java | 6 +- .../DependencyExtentSearchResult.java | 3 +- .../DependencyExtentSearchResultPage.java | 3 +- .../search/dependencies/JavaEditorOpener.java | 6 +- .../ui/search/dependencies/PackageFinder.java | 3 +- .../dialogs/FilteredIUSelectionDialog.java | 9 +- ...ilteredPluginArtifactsSelectionDialog.java | 105 ++++++------------ .../dialogs/PluginArtifactSearchHandler.java | 3 +- .../shared/target/BundleContainerFactory.java | 9 +- .../target/EditTargetContainerPage.java | 3 +- .../internal/ui/shared/target/IUFactory.java | 6 +- .../shared/target/LegacyAdapterFactory.java | 3 +- .../target/StyledBundleLabelProvider.java | 27 ++--- .../ui/shared/target/TargetContentsGroup.java | 3 +- .../target/TargetLocationContentProvider.java | 3 +- ...eferenceBundleContainerAdapterFactory.java | 15 +-- .../ui/util/ExtensionsFilterUtil.java | 6 +- .../pde/internal/ui/util/PDEModelUtility.java | 6 +- .../ui/util/PersistablePluginObject.java | 3 +- .../dependencies/CalleesContentProvider.java | 3 +- .../DependenciesLabelProvider.java | 3 +- .../dependencies/DependenciesViewPage.java | 6 +- .../dependencies/OpenDependenciesAction.java | 3 +- .../features/support/FeatureSupport.java | 6 +- .../views/features/support/PluginSupport.java | 6 +- .../features/support/ProductSupport.java | 3 +- .../AbstractFeatureTreeContentProvider.java | 3 +- .../viewer/FeatureChildViewerFilter.java | 3 +- .../FeatureTreeCalleesContentProvider.java | 14 +-- .../FeatureTreeCallersContentProvider.java | 3 +- .../viewer/FeatureViewerComparator.java | 3 +- .../ui/views/plugins/ImportActionGroup.java | 6 +- .../views/plugins/JavaSearchActionGroup.java | 4 +- .../views/plugins/PluginsContentProvider.java | 9 +- .../views/plugins/PluginsLabelProvider.java | 3 +- .../ui/views/target/StateViewPage.java | 15 +-- .../wizards/exports/BaseExportWizardPage.java | 6 +- .../exports/CrossPlatformExportPage.java | 3 +- .../ui/wizards/exports/FeatureOptionsTab.java | 6 +- .../exports/ProductConfigurationSection.java | 6 +- .../wizards/extension/NewExtensionWizard.java | 6 +- .../wizards/extension/PointSelectionPage.java | 9 +- .../imports/BaseImportWizardSecondPage.java | 3 +- .../imports/PluginImportLabelProvider.java | 3 +- .../wizards/imports/PluginImportWizard.java | 3 +- .../PluginImportWizardExpressPage.java | 3 +- .../wizards/plugin/LibraryPluginJarsPage.java | 3 +- .../plugin/NewProjectCreationOperation.java | 13 +-- .../product/BaseManifestOperation.java | 6 +- .../product/ProductIntroOperation.java | 3 +- .../RemoveSplashHandlerBindingAction.java | 3 +- .../product/UpdateSplashHandlerAction.java | 9 +- .../wizards/tools/ConvertProjectsAction.java | 3 +- .../ui/wizards/tools/OrganizeManifest.java | 3 +- .../tools/OrganizeManifestsAction.java | 3 +- .../wizards/tools/UpdateClasspathAction.java | 3 +- .../ui/launcher/EclipseLaunchShortcut.java | 3 +- .../ui/templates/AbstractTemplateSection.java | 3 +- .../templates/OptionTemplateWizardPage.java | 3 +- .../pde/ui/templates/PluginReference.java | 3 +- .../ShowErrorInStackTraceConsoleHandler.java | 3 +- .../log/jdt/ShowInConsolePropertyTester.java | 3 +- .../pde/internal/ui/samples/SampleEditor.java | 3 +- 196 files changed, 453 insertions(+), 885 deletions(-) diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDELabelProvider.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDELabelProvider.java index d2fb57ad05..ae5a73ef94 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDELabelProvider.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDELabelProvider.java @@ -279,8 +279,7 @@ public String getObjectText(IPluginLibrary obj) { public String getObjectText(ISchemaObject obj) { StringBuilder text = new StringBuilder(obj.getName()); - if (obj instanceof ISchemaRepeatable) { - ISchemaRepeatable rso = (ISchemaRepeatable) obj; + if (obj instanceof ISchemaRepeatable rso) { boolean unbounded = rso.getMaxOccurs() == Integer.MAX_VALUE; int maxOccurs = rso.getMaxOccurs(); int minOccurs = rso.getMinOccurs(); @@ -863,8 +862,7 @@ public Image getObjectImage(ExportPackageObject obj) { public Image getObjectImage(PackageObject obj) { int flags = 0; - if (obj instanceof ImportPackageObject) { - ImportPackageObject importPackageObject = (ImportPackageObject) obj; + if (obj instanceof ImportPackageObject importPackageObject) { if (importPackageObject.isOptional()) { flags |= F_OPTIONAL; } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEPlugin.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEPlugin.java index 4430ef44e8..ef4fac33b9 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEPlugin.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEPlugin.java @@ -156,9 +156,9 @@ public static void logException(Throwable e, final String title, String message) e = ((InvocationTargetException) e).getTargetException(); } IStatus status = null; - if (e instanceof CoreException) { - // Re-use status only if it has attached exception with the stack trace - CoreException ce = (CoreException) e; + if (e instanceof CoreException ce) { + // Re-use status only if it has attached exception with the stack + // trace if (ce.getStatus().getException() != null) { status = ce.getStatus(); } @@ -187,9 +187,8 @@ public static void log(Throwable e) { e = ((InvocationTargetException) e).getTargetException(); } IStatus status = null; - if (e instanceof CoreException) { + if (e instanceof CoreException ce) { // Re-use status only if it has attached exception with the stack trace - CoreException ce = (CoreException) e; if (ce.getStatus().getException() != null) { status = ce.getStatus(); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/annotations/OSGiAnnotationsASTVisitor.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/annotations/OSGiAnnotationsASTVisitor.java index 4d3bdc9922..6ff0da36bd 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/annotations/OSGiAnnotationsASTVisitor.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/annotations/OSGiAnnotationsASTVisitor.java @@ -60,8 +60,7 @@ public boolean visit(PackageDeclaration packageDeclaration) { } List processors = getPackageProcessors(packageDeclaration.getName().toString()); for (Object item : packageDeclaration.annotations()) { - if (item instanceof Annotation) { - Annotation annotation = (Annotation) item; + if (item instanceof Annotation annotation) { IAnnotationBinding annotationBinding = annotation.resolveAnnotationBinding(); if (annotationBinding == null) { // not resolvable diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/commands/CommandList.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/commands/CommandList.java index 6de456c352..d235dcfede 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/commands/CommandList.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/commands/CommandList.java @@ -142,15 +142,13 @@ public boolean select(Viewer viewer, Object parentElement, Object element) { } protected static String getText(Object obj) { - if (obj instanceof Command) { - Command com = (Command) obj; + if (obj instanceof Command com) { try { return com.getName(); } catch (NotDefinedException e) { return com.getId(); } - } else if (obj instanceof Category) { - Category cat = (Category) obj; + } else if (obj instanceof Category cat) { try { return cat.getName(); } catch (NotDefinedException e) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/compare/ManifestStructureCreator.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/compare/ManifestStructureCreator.java index 36916f9145..589c74366c 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/compare/ManifestStructureCreator.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/compare/ManifestStructureCreator.java @@ -81,8 +81,7 @@ public IStructureComparator locate(Object path, Object input) { @Override public String getContents(Object node, boolean ignoreWhitespace) { - if (node instanceof IStreamContentAccessor) { - IStreamContentAccessor sca = (IStreamContentAccessor) node; + if (node instanceof IStreamContentAccessor sca) { try { return readString(sca); } catch (CoreException ex) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddActivationHeaderResolution.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddActivationHeaderResolution.java index 99eaff0a14..7cfbbbf130 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddActivationHeaderResolution.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddActivationHeaderResolution.java @@ -36,8 +36,7 @@ protected void createChange(BundleModel model) { String markerHeader = marker.getAttribute("header", ICoreConstants.ECLIPSE_AUTOSTART); //$NON-NLS-1$ IBundle bundle = model.getBundle(); IManifestHeader header = bundle.getManifestHeader(markerHeader); - if (header instanceof LazyStartHeader) { - LazyStartHeader lheader = (LazyStartHeader) header; + if (header instanceof LazyStartHeader lheader) { String exceptions = lheader.getAttribute("exceptions"); //$NON-NLS-1$ if (TargetPlatformHelper.getTargetVersion() >= 3.4) { bundle.setHeader(Constants.BUNDLE_ACTIVATIONPOLICY, Constants.ACTIVATION_LAZY); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddActivationPolicyResolution.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddActivationPolicyResolution.java index 6258959c7f..6a91cb2583 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddActivationPolicyResolution.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddActivationPolicyResolution.java @@ -30,8 +30,7 @@ public AddActivationPolicyResolution(int type, IMarker marker) { @Override protected void createChange(BundleModel model) { IBundle bundle = model.getBundle(); - if (bundle instanceof Bundle) { - Bundle bun = (Bundle) bundle; + if (bundle instanceof Bundle bun) { IManifestHeader header = bun.getManifestHeader(Constants.BUNDLE_ACTIVATIONPOLICY); if (header == null) { bundle.setHeader(Constants.BUNDLE_ACTIVATIONPOLICY, Constants.ACTIVATION_LAZY); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddAutomaticModuleResolution.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddAutomaticModuleResolution.java index de9116cef1..296c8a2d3b 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddAutomaticModuleResolution.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddAutomaticModuleResolution.java @@ -49,8 +49,7 @@ public IMarker[] findOtherMarkers(IMarker[] markers) { @Override protected void createChange(BundleModel model) { IBundle bundle = model.getBundle(); - if (bundle instanceof Bundle) { - Bundle bun = (Bundle) bundle; + if (bundle instanceof Bundle bun) { IManifestHeader header = bun.getManifestHeader(ICoreConstants.AUTOMATIC_MODULE_NAME); if (header == null) { IManifestHeader headerName = bun.getManifestHeader(Constants.BUNDLE_SYMBOLICNAME); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddExportPackageInternalDirectiveMarkerResolution.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddExportPackageInternalDirectiveMarkerResolution.java index f250f06c95..e12ab495f1 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddExportPackageInternalDirectiveMarkerResolution.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddExportPackageInternalDirectiveMarkerResolution.java @@ -35,8 +35,7 @@ public String getLabel() { @Override protected void createChange(BundleModel model) { IBundle bundle = model.getBundle(); - if (bundle instanceof Bundle) { - Bundle bun = (Bundle) bundle; + if (bundle instanceof Bundle bun) { ExportPackageHeader header = (ExportPackageHeader) bun.getManifestHeader(Constants.EXPORT_PACKAGE); if (header == null) { bundle.setHeader(Constants.EXPORT_PACKAGE, ""); //$NON-NLS-1$ diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddExportPackageMarkerResolution.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddExportPackageMarkerResolution.java index 4dcb047dbf..39e31bd908 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddExportPackageMarkerResolution.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddExportPackageMarkerResolution.java @@ -43,8 +43,7 @@ public String getLabel() { @Override protected void createChange(BundleModel model) { IBundle bundle = model.getBundle(); - if (bundle instanceof Bundle) { - Bundle bun = (Bundle) bundle; + if (bundle instanceof Bundle bun) { ExportPackageHeader header = (ExportPackageHeader) bun.getManifestHeader(Constants.EXPORT_PACKAGE); if (header == null) { bundle.setHeader(Constants.EXPORT_PACKAGE, ""); //$NON-NLS-1$ diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddNewExtensionPointResolution.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddNewExtensionPointResolution.java index 3a4a13b4b8..53d8d74da6 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddNewExtensionPointResolution.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddNewExtensionPointResolution.java @@ -38,11 +38,9 @@ public String getLabel() { @Override protected void createChange(IBaseModel model) { IEditorPart part = PDEPlugin.getActivePage().getActiveEditor(); - if (part instanceof ManifestEditor) { - ManifestEditor editor = (ManifestEditor) part; + if (part instanceof ManifestEditor editor) { IBaseModel base = editor.getAggregateModel(); - if (base instanceof IBundlePluginModelBase) { - IBundlePluginModelBase pluginModel = (IBundlePluginModelBase) base; + if (base instanceof IBundlePluginModelBase pluginModel) { NewExtensionPointWizard wizard = new NewExtensionPointWizard(pluginModel.getUnderlyingResource().getProject(), pluginModel, editor) { @Override public boolean performFinish() { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddNewExtensionResolution.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddNewExtensionResolution.java index c56c137569..643282f4bc 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddNewExtensionResolution.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddNewExtensionResolution.java @@ -38,11 +38,9 @@ public String getLabel() { @Override protected void createChange(IBaseModel model) { IEditorPart part = PDEPlugin.getActivePage().getActiveEditor(); - if (part instanceof ManifestEditor) { - ManifestEditor editor = (ManifestEditor) part; + if (part instanceof ManifestEditor editor) { IBaseModel base = editor.getAggregateModel(); - if (base instanceof IBundlePluginModelBase) { - IBundlePluginModelBase pluginModel = (IBundlePluginModelBase) base; + if (base instanceof IBundlePluginModelBase pluginModel) { NewExtensionWizard wizard = new NewExtensionWizard(pluginModel.getUnderlyingResource().getProject(), pluginModel, editor) { @Override public boolean performFinish() { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddSingletonToSymbolicName.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddSingletonToSymbolicName.java index d606c2f178..1104b589b9 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddSingletonToSymbolicName.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/AddSingletonToSymbolicName.java @@ -49,8 +49,7 @@ public String getLabel() { @Override protected void createChange(BundleModel model) { IBundle bundle = model.getBundle(); - if (bundle instanceof Bundle) { - Bundle bun = (Bundle) bundle; + if (bundle instanceof Bundle bun) { IManifestHeader header = bun.getManifestHeader(Constants.BUNDLE_SYMBOLICNAME); if (header instanceof BundleSymbolicNameHeader) { if (fisDirective && TargetPlatformHelper.getTargetVersion() >= 3.1) diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/ChooseClassXMLResolution.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/ChooseClassXMLResolution.java index e5029bdaff..0f80976863 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/ChooseClassXMLResolution.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/ChooseClassXMLResolution.java @@ -30,9 +30,8 @@ public ChooseClassXMLResolution(int resolutionType, IMarker marker) { @Override protected void createChange(IPluginModelBase model) { Object object = findNode(model); - if (!(object instanceof PluginAttribute)) + if (!(object instanceof PluginAttribute attrib)) return; - PluginAttribute attrib = (PluginAttribute) object; IDocumentElementNode element = attrib.getEnclosingElement(); String type = PDEJavaHelperUI.selectType(fResource, IJavaElementSearchConstants.CONSIDER_CLASSES_AND_INTERFACES); if (type != null) diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/CreateClassXMLResolution.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/CreateClassXMLResolution.java index 03cbd0a308..bf286209b4 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/CreateClassXMLResolution.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/CreateClassXMLResolution.java @@ -40,10 +40,9 @@ public CreateClassXMLResolution(int resolutionType, IMarker marker) { @Override protected void createChange(IPluginModelBase model) { Object object = findNode(model); - if (!(object instanceof PluginAttribute)) + if (!(object instanceof PluginAttribute attr)) return; - PluginAttribute attr = (PluginAttribute) object; String name = TextUtil.trimNonAlphaChars(attr.getValue()).replace('$', '.'); IProject project = model.getUnderlyingResource().getProject(); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/MultiFixResolution.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/MultiFixResolution.java index 601275b667..57ca05c038 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/MultiFixResolution.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/MultiFixResolution.java @@ -106,9 +106,8 @@ private void fixMarker(IMarker marker) { @Override public boolean equals(Object obj) { - if (!(obj instanceof MultiFixResolution)) + if (!(obj instanceof MultiFixResolution multiFix)) return false; - MultiFixResolution multiFix = (MultiFixResolution) obj; try { String categoryId = (String) multiFix.fMarker.getAttribute(PDEMarkerFactory.CAT_ID); if (categoryId == null) diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/RemoveNodeXMLResolution.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/RemoveNodeXMLResolution.java index b676fbd649..8c1bde478a 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/RemoveNodeXMLResolution.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/RemoveNodeXMLResolution.java @@ -41,8 +41,7 @@ protected void createChange(IPluginModelBase model) { ((IPluginParent) parent).remove(pluginObject); else if (parent instanceof PluginBaseNode) ((PluginBaseNode) parent).remove(pluginObject); - else if (pluginObject instanceof PluginAttribute) { - PluginAttribute attr = (PluginAttribute) pluginObject; + else if (pluginObject instanceof PluginAttribute attr) { attr.getEnclosingElement().setXMLAttribute(attr.getName(), null); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/RemoveUnknownExecEnvironments.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/RemoveUnknownExecEnvironments.java index 71fafa4b80..66728165d1 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/RemoveUnknownExecEnvironments.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/RemoveUnknownExecEnvironments.java @@ -32,8 +32,7 @@ public RemoveUnknownExecEnvironments(int type, IMarker marker) { @Override protected void createChange(BundleModel model) { IManifestHeader header = model.getBundle().getManifestHeader(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT); - if (header instanceof RequiredExecutionEnvironmentHeader) { - RequiredExecutionEnvironmentHeader reqHeader = (RequiredExecutionEnvironmentHeader) header; + if (header instanceof RequiredExecutionEnvironmentHeader reqHeader) { ExecutionEnvironment[] bundleEnvs = reqHeader.getEnvironments(); IExecutionEnvironment[] systemEnvs = JavaRuntime.getExecutionEnvironmentsManager().getExecutionEnvironments(); for (ExecutionEnvironment bundleEnv : bundleEnvs) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/ReplaceExecEnvironment.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/ReplaceExecEnvironment.java index c153005631..ef1a22ccff 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/ReplaceExecEnvironment.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/ReplaceExecEnvironment.java @@ -41,8 +41,7 @@ public String getLabel() { @Override protected void createChange(BundleModel model) { IManifestHeader header = model.getBundle().getManifestHeader(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT); - if (header instanceof RequiredExecutionEnvironmentHeader) { - RequiredExecutionEnvironmentHeader reqHeader = (RequiredExecutionEnvironmentHeader) header; + if (header instanceof RequiredExecutionEnvironmentHeader reqHeader) { ExecutionEnvironment[] bundleEnvs = reqHeader.getEnvironments(); IExecutionEnvironment[] systemEnvs = JavaRuntime.getExecutionEnvironmentsManager() .getExecutionEnvironments(); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/UnsupportedSingletonDirectiveResolution.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/UnsupportedSingletonDirectiveResolution.java index 9cb1578dd2..369c5ee8c4 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/UnsupportedSingletonDirectiveResolution.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/UnsupportedSingletonDirectiveResolution.java @@ -41,8 +41,7 @@ public String getLabel() { @Override protected void createChange(BundleModel model) { IBundle bundle = model.getBundle(); - if (bundle instanceof Bundle) { - Bundle bun = (Bundle) bundle; + if (bundle instanceof Bundle bun) { IManifestHeader header = bun.getManifestHeader(Constants.BUNDLE_SYMBOLICNAME); if (header instanceof BundleSymbolicNameHeader) { ((BundleSymbolicNameHeader) header).fixUnsupportedDirective(); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/java/FindClassResolutionsOperation.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/java/FindClassResolutionsOperation.java index f3430819e1..ff89f07d0a 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/java/FindClassResolutionsOperation.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/java/FindClassResolutionsOperation.java @@ -306,8 +306,7 @@ private Map findValidPackagesContainingSimpleT @Override public void acceptSearchMatch(SearchMatch aMatch) throws CoreException { Object element = aMatch.getElement(); - if (element instanceof IType) { - IType type = (IType) element; + if (element instanceof IType type) { // Only try to import types we can access (Bug 406232) if (Flags.isPublic(type.getFlags())) { if (!currentJavaProject.equals(type.getJavaProject())) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/java/JavaResolutionFactory.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/java/JavaResolutionFactory.java index 7ab7a9c0c0..b2b9c196b8 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/java/JavaResolutionFactory.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/java/JavaResolutionFactory.java @@ -196,9 +196,8 @@ public Change perform(IProgressMonitor pm) throws CoreException { PDEModelUtility.modifyModel(new ModelModification(getProject()) { @Override protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws CoreException { - if (!(model instanceof IPluginModelBase)) + if (!(model instanceof IPluginModelBase base)) return; - IPluginModelBase base = (IPluginModelBase) model; String[] pluginIdStrings = null; if ("JUnit 5 bundles".equals(getChangeObject())) { //$NON-NLS-1$ pluginIdStrings = getJUnit5Bundles(); @@ -319,16 +318,14 @@ public Change perform(IProgressMonitor pm) throws CoreException { PDEModelUtility.modifyModel(new ModelModification(getProject()) { @Override protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws CoreException { - if (!(model instanceof IBundlePluginModelBase)) + if (!(model instanceof IBundlePluginModelBase base)) return; - IBundlePluginModelBase base = (IBundlePluginModelBase) model; IBundle bundle = base.getBundleModel().getBundle(); String pkgId = ((ExportPackageDescription) getChangeObject()).getName(); IManifestHeader header = bundle.getManifestHeader(Constants.IMPORT_PACKAGE); if (header == null) { bundle.setHeader(Constants.IMPORT_PACKAGE, pkgId); - } else if (header instanceof ImportPackageHeader) { - ImportPackageHeader ipHeader = (ImportPackageHeader) header; + } else if (header instanceof ImportPackageHeader ipHeader) { int manifestVersion = BundlePluginBase.getBundleManifestVersion(bundle); String versionAttr = (manifestVersion < 2) ? ICoreConstants.PACKAGE_SPECIFICATION_VERSION : Constants.VERSION_ATTRIBUTE; ImportPackageObject impObject = new ImportPackageObject((ManifestHeader) header, (ExportPackageDescription) getChangeObject(), versionAttr); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/dialogs/FeatureSelectionDialog.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/dialogs/FeatureSelectionDialog.java index 39683af5f6..4f68f4e481 100755 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/dialogs/FeatureSelectionDialog.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/dialogs/FeatureSelectionDialog.java @@ -49,8 +49,7 @@ public class FeatureSelectionDialog extends FilteredItemsSelectionDialog { private final class FeatureDetailsLabelProvider extends LabelProvider { @Override public String getText(Object element) { - if (element instanceof IFeatureModel) { - IFeatureModel featureModel = (IFeatureModel) element; + if (element instanceof IFeatureModel featureModel) { if (filter.matchesFeatureId(featureModel)) { return NLS.bind(PDEUIMessages.FeatureSelectionDialog_IdMatched, featureModel.getFeature().getId()); } @@ -81,8 +80,7 @@ public boolean isConsistentItem(Object item) { @Override public boolean matchItem(Object item) { - if (item instanceof IFeatureModel) { - IFeatureModel model = (IFeatureModel) item; + if (item instanceof IFeatureModel model) { if (matchesFeatureId(model)) return true; return matchesPluginId(model) != null; @@ -135,8 +133,7 @@ private int getId(Object element) { } private int compareSimilarObjects(Object o1, Object o2) { - if (o1 instanceof IFeatureModel && o2 instanceof IFeatureModel) { - IFeatureModel ipmb1 = (IFeatureModel) o1; + if (o1 instanceof IFeatureModel ipmb1 && o2 instanceof IFeatureModel) { IFeatureModel ipmb2 = (IFeatureModel) o2; return compareFeatures(ipmb1.getFeature(), ipmb2.getFeature()); } @@ -215,8 +212,7 @@ protected void fillContentProvider(AbstractContentProvider contentProvider, Item @Override public String getElementName(Object item) { - if (item instanceof IFeatureModel) { - IFeatureModel model = (IFeatureModel) item; + if (item instanceof IFeatureModel model) { return model.getFeature().getId(); } return null; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/dialogs/PluginSelectionDialog.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/dialogs/PluginSelectionDialog.java index 34f27522e6..6bc75b3004 100755 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/dialogs/PluginSelectionDialog.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/dialogs/PluginSelectionDialog.java @@ -76,8 +76,7 @@ public boolean isConsistentItem(Object item) { @Override public boolean matchItem(Object item) { String id = null; - if (item instanceof IPluginModelBase) { - IPluginModelBase model = (IPluginModelBase) item; + if (item instanceof IPluginModelBase model) { id = model.getPluginBase().getId(); } @@ -106,8 +105,7 @@ private int getId(Object element) { } private int compareSimilarObjects(Object o1, Object o2) { - if (o1 instanceof IPluginModelBase && o2 instanceof IPluginModelBase) { - IPluginModelBase ipmb1 = (IPluginModelBase) o1; + if (o1 instanceof IPluginModelBase ipmb1 && o2 instanceof IPluginModelBase) { IPluginModelBase ipmb2 = (IPluginModelBase) o2; return comparePlugins(ipmb1.getPluginBase(), ipmb2.getPluginBase()); } @@ -277,8 +275,7 @@ protected IDialogSettings getDialogSettings() { @Override public String getElementName(Object item) { - if (item instanceof IPluginModelBase) { - IPluginModelBase model = (IPluginModelBase) item; + if (item instanceof IPluginModelBase model) { return model.getPluginBase().getId(); } return null; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/FormOutlinePage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/FormOutlinePage.java index 27b4c2b7a0..8335522fc9 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/FormOutlinePage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/FormOutlinePage.java @@ -218,8 +218,7 @@ public void selectionChanged(SelectionChangedEvent event) { fOutlineSelection = true; try { ISelection selection = event.getSelection(); - if (selection.isEmpty() == false && selection instanceof IStructuredSelection) { - IStructuredSelection ssel = (IStructuredSelection) selection; + if (selection.isEmpty() == false && selection instanceof IStructuredSelection ssel) { Object item = ssel.getFirstElement(); selectionChanged(item); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/JarEntryEditorInput.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/JarEntryEditorInput.java index ed93844304..2cd64180c3 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/JarEntryEditorInput.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/JarEntryEditorInput.java @@ -39,9 +39,8 @@ public JarEntryEditorInput(IStorage jarEntryFile) { public boolean equals(Object obj) { if (this == obj) return true; - if (!(obj instanceof JarEntryEditorInput)) + if (!(obj instanceof JarEntryEditorInput other)) return false; - JarEntryEditorInput other = (JarEntryEditorInput) obj; return fJarEntryFile.equals(other.fJarEntryFile); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/KeyValueSourcePage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/KeyValueSourcePage.java index 725962cfc6..1e0e1fa926 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/KeyValueSourcePage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/KeyValueSourcePage.java @@ -31,8 +31,7 @@ public ViewerComparator createDefaultOutlineComparator() { return new ViewerComparator() { @Override public int compare(Viewer viewer, Object e1, Object e2) { - if ((e1 instanceof IDocumentKey) && (e2 instanceof IDocumentKey)) { - IDocumentKey key1 = (IDocumentKey) e1; + if ((e1 instanceof IDocumentKey key1) && (e2 instanceof IDocumentKey)) { IDocumentKey key2 = (IDocumentKey) e2; return Integer.compare(key1.getOffset(), key2.getOffset()); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/ModelDataTransfer.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/ModelDataTransfer.java index df9cae16ee..1292265364 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/ModelDataTransfer.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/ModelDataTransfer.java @@ -60,10 +60,9 @@ protected String[] getTypeNames() { @Override protected void javaToNative(Object data, TransferData transferData) { - if (!(data instanceof Object[])) { + if (!(data instanceof Object[] objects)) { return; } - Object[] objects = (Object[]) data; int count = objects.length; try (ByteArrayOutputStream out = new ByteArrayOutputStream(); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/OpenManifestHandler.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/OpenManifestHandler.java index dfc2d20758..f4773c389b 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/OpenManifestHandler.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/OpenManifestHandler.java @@ -64,8 +64,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException { } } ISelection selection = HandlerUtil.getCurrentSelection(event); - if (selection instanceof IStructuredSelection) { - IStructuredSelection ssel = (IStructuredSelection) selection; + if (selection instanceof IStructuredSelection ssel) { Iterator it = ssel.iterator(); while (it.hasNext()) { Object element = it.next(); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/PDEFormEditor.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/PDEFormEditor.java index 61794f2e43..2e7fb8a4dc 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/PDEFormEditor.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/PDEFormEditor.java @@ -112,8 +112,7 @@ public void install(ISelectionProvider selectionProvider) { return; } - if (selectionProvider instanceof IPostSelectionProvider) { - IPostSelectionProvider provider = (IPostSelectionProvider) selectionProvider; + if (selectionProvider instanceof IPostSelectionProvider provider) { provider.addPostSelectionChangedListener(this); } else { selectionProvider.addSelectionChangedListener(this); @@ -137,8 +136,7 @@ public void uninstall(ISelectionProvider selectionProvider) { return; } - if (selectionProvider instanceof IPostSelectionProvider) { - IPostSelectionProvider provider = (IPostSelectionProvider) selectionProvider; + if (selectionProvider instanceof IPostSelectionProvider provider) { provider.removePostSelectionChangedListener(this); } else { selectionProvider.removeSelectionChangedListener(this); @@ -232,8 +230,7 @@ protected void createInputContexts(InputContextManager contextManager) { createResourceContexts(contextManager, (IFileEditorInput) input); } else if (input instanceof IStorageEditorInput) { createStorageContexts(contextManager, (IStorageEditorInput) input); - } else if (input instanceof IURIEditorInput) { - IURIEditorInput uriEditorInput = (IURIEditorInput) input; + } else if (input instanceof IURIEditorInput uriEditorInput) { try { IFileStore store = EFS.getStore(uriEditorInput.getURI()); if (!EFS.SCHEME_FILE.equals(store.getFileSystem().getScheme())) @@ -404,8 +401,7 @@ public void doRevert() { private boolean doRevertFormPage() { boolean reverted = false; IBaseModel model = getAggregateModel(); - if (model instanceof IWorkspaceModel) { - IWorkspaceModel workspaceModel = (IWorkspaceModel) model; + if (model instanceof IWorkspaceModel workspaceModel) { workspaceModel.reload(); reverted = true; } @@ -416,8 +412,7 @@ private boolean doRevertSourcePages() { boolean reverted = false; IFormPage[] pages = getPages(); for (IFormPage page : pages) { - if (page instanceof PDESourcePage) { - PDESourcePage sourcePage = (PDESourcePage) page; + if (page instanceof PDESourcePage sourcePage) { // Flush any pending editor operations into the document // so that the revert operation executes (revert operation is // aborted if the current document has not changed) @@ -440,8 +435,7 @@ public void doRevert(IEditorInput input) { ((PDEFormPage) currentPage).cancelEdit(); InputContext context = fInputContextManager.getContext(input); IFormPage page = findPage(context.getId()); - if (page != null && page instanceof PDESourcePage) { - PDESourcePage spage = (PDESourcePage) page; + if (page != null && page instanceof PDESourcePage spage) { spage.doRevertToSaved(); } editorDirtyStateChanged(); @@ -453,8 +447,7 @@ public void flushEdits() { if (mForm != null) mForm.commit(false); for (IFormPage page : pages) { - if (page instanceof PDESourcePage) { - PDESourcePage sourcePage = (PDESourcePage) page; + if (page instanceof PDESourcePage sourcePage) { sourcePage.getInputContext().flushEditorInput(); } } @@ -806,8 +799,7 @@ protected void performGlobalAction(String id) { private void copyToClipboard(ISelection selection) { Object[] objects = null; String textVersion = null; - if (selection instanceof IStructuredSelection) { - IStructuredSelection ssel = (IStructuredSelection) selection; + if (selection instanceof IStructuredSelection ssel) { if (ssel.isEmpty()) return; objects = ssel.toArray(); @@ -869,8 +861,7 @@ public boolean canCopy(ISelection selection) { return false; if (selection instanceof IStructuredSelection) return !selection.isEmpty(); - if (selection instanceof ITextSelection) { - ITextSelection textSelection = (ITextSelection) selection; + if (selection instanceof ITextSelection textSelection) { return textSelection.getLength() > 0; } return false; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/PDEFormEditorContributor.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/PDEFormEditorContributor.java index 54660eb83e..9552ddc82b 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/PDEFormEditorContributor.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/PDEFormEditorContributor.java @@ -281,12 +281,11 @@ protected void makeActions() { @Override public void setActiveEditor(IEditorPart targetEditor) { - if (targetEditor instanceof PDESourcePage) { + if (targetEditor instanceof PDESourcePage page) { // Fixing the 'goto line' problem - - // the action is thinking that source page - // is a standalone editor and tries to activate it + // the action is thinking that source page is a standalone editor + // and tries to activate it // #19361 - PDESourcePage page = (PDESourcePage) targetEditor; PDEPlugin.getActivePage().activate(page.getEditor()); return; } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/PDEFormPage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/PDEFormPage.java index 4fa17e796c..fb79067d4f 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/PDEFormPage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/PDEFormPage.java @@ -86,8 +86,7 @@ public void dispose() { } private void resetMenu(Menu menu, Control c) { - if (c instanceof Composite) { - Composite comp = (Composite) c; + if (c instanceof Composite comp) { Control[] children = comp.getChildren(); for (Control child : children) { resetMenu(menu, child); @@ -124,8 +123,7 @@ public void run() { //check to see if our form parts are contributing actions IFormPart[] parts = managedForm.getParts(); for (IFormPart part : parts) { - if (part instanceof IAdaptable) { - IAdaptable adapter = (IAdaptable) part; + if (part instanceof IAdaptable adapter) { IAction[] actions = adapter.getAdapter(IAction[].class); if (actions != null) { for (IAction action : actions) { @@ -246,8 +244,7 @@ private AbstractFormPart getFocusSection() { } protected boolean canPerformDirectly(String id, Control control) { - if (control instanceof Text) { - Text text = (Text) control; + if (control instanceof Text text) { if (id.equals(ActionFactory.CUT.getId())) { text.cut(); return true; @@ -356,8 +353,7 @@ public void updateFormSelection() { // Set focus on the control lastControl.forceFocus(); // If the control is a Text widget, select its contents - if (lastControl instanceof Text) { - Text text = (Text) lastControl; + if (lastControl instanceof Text text) { text.setSelection(0, text.getText().length()); } } else { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/PDEProjectionViewer.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/PDEProjectionViewer.java index 816622166d..435f535b2e 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/PDEProjectionViewer.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/PDEProjectionViewer.java @@ -90,8 +90,7 @@ public void configure(SourceViewerConfiguration configuration) { super.configure(configuration); // Configure quick outline operation for the source viewer only if the // given source viewer supports it - if (fIsQuickOutlineEnabled && configuration instanceof ChangeAwareSourceViewerConfiguration) { - ChangeAwareSourceViewerConfiguration sourceConfiguration = (ChangeAwareSourceViewerConfiguration) configuration; + if (fIsQuickOutlineEnabled && configuration instanceof ChangeAwareSourceViewerConfiguration sourceConfiguration) { fOutlinePresenter = sourceConfiguration.getOutlinePresenter(this); if (fOutlinePresenter != null) { fOutlinePresenter.install(this); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/PDESourcePage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/PDESourcePage.java index 2e10209f46..397738bf7c 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/PDESourcePage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/PDESourcePage.java @@ -104,8 +104,7 @@ private class PDESourcePageChangedListener implements ISelectionChangedListener */ public void install(ISelectionProvider selectionProvider) { if (selectionProvider != null) { - if (selectionProvider instanceof IPostSelectionProvider) { - IPostSelectionProvider provider = (IPostSelectionProvider) selectionProvider; + if (selectionProvider instanceof IPostSelectionProvider provider) { provider.addPostSelectionChangedListener(this); } else { selectionProvider.addSelectionChangedListener(this); @@ -124,8 +123,7 @@ public void selectionChanged(SelectionChangedEvent event) { */ public void uninstall(ISelectionProvider selectionProvider) { if (selectionProvider != null) { - if (selectionProvider instanceof IPostSelectionProvider) { - IPostSelectionProvider provider = (IPostSelectionProvider) selectionProvider; + if (selectionProvider instanceof IPostSelectionProvider provider) { provider.removePostSelectionChangedListener(this); } else { selectionProvider.removeSelectionChangedListener(this); @@ -195,8 +193,7 @@ public void dispose() { @Override public void updateSelection(SelectionChangedEvent event) { ISelection sel = event.getSelection(); - if (sel instanceof IStructuredSelection) { - IStructuredSelection structuredSelection = (IStructuredSelection) sel; + if (sel instanceof IStructuredSelection structuredSelection) { updateSelection(structuredSelection.getFirstElement()); } } @@ -378,8 +375,7 @@ protected void createActions() { PDESelectAnnotationRulerAction action = new PDESelectAnnotationRulerAction(getBundleForConstructedKeys(), "PDESelectAnnotationRulerAction.", this, getVerticalRuler()); //$NON-NLS-1$ setAction(ITextEditorActionConstants.RULER_CLICK, action); PDEFormEditorContributor contributor = fEditor == null ? null : fEditor.getContributor(); - if (contributor instanceof PDEFormTextEditorContributor) { - PDEFormTextEditorContributor textContributor = (PDEFormTextEditorContributor) contributor; + if (contributor instanceof PDEFormTextEditorContributor textContributor) { setAction(PDEActionConstants.OPEN, textContributor.getHyperlinkAction()); setAction(PDEActionConstants.FORMAT, textContributor.getFormatAction()); } @@ -407,16 +403,12 @@ public final void selectionChanged(SelectionChangedEvent event) { if (event.getSource() == getSelectionProvider()) return; ISelection sel = event.getSelection(); - if (sel instanceof IStructuredSelection) { - - IStructuredSelection structuredSel = (IStructuredSelection) sel; + if (sel instanceof IStructuredSelection structuredSel) { // Store the selected object to save us having to do this again. setSelectedObject(structuredSel.getFirstElement()); - } else if (sel instanceof ITextSelection) { - - ITextSelection textSel = (ITextSelection) sel; + } else if (sel instanceof ITextSelection textSel) { setSelectedObject(getRangeElement(textSel.getOffset(), false)); @@ -467,8 +459,7 @@ public ISourceViewer getViewer() { @Override protected void editorContextMenuAboutToShow(IMenuManager menu) { PDEFormEditorContributor contributor = fEditor == null ? null : fEditor.getContributor(); - if (contributor instanceof PDEFormTextEditorContributor) { - PDEFormTextEditorContributor textContributor = (PDEFormTextEditorContributor) contributor; + if (contributor instanceof PDEFormTextEditorContributor textContributor) { HyperlinkAction action = textContributor.getHyperlinkAction(); if ((action != null) && action.isEnabled() && ((action.getHyperLink() instanceof ExtensionHyperLink) == false)) { // Another detector handles this the extension hyperlink case @@ -532,9 +523,7 @@ protected void updateOutlinePageSelection(Object rangeElement) { protected void handleSelectionChangedSourcePage(SelectionChangedEvent event) { ISelection selection = event.getSelection(); - if (!selection.isEmpty() && selection instanceof ITextSelection) { - - ITextSelection textSel = (ITextSelection) selection; + if (!selection.isEmpty() && selection instanceof ITextSelection textSel) { // Get the current element from the offset int offset = textSel.getOffset(); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/PDEStorageDocumentProvider.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/PDEStorageDocumentProvider.java index f2c249d6b7..314cec37be 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/PDEStorageDocumentProvider.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/PDEStorageDocumentProvider.java @@ -45,8 +45,7 @@ public PDEStorageDocumentProvider(IDocumentSetupParticipant participant) { protected boolean setDocumentContent(IDocument document, IEditorInput editorInput, String encoding) throws CoreException { boolean set = super.setDocumentContent(document, editorInput, encoding); if (!set) { - if (editorInput instanceof IURIEditorInput) { - IURIEditorInput input = (IURIEditorInput) editorInput; + if (editorInput instanceof IURIEditorInput input) { IFileStore store = EFS.getStore(input.getURI()); try (InputStream is = store.openInputStream(EFS.CACHE, new NullProgressMonitor())) { setDocumentContent(document, is, encoding); @@ -68,8 +67,7 @@ protected void setupDocument(Object element, IDocument document) { @Override protected IAnnotationModel createAnnotationModel(Object element) throws CoreException { - if (element instanceof IAdaptable) { - IAdaptable input = (IAdaptable) element; + if (element instanceof IAdaptable input) { File file = input.getAdapter(File.class); if (file == null && (input instanceof IURIEditorInput)) { URI uri = ((IURIEditorInput) input).getURI(); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/actions/ToggleExpandStateAction.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/actions/ToggleExpandStateAction.java index 3602c0f03e..6c06595846 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/actions/ToggleExpandStateAction.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/actions/ToggleExpandStateAction.java @@ -144,8 +144,7 @@ private int getExtensionsChildCount(IPluginParent leafData) { */ private void expandChildrenElements(Object[] children, boolean fullExpand) { for (Object child : children) { - if (child instanceof PluginParentNode) { - PluginParentNode node = (PluginParentNode) child; + if (child instanceof PluginParentNode node) { if (node.getChildCount() > 0 && fullExpand) { boolean furtherExpanding = !(node instanceof PluginExtensionNode && !fExtensionTree.getExpandedState(node)); expandChildrenElements(node.getChildren(), furtherExpanding); @@ -168,8 +167,7 @@ public static boolean isExpandable(IStructuredSelection selection) { if (!selection.isEmpty()) { for (Iterator iterator = selection.iterator(); iterator.hasNext();) { Object element = iterator.next(); - if (element instanceof PluginParentNode) { - PluginParentNode node = (PluginParentNode) element; + if (element instanceof PluginParentNode node) { if (node.getChildCount() > 0) { isExpandable = true; break; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/build/BuildHyperlinkDetector.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/build/BuildHyperlinkDetector.java index 1e9e813f70..6e756d5da9 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/build/BuildHyperlinkDetector.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/build/BuildHyperlinkDetector.java @@ -42,10 +42,9 @@ public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boo return null; IDocumentRange element = fSourcePage.getRangeElement(region.getOffset(), true); - if (!(element instanceof BuildEntry)) + if (!(element instanceof BuildEntry entry)) return null; - BuildEntry entry = (BuildEntry) element; if (!entry.getModel().isEditable() || !(entry.getModel() instanceof IEditingModel)) return null; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/build/BuildOutlinePage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/build/BuildOutlinePage.java index e34a408d36..7100d2ba70 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/build/BuildOutlinePage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/build/BuildOutlinePage.java @@ -30,8 +30,7 @@ public BuildOutlinePage(PDEFormEditor editor) { @Override protected Object[] getChildren(Object parent) { - if (parent instanceof PDEFormPage) { - PDEFormPage page = (PDEFormPage) parent; + if (parent instanceof PDEFormPage page) { IBuildModel model = (IBuildModel) page.getModel(); if (model.isValid()) { IBuild build = model.getBuild(); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/build/BuildSourcePage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/build/BuildSourcePage.java index 6caaadb716..d76406565c 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/build/BuildSourcePage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/build/BuildSourcePage.java @@ -61,8 +61,7 @@ public Object getParent(Object child) { @Override public Object[] getElements(Object parent) { - if (parent instanceof IBuildModel) { - IBuildModel model = (IBuildModel) parent; + if (parent instanceof IBuildModel model) { IBuild build = model.getBuild(); return build.getBuildEntries(); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/build/BuildUndoManager.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/build/BuildUndoManager.java index c55c2f400c..1cc05a41fd 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/build/BuildUndoManager.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/build/BuildUndoManager.java @@ -95,8 +95,7 @@ private void executeRemove(IBuildModel model, Object[] elements) { } private void executeChange(Object element, String propertyName, Object oldValue, Object newValue) { - if (element instanceof BuildObject) { - BuildObject bobj = (BuildObject) element; + if (element instanceof BuildObject bobj) { try { bobj.restoreProperty(propertyName, oldValue, newValue); } catch (CoreException e) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/build/RuntimeInfoSection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/build/RuntimeInfoSection.java index adbe2812b4..8069ac915b 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/build/RuntimeInfoSection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/build/RuntimeInfoSection.java @@ -907,9 +907,8 @@ public void modelChanged(IModelChangedEvent event) { String keyName = event.getChangedProperty(); // check if model change applies to this section - if (!(changeObject instanceof IBuildEntry)) + if (!(changeObject instanceof IBuildEntry entry)) return; - IBuildEntry entry = (IBuildEntry) changeObject; String entryName = entry.getName(); if (!entryName.startsWith(IBuildEntry.JAR_PREFIX) && !entryName.equals(PROPERTY_JAR_ORDER) && !entryName.equals(PROPERTY_BIN_INCLUDES)) return; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/CategoryOutlinePage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/CategoryOutlinePage.java index 7c5c5c889c..dc2b8ea0e5 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/CategoryOutlinePage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/CategoryOutlinePage.java @@ -43,8 +43,7 @@ public CategoryOutlinePage(PDEFormEditor editor) { @Override protected Object[] getChildren(Object parent) { - if (parent instanceof PDEFormPage) { - PDEFormPage page = (PDEFormPage) parent; + if (parent instanceof PDEFormPage page) { ISiteModel model = (ISiteModel) page.getModel(); if (model.isValid()) { ISite site = model.getSite(); @@ -67,8 +66,7 @@ protected Object[] getChildren(Object parent) { } } } - if (parent instanceof ISiteCategoryDefinition) { - ISiteCategoryDefinition catDef = (ISiteCategoryDefinition) parent; + if (parent instanceof ISiteCategoryDefinition catDef) { ISiteModel model = catDef.getModel(); if (model.isValid()) { ISite site = model.getSite(); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/CategorySection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/CategorySection.java index 4864f846e5..93599766dd 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/CategorySection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/CategorySection.java @@ -259,10 +259,9 @@ public void dragOver(DropTargetEvent event) { */ @Override protected int determineLocation(DropTargetEvent event) { - if (!(event.item instanceof Item)) { + if (!(event.item instanceof Item item)) { return LOCATION_NONE; } - Item item = (Item) event.item; Point coordinates = new Point(event.x, event.y); coordinates = getViewer().getControl().toControl(coordinates); if (item != null) { @@ -298,8 +297,7 @@ public boolean performDrop(Object data) { } return true; } - if (objects.length > 0 && objects[0] instanceof SiteCategoryDefinitionAdapter) { - SiteCategoryDefinitionAdapter adapter = (SiteCategoryDefinitionAdapter) objects[0]; + if (objects.length > 0 && objects[0] instanceof SiteCategoryDefinitionAdapter adapter) { if (op == DND.DROP_COPY && target != null) { copyCategory(adapter, target); } else { @@ -544,9 +542,8 @@ private void handleAddCategoryDefinition() { categoryDef.setName(name); categoryDef.setLabel(label); Object firstElement = fCategoryViewer.getStructuredSelection().getFirstElement(); - if (firstElement instanceof SiteCategoryDefinitionAdapter) { + if (firstElement instanceof SiteCategoryDefinitionAdapter adapter) { // creating new nested category inside of something existing - SiteCategoryDefinitionAdapter adapter = (SiteCategoryDefinitionAdapter) firstElement; catDefReference = adapter.category.getName(); addCategory(categoryDef, catDefReference); } @@ -575,18 +572,18 @@ private boolean handleRemove() { if (!handleRemoveCategoryDefinition((SiteCategoryDefinitionAdapter) object)) { success = false; } - } else if (object instanceof SiteFeatureAdapter) { - // No need to remove the feature if its category is already removed - SiteFeatureAdapter fa = (SiteFeatureAdapter) object; + } else if (object instanceof SiteFeatureAdapter fa) { + // No need to remove the feature if its category is already + // removed if (removedCategories.contains(fa.category)) continue; if (!handleRemoveSiteFeatureAdapter(fa)) { success = false; } - } else if (object instanceof SiteBundleAdapter) { - // No need to remove the bundle if its category is already removed - SiteBundleAdapter ba = (SiteBundleAdapter) object; + } else if (object instanceof SiteBundleAdapter ba) { + // No need to remove the bundle if its category is already + // removed if (removedCategories.contains(ba.category)) continue; @@ -602,12 +599,10 @@ private boolean handleRemoveCategoryDefinition(SiteCategoryDefinitionAdapter cat try { Object[] children = ((CategoryContentProvider) fCategoryViewer.getContentProvider()).getChildren(catDef); for (Object element : children) { - if (element instanceof SiteCategoryDefinitionAdapter) { - SiteCategoryDefinitionAdapter adapter = (SiteCategoryDefinitionAdapter) element; + if (element instanceof SiteCategoryDefinitionAdapter adapter) { removeCategory(adapter.category, catDef.category.getName()); handleRemoveCategoryDefinition(adapter); - } else if (element instanceof SiteFeatureAdapter) { - SiteFeatureAdapter adapter = (SiteFeatureAdapter) element; + } else if (element instanceof SiteFeatureAdapter adapter) { ISiteCategory[] cats = adapter.feature.getCategories(); for (ISiteCategory cat : cats) { if (adapter.category.equals(cat.getName())) @@ -616,8 +611,7 @@ private boolean handleRemoveCategoryDefinition(SiteCategoryDefinitionAdapter cat if (adapter.feature.getCategories().length == 0) { fModel.getSite().removeFeatures(new ISiteFeature[] {adapter.feature}); } - } else if (element instanceof SiteBundleAdapter) { - SiteBundleAdapter adapter = (SiteBundleAdapter) element; + } else if (element instanceof SiteBundleAdapter adapter) { ISiteCategory[] cats = adapter.bundle.getCategories(); for (ISiteCategory cat : cats) { if (adapter.category.equals(cat.getName())) diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/CategoryUndoManager.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/CategoryUndoManager.java index de8f7e5831..298c7ad293 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/CategoryUndoManager.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/CategoryUndoManager.java @@ -87,8 +87,7 @@ private void executeAdd(IModelChangeProvider model, Object[] elements) { site.addArchives(new ISiteArchive[] {(ISiteArchive) element}); } else if (element instanceof ISiteCategoryDefinition) { site.addCategoryDefinitions(new ISiteCategoryDefinition[] {(ISiteCategoryDefinition) element}); - } else if (element instanceof ISiteCategory) { - ISiteCategory category = (ISiteCategory) element; + } else if (element instanceof ISiteCategory category) { ISiteObject siteObject = category.getParent(); if (siteObject instanceof ISiteFeature) { ((ISiteFeature) siteObject).addCategories(new ISiteCategory[] {category}); @@ -116,8 +115,7 @@ private void executeRemove(IModelChangeProvider model, Object[] elements) { site.removeArchives(new ISiteArchive[] {(ISiteArchive) element}); } else if (element instanceof ISiteCategoryDefinition) { site.removeCategoryDefinitions(new ISiteCategoryDefinition[] {(ISiteCategoryDefinition) element}); - } else if (element instanceof ISiteCategory) { - ISiteCategory category = (ISiteCategory) element; + } else if (element instanceof ISiteCategory category) { ISiteObject siteObject = category.getParent(); if (siteObject instanceof ISiteFeature) { ((ISiteFeature) siteObject).removeCategories(new ISiteCategory[] {category}); @@ -134,8 +132,7 @@ private void executeRemove(IModelChangeProvider model, Object[] elements) { private void executeChange(Object element, String propertyName, Object oldValue, Object newValue) { - if (element instanceof SiteObject) { - SiteObject sobj = (SiteObject) element; + if (element instanceof SiteObject sobj) { try { sobj.restoreProperty(propertyName, oldValue, newValue); } catch (CoreException e) { @@ -148,8 +145,7 @@ private void executeChange(Object element, String propertyName, Object oldValue, public void modelChanged(IModelChangedEvent event) { if (event.getChangeType() == IModelChangedEvent.CHANGE) { Object object = event.getChangedObjects()[0]; - if (object instanceof ISiteObject) { - ISiteObject obj = (ISiteObject) object; + if (object instanceof ISiteObject obj) { //Ignore events from objects that are not yet in the model. if (!(obj instanceof ISite) && !obj.isInTheModel()) return; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/IUDetailsSection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/IUDetailsSection.java index c512a9bbea..1f601d3cf0 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/IUDetailsSection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/IUDetailsSection.java @@ -178,8 +178,7 @@ protected void fillControls(T currentItem) { @Override public void selectionChanged(IFormPart part, ISelection selection) { T item = null; - if (selection instanceof IStructuredSelection) { - IStructuredSelection structured = (IStructuredSelection) selection; + if (selection instanceof IStructuredSelection structured) { item = fSelectionExtractor.apply(structured.getFirstElement()); } fCurrentItem = item; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/SiteBundleAdapter.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/SiteBundleAdapter.java index 8f390f867b..e860fc3153 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/SiteBundleAdapter.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/SiteBundleAdapter.java @@ -44,8 +44,7 @@ public void write(String indent, PrintWriter writer) { */ @Override public boolean equals(Object obj) { - if (obj instanceof SiteBundleAdapter) { - SiteBundleAdapter adapter = (SiteBundleAdapter) obj; + if (obj instanceof SiteBundleAdapter adapter) { return Objects.equals(bundle, adapter.bundle); } return super.equals(obj); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/SiteCategoryDefinitionAdapter.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/SiteCategoryDefinitionAdapter.java index 6fb97a2670..4561edc874 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/SiteCategoryDefinitionAdapter.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/SiteCategoryDefinitionAdapter.java @@ -43,8 +43,7 @@ public void write(String indent, PrintWriter writer) { */ @Override public boolean equals(Object obj) { - if (obj instanceof SiteCategoryDefinitionAdapter) { - SiteCategoryDefinitionAdapter otherAdapter = (SiteCategoryDefinitionAdapter) obj; + if (obj instanceof SiteCategoryDefinitionAdapter otherAdapter) { String id = category.getName(); String id2 = otherAdapter.category.getName(); boolean sameCategory = id != null && id2 != null && id.equals(id2); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/SiteFeatureAdapter.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/SiteFeatureAdapter.java index a10fc87b1c..3a5b48ce0c 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/SiteFeatureAdapter.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/category/SiteFeatureAdapter.java @@ -44,8 +44,7 @@ public void write(String indent, PrintWriter writer) { */ @Override public boolean equals(Object obj) { - if (obj instanceof SiteFeatureAdapter) { - SiteFeatureAdapter adapter = (SiteFeatureAdapter) obj; + if (obj instanceof SiteFeatureAdapter adapter) { return Objects.equals(feature, adapter.feature); } return super.equals(obj); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/contentassist/TypePackageCompletionProcessor.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/contentassist/TypePackageCompletionProcessor.java index c293481d84..0b899e2d00 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/contentassist/TypePackageCompletionProcessor.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/contentassist/TypePackageCompletionProcessor.java @@ -241,8 +241,7 @@ private Comparator getComparator() { fComparator = new Comparator<>() { @Override public int compare(Object arg0, Object arg1) { - if (arg0 instanceof ICompletionProposal && arg1 instanceof ICompletionProposal) { - ICompletionProposal p1 = (ICompletionProposal) arg0; + if (arg0 instanceof ICompletionProposal p1 && arg1 instanceof ICompletionProposal) { ICompletionProposal p2 = (ICompletionProposal) arg1; return getSortKey(p1).compareToIgnoreCase(getSortKey(p2)); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/contentassist/XMLElementProposalComputer.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/contentassist/XMLElementProposalComputer.java index d3ecd380c4..ec1fa388bb 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/contentassist/XMLElementProposalComputer.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/contentassist/XMLElementProposalComputer.java @@ -151,11 +151,9 @@ private static void adjustChoiceSiblings(ISchemaCompositor compositor, HashMap elementSet, HashMap siblings, int multiplicityTracker) { - if (schemaObject instanceof ISchemaElement) { - ISchemaElement schemaElement = (ISchemaElement) schemaObject; + if (schemaObject instanceof ISchemaElement schemaElement) { computeElementChildProposal(schemaElement, elementSet, siblings, multiplicityTracker); - } else if (schemaObject instanceof ISchemaCompositor) { - ISchemaCompositor sCompositor = (ISchemaCompositor) schemaObject; + } else if (schemaObject instanceof ISchemaCompositor sCompositor) { computeCompositorChildProposal(sCompositor, elementSet, siblings, multiplicityTracker); } } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/contentassist/XMLInsertionComputer.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/contentassist/XMLInsertionComputer.java index c1a6630f6e..7376b08822 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/contentassist/XMLInsertionComputer.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/contentassist/XMLInsertionComputer.java @@ -171,11 +171,9 @@ protected static void computeInsertionType(ISchemaElement sElement, IPluginParen } protected static void computeInsertionObject(IPluginParent pElement, HashSet visited, ISchemaObject schemaObject) throws CoreException { - if (schemaObject instanceof ISchemaElement) { - ISchemaElement schemaElement = (ISchemaElement) schemaObject; + if (schemaObject instanceof ISchemaElement schemaElement) { computeInsertionElement(pElement, visited, schemaElement); - } else if (schemaObject instanceof ISchemaCompositor) { - ISchemaCompositor sCompositor = (ISchemaCompositor) schemaObject; + } else if (schemaObject instanceof ISchemaCompositor sCompositor) { computeInsertionSequence(sCompositor, pElement, visited); } else { // Unknown schema object @@ -345,8 +343,7 @@ protected static void computeInsertionSequence(ISchemaCompositor compositor, IPl protected static void setAttribute(IPluginParent parent, String attName, String attValue, int counter) throws CoreException { if (parent instanceof IPluginElement) { ((IPluginElement) parent).setAttribute(attName, attValue); - } else if (parent instanceof IPluginExtension) { - IPluginExtension pe = (IPluginExtension) parent; + } else if (parent instanceof IPluginExtension pe) { if (attName.equals(IIdentifiable.P_ID)) { String currValue = pe.getId(); // If a value was already defined, do not override it with the diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/context/InputContext.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/context/InputContext.java index 51eaf25606..4953a86326 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/context/InputContext.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/context/InputContext.java @@ -249,8 +249,7 @@ protected void flushModel(IDocument doc) { if (fModel instanceof IEditingModel) ((IEditingModel) fModel).setStale(true); edit.apply(doc); - if (fModel instanceof IEditingModel) { - IEditingModel editingModel = (IEditingModel) fModel; + if (fModel instanceof IEditingModel editingModel) { editingModel.reconciled(doc); } fEditOperations.clear(); @@ -416,8 +415,7 @@ protected boolean synchronizeModel(IDocument doc) { } public boolean matches(IResource resource) { - if (fEditorInput instanceof IFileEditorInput) { - IFileEditorInput finput = (IFileEditorInput) fEditorInput; + if (fEditorInput instanceof IFileEditorInput finput) { IFile file = finput.getFile(); if (file.equals(resource)) return true; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/context/InputContextManager.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/context/InputContextManager.java index c88b02e040..2f1b8ad965 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/context/InputContextManager.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/context/InputContextManager.java @@ -273,8 +273,7 @@ protected void structureChanged(IFile file, boolean added) { private void removeContext(IFile file) { for (InputContext context : inputContexts.values()) { IEditorInput input = context.getInput(); - if (input instanceof IFileEditorInput) { - IFileEditorInput fileInput = (IFileEditorInput) input; + if (input instanceof IFileEditorInput fileInput) { if (file.equals(fileInput.getFile())) { inputContexts.remove(input); fireContextChange(context, false); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/context/XMLDocumentSetupParticpant.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/context/XMLDocumentSetupParticpant.java index 8f24dd15af..bf436be404 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/context/XMLDocumentSetupParticpant.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/context/XMLDocumentSetupParticpant.java @@ -34,8 +34,7 @@ public void setup(IDocument document) { IDocumentPartitioner partitioner = createDocumentPartitioner(); if (partitioner != null) { partitioner.connect(document); - if (document instanceof IDocumentExtension3) { - IDocumentExtension3 de3 = (IDocumentExtension3) document; + if (document instanceof IDocumentExtension3 de3) { de3.setDocumentPartitioner(XML_PARTITIONING, partitioner); partitioner = new FastPartitioner(new XMLStringPartitionScanner(), XMLStringPartitionScanner.STRING_PARTITIONS); partitioner.connect(document); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/context/XMLInputContext.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/context/XMLInputContext.java index 7c372ddc8b..4669c65ab6 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/context/XMLInputContext.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/context/XMLInputContext.java @@ -69,8 +69,7 @@ protected void addTextEditOperation(ArrayList ops, IModelChangedEvent insertNode((IDocumentElementNode) object, ops); break; case IModelChangedEvent.CHANGE : - if (object instanceof IDocumentElementNode) { - IDocumentElementNode node = (IDocumentElementNode) object; + if (object instanceof IDocumentElementNode node) { IDocumentAttributeNode attr = node.getDocumentAttribute(event.getChangedProperty()); if (attr != null) { addAttributeOperation(attr, ops, event); @@ -486,8 +485,7 @@ protected void removeUnnecessaryOperations() { Iterator iter = fOperationTable.values().iterator(); while (iter.hasNext()) { Object object = iter.next(); - if (object instanceof IDocumentElementNode) { - IDocumentElementNode node = (IDocumentElementNode) object; + if (object instanceof IDocumentElementNode node) { if (node.getOffset() > -1) { IDocumentAttributeNode[] attrs = node.getNodeAttributes(); for (IDocumentAttributeNode attr : attrs) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/FeatureReferencePage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/FeatureReferencePage.java index d4dd64389a..496021f9b6 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/FeatureReferencePage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/FeatureReferencePage.java @@ -108,11 +108,10 @@ public void setFocus() { @Override public boolean selectReveal(final Object object) { - if (object instanceof IFeaturePlugin) { - // selecton has to be done by detecting item from content provider by id of feature - // and using that in new selection - // because just using #setSelection(object) will not work - final IFeaturePlugin featurePlugin = (IFeaturePlugin) object; + if (object instanceof final IFeaturePlugin featurePlugin) { + // selection has to be done by detecting item from content provider + // by id of feature and using that in new selection because just + // using #setSelection(object) will not work final StructuredViewer fPluginViewer = fPluginSection.getStructuredViewerPart().getViewer(); final IStructuredContentProvider provider = (IStructuredContentProvider) fPluginViewer.getContentProvider(); for (Object o : provider.getElements(fPluginViewer.getInput())) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/FeatureUndoManager.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/FeatureUndoManager.java index 6cff33a503..86581e5b04 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/FeatureUndoManager.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/FeatureUndoManager.java @@ -110,8 +110,7 @@ private void executeRemove(IFeatureModel model, Object[] elements) { } private void executeChange(Object element, String propertyName, Object oldValue, Object newValue) { - if (element instanceof FeatureObject) { - FeatureObject pobj = (FeatureObject) element; + if (element instanceof FeatureObject pobj) { try { pobj.restoreProperty(propertyName, oldValue, newValue); } catch (CoreException e) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/IncludedFeaturesSection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/IncludedFeaturesSection.java index c2dcb38532..da8db034d7 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/IncludedFeaturesSection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/IncludedFeaturesSection.java @@ -516,8 +516,7 @@ protected void doPaste(Object target, Object[] objects) { FeatureChild[] fChildren = new FeatureChild[objects.length]; try { for (int i = 0; i < objects.length; i++) { - if (objects[i] instanceof FeatureChild) { - FeatureChild fChild = (FeatureChild) objects[i]; + if (objects[i] instanceof FeatureChild fChild) { fChild.setModel(model); fChild.setParent(feature); fChildren[i] = fChild; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/InfoSection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/InfoSection.java index c178bf3df5..f559639ddd 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/InfoSection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/InfoSection.java @@ -270,8 +270,7 @@ public boolean doGlobalAction(String actionId) { @Override public boolean setFormInput(Object input) { - if (input instanceof IFeatureInfo) { - IFeatureInfo info = (IFeatureInfo) input; + if (input instanceof IFeatureInfo info) { int index = info.getIndex(); if (index != -1) fTabFolder.setSelection(index); @@ -463,8 +462,7 @@ public void updateEditorInput(Object input, boolean commitPrevious) { fIgnoreChange = true; String text = ""; //$NON-NLS-1$ String url = null; - if (input instanceof IFeatureInfo) { - IFeatureInfo info = (IFeatureInfo) input; + if (input instanceof IFeatureInfo info) { text = info.getDescription(); url = info.getURL(); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/OpenReferenceAction.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/OpenReferenceAction.java index 63d9fa9c96..f00de80aa0 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/OpenReferenceAction.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/OpenReferenceAction.java @@ -47,8 +47,7 @@ public void run() { IPluginBase base = ((FeaturePlugin) obj).getPluginBase(); if (base != null) ManifestEditor.openPluginEditor((IPluginModelBase) base.getModel()); - } else if (obj instanceof IFeatureData) { - IFeatureData data = (IFeatureData) obj; + } else if (obj instanceof IFeatureData data) { String id = data.getId(); IResource resource = data.getModel().getUnderlyingResource(); if (resource != null) { @@ -62,8 +61,7 @@ public void run() { } } } - } else if (obj instanceof IFeatureChild) { - IFeatureChild included = (IFeatureChild) obj; + } else if (obj instanceof IFeatureChild included) { IFeature feature = ((FeatureChild) included).getReferencedFeature(); FeatureEditor.openFeatureEditor(feature); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/PluginDetailsSection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/PluginDetailsSection.java index 0d243d3a70..40df518292 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/PluginDetailsSection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/PluginDetailsSection.java @@ -194,8 +194,7 @@ public void refresh() { @Override public void selectionChanged(IFormPart part, ISelection selection) { - if (selection instanceof IStructuredSelection && ((IStructuredSelection) selection).size() == 1) { - IStructuredSelection s = ((IStructuredSelection) selection); + if (selection instanceof IStructuredSelection s && ((IStructuredSelection) selection).size() == 1) { Object o = s.getFirstElement(); if (o instanceof IFeaturePlugin) { fInput = (IFeaturePlugin) o; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/URLSection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/URLSection.java index b82a21cc54..edc55944ce 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/URLSection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/feature/URLSection.java @@ -347,8 +347,7 @@ protected void doPaste(Object target, Object[] objects) { } IFeature feature = model.getFeature(); for (Object object : objects) { - if (object instanceof FeatureURLElement) { - FeatureURLElement element = (FeatureURLElement) object; + if (object instanceof FeatureURLElement element) { element.setModel(model); element.setParent(feature); try { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/BundleHyperlinkDetector.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/BundleHyperlinkDetector.java index f0f70dad8b..d1507af2db 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/BundleHyperlinkDetector.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/BundleHyperlinkDetector.java @@ -47,10 +47,9 @@ public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boo return null; IDocumentRange element = fSourcePage.getRangeElement(region.getOffset(), false); - if (!(element instanceof ManifestHeader)) + if (!(element instanceof ManifestHeader header)) return null; - ManifestHeader header = (ManifestHeader) element; if (!header.getModel().isEditable()) return null; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/BundleInputContext.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/BundleInputContext.java index e09fdeba3f..1ea35a66db 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/BundleInputContext.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/BundleInputContext.java @@ -112,8 +112,7 @@ protected void addTextEditOperation(ArrayList ops, IModelChangedEvent else if (object instanceof PackageFriend) object = ((PackageFriend) object).getHeader(); - if (object instanceof ManifestHeader) { - ManifestHeader header = (ManifestHeader) object; + if (object instanceof ManifestHeader header) { TextEdit op = fOperationTable.get(header); if (op != null) { fOperationTable.remove(header); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/BundleSourcePage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/BundleSourcePage.java index e95ed9fe4a..0ee21df889 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/BundleSourcePage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/BundleSourcePage.java @@ -143,8 +143,7 @@ public Object getParent(Object child) { @Override public Object[] getElements(Object parent) { - if (parent instanceof BundleModel) { - BundleModel model = (BundleModel) parent; + if (parent instanceof BundleModel model) { Map manifest = ((Bundle) model.getBundle()).getHeaders(); ArrayList keys = new ArrayList<>(); for (IManifestHeader header : manifest.values()) { @@ -162,8 +161,7 @@ private IPluginLibrary[] getBundleClasspathLibraries() { // The bundle classpath header has no model data members // Retrieve the plug-in library equivalents from the editor model FormEditor editor = getEditor(); - if (editor instanceof PDEFormEditor) { - PDEFormEditor formEditor = (PDEFormEditor) editor; + if (editor instanceof PDEFormEditor formEditor) { IBaseModel baseModel = formEditor.getAggregateModel(); if (baseModel instanceof IPluginModelBase) { IPluginLibrary[] libraries = ((IPluginModelBase) baseModel).getPluginBase().getLibraries(); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/DependencyManagementSection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/DependencyManagementSection.java index 41fe58c566..7e7b09dbd7 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/DependencyManagementSection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/DependencyManagementSection.java @@ -356,8 +356,7 @@ protected void handleDoubleClick(IStructuredSelection sel) { } private void handleOpen(ISelection sel) { - if (sel instanceof IStructuredSelection) { - IStructuredSelection ssel = (IStructuredSelection) sel; + if (sel instanceof IStructuredSelection ssel) { if (ssel.size() == 1) { Object obj = ssel.getFirstElement(); IPluginModelBase base = PluginRegistry.findModel((String) obj); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExecutionEnvironmentSection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExecutionEnvironmentSection.java index ba5488a8ed..4341b6df8c 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExecutionEnvironmentSection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExecutionEnvironmentSection.java @@ -115,8 +115,7 @@ public void dispose() { static class ContentProvider implements IStructuredContentProvider { @Override public Object[] getElements(Object inputElement) { - if (inputElement instanceof IBundleModel) { - IBundleModel model = (IBundleModel) inputElement; + if (inputElement instanceof IBundleModel model) { IBundle bundle = model.getBundle(); IManifestHeader header = bundle.getManifestHeader(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT); if (header instanceof RequiredExecutionEnvironmentHeader) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExportPackageSection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExportPackageSection.java index 153b3a2947..50c9fe330f 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExportPackageSection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExportPackageSection.java @@ -277,8 +277,7 @@ protected void doPaste(Object targetObject, Object[] sourceObjects) { IBundle bundle = model.getBundle(); // Paste all source objects for (Object sourceObject : sourceObjects) { - if (sourceObject instanceof ExportPackageObject) { - ExportPackageObject exportPackageObject = (ExportPackageObject) sourceObject; + if (sourceObject instanceof ExportPackageObject exportPackageObject) { // Export package object // Adjust all the source object transient field values to // acceptable values @@ -342,8 +341,7 @@ protected void handleDoubleClick(IStructuredSelection selection) { } private IPackageFragment getPackageFragment(ISelection sel) { - if (sel instanceof IStructuredSelection) { - IStructuredSelection selection = (IStructuredSelection) sel; + if (sel instanceof IStructuredSelection selection) { if (selection.size() != 1) return null; @@ -493,8 +491,7 @@ public void modelChanged(IModelChangedEvent event) { Object[] objects = event.getChangedObjects(); for (Object changedObject : objects) { - if (changedObject instanceof ExportPackageObject) { - ExportPackageObject object = (ExportPackageObject) changedObject; + if (changedObject instanceof ExportPackageObject object) { switch (event.getChangeType()) { case IModelChangedEvent.INSERT : fPackageViewer.add(object); @@ -579,8 +576,7 @@ private void doSearch(ISelection sel) { if (frag != null) { FindReferencesAction action = new FindReferencesAction(getPage().getEditorSite()); action.run(frag); - } else if (sel instanceof IStructuredSelection) { - IStructuredSelection selection = (IStructuredSelection) sel; + } else if (sel instanceof IStructuredSelection selection) { PackageObject exportObject = (PackageObject) selection.getFirstElement(); NewSearchUI.runQueryInBackground(new BlankQuery(exportObject)); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExportPackageVisibilitySection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExportPackageVisibilitySection.java index 67c4f3e949..0a8ae16b16 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExportPackageVisibilitySection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExportPackageVisibilitySection.java @@ -240,9 +240,8 @@ private boolean isOneObjectSelected() { protected void doPaste(Object targetObject, Object[] sourceObjects) { // Paste all source objects for (Object sourceObject : sourceObjects) { - if ((sourceObject instanceof PackageFriend) && isOneObjectSelected()) { + if ((sourceObject instanceof PackageFriend friend) && isOneObjectSelected()) { // Package friend object - PackageFriend friend = (PackageFriend) sourceObject; // Adjust all the source object transient field values to // acceptable values friend.reconnect(fSelectedObjects[0]); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExtensionPointDetails.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExtensionPointDetails.java index 2ef71cd634..ce2d2810be 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExtensionPointDetails.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExtensionPointDetails.java @@ -207,9 +207,8 @@ public boolean select(Viewer viewer, Object parent, Object element) { } }); dialog.setValidator(selection -> { - if (selection == null || selection.length != 1 || !(selection[0] instanceof IFile)) + if (selection == null || selection.length != 1 || !(selection[0] instanceof IFile file)) return Status.error(PDEUIMessages.ManifestEditor_ExtensionPointDetails_validate_errorStatus); - IFile file = (IFile) selection[0]; String ext = file.getFullPath().getFileExtension(); if ("exsd".equals(ext) || "mxsd".equals(ext)) //$NON-NLS-1$ //$NON-NLS-2$ return Status.OK_STATUS; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExtensionsSection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExtensionsSection.java index 9cc4ae987a..aef2a37450 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExtensionsSection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ExtensionsSection.java @@ -451,8 +451,7 @@ protected void fillContextMenu(IMenuManager manager) { IStructuredSelection selection = fExtensionTree.getStructuredSelection(); if (selection.size() == 1) { Object object = selection.getFirstElement(); - if (object instanceof IPluginParent) { - IPluginParent parent = (IPluginParent) object; + if (object instanceof IPluginParent parent) { if (parent.getModel().getUnderlyingResource() != null) { boolean removeEnabled = !fFilteredTree.isFiltered() || isRemoveEnabled(selection); fillContextMenu(getPage(), parent, manager, false, removeEnabled); @@ -596,8 +595,7 @@ private void handleDelete() { try { IStructuredSelection newSelection = null; boolean sorted = fSortAction != null && fSortAction.isChecked(); - if (object instanceof IPluginElement) { - IPluginElement ee = (IPluginElement) object; + if (object instanceof IPluginElement ee) { IPluginParent parent = (IPluginParent) ee.getParent(); if (!sorted) { int index = getNewSelectionIndex(parent.getIndexOf(ee), parent.getChildCount()); @@ -609,8 +607,7 @@ private void handleDelete() { newSelection = index == -1 ? new StructuredSelection(parent) : new StructuredSelection(objects[index]); } parent.remove(ee); - } else if (object instanceof IPluginExtension) { - IPluginExtension extension = (IPluginExtension) object; + } else if (object instanceof IPluginExtension extension) { IPluginBase plugin = extension.getPluginBase(); if (!sorted) { int index = getNewSelectionIndex(plugin.getIndexOf(extension), plugin.getExtensions().length); @@ -910,16 +907,14 @@ public void modelChanged(IModelChangedEvent event) { // fExtensionTree.refresh(parent); - if (changeObject instanceof IPluginExtension) { - IPluginExtension ext = (IPluginExtension) changeObject; + if (changeObject instanceof IPluginExtension ext) { if (ext.getSchema() == null) reportMissingExtensionPointSchema(ext.getPoint()); } fExtensionTree.setSelection(new StructuredSelection(changeObject), true); fExtensionTree.getTree().setFocus(); } else if (event.getChangeType() == IModelChangedEvent.REMOVE) { - if (changeObject instanceof IPluginExtension) { - IPluginExtension ext = (IPluginExtension) changeObject; + if (changeObject instanceof IPluginExtension ext) { IPluginExtension[] extensions = ((IPluginBase) parent).getExtensions(); boolean found = false; // search if there is at least another extension extending the same point than the one being removed @@ -952,8 +947,7 @@ private Image resolveObjectImage(Object obj) { return fExtensionImage; } Image elementImage = fGenericElementImage; - if (obj instanceof IPluginElement) { - IPluginElement element = (IPluginElement) obj; + if (obj instanceof IPluginElement element) { Image customImage = getCustomImage(element); if (customImage == null) customImage = PDEPlugin.getDefault().getLabelProvider().getImage(obj); @@ -1025,8 +1019,7 @@ private SchemaRegistry getSchemaRegistry() { public static String resolveObjectName(SchemaRegistry schemaRegistry, Object obj) { boolean fullNames = PDEPlugin.isFullNameModeEnabled(); - if (obj instanceof IPluginExtension) { - IPluginExtension extension = (IPluginExtension) obj; + if (obj instanceof IPluginExtension extension) { if (!fullNames) { return extension.getPoint(); } @@ -1039,8 +1032,7 @@ public static String resolveObjectName(SchemaRegistry schemaRegistry, Object obj return schema.getName(); } return extension.getPoint(); - } else if (obj instanceof IPluginElement) { - IPluginElement element = (IPluginElement) obj; + } else if (obj instanceof IPluginElement element) { String baseName = element.getName(); String fullName = null; ISchemaElement elementInfo = getSchemaElement(element); @@ -1341,8 +1333,7 @@ private void handleMove(boolean up) { } catch (CoreException e) { PDEPlugin.logException(e); } - } else if (object instanceof IPluginExtension) { - IPluginExtension extension = (IPluginExtension) object; + } else if (object instanceof IPluginExtension extension) { IPluginBase plugin = extension.getPluginBase(); IPluginExtension[] extensions = plugin.getExtensions(); int index = plugin.getIndexOf(extension); @@ -1395,8 +1386,7 @@ private void updateButtons(Object item) { } else { if (selection != null && selection.size() == 1) { Object selected = selection.getFirstElement(); - if (selected instanceof IPluginElement) { - IPluginElement element = (IPluginElement) selected; + if (selected instanceof IPluginElement element) { IPluginParent parent = (IPluginParent) element.getParent(); // check up int index = parent.getIndexOf(element); @@ -1404,8 +1394,7 @@ private void updateButtons(Object item) { upEnabled = true; if (index < parent.getChildCount() - 1) downEnabled = true; - } else if (selected instanceof IPluginExtension) { - IPluginExtension extension = (IPluginExtension) selected; + } else if (selected instanceof IPluginExtension extension) { IExtensions extensions = (IExtensions) extension.getParent(); int index = extensions.getIndexOf(extension); int size = extensions.getExtensions().length; @@ -1618,29 +1607,24 @@ public boolean canDropMove(Object targetObject, Object[] sourceObjects, int targ return false; } // Validate move - if (sourcePluginObject instanceof IPluginExtension) { - IPluginExtension sourceExtensionObject = (IPluginExtension) sourcePluginObject; - if (targetPluginObject instanceof IPluginExtension) { - // Source: Extension - // Target: Extension - IPluginExtension targetExtensionObject = (IPluginExtension) targetPluginObject; + if (sourcePluginObject instanceof IPluginExtension sourceExtensionObject) { + if (targetPluginObject instanceof IPluginExtension targetExtensionObject) { + // Source: Extension + // Target: Extension return canDropMove(targetExtensionObject, sourceExtensionObject, targetLocation); } else if (targetPluginObject instanceof IPluginElement) { // Source: Extension // Target: Element return false; } - } else if (sourcePluginObject instanceof IPluginElement) { - IPluginElement sourceElementObject = (IPluginElement) sourcePluginObject; - if (targetPluginObject instanceof IPluginExtension) { - // Source: Element - // Target: Extension - IPluginExtension targetExtensionObject = (IPluginExtension) targetPluginObject; + } else if (sourcePluginObject instanceof IPluginElement sourceElementObject) { + if (targetPluginObject instanceof IPluginExtension targetExtensionObject) { + // Source: Element + // Target: Extension return canDropMove(targetExtensionObject, sourceElementObject, targetLocation); - } else if (targetPluginObject instanceof IPluginElement) { - // Source: Element - // Target: Element - IPluginElement targetElementObject = (IPluginElement) targetPluginObject; + } else if (targetPluginObject instanceof IPluginElement targetElementObject) { + // Source: Element + // Target: Element return canDropMove(targetElementObject, sourceElementObject, targetLocation); } } @@ -1826,14 +1810,12 @@ public void doDragRemove(Object[] sourceObjects) { IPluginParent pluginParentObject = (IPluginParent) sourceObjects[0]; // Remove the object from the model try { - if (pluginParentObject instanceof IPluginExtension) { - IPluginExtension extension = (IPluginExtension) pluginParentObject; + if (pluginParentObject instanceof IPluginExtension extension) { IPluginBase pluginBase = pluginParentObject.getPluginBase(); if (pluginBase != null) { pluginBase.remove(extension); } - } else if (pluginParentObject instanceof IPluginElement) { - IPluginElement element = (IPluginElement) pluginParentObject; + } else if (pluginParentObject instanceof IPluginElement element) { IPluginObject object = element.getParent(); if (object instanceof IPluginParent) { ((IPluginParent) object).remove(element); @@ -1866,29 +1848,24 @@ public void doDropMove(Object targetObject, Object[] sourceObjects, int targetLo IPluginParent targetPluginObject = (IPluginParent) targetObject; // Validate move try { - if (sourcePluginObject instanceof IPluginExtension) { - IPluginExtension sourceExtensionObject = (IPluginExtension) sourcePluginObject; - if (targetPluginObject instanceof IPluginExtension) { - // Source: Extension - // Target: Extension - IPluginExtension targetExtensionObject = (IPluginExtension) targetPluginObject; + if (sourcePluginObject instanceof IPluginExtension sourceExtensionObject) { + if (targetPluginObject instanceof IPluginExtension targetExtensionObject) { + // Source: Extension + // Target: Extension doDropMove(targetExtensionObject, sourceExtensionObject, targetLocation); } else if (targetPluginObject instanceof IPluginElement) { // Source: Extension // Target: Element return; } - } else if (sourcePluginObject instanceof IPluginElement) { - IPluginElement sourceElementObject = (IPluginElement) sourcePluginObject; - if (targetPluginObject instanceof IPluginExtension) { - // Source: Element - // Target: Extension - IPluginExtension targetExtensionObject = (IPluginExtension) targetPluginObject; + } else if (sourcePluginObject instanceof IPluginElement sourceElementObject) { + if (targetPluginObject instanceof IPluginExtension targetExtensionObject) { + // Source: Element + // Target: Extension doDropMove(targetExtensionObject, sourceElementObject, targetLocation); - } else if (targetPluginObject instanceof IPluginElement) { - // Source: Element - // Target: Element - IPluginElement targetElementObject = (IPluginElement) targetPluginObject; + } else if (targetPluginObject instanceof IPluginElement targetElementObject) { + // Source: Element + // Target: Element doDropMove(targetElementObject, sourceElementObject, targetLocation); } } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ImportPackageSection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ImportPackageSection.java index b9a61beae3..4dd8f6ff17 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ImportPackageSection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ImportPackageSection.java @@ -127,8 +127,7 @@ public String toString() { @Override public boolean equals(Object obj) { - if (obj instanceof ImportItemWrapper) { - ImportItemWrapper item = (ImportItemWrapper) obj; + if (obj instanceof ImportItemWrapper item) { return getName().equals(item.getName()); } return false; @@ -334,8 +333,7 @@ protected void doPaste(Object targetObject, Object[] sourceObjects) { IBundle bundle = model.getBundle(); // Paste all source objects for (Object sourceObject : sourceObjects) { - if (sourceObject instanceof ImportPackageObject) { - ImportPackageObject importPackageObject = (ImportPackageObject) sourceObject; + if (sourceObject instanceof ImportPackageObject importPackageObject) { // Import package object // Adjust all the source object transient field values to // acceptable values @@ -391,8 +389,7 @@ protected void buttonSelected(int index) { } private IPackageFragment getPackageFragment(ISelection sel) { - if (sel instanceof IStructuredSelection) { - IStructuredSelection selection = (IStructuredSelection) sel; + if (sel instanceof IStructuredSelection selection) { if (selection.size() != 1) return null; @@ -471,12 +468,10 @@ private void handleAdd() { if (selected[i] instanceof ExportPackageDescription) impObject = new ImportPackageObject(fHeader, (ExportPackageDescription) selected[i], getVersionAttribute()); - else if (selected[i] instanceof IPackageFragment) { + else if (selected[i] instanceof IPackageFragment fragment) { // non exported package - IPackageFragment fragment = ((IPackageFragment) selected[i]); impObject = new ImportPackageObject(fHeader, fragment.getElementName(), null, getVersionAttribute()); - } else if (selected[i] instanceof ExportPackageObject) { - ExportPackageObject epo = (ExportPackageObject) selected[i]; + } else if (selected[i] instanceof ExportPackageObject epo) { impObject = new ImportPackageObject(fHeader, epo.getName(), epo.getVersion(), getVersionAttribute()); } if (impObject != null && names.add(impObject.getName())) @@ -647,8 +642,7 @@ public void modelChanged(final IModelChangedEvent event) { } else { Object[] objects = event.getChangedObjects(); for (Object changedObject : objects) { - if (changedObject instanceof ImportPackageObject) { - ImportPackageObject object = (ImportPackageObject) changedObject; + if (changedObject instanceof ImportPackageObject object) { switch (event.getChangeType()) { case IModelChangedEvent.INSERT: @@ -754,8 +748,7 @@ private void doReferenceSearch(final ISelection sel) { IWorkingSet set = manager.createWorkingSet("temp", roots); //$NON-NLS-1$ new FindReferencesInWorkingSetAction(getPage().getEditorSite(), new IWorkingSet[] {set}).run(fragment); manager.removeWorkingSet(set); - } else if (sel instanceof IStructuredSelection) { - IStructuredSelection selection = (IStructuredSelection) sel; + } else if (sel instanceof IStructuredSelection selection) { PackageObject importObject = (PackageObject) selection.getFirstElement(); NewSearchUI.runQueryInBackground(new BlankQuery(importObject)); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/LibrarySection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/LibrarySection.java index 4763673f78..b34a1e68f6 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/LibrarySection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/LibrarySection.java @@ -313,8 +313,7 @@ private void handleRemove() { String[] remove = new String[selection.length]; for (int i = 0; i < selection.length; i++) { - if (selection[i] != null && selection[i] instanceof IPluginLibrary) { - IPluginLibrary ep = (IPluginLibrary) selection[i]; + if (selection[i] != null && selection[i] instanceof IPluginLibrary ep) { IPluginBase plugin = ep.getPluginBase(); try { plugin.remove(ep); @@ -656,9 +655,8 @@ protected void doPaste(Object targetObject, Object[] sourceObjects) { try { // Paste all source objects for (Object sourceObject : sourceObjects) { - if (sourceObject instanceof PluginLibrary) { + if (sourceObject instanceof PluginLibrary library) { // Plugin library object - PluginLibrary library = (PluginLibrary) sourceObject; // Adjust all the source object transient field values to // acceptable values library.reconnect(model, plugin); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ManifestOutlinePage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ManifestOutlinePage.java index a97a21f2c4..007eef3fc7 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ManifestOutlinePage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ManifestOutlinePage.java @@ -38,8 +38,7 @@ public ManifestOutlinePage(PDEFormEditor editor) { @Override protected Object[] getChildren(Object parent) { - if (parent instanceof PDEFormPage) { - PDEFormPage page = (PDEFormPage) parent; + if (parent instanceof PDEFormPage page) { if (page.getModel() instanceof IPluginModelBase model) { if (model.isValid()) { IPluginBase pluginBase = model.getPluginBase(); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ManifestSourcePage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ManifestSourcePage.java index a65e5d869f..85ba56b9a2 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ManifestSourcePage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/ManifestSourcePage.java @@ -109,8 +109,7 @@ public Object[] getChildren(Object parent) { PluginModelBase model = (PluginModelBase) getInputContext().getModel(); ArrayList result = new ArrayList<>(); - if (parent instanceof IPluginBase) { - IPluginBase pluginBase = (IPluginBase) parent; + if (parent instanceof IPluginBase pluginBase) { if (pluginBase.getLibraries().length > 0) result.add(fLibraries); if (pluginBase.getImports().length > 0) diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/MatchSection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/MatchSection.java index 1e83c3ae9c..5036865f53 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/MatchSection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/MatchSection.java @@ -278,8 +278,7 @@ protected void update(IPluginReference iimport) { } fCurrentImport = iimport; - if (fCurrentImport instanceof IPluginImport) { - IPluginImport pimport = (IPluginImport) fCurrentImport; + if (fCurrentImport instanceof IPluginImport pimport) { fOptionalButton.setEnabled(isEditable()); fOptionalButton.setSelection(pimport.isOptional()); fReexportButton.setEnabled(isEditable()); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/PluginInputContext.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/PluginInputContext.java index 8a43f2f476..6e7605530f 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/PluginInputContext.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/PluginInputContext.java @@ -100,8 +100,7 @@ protected void reorderInsertEdits(ArrayList ops) { while (iter.hasNext()) { Object object = iter.next(); - if (object instanceof IDocumentElementNode) { - IDocumentElementNode node = (IDocumentElementNode) object; + if (object instanceof IDocumentElementNode node) { if (node.getParentNode() instanceof PluginBaseNode) { TextEdit edit = map.get(node); if (edit instanceof InsertEdit) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/PluginInputContextManager.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/PluginInputContextManager.java index 04f1e0aa21..cda22a0e36 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/PluginInputContextManager.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/PluginInputContextManager.java @@ -131,8 +131,7 @@ private void bundleRemoved(InputContext bundleContext) { } private void transferListeners(IModel source, IModel target) { - if (source instanceof IModelChangeProviderExtension && target instanceof IModelChangeProviderExtension) { - IModelChangeProviderExtension smodel = (IModelChangeProviderExtension) source; + if (source instanceof IModelChangeProviderExtension smodel && target instanceof IModelChangeProviderExtension) { IModelChangeProviderExtension tmodel = (IModelChangeProviderExtension) target; // first fire one last event to all the listeners to // refresh diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/PluginUndoManager.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/PluginUndoManager.java index 03b7a340b2..c580c91c84 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/PluginUndoManager.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/PluginUndoManager.java @@ -134,16 +134,14 @@ private void executeAdd(IModelChangeProvider model, Object[] elements) { pluginBase.add((IPluginExtensionPoint) element); } else if (element instanceof IPluginExtension) { pluginBase.add((IPluginExtension) element); - } else if (element instanceof IPluginElement) { - IPluginElement e = (IPluginElement) element; + } else if (element instanceof IPluginElement e) { Object parent = e.getParent(); if (parent instanceof PluginLibraryNode && e instanceof PluginElementNode) { ((PluginLibraryNode) parent).addContentFilter((PluginElementNode) e); } else if (parent instanceof IPluginParent) { ((IPluginParent) parent).add(e); } - } else if (element instanceof IBuildEntry) { - IBuildEntry e = (IBuildEntry) element; + } else if (element instanceof IBuildEntry e) { build.add(e); } else if (element instanceof BundleObject) { if (element instanceof ImportPackageObject) { @@ -154,8 +152,7 @@ private void executeAdd(IModelChangeProvider model, Object[] elements) { } if (element instanceof RequireBundleObject) { IBaseModel aggModel = getEditor().getAggregateModel(); - if (aggModel instanceof BundlePluginModel) { - BundlePluginModel pluginModel = (BundlePluginModel) aggModel; + if (aggModel instanceof BundlePluginModel pluginModel) { RequireBundleObject requireBundle = (RequireBundleObject) element; pluginBase = pluginModel.getPluginBase(); String elementValue = requireBundle.getValue(); @@ -211,16 +208,14 @@ private void executeRemove(IModelChangeProvider model, Object[] elements) { pluginBase.remove((IPluginExtensionPoint) element); } else if (element instanceof IPluginExtension) { pluginBase.remove((IPluginExtension) element); - } else if (element instanceof IPluginElement) { - IPluginElement e = (IPluginElement) element; + } else if (element instanceof IPluginElement e) { Object parent = e.getParent(); if (parent instanceof PluginLibraryNode && e instanceof PluginElementNode) { ((PluginLibraryNode) parent).removeContentFilter((PluginElementNode) e); } else if (parent instanceof IPluginParent) { ((IPluginParent) parent).remove(e); } - } else if (element instanceof IBuildEntry) { - IBuildEntry e = (IBuildEntry) element; + } else if (element instanceof IBuildEntry e) { build.remove(e); } else if (element instanceof BundleObject) { if (element instanceof ImportPackageObject) { @@ -231,8 +226,7 @@ private void executeRemove(IModelChangeProvider model, Object[] elements) { } if (element instanceof RequireBundleObject) { IBaseModel aggModel = getEditor().getAggregateModel(); - if (aggModel instanceof BundlePluginModel) { - BundlePluginModel mod = (BundlePluginModel) aggModel; + if (aggModel instanceof BundlePluginModel mod) { pluginBase = mod.getPluginBase(); IPluginImport[] imports = pluginBase.getImports(); IPluginImport currentImport = null; @@ -277,27 +271,23 @@ private void executeAttributeChange(AttributeChangedEvent e, boolean undo) { } private void executeChange(Object element, String propertyName, Object oldValue, Object newValue) { - if (element instanceof PluginObject) { - PluginObject pobj = (PluginObject) element; + if (element instanceof PluginObject pobj) { try { pobj.restoreProperty(propertyName, oldValue, newValue); } catch (CoreException e) { PDEPlugin.logException(e); } - } else if (element instanceof BuildObject) { - BuildObject bobj = (BuildObject) element; + } else if (element instanceof BuildObject bobj) { try { bobj.restoreProperty(propertyName, oldValue, newValue); } catch (CoreException e) { PDEPlugin.logException(e); } - } else if (element instanceof PluginObjectNode) { - PluginObjectNode node = (PluginObjectNode) element; + } else if (element instanceof PluginObjectNode node) { String newString = newValue != null ? newValue.toString() : null; node.setXMLAttribute(propertyName, newString); } else if (element instanceof BundleObject) { - if (element instanceof ImportPackageObject) { - ImportPackageObject ipObj = (ImportPackageObject) element; + if (element instanceof ImportPackageObject ipObj) { ipObj.restoreProperty(propertyName, oldValue, newValue); } } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/RequiresSection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/RequiresSection.java index b7d9689c59..228b1687df 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/RequiresSection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/RequiresSection.java @@ -318,9 +318,8 @@ protected void doPaste(Object targetObject, Object[] sourceObjects) { try { // Paste all source objects for (Object sourceObject : sourceObjects) { - if (sourceObject instanceof ImportObject) { + if (sourceObject instanceof ImportObject importObject) { // Import object - ImportObject importObject = (ImportObject) sourceObject; // Adjust all the source object transient field values to // acceptable values // TODO: MP: CCP: Remove unnecessary reconnected Plugin attributes @@ -386,8 +385,7 @@ protected void registerPopupMenu(MenuManager popupMenuManager) { } private void handleOpen(ISelection sel) { - if (sel instanceof IStructuredSelection) { - IStructuredSelection ssel = (IStructuredSelection) sel; + if (sel instanceof IStructuredSelection ssel) { if (ssel.size() == 1) { Object obj = ssel.getFirstElement(); if (obj instanceof ImportObject) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/product/IntroSection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/product/IntroSection.java index 490fa89e0c..b734ad2e4c 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/product/IntroSection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/product/IntroSection.java @@ -238,9 +238,8 @@ private void addRequiredBundle() { ModelModification mod = new ModelModification(fManifest) { @Override protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws CoreException { - if (!(model instanceof IBundlePluginModelBase)) + if (!(model instanceof IBundlePluginModelBase modelBase)) return; - IBundlePluginModelBase modelBase = (IBundlePluginModelBase) model; IBundle bundle = modelBase.getBundleModel().getBundle(); IManifestHeader header = bundle.getManifestHeader(Constants.REQUIRE_BUNDLE); if (header instanceof RequireBundleHeader) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/product/JRESection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/product/JRESection.java index 2cb075c170..8afdb7dd89 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/product/JRESection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/product/JRESection.java @@ -61,9 +61,8 @@ public class JRESection extends PDESection { private static final class EELabelProvider extends LabelProvider { @Override public String getText(Object element) { - if (!(element instanceof IExecutionEnvironment)) + if (!(element instanceof IExecutionEnvironment env)) return ""; //$NON-NLS-1$ - IExecutionEnvironment env = (IExecutionEnvironment) element; IPath path = JavaRuntime.newJREContainerPath(env); IVMInstall install = JavaRuntime.getVMInstall(path); String eeItem; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/DocSection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/DocSection.java index 3c8f904f6f..8ba3f7f610 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/DocSection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/DocSection.java @@ -189,8 +189,7 @@ public boolean setFormInput(Object input) { private String getTopicName(Object object) { if (object instanceof ISchema) { return PDEUIMessages.SchemaEditor_topic_overview; - } else if (object instanceof IDocumentSection) { - IDocumentSection section = (IDocumentSection) object; + } else if (object instanceof IDocumentSection section) { String sectionId = section.getSectionId(); if (sectionId.equals(IDocumentSection.EXAMPLES)) return PDEUIMessages.SchemaEditor_topic_examples; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/ElementSection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/ElementSection.java index b5eb04563f..56976c1074 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/ElementSection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/ElementSection.java @@ -83,8 +83,7 @@ public class ElementSection extends TreeSection { static class ContentProvider implements ITreeContentProvider { @Override public Object[] getElements(Object object) { - if (object instanceof Schema) { - Schema schema = (Schema) object; + if (object instanceof Schema schema) { return schema.getElements(); } return new Object[0]; @@ -393,8 +392,7 @@ private IStructuredSelection handleDelete(Object object, boolean generateSelecti newSelection = handleReferenceDelete((SchemaElementReference) object, generateSelection); } else if (object instanceof ISchemaElement) { newSelection = handleElementDelete((ISchemaElement) object, generateSelection); - } else if (object instanceof ISchemaAttribute) { - ISchemaAttribute att = (ISchemaAttribute) object; + } else if (object instanceof ISchemaAttribute att) { if (!(att.getParent() instanceof ISchemaRootElement)) { newSelection = handleAttributeDelete(att, generateSelection); } else { @@ -464,8 +462,7 @@ private IStructuredSelection handleCompositorDelete(ISchemaCompositor comp, bool IStructuredSelection newSelection = null; if (generateSelection) { ISchemaObject parent = comp.getParent(); - if (parent instanceof ISchemaElement) { - ISchemaElement element = (ISchemaElement) parent; + if (parent instanceof ISchemaElement element) { ISchemaAttribute[] attributes = element.getAttributes(); if (attributes.length > 0) newSelection = new StructuredSelection(attributes[0]); @@ -771,9 +768,8 @@ protected void doPaste(Object target, Object[] objects) { public void handleOp(Object currentTarget, Object[] objects, int currentOperation) { for (int i = 0; i < objects.length; i++) { - if (!(objects[i] instanceof ISchemaObject)) + if (!(objects[i] instanceof ISchemaObject object)) continue; - ISchemaObject object = (ISchemaObject) objects[i]; ISchemaObject realTarget = getRealTarget(currentTarget, object); ISchemaObject sibling = getSibling(currentTarget, object); if (realTarget == null) diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/FilteredSchemaAttributeSelectionDialog.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/FilteredSchemaAttributeSelectionDialog.java index f92c2ada45..39cdbe45bd 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/FilteredSchemaAttributeSelectionDialog.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/FilteredSchemaAttributeSelectionDialog.java @@ -84,8 +84,7 @@ public boolean select(Viewer viewer, Object parentElement, Object element) { if (enabled) // select everything return true; - if (element instanceof ISchemaAttribute) { - ISchemaAttribute attribute = (ISchemaAttribute) element; + if (element instanceof ISchemaAttribute attribute) { return attribute.getUse() != ISchemaAttribute.OPTIONAL; } return true; @@ -122,8 +121,7 @@ public Image getImage(Object element) { @Override public String getText(Object element) { - if (element instanceof ISchemaAttribute) { - ISchemaAttribute attribute = (ISchemaAttribute) element; + if (element instanceof ISchemaAttribute attribute) { if (isDuplicateElement(element)) { ISchemaObject object = attribute.getParent(); if (object != null) @@ -140,8 +138,7 @@ public Image decorateImage(Image image, Object element) { @Override public String decorateText(String text, Object element) { - if (element instanceof ISchemaAttribute) { - ISchemaAttribute attribute = (ISchemaAttribute) element; + if (element instanceof ISchemaAttribute attribute) { ISchemaObject object = attribute.getParent(); if (object != null && !isDuplicateElement(element)) return getQualifiedName(attribute); @@ -160,8 +157,7 @@ public Image getImage(Object element) { @Override public String getText(Object element) { - if (element instanceof ISchemaAttribute) { - ISchemaAttribute attribute = (ISchemaAttribute) element; + if (element instanceof ISchemaAttribute attribute) { ISchema schema = attribute.getSchema(); return schema.getPointId() + ' ' + '(' + schema.getPluginId() + ')'; } @@ -178,8 +174,7 @@ public boolean isConsistentItem(Object item) { @Override public boolean matchItem(Object item) { - if (item instanceof ISchemaAttribute) { - ISchemaAttribute attribute = (ISchemaAttribute) item; + if (item instanceof ISchemaAttribute attribute) { ISchemaObject object = attribute.getParent(); ISchema schema = attribute.getSchema(); String id = getQualifiedName(attribute); @@ -251,8 +246,7 @@ protected IDialogSettings getDialogSettings() { @Override public String getElementName(Object item) { - if (item instanceof ISchemaAttribute) { - ISchemaAttribute attribute = (ISchemaAttribute) item; + if (item instanceof ISchemaAttribute attribute) { return attribute.getName(); } return null; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/NewReferenceAction.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/NewReferenceAction.java index b792700bc8..4d1cd58ae4 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/NewReferenceAction.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/NewReferenceAction.java @@ -36,8 +36,7 @@ public NewReferenceAction(ISchemaElement source, Object object, ISchemaElement r @Override public void run() { - if (object != null && object instanceof SchemaCompositor) { - SchemaCompositor parent = (SchemaCompositor) object; + if (object != null && object instanceof SchemaCompositor parent) { SchemaElementReference reference = new SchemaElementReference(parent, referencedElement.getName()); reference.setReferencedObject(referencedElement); parent.addChild(reference); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaEditor.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaEditor.java index f83d3127b4..ead3667165 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaEditor.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaEditor.java @@ -252,9 +252,8 @@ public static boolean openSchema(File jarFile, String schemaJarFileEntry) { public static void openToElement(IPath path, ISchemaElement element) { if (openSchema(path)) { IEditorPart editorPart = PDEPlugin.getActivePage().getActiveEditor(); - if (!(editorPart instanceof SchemaEditor)) + if (!(editorPart instanceof SchemaEditor schemaEditor)) return; // something messed up, schema editor should be open - SchemaEditor schemaEditor = (SchemaEditor) editorPart; schemaEditor.selectReveal(element); } } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaFormOutlinePage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaFormOutlinePage.java index 2755b43533..96a9afb969 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaFormOutlinePage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaFormOutlinePage.java @@ -102,8 +102,7 @@ protected String getObjectLabel(Object obj) { if (obj instanceof ISchema) { return PDEUIMessages.SchemaEditor_topic_overview; } - if (obj instanceof IDocumentSection) { - IDocumentSection section = (IDocumentSection) obj; + if (obj instanceof IDocumentSection section) { String sectionId = section.getSectionId(); if (sectionId.equals(IDocumentSection.EXAMPLES)) return PDEUIMessages.SchemaEditor_topic_examples; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaFormPage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaFormPage.java index ace9f04ece..d8a0f3811e 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaFormPage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaFormPage.java @@ -89,8 +89,7 @@ else if (object instanceof ISchemaElement) return ISchemaElement.class; else if (object instanceof ISchemaCompositor) return ISchemaCompositor.class; - else if (object instanceof ISchemaAttribute) { - ISchemaAttribute att = (ISchemaAttribute) object; + else if (object instanceof ISchemaAttribute att) { int kind = att.getKind(); switch (kind) { case IMetaAttribute.JAVA : diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaIdentifierAttributeDetails.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaIdentifierAttributeDetails.java index df91145747..f9b3acb770 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaIdentifierAttributeDetails.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaIdentifierAttributeDetails.java @@ -212,8 +212,7 @@ private void doOpenSelectionDialog(FormEntry entry) { Object[] selectedAttributes = dialog.getResult(); StringBuilder result = new StringBuilder(); for (Object object : selectedAttributes) { - if (object instanceof ISchemaAttribute) { - ISchemaAttribute attribute = (ISchemaAttribute) object; + if (object instanceof ISchemaAttribute attribute) { String id = PDESchemaHelper.getReferenceIdentifier(attribute); if (result.length() > 0) { result.append(","); //$NON-NLS-1$ diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaIncludesSection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaIncludesSection.java index a5c1b0c275..adac16cdbc 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaIncludesSection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaIncludesSection.java @@ -178,10 +178,8 @@ protected void handleNewInclude() { if (dialog.open() == Window.OK) { Object result = dialog.getFirstResult(); - if (!(result instanceof IFile)) + if (!(result instanceof IFile newInclude)) return; - IFile newInclude = (IFile) result; - String location = getIncludeLocation(newInclude); ISchemaInclude include = new SchemaInclude(getSchema(), location, false); ISchema schema = getSchema(); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaRearranger.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaRearranger.java index d8bcc9ddd5..43359a1449 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaRearranger.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaRearranger.java @@ -47,8 +47,7 @@ public void moveCompositor(ISchemaObject newParent, ISchemaCompositor compositor if (newParent.equals(oldParent)) { return; } - if (newParent instanceof SchemaElement) { - SchemaElement element = (SchemaElement) newParent; + if (newParent instanceof SchemaElement element) { SchemaComplexType type = null; if (element.getType() instanceof SchemaComplexType) { type = (SchemaComplexType) element.getType(); @@ -134,8 +133,7 @@ public void moveAttribute(ISchemaElement newParent, ISchemaAttribute attribute, } public void pasteCompositor(ISchemaObject realTarget, ISchemaCompositor compositor, ISchemaObject sibling) { - if (realTarget instanceof SchemaElement) { - SchemaElement element = (SchemaElement) realTarget; + if (realTarget instanceof SchemaElement element) { SchemaComplexType type = null; if (element.getType() instanceof SchemaComplexType) { type = (SchemaComplexType) element.getType(); @@ -151,8 +149,7 @@ public void pasteCompositor(ISchemaObject realTarget, ISchemaCompositor composit } public void pasteReference(ISchemaObject realTarget, ISchemaObjectReference object, ISchemaObject sibling) { - if (realTarget instanceof SchemaCompositor) { - SchemaCompositor parent = (SchemaCompositor) realTarget; + if (realTarget instanceof SchemaCompositor parent) { ((SchemaElementReference) object).setCompositor(parent); parent.addChild((SchemaElementReference) object, sibling); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/site/CategorySection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/site/CategorySection.java index 7000e3f7b7..eec8e3335f 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/site/CategorySection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/site/CategorySection.java @@ -116,8 +116,7 @@ public Object[] getElements(Object inputElement) { @Override public Object[] getChildren(Object parent) { - if (parent instanceof ISiteCategoryDefinition) { - ISiteCategoryDefinition catDef = (ISiteCategoryDefinition) parent; + if (parent instanceof ISiteCategoryDefinition catDef) { ISiteFeature[] features = fModel.getSite().getFeatures(); HashSet result = new HashSet<>(); for (ISiteFeature feature : features) { @@ -140,8 +139,7 @@ public Object getParent(Object element) { @Override public boolean hasChildren(Object element) { - if (element instanceof ISiteCategoryDefinition) { - ISiteCategoryDefinition catDef = (ISiteCategoryDefinition) element; + if (element instanceof ISiteCategoryDefinition catDef) { ISiteFeature[] features = fModel.getSite().getFeatures(); for (ISiteFeature feature : features) { ISiteCategory[] cats = feature.getCategories(); @@ -220,10 +218,9 @@ public void dragOver(DropTargetEvent event) { */ @Override protected int determineLocation(DropTargetEvent event) { - if (!(event.item instanceof Item)) { + if (!(event.item instanceof Item item)) { return LOCATION_NONE; } - Item item = (Item) event.item; Point coordinates = new Point(event.x, event.y); coordinates = getViewer().getControl().toControl(coordinates); if (item != null) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/site/SiteFeatureAdapter.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/site/SiteFeatureAdapter.java index 3e32f8fa38..c3665bcec0 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/site/SiteFeatureAdapter.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/site/SiteFeatureAdapter.java @@ -42,8 +42,7 @@ public void write(String indent, PrintWriter writer) { */ @Override public boolean equals(Object obj) { - if (obj instanceof SiteFeatureAdapter) { - SiteFeatureAdapter adapter = (SiteFeatureAdapter) obj; + if (obj instanceof SiteFeatureAdapter adapter) { String id = feature.getId(); String id2 = adapter.feature.getId(); boolean sameFeature = id != null && id2 != null && id.equals(id2); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/site/SiteOutlinePage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/site/SiteOutlinePage.java index 11d6b33f50..fc1eca1fbb 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/site/SiteOutlinePage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/site/SiteOutlinePage.java @@ -42,8 +42,7 @@ public SiteOutlinePage(PDEFormEditor editor) { @Override protected Object[] getChildren(Object parent) { - if (parent instanceof PDEFormPage) { - PDEFormPage page = (PDEFormPage) parent; + if (parent instanceof PDEFormPage page) { ISiteModel model = (ISiteModel) page.getModel(); if (model != null && model.isValid()) { ISite site = model.getSite(); @@ -62,8 +61,7 @@ protected Object[] getChildren(Object parent) { return site.getArchives(); } } - if (parent instanceof ISiteCategoryDefinition) { - ISiteCategoryDefinition catDef = (ISiteCategoryDefinition) parent; + if (parent instanceof ISiteCategoryDefinition catDef) { ISiteModel model = catDef.getModel(); if (model.isValid()) { ISite site = model.getSite(); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/site/SiteUndoManager.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/site/SiteUndoManager.java index 6e499f5fce..6d8a1fa7c2 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/site/SiteUndoManager.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/site/SiteUndoManager.java @@ -87,8 +87,7 @@ private void executeAdd(IModelChangeProvider model, Object[] elements) { site.addArchives(new ISiteArchive[] {(ISiteArchive) element}); } else if (element instanceof ISiteCategoryDefinition) { site.addCategoryDefinitions(new ISiteCategoryDefinition[] {(ISiteCategoryDefinition) element}); - } else if (element instanceof ISiteCategory) { - ISiteCategory category = (ISiteCategory) element; + } else if (element instanceof ISiteCategory category) { ISiteFeature feature = (ISiteFeature) category.getParent(); feature.addCategories(new ISiteCategory[] {category}); } @@ -110,8 +109,7 @@ private void executeRemove(IModelChangeProvider model, Object[] elements) { site.removeArchives(new ISiteArchive[] {(ISiteArchive) element}); } else if (element instanceof ISiteCategoryDefinition) { site.removeCategoryDefinitions(new ISiteCategoryDefinition[] {(ISiteCategoryDefinition) element}); - } else if (element instanceof ISiteCategory) { - ISiteCategory category = (ISiteCategory) element; + } else if (element instanceof ISiteCategory category) { ISiteFeature feature = (ISiteFeature) category.getParent(); feature.removeCategories(new ISiteCategory[] {category}); } @@ -123,8 +121,7 @@ private void executeRemove(IModelChangeProvider model, Object[] elements) { private void executeChange(Object element, String propertyName, Object oldValue, Object newValue) { - if (element instanceof SiteObject) { - SiteObject sobj = (SiteObject) element; + if (element instanceof SiteObject sobj) { try { sobj.restoreProperty(propertyName, oldValue, newValue); } catch (CoreException e) { @@ -137,8 +134,7 @@ private void executeChange(Object element, String propertyName, Object oldValue, public void modelChanged(IModelChangedEvent event) { if (event.getChangeType() == IModelChangedEvent.CHANGE) { Object object = event.getChangedObjects()[0]; - if (object instanceof ISiteObject) { - ISiteObject obj = (ISiteObject) object; + if (object instanceof ISiteObject obj) { //Ignore events from objects that are not yet in the model. if (!(obj instanceof ISite) && !obj.isInTheModel()) return; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/targetdefinition/TargetEditor.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/targetdefinition/TargetEditor.java index 6cd22f6f74..c9b2f1eb0c 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/targetdefinition/TargetEditor.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/targetdefinition/TargetEditor.java @@ -692,8 +692,7 @@ private void updateHyperlinkText(String s) { fLoadHyperlink.setText(s); } ITextViewer viewer = fTextualEditor.getAdapter(ITextViewer.class); - if (viewer instanceof ISourceViewerExtension5) { - ISourceViewerExtension5 extension5 = (ISourceViewerExtension5) viewer; + if (viewer instanceof ISourceViewerExtension5 extension5) { extension5.updateCodeMinings(); } } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/AnnotationHover.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/AnnotationHover.java index 22cc31d044..02868d11a2 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/AnnotationHover.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/AnnotationHover.java @@ -58,8 +58,7 @@ private String[] getMessagesForLine(ISourceViewer viewer, int line) { Iterator iter = model.getAnnotationIterator(); while (iter.hasNext()) { Annotation object = iter.next(); - if (object instanceof MarkerAnnotation) { - MarkerAnnotation annotation = (MarkerAnnotation) object; + if (object instanceof MarkerAnnotation annotation) { if (compareRulerLine(model.getPosition(annotation), document, line)) { IMarker marker = annotation.getMarker(); String message = marker.getAttribute(IMarker.MESSAGE, (String) null); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/ManifestTextHover.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/ManifestTextHover.java index 3b927892c2..c36ea8740d 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/ManifestTextHover.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/ManifestTextHover.java @@ -71,8 +71,7 @@ public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) { public String getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) { int offset = hoverRegion.getOffset(); IDocumentRange range = fSourcePage.getRangeElement(offset, false); - if (range instanceof IManifestHeader) { - IManifestHeader header = (IManifestHeader) range; + if (range instanceof IManifestHeader header) { String headerName = header.getName(); if (offset >= header.getOffset() + headerName.length()) return checkForTranslatable(header); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/PDEQuickAssistAssistant.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/PDEQuickAssistAssistant.java index 85515a695d..91941959ea 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/PDEQuickAssistAssistant.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/PDEQuickAssistAssistant.java @@ -107,8 +107,7 @@ public Image getImage() { default -> null; }; } - if (fResolution instanceof IMarkerResolution2) { - IMarkerResolution2 resolution = (IMarkerResolution2) fResolution; + if (fResolution instanceof IMarkerResolution2 resolution) { return resolution.getImage(); } return null; @@ -141,10 +140,9 @@ public boolean isAutoInsertable() { @Override public boolean equals(Object obj) { - if (!(obj instanceof PDECompletionProposal)) { + if (!(obj instanceof PDECompletionProposal proposal)) { return false; } - PDECompletionProposal proposal = (PDECompletionProposal) obj; return proposal.fPosition.equals(fPosition) && proposal.fResolution.equals(fResolution); } @@ -155,9 +153,8 @@ public int hashCode() { @Override public int compareTo(Object arg0) { - if (!(arg0 instanceof PDECompletionProposal)) + if (!(arg0 instanceof PDECompletionProposal obj)) return -1; - PDECompletionProposal obj = (PDECompletionProposal) arg0; if (getDisplayString() != null) { if (obj.getDisplayString() != null) { return getDisplayString().compareTo(obj.getDisplayString()); @@ -243,9 +240,8 @@ public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationC }); while (it.hasNext()) { Annotation key = it.next(); - if (!(key instanceof SimpleMarkerAnnotation)) { - if (key instanceof SpellingAnnotation) { - SpellingAnnotation annotation = (SpellingAnnotation) key; + if (!(key instanceof SimpleMarkerAnnotation annotation)) { + if (key instanceof SpellingAnnotation annotation) { if (amodel.getPosition(annotation).overlapsWith(offset, 1)) { ICompletionProposal[] proposals = annotation.getSpellingProblem().getProposals(); Collections.addAll(proposalSet, proposals); @@ -254,7 +250,6 @@ public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationC continue; } - SimpleMarkerAnnotation annotation = (SimpleMarkerAnnotation) key; populateDataModelForAnnotation(annotation); IMarker marker = annotation.getMarker(); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/TranslationHyperlink.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/TranslationHyperlink.java index a4cfcb2f72..80aa75be74 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/TranslationHyperlink.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/TranslationHyperlink.java @@ -79,9 +79,8 @@ public boolean openHyperLink() { try { IEditorPart editor = IDE.openEditor(PDEPlugin.getActivePage(), file); - if (!(editor instanceof TextEditor)) + if (!(editor instanceof TextEditor tEditor)) return false; - TextEditor tEditor = (TextEditor) editor; IDocument doc = tEditor.getDocumentProvider().getDocument(tEditor.getEditorInput()); if (doc == null) return false; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/XMLReconcilingStrategy.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/XMLReconcilingStrategy.java index 173717bf89..b1a3a2fa99 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/XMLReconcilingStrategy.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/text/XMLReconcilingStrategy.java @@ -114,8 +114,7 @@ private void deleteAllAnnotations(IRegion region) { while (iter.hasNext()) { Annotation annotation = iter.next(); - if (annotation instanceof SpellingAnnotation) { - SpellingAnnotation spellingAnnotation = (SpellingAnnotation) annotation; + if (annotation instanceof SpellingAnnotation spellingAnnotation) { Position position = model.getPosition(spellingAnnotation); if (position.overlapsWith(region.getOffset(), region.getLength())) { model.removeAnnotation(spellingAnnotation); @@ -138,8 +137,7 @@ private void deleteNonstringSpellingAnnotations(Iterator ite while (iter.hasNext()) { Object annotation = iter.next(); - if (annotation instanceof SpellingAnnotation) { - SpellingAnnotation spellingAnnotation = (SpellingAnnotation) annotation; + if (annotation instanceof SpellingAnnotation spellingAnnotation) { Position position = model.getPosition(spellingAnnotation); String docContentType = docPartitioner.getContentType(position.getOffset()); String pdeXMLContentType = pdeXMLPartitioner.getContentType(position.getOffset()); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/AbstractPluginBlock.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/AbstractPluginBlock.java index e7059870e9..1bb1031e02 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/AbstractPluginBlock.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/AbstractPluginBlock.java @@ -636,8 +636,7 @@ private void createEditors() { private boolean isEditable(TreeItem item) { Object obj = item.getData(); - if (obj instanceof IPluginModelBase) { - IPluginModelBase model = (IPluginModelBase) obj; + if (obj instanceof IPluginModelBase model) { String systemBundleId = PDECore.getDefault().getModelManager().getSystemBundleId(); if (!(systemBundleId.equals(model.getPluginBase().getId()))) { return fPluginTreeViewer.getChecked(model); @@ -725,8 +724,7 @@ protected void handleCheckStateChanged(CheckStateChangedEvent event) { protected void setText(IPluginModelBase model, String value) { Widget widget = fPluginTreeViewer.testFindItem(model); - if (widget instanceof TreeItem) { - TreeItem item = (TreeItem) widget; + if (widget instanceof TreeItem item) { int index = value == null ? -1 : value.indexOf(':'); String levelValue = index == -1 ? "" : value.substring(0, index); //$NON-NLS-1$ String autoValue = null; @@ -789,8 +787,7 @@ protected void handleGroupStateChanged(Object group, boolean checked) { fPluginTreeViewer.setChecked(group, checked); - if (group instanceof NamedElement) { - NamedElement namedElement = (NamedElement) group; + if (group instanceof NamedElement namedElement) { TreeItem item = (TreeItem) fPluginTreeViewer.testFindItem(namedElement); if (item != null) { TreeItem[] children = item.getItems(); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/FeatureBlock.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/FeatureBlock.java index 0703bbd589..df3124a726 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/FeatureBlock.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/FeatureBlock.java @@ -130,8 +130,7 @@ class FeatureTreeLabelProvider extends StyledCellLabelProvider implements ILabel public Image getColumnImage(Object obj, int index) { // If there is a workspace feature available, display the workspace feature icon, even if the user has selected external if (index == COLUMN_FEATURE_NAME) { - if (obj instanceof FeatureLaunchModel) { - FeatureLaunchModel model = (FeatureLaunchModel) obj; + if (obj instanceof FeatureLaunchModel model) { return pdeLabelProvider.getImage(model.getModel(true)); } else if (obj instanceof NamedElement) { return ((NamedElement) obj).getImage(); @@ -140,8 +139,7 @@ public Image getColumnImage(Object obj, int index) { return pdeLabelProvider.getColumnImage(pluginModelBase, index); } } else if (index == COLUMN_PLUGIN_RESOLUTION) { - if (obj instanceof PluginLaunchModel) { - PluginLaunchModel pluginLaunchModel = ((PluginLaunchModel) obj); + if (obj instanceof PluginLaunchModel pluginLaunchModel) { if (IPDELauncherConstants.LOCATION_WORKSPACE.equalsIgnoreCase(pluginLaunchModel.getPluginResolution())) { ModelEntry modelEntry = PluginRegistry.findEntry(pluginLaunchModel.getPluginModelId()); if (!modelEntry.hasWorkspaceModels()) { @@ -161,8 +159,7 @@ public Image getColumnImage(Object obj, int index) { public String getColumnText(Object obj, int index) { if (obj instanceof NamedElement && index == COLUMN_FEATURE_NAME) return ((NamedElement) obj).getLabel(); - if (obj instanceof PluginLaunchModel) { - PluginLaunchModel pluginLaunchModel = (PluginLaunchModel) obj; + if (obj instanceof PluginLaunchModel pluginLaunchModel) { switch (index) { case COLUMN_FEATURE_NAME : return pluginLaunchModel.getPluginModelId(); @@ -170,8 +167,7 @@ public String getColumnText(Object obj, int index) { return getResolutionLabel(pluginLaunchModel.getPluginResolution()); } } - if (obj instanceof FeatureLaunchModel) { - FeatureLaunchModel model = (FeatureLaunchModel) obj; + if (obj instanceof FeatureLaunchModel model) { return switch (index) { case COLUMN_FEATURE_NAME -> model.getId(); case COLUMN_PLUGIN_RESOLUTION -> getResolutionLabel(model.getResolutionValue()); @@ -200,8 +196,7 @@ public void update(ViewerCell cell) { private StyledString getStyledText(Object element) { StyledString styledString = new StyledString(getColumnText(element, COLUMN_FEATURE_NAME)); - if (element instanceof FeatureLaunchModel) { - FeatureLaunchModel featureModel = (FeatureLaunchModel) element; + if (element instanceof FeatureLaunchModel featureModel) { styledString.append(" (", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$ String version = featureModel.getVersion(); int index = version.indexOf('-'); @@ -209,8 +204,7 @@ private StyledString getStyledText(Object element) { version = version.substring(0, index); styledString.append(version, StyledString.QUALIFIER_STYLER); styledString.append(")", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$ - } else if (element instanceof PluginLaunchModel) { - PluginLaunchModel pluginLaunchModel = (PluginLaunchModel) element; + } else if (element instanceof PluginLaunchModel pluginLaunchModel) { styledString.append(" (", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$ String version = pluginLaunchModel.getPluginModelBase().getPluginBase().getVersion(); int index = version.indexOf('-'); @@ -582,15 +576,13 @@ public void modify(Object item, String property, Object value) { Object data = ((TreeItem) item).getData(); int comboIndex = ((Integer) value).intValue(); String location = getLocation(comboIndex); - if (data instanceof FeatureLaunchModel) { - FeatureLaunchModel model = (FeatureLaunchModel) data; + if (data instanceof FeatureLaunchModel model) { if (!location.equalsIgnoreCase(model.getResolutionValue())) { model.setPluginResolution(location); fTree.refresh(model, true); fTab.updateLaunchConfigurationDialog(); } - } else if (data instanceof PluginLaunchModel) { - PluginLaunchModel pluginLaunchModel = (PluginLaunchModel) data; + } else if (data instanceof PluginLaunchModel pluginLaunchModel) { if (!location.equalsIgnoreCase(pluginLaunchModel.getPluginResolution())) { pluginLaunchModel.setPluginResolution(location); fTree.refresh(pluginLaunchModel, true); @@ -1228,12 +1220,10 @@ private void savePluginState(ILaunchConfigurationWorkingCopy config) { Object[] models = fTree.getCheckedLeafElements(); for (Object model : models) { - if (model instanceof FeatureLaunchModel) { - FeatureLaunchModel feature = (FeatureLaunchModel) model; + if (model instanceof FeatureLaunchModel feature) { String entry = BundleLauncherHelper.formatFeatureEntry(feature.getId(), feature.getResolutionValue()); featuresEntry.add(entry); - } else if (model instanceof PluginLaunchModel) { - PluginLaunchModel pluginLaunchModel = (PluginLaunchModel) model; + } else if (model instanceof PluginLaunchModel pluginLaunchModel) { pluginsEntry.add(buildAdditionalPluginEntry(pluginLaunchModel, true)); checkPluginLaunchModels.add(pluginLaunchModel); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/LauncherUtilsStatusHandler.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/LauncherUtilsStatusHandler.java index ff5af628e0..050bf981f4 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/LauncherUtilsStatusHandler.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/LauncherUtilsStatusHandler.java @@ -92,8 +92,7 @@ private void selectWorkspaceField(ILaunchConfigurationDialog dialog) { ILaunchConfigurationTab[] tabs = dialog.getTabs(); if (tabs != null) { for (ILaunchConfigurationTab tab : tabs) { - if (tab instanceof MainTab) { - MainTab mainTab = (MainTab) tab; + if (tab instanceof MainTab mainTab) { dialog.setActiveTab(mainTab); mainTab.applyData(IPDELauncherConstants.LOCATION); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/OSGiBundleBlock.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/OSGiBundleBlock.java index 5e229eb1f6..0d9de821ca 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/OSGiBundleBlock.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/OSGiBundleBlock.java @@ -40,8 +40,7 @@ protected void savePluginState(ILaunchConfigurationWorkingCopy config) { PluginModelNameBuffer tBuffer = new PluginModelNameBuffer(); for (Object selectedElement : selected) { - if (selectedElement instanceof IPluginModelBase) { - IPluginModelBase model = (IPluginModelBase) selectedElement; + if (selectedElement instanceof IPluginModelBase model) { if (model.getUnderlyingResource() == null) { tBuffer.add(model); } else { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/PluginBlock.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/PluginBlock.java index ff5e0a921e..086737b4e4 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/PluginBlock.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/launcher/PluginBlock.java @@ -136,8 +136,7 @@ protected void savePluginState(ILaunchConfigurationWorkingCopy config) { // If we have checked elements, save them to the config Object[] selected = fPluginTreeViewer.getCheckedLeafElements(); for (Object selectedElement : selected) { - if (selectedElement instanceof IPluginModelBase) { - IPluginModelBase model = (IPluginModelBase) selectedElement; + if (selectedElement instanceof IPluginModelBase model) { if (model.getUnderlyingResource() == null) { tBuffer.add(model); } else { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/nls/ExternalizeStringsLabelProvider.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/nls/ExternalizeStringsLabelProvider.java index 2a10e95471..ef5b416593 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/nls/ExternalizeStringsLabelProvider.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/nls/ExternalizeStringsLabelProvider.java @@ -31,8 +31,7 @@ public ExternalizeStringsLabelProvider() { @Override public String getColumnText(Object element, int columnIndex) { - if (element instanceof ModelChangeElement) { - ModelChangeElement changeElement = (ModelChangeElement) element; + if (element instanceof ModelChangeElement changeElement) { if (columnIndex == ExternalizeStringsWizardPage.VALUE) { return StringHelper.unwindEscapeChars(changeElement.getValue()); } else if (columnIndex == ExternalizeStringsWizardPage.KEY) { @@ -49,8 +48,7 @@ public Image getColumnImage(Object element, int columnIndex) { @Override public Font getFont(Object element) { - if (element instanceof ModelChangeElement) { - ModelChangeElement changeElement = (ModelChangeElement) element; + if (element instanceof ModelChangeElement changeElement) { if (changeElement.isExternalized()) { return fFontRegistry.getBold(JFaceResources.DIALOG_FONT); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/nls/ExternalizeStringsOperation.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/nls/ExternalizeStringsOperation.java index 6833d3faa5..d21c3f07a0 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/nls/ExternalizeStringsOperation.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/nls/ExternalizeStringsOperation.java @@ -69,8 +69,7 @@ public ExternalizeStringsOperation(Object[] changeFiles, CompositeChange parentC @Override protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { for (Object changeFileObject : fChangeFiles) { - if (changeFileObject instanceof ModelChangeFile) { - ModelChangeFile changeFile = (ModelChangeFile) changeFileObject; + if (changeFileObject instanceof ModelChangeFile changeFile) { CompositeChange pluginChange = getChangeForPlugin(changeFile.getModel().getParentModel().getPluginBase().getId()); ModelChange change = changeFile.getModel(); IFile pFile = change.getPropertiesFile(); @@ -115,8 +114,7 @@ private void getChangeForBuild(IFile buildPropsFile, IProgressMonitor monitor, C protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws CoreException { // Get model & set includes entry... - if (model instanceof IBuildModel) { - IBuildModel buildModel = (IBuildModel) model; + if (model instanceof IBuildModel buildModel) { IBuildEntry binIncludes = buildModel.getBuild().getEntry(IBuildEntry.BIN_INCLUDES); if (binIncludes == null) { binIncludes = buildModel.getFactory().createEntry(IBuildEntry.BIN_INCLUDES); @@ -200,8 +198,7 @@ private void addBundleLocalization(ModelChange change, IProgressMonitor mon, Com TextFileChange[] result = PDEModelUtility.changesForModelModication(new ModelModification(manifest) { @Override protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws CoreException { - if (model instanceof IBundlePluginModelBase) { - IBundlePluginModelBase bundleModel = (IBundlePluginModelBase) model; + if (model instanceof IBundlePluginModelBase bundleModel) { IBundle bundle = bundleModel.getBundleModel().getBundle(); bundle.setHeader(Constants.BUNDLE_LOCALIZATION, localiz); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/nls/ExternalizeStringsWizardPage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/nls/ExternalizeStringsWizardPage.java index 6ac0bbe252..78932c19b6 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/nls/ExternalizeStringsWizardPage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/nls/ExternalizeStringsWizardPage.java @@ -129,8 +129,7 @@ public boolean canModify(Object element, String property) { @Override public Object getValue(Object element, String property) { - if (element instanceof ModelChangeElement) { - ModelChangeElement changeElement = (ModelChangeElement) element; + if (element instanceof ModelChangeElement changeElement) { if (TABLE_PROPERTIES[KEY].equals(property)) { return StringHelper.unwindEscapeChars(changeElement.getKey()); } @@ -142,8 +141,7 @@ public Object getValue(Object element, String property) { public void modify(Object element, String property, Object value) { if (element instanceof TableItem) { Object data = ((TableItem) element).getData(); - if (data instanceof ModelChangeElement) { - ModelChangeElement changeElement = (ModelChangeElement) data; + if (data instanceof ModelChangeElement changeElement) { if (TABLE_PROPERTIES[KEY].equals(property)) { String newKey = StringHelper.windEscapeChars((String) value); validateKey(newKey, changeElement); @@ -189,9 +187,8 @@ protected ExternalizeStringsWizardPage(ModelChangeTable changeTable) { fErrorElementFilter = new ViewerFilter() { @Override public boolean select(Viewer viewer, Object parentElement, Object element) { - if (!(element instanceof ModelChangeElement)) + if (!(element instanceof ModelChangeElement change)) return false; - ModelChangeElement change = (ModelChangeElement) element; return change.equals(fErrorElement); } }; @@ -348,8 +345,7 @@ private void createTableViewer(Composite parent) { fPropertiesViewer.setContentProvider((IStructuredContentProvider) inputElement -> { if (fInputViewer.getSelection() instanceof IStructuredSelection) { Object selection = fInputViewer.getStructuredSelection().getFirstElement(); - if (selection instanceof ModelChangeFile) { - ModelChangeFile cf = (ModelChangeFile) selection; + if (selection instanceof ModelChangeFile cf) { return (cf).getModel().getChangesInFile(cf.getFile()).toArray(); } } @@ -463,8 +459,7 @@ private void updatePropertiesLabel(IPluginModelBase model) { private void handlePropertySelection() { Object selection = fPropertiesViewer.getStructuredSelection().getFirstElement(); - if (selection instanceof ModelChangeElement && fSourceViewer.getDocument() != null) { - ModelChangeElement element = (ModelChangeElement) selection; + if (selection instanceof ModelChangeElement element && fSourceViewer.getDocument() != null) { int offset = element.getOffset(); int length = element.getLength(); fSourceViewer.setSelectedRange(offset, length); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/nls/GetNonExternalizedStringsOperation.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/nls/GetNonExternalizedStringsOperation.java index c1627085df..5265359b3e 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/nls/GetNonExternalizedStringsOperation.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/nls/GetNonExternalizedStringsOperation.java @@ -199,8 +199,7 @@ private void inspectXML(IPluginModelBase model, IProgressMonitor monitor) throws } private void inspectExtension(ISchema schema, IPluginParent parent, IPluginModelBase memModel, IFile file) { - if (parent instanceof PluginExtensionNode) { - PluginExtensionNode parentNode = (PluginExtensionNode) parent; + if (parent instanceof PluginExtensionNode parentNode) { IDocumentAttributeNode[] attributes = parentNode.getNodeAttributes(); ISchemaElement schemaElement = schema.findElement(parentNode.getXMLTagName()); if (schemaElement != null) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/nls/ModelChangeElement.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/nls/ModelChangeElement.java index 3bcb4bdd9d..5b3ff238e5 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/nls/ModelChangeElement.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/nls/ModelChangeElement.java @@ -41,28 +41,24 @@ public class ModelChangeElement { public ModelChangeElement(ModelChange parent, Object incoming) { fParent = parent; fUnderlying = incoming; - if (incoming instanceof PluginElementNode) { - PluginElementNode elem = (PluginElementNode) incoming; + if (incoming instanceof PluginElementNode elem) { IDocumentTextNode text = elem.getTextNode(); fValue = elem.getText(); generateValidKey(elem.getParent().getName(), elem.getName()); fOffset = text.getOffset(); fLength = text.getLength(); - } else if (incoming instanceof PluginAttribute) { - PluginAttribute attr = (PluginAttribute) incoming; + } else if (incoming instanceof PluginAttribute attr) { fValue = attr.getValue(); generateValidKey(attr.getEnclosingElement().getXMLTagName(), attr.getName()); fOffset = attr.getValueOffset(); fLength = attr.getValueLength(); - } else if (incoming instanceof PluginExtensionPointNode) { - PluginExtensionPointNode extP = (PluginExtensionPointNode) incoming; + } else if (incoming instanceof PluginExtensionPointNode extP) { fValue = extP.getName(); generateValidKey("extension-point", "name"); //$NON-NLS-1$ //$NON-NLS-2$ IDocumentAttributeNode attr = extP.getDocumentAttribute("name"); //$NON-NLS-1$ fOffset = attr.getValueOffset(); fLength = attr.getValueLength(); - } else if (incoming instanceof ManifestHeader) { - ManifestHeader header = (ManifestHeader) incoming; + } else if (incoming instanceof ManifestHeader header) { fValue = header.getValue(); generateValidKey(header.getName()); fLength = fValue.length(); @@ -127,18 +123,14 @@ public String getExternKey() { public boolean updateValue() { try { String key = getExternKey(); - if (fUnderlying instanceof PluginElementNode) { - PluginElementNode elem = (PluginElementNode) fUnderlying; + if (fUnderlying instanceof PluginElementNode elem) { elem.setText(key); - } else if (fUnderlying instanceof PluginAttribute) { - PluginAttribute attr = (PluginAttribute) fUnderlying; + } else if (fUnderlying instanceof PluginAttribute attr) { String attrName = attr.getName(); attr.getEnclosingElement().setXMLAttribute(attrName, key); - } else if (fUnderlying instanceof PluginExtensionPointNode) { - PluginExtensionPointNode extP = (PluginExtensionPointNode) fUnderlying; + } else if (fUnderlying instanceof PluginExtensionPointNode extP) { extP.setName(key); - } else if (fUnderlying instanceof ManifestHeader) { - ManifestHeader header = (ManifestHeader) fUnderlying; + } else if (fUnderlying instanceof ManifestHeader header) { header.setValue(key); } else return false; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/nls/NLSFragmentGenerator.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/nls/NLSFragmentGenerator.java index 08e9df7256..2b2e33b69e 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/nls/NLSFragmentGenerator.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/nls/NLSFragmentGenerator.java @@ -510,8 +510,7 @@ public void add(Filter filter) { } public boolean include(Object object) { - if (object instanceof IResource) { - IResource resource = (IResource) object; + if (object instanceof IResource resource) { IPath path = IResource.FILE == resource.getType() ? resource.getFullPath() : resource.getFullPath().addTrailingSeparator(); object = path.toPortableString(); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/parts/PluginVersionPart.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/parts/PluginVersionPart.java index 485ae5cab3..3ba76b78cc 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/parts/PluginVersionPart.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/parts/PluginVersionPart.java @@ -90,8 +90,7 @@ private static class PluginVersionContentProvider implements IStructuredContentP @Override public Object[] getElements(Object element) { - if (element instanceof ModelEntry) { - ModelEntry entry = (ModelEntry) element; + if (element instanceof ModelEntry entry) { return entry.getActiveModels(); } return new Object[0]; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/preferences/BuildJob.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/preferences/BuildJob.java index bc48d496d2..7bd919ff06 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/preferences/BuildJob.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/preferences/BuildJob.java @@ -145,8 +145,7 @@ protected IStatus run(IProgressMonitor monitor) { private void cancelBuild(Object jobfamily) { Job[] buildJobs = Job.getJobManager().find(jobfamily); for (Job curr : buildJobs) { - if (curr != this && curr instanceof BuildJob) { - BuildJob job = (BuildJob) curr; + if (curr != this && curr instanceof BuildJob job) { if (job.isCoveredBy(this)) { curr.cancel(); // cancel all other build jobs of our // kind diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/preferences/PDECompilersConfigurationBlock.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/preferences/PDECompilersConfigurationBlock.java index e174a8c6f6..6e3b5cfd5b 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/preferences/PDECompilersConfigurationBlock.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/preferences/PDECompilersConfigurationBlock.java @@ -366,8 +366,7 @@ public static Key[] getAllKeys() { data.key.setStoredValue(fLookupOrder[0], Integer.toString(selectionIndex), fManager); fDirty = true; fRebuildcount = 0; - } else if (e.widget instanceof Button) { - Button button = (Button) e.widget; + } else if (e.widget instanceof Button button) { ControlData data = (ControlData) button.getData(); data.key.setStoredValue(fLookupOrder[0], Boolean.toString(button.getSelection()), fManager); fDirty = true; @@ -480,8 +479,7 @@ private void updateControls() { continue; } for (Control control : controls) { - if (control instanceof Combo) { - Combo combo = (Combo) control; + if (control instanceof Combo combo) { ControlData data = (ControlData) combo.getData(); int index = 0; try { @@ -492,12 +490,10 @@ private void updateControls() { } index = adjustIndex(index); combo.select(data.getSelection(SEVERITIES[index])); - } else if (control instanceof Button) { - Button button = (Button) control; + } else if (control instanceof Button button) { ControlData data = (ControlData) button.getData(); button.setSelection(Boolean.parseBoolean(data.key.getStoredValue(fLookupOrder, false, fManager))); - } else if (control instanceof Text) { - Text text = (Text) control; + } else if (control instanceof Text text) { ControlData data = (ControlData) text.getData(); text.setText(data.key.getStoredValue(fLookupOrder, false, fManager)); } @@ -512,8 +508,7 @@ private void updateControls() { */ private void enableControl(Control ctrl, boolean enabled) { ctrl.setEnabled(enabled); - if (ctrl instanceof Composite) { - Composite comp = (Composite) ctrl; + if (ctrl instanceof Composite comp) { Control[] children = comp.getChildren(); for (Control child : children) { enableControl(child, enabled); @@ -765,8 +760,7 @@ public void expansionStateChanged(ExpansionEvent e) { * @return the scrolling parent of the given object or null if there isn't one */ private ScrolledComposite getScrollingParent(Object obj) { - if (obj instanceof ExpandableComposite) { - ExpandableComposite ecomp = (ExpandableComposite) obj; + if (obj instanceof ExpandableComposite ecomp) { Composite parent = ecomp.getParent(); while (parent != null && !(parent instanceof ScrolledComposite)) { parent = parent.getParent(); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/preferences/ProjectSelectionDialog.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/preferences/ProjectSelectionDialog.java index 65aabf7b63..12a9a64145 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/preferences/ProjectSelectionDialog.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/preferences/ProjectSelectionDialog.java @@ -57,8 +57,7 @@ public class ProjectSelectionDialog extends SelectionStatusDialog { class ApiJavaElementContentProvider extends StandardJavaElementContentProvider { @Override public Object[] getChildren(Object element) { - if (element instanceof IJavaModel) { - IJavaModel model = (IJavaModel) element; + if (element instanceof IJavaModel model) { HashSet set = new HashSet<>(); try { IJavaProject[] projects = model.getJavaProjects(); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/preferences/TargetPlatformPreferencePage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/preferences/TargetPlatformPreferencePage.java index bf24e419d8..d20dbd6199 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/preferences/TargetPlatformPreferencePage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/preferences/TargetPlatformPreferencePage.java @@ -393,10 +393,9 @@ public Control createContents(Composite parent) { * */ private void performResolve(Object element) { - if (!(element instanceof ITargetDefinition)) { + if (!(element instanceof final ITargetDefinition target)) { return; } - final ITargetDefinition target = (ITargetDefinition) element; if (target.isResolved()) return; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/BundleManifestChange.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/BundleManifestChange.java index a014b0ab68..0a61b39f28 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/BundleManifestChange.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/BundleManifestChange.java @@ -190,16 +190,14 @@ private static boolean isGoodMatch(String value, String oldName, boolean isPacka } private static void renamePackage(IManifestHeader header, String oldName, String newName) { - if (header instanceof BasePackageHeader) { - BasePackageHeader bHeader = (BasePackageHeader) header; + if (header instanceof BasePackageHeader bHeader) { bHeader.renamePackage(oldName, newName); } } private static PDEManifestElement removePackage(IManifestHeader header, String name) { PDEManifestElement result = null; - if (header instanceof BasePackageHeader) { - BasePackageHeader bHeader = (BasePackageHeader) header; + if (header instanceof BasePackageHeader bHeader) { result = ((PackageObject) bHeader.removePackage(name)); } return result; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/CreateHeaderChangeOperation.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/CreateHeaderChangeOperation.java index 49efaa7a82..aa2da01241 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/CreateHeaderChangeOperation.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/CreateHeaderChangeOperation.java @@ -87,8 +87,7 @@ protected TextFileChange updateBundleHeader(IFile manifest, IProgressMonitor mon IManifestHeader mHeader = bundle.getManifestHeader(fHeaderKey); if (mHeader instanceof BundleSymbolicNameHeader) { ((BundleSymbolicNameHeader) mHeader).setId(fNewValue); - } else if (mHeader instanceof RequireBundleHeader) { - RequireBundleHeader header = (RequireBundleHeader) mHeader; + } else if (mHeader instanceof RequireBundleHeader header) { RequireBundleObject bundles[] = header.getRequiredBundles(); for (RequireBundleObject requiredBundle : bundles) { if (requiredBundle.getId().equals(fOldValue)) diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/ManifestPackageMoveParticipant.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/ManifestPackageMoveParticipant.java index db477baf22..0d3ea40229 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/ManifestPackageMoveParticipant.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/ManifestPackageMoveParticipant.java @@ -34,8 +34,7 @@ public class ManifestPackageMoveParticipant extends PDEMoveParticipant { @Override protected boolean initialize(Object element) { - if (element instanceof IPackageFragment) { - IPackageFragment fragment = (IPackageFragment) element; + if (element instanceof IPackageFragment fragment) { IJavaProject javaProject = (IJavaProject) fragment.getAncestor(IJavaElement.JAVA_PROJECT); IProject project = javaProject.getProject(); if (PDEProject.getManifest(project).exists()) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/ManifestPackageRenameParticipant.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/ManifestPackageRenameParticipant.java index 64bc3043d1..a4dd90f9d3 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/ManifestPackageRenameParticipant.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/ManifestPackageRenameParticipant.java @@ -40,8 +40,7 @@ public class ManifestPackageRenameParticipant extends PDERenameParticipant { @Override protected boolean initialize(Object element) { try { - if (element instanceof IPackageFragment) { - IPackageFragment fragment = (IPackageFragment) element; + if (element instanceof IPackageFragment fragment) { if (!fragment.containsJavaResources()) return false; IJavaProject javaProject = (IJavaProject) fragment.getAncestor(IJavaElement.JAVA_PROJECT); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/ManifestTypeMoveParticipant.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/ManifestTypeMoveParticipant.java index eff7c53b2a..43b8bcef77 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/ManifestTypeMoveParticipant.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/ManifestTypeMoveParticipant.java @@ -33,8 +33,7 @@ public class ManifestTypeMoveParticipant extends PDEMoveParticipant { @Override protected boolean initialize(Object element) { - if (element instanceof IType) { - IType type = (IType) element; + if (element instanceof IType type) { IJavaProject javaProject = (IJavaProject) type.getAncestor(IJavaElement.JAVA_PROJECT); IProject project = javaProject.getProject(); if (WorkspaceModelManager.isPluginProject(project)) { @@ -55,8 +54,7 @@ public String getName() { @Override protected boolean isInterestingForExtensions() { Object dest = getArguments().getDestination(); - if (dest instanceof IJavaElement) { - IJavaElement destination = (IJavaElement) dest; + if (dest instanceof IJavaElement destination) { IJavaProject jProject = (IJavaProject) destination.getAncestor(IJavaElement.JAVA_PROJECT); return jProject.getProject().equals(fProject); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/ManifestTypeRenameParticipant.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/ManifestTypeRenameParticipant.java index 6c70d69a40..620d14bbad 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/ManifestTypeRenameParticipant.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/ManifestTypeRenameParticipant.java @@ -30,8 +30,7 @@ public class ManifestTypeRenameParticipant extends PDERenameParticipant { @Override protected boolean initialize(Object element) { - if (element instanceof IType) { - IType type = (IType) element; + if (element instanceof IType type) { IJavaProject javaProject = (IJavaProject) type.getAncestor(IJavaElement.JAVA_PROJECT); IProject project = javaProject.getProject(); if (WorkspaceModelManager.isPluginProject(project)) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/RenameExtensionPointProcessor.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/RenameExtensionPointProcessor.java index 222a7ad91d..1e5e9b7b71 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/RenameExtensionPointProcessor.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/refactoring/RenameExtensionPointProcessor.java @@ -150,9 +150,8 @@ protected ModelModification getExtensionPointModification(IFile file) { @Override protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws CoreException { - if (!(model instanceof IPluginModelBase)) + if (!(model instanceof IPluginModelBase modelBase)) return; - IPluginModelBase modelBase = (IPluginModelBase) model; IPluginBase base = modelBase.getPluginBase(); IPluginExtensionPoint[] points = base.getExtensionPoints(); for (IPluginExtensionPoint point : points) { @@ -171,9 +170,8 @@ protected ModelModification getExtensionModification(IFile file) { @Override protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws CoreException { - if (!(model instanceof IPluginModelBase)) + if (!(model instanceof IPluginModelBase modelBase)) return; - IPluginModelBase modelBase = (IPluginModelBase) model; IPluginBase base = modelBase.getPluginBase(); IPluginExtension[] extensions = base.getExtensions(); String oldValue = getId(); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/ClassSearchParticipant.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/ClassSearchParticipant.java index 0c8bbe3e75..f0b047073c 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/ClassSearchParticipant.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/ClassSearchParticipant.java @@ -165,9 +165,9 @@ protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws Co private void inspectExtension(ISchema schema, IPluginParent parent, IFile file) { IPluginObject[] children = parent.getChildren(); - if (parent instanceof PluginElementNode && parent.getParent() instanceof PluginElementNode) { - // check if this node corresponds to a Java type attribute which would have been defined has an element - PluginElementNode node = (PluginElementNode) parent; + if (parent instanceof PluginElementNode node && parent.getParent() instanceof PluginElementNode) { + // check if this node corresponds to a Java type attribute which + // would have been defined has an element PluginElementNode parentNode = (PluginElementNode) parent.getParent(); ISchemaElement schemaElement = schema.findElement(parentNode.getName()); if (schemaElement != null) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/ExtensionsPatternFilter.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/ExtensionsPatternFilter.java index 885666466b..366cba45ac 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/ExtensionsPatternFilter.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/ExtensionsPatternFilter.java @@ -265,8 +265,7 @@ protected boolean doFilter(Viewer viewer, Object parent, IPluginObject[] childre // traverse children when available boolean isAnyChildMatch = false; for (IPluginObject iPluginObject : children) { - if (iPluginObject instanceof IPluginParent) { - IPluginParent pluginElement = (IPluginParent) iPluginObject; + if (iPluginObject instanceof IPluginParent pluginElement) { if (pluginElement.getChildren().length > 0) { boolean isChildrenMatch = doFilter(viewer, pluginElement, pluginElement.getChildren(), addChildren || fMatchingLeafs.contains(pluginElement)); isAnyChildMatch |= isChildrenMatch; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/FindPluginReferencesAction.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/FindPluginReferencesAction.java index dadb72e94e..1bc24daa68 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/FindPluginReferencesAction.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/FindPluginReferencesAction.java @@ -53,8 +53,7 @@ private ISearchQuery createSearchQuery() { @Override public void selectionChanged(IAction action, ISelection selection) { fSearchString = null; - if (selection instanceof IStructuredSelection) { - IStructuredSelection sSelection = (IStructuredSelection) selection; + if (selection instanceof IStructuredSelection sSelection) { if (sSelection.size() == 1) { IFile file = (IFile) sSelection.getFirstElement(); IPluginModelBase model = PluginRegistry.findModel(file.getProject()); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/ManifestEditorOpener.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/ManifestEditorOpener.java index 0dab7c5854..bb6e1bad13 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/ManifestEditorOpener.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/ManifestEditorOpener.java @@ -46,8 +46,7 @@ public class ManifestEditorOpener { public static IEditorPart open(Match match, boolean activate) { IEditorPart editorPart = ManifestEditor.open(match.getElement(), true); - if (editorPart != null && editorPart instanceof ManifestEditor) { - ManifestEditor editor = (ManifestEditor) editorPart; + if (editorPart != null && editorPart instanceof ManifestEditor editor) { if (match.getBaseUnit() != AttributesMatch.UNIT_ATTRIBUTE_SEARCH_PATTERN) { IDocument doc = editor.getDocument(match); if (doc != null) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/PluginSearchActionGroup.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/PluginSearchActionGroup.java index 8a67d2b329..b35ab9078d 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/PluginSearchActionGroup.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/PluginSearchActionGroup.java @@ -43,8 +43,7 @@ public void setBaseModel(IBaseModel model) { public void fillContextMenu(IMenuManager menu) { ActionContext context = getContext(); ISelection selection = context.getSelection(); - if (selection instanceof IStructuredSelection) { - IStructuredSelection sSelection = (IStructuredSelection) selection; + if (selection instanceof IStructuredSelection sSelection) { if (sSelection.size() == 1) { Object object = sSelection.getFirstElement(); addShowDescriptionAction(object, menu); @@ -95,8 +94,7 @@ private void addFindDeclarationsAction(Object object, IMenuManager menu) { } private void addShowDescriptionAction(Object object, IMenuManager menu) { - if (object instanceof IPluginExtensionPoint) { - IPluginExtensionPoint extPoint = (IPluginExtensionPoint) object; + if (object instanceof IPluginExtensionPoint extPoint) { String pointID = extPoint.getFullId(); if (pointID.indexOf('.') == -1) { // Point ID is not fully qualified diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/PluginSearchQuery.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/PluginSearchQuery.java index 2b5077e140..c6e88bfc62 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/PluginSearchQuery.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/PluginSearchQuery.java @@ -42,12 +42,10 @@ public IStatus run(IProgressMonitor monitor) { final AbstractTextSearchResult result = (AbstractTextSearchResult) getSearchResult(); result.removeAll(); ISearchResultCollector collector = match -> { - if (match instanceof ISourceObject) { - ISourceObject object1 = (ISourceObject) match; + if (match instanceof ISourceObject object1) { result.addMatch(new Match(match, Match.UNIT_LINE, object1.getStartLine() - 1, 1)); } - if (match instanceof IFeaturePlugin) { - IFeaturePlugin object2 = (IFeaturePlugin) match; + if (match instanceof IFeaturePlugin object2) { result.addMatch(new Match(object2, Match.UNIT_LINE, -1, 1)); } }; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/PluginSearchResultPage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/PluginSearchResultPage.java index 35f43c10db..1e7bce73be 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/PluginSearchResultPage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/PluginSearchResultPage.java @@ -51,14 +51,12 @@ public String getText(Object object) { if (object instanceof IPluginBase) return ((IPluginBase) object).getId(); - if (object instanceof IPluginImport) { - IPluginImport dep = (IPluginImport) object; + if (object instanceof IPluginImport dep) { return dep.getId() + " - " //$NON-NLS-1$ + dep.getPluginBase().getId(); } - if (object instanceof IPluginExtension) { - IPluginExtension extension = (IPluginExtension) object; + if (object instanceof IPluginExtension extension) { return extension.getPoint() + " - " + extension.getPluginBase().getId(); //$NON-NLS-1$ } @@ -66,8 +64,7 @@ public String getText(Object object) { return ((IPluginExtensionPoint) object).getFullId(); } - if (object instanceof IFeaturePlugin) { - final IFeaturePlugin featurePlugin = (IFeaturePlugin) object; + if (object instanceof final IFeaturePlugin featurePlugin) { final String pluginId = featurePlugin.getId(); final String featureId = featurePlugin.getFeature().getId(); return pluginId + " - " + featureId; //$NON-NLS-1$ diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/SearchResult.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/SearchResult.java index bbc66f242a..d7e5b89cad 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/SearchResult.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/SearchResult.java @@ -87,8 +87,7 @@ public Match[] computeContainedMatches(AbstractTextSearchResult result, IEditorP ArrayList list = new ArrayList<>(); Object[] objects = result.getElements(); for (Object o : objects) { - if (o instanceof IPluginObject) { - IPluginObject object = (IPluginObject) o; + if (o instanceof IPluginObject object) { if (isMatchContained(editor, object)) { Match[] matches = getMatches(object); for (Match matche : matches) { @@ -98,8 +97,7 @@ public Match[] computeContainedMatches(AbstractTextSearchResult result, IEditorP } } } - if (o instanceof IFeaturePlugin) { - IFeaturePlugin object = (IFeaturePlugin) o; + if (o instanceof IFeaturePlugin object) { if (isMatchContained(editor, object)) { Collections.addAll(list, getMatches(object)); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/AddNewDependenciesOperation.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/AddNewDependenciesOperation.java index 4ada51e3d6..d6727e1d7e 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/AddNewDependenciesOperation.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/AddNewDependenciesOperation.java @@ -421,8 +421,7 @@ protected final void addImportPackages(final Collection depsToAdd, final HashSet added = new HashSet<>(); Iterator it = depsToAdd.iterator(); IManifestHeader mheader = bundle.getManifestHeader(Constants.REQUIRE_BUNDLE); - if (mheader instanceof RequireBundleHeader) { - RequireBundleHeader header = (RequireBundleHeader) mheader; + if (mheader instanceof RequireBundleHeader header) { while (it.hasNext()) { String pluginId = it.next(); if (!added.contains(pluginId)) diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/DependencyExtentSearchResult.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/DependencyExtentSearchResult.java index 7f0d515468..3c0be3dcc1 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/DependencyExtentSearchResult.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/DependencyExtentSearchResult.java @@ -75,8 +75,7 @@ private void collectMatches(Set matches, IJavaElement element) { if (m.length != 0) { Collections.addAll(matches, m); } - if (element instanceof IParent) { - IParent parent = (IParent) element; + if (element instanceof IParent parent) { try { IJavaElement[] children = parent.getChildren(); for (IJavaElement child : children) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/DependencyExtentSearchResultPage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/DependencyExtentSearchResultPage.java index 65b88df935..d65262431c 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/DependencyExtentSearchResultPage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/DependencyExtentSearchResultPage.java @@ -74,8 +74,7 @@ public String getText(Object element) { if (element instanceof IPluginExtension) return ((IPluginExtension) element).getPoint(); - if (element instanceof IJavaElement) { - IJavaElement javaElement = (IJavaElement) element; + if (element instanceof IJavaElement javaElement) { String text = super.getText(javaElement) + " - " //$NON-NLS-1$ + javaElement.getAncestor(IJavaElement.PACKAGE_FRAGMENT).getElementName(); if (!(javaElement instanceof IType)) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/JavaEditorOpener.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/JavaEditorOpener.java index e301ab9546..dc20f13463 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/JavaEditorOpener.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/JavaEditorOpener.java @@ -38,12 +38,10 @@ public static IEditorPart open(Match match, int offset, int length, boolean acti } if (editor != null && activate) editor.getEditorSite().getPage().activate(editor); - if (editor instanceof ITextEditor) { - ITextEditor textEditor = (ITextEditor) editor; + if (editor instanceof ITextEditor textEditor) { textEditor.selectAndReveal(offset, length); } else if (editor != null) { - if (element instanceof IFile) { - IFile file = (IFile) element; + if (element instanceof IFile file) { showWithMarker(editor, file, offset, length); } } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/PackageFinder.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/PackageFinder.java index f30b522c23..5b7fb57385 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/PackageFinder.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dependencies/PackageFinder.java @@ -255,8 +255,7 @@ private static void addClassFilesFromResource(IResource res, List cl try { IJavaElement[] children = root.getChildren(); for (IJavaElement child : children) { - if (child instanceof IPackageFragment) { - IPackageFragment frag = (IPackageFragment) child; + if (child instanceof IPackageFragment frag) { IClassFile[] files = frag.getClassFiles(); Collections.addAll(classFiles, files); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dialogs/FilteredIUSelectionDialog.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dialogs/FilteredIUSelectionDialog.java index 8d5007cefe..89d6ec61e9 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dialogs/FilteredIUSelectionDialog.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dialogs/FilteredIUSelectionDialog.java @@ -76,8 +76,7 @@ public IUWrapperLabelProvider() { public StyledString getStyledText(Object element) { StyledString styledString = new StyledString(); - if (element instanceof IUPackage) { - IUPackage iuPackage = (IUPackage) element; + if (element instanceof IUPackage iuPackage) { styledString.append(iuPackage.getId()); styledString.append(' '); styledString.append("(", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$ @@ -90,8 +89,7 @@ public StyledString getStyledText(Object element) { styledString.append("(", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$ styledString.append(iu.getVersion().toString(), StyledString.QUALIFIER_STYLER); styledString.append(")", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$ - } else if (element instanceof IInstallableUnit) { - IInstallableUnit iu = (IInstallableUnit) element; + } else if (element instanceof IInstallableUnit iu) { String name = iu.getProperty(IInstallableUnit.PROP_NAME, null); styledString.append(iu.getId()); styledString.append(' '); @@ -109,8 +107,7 @@ public StyledString getStyledText(Object element) { public Image getImage(Object element) { if (element instanceof IUPackage) { return labelProvider.get(PDEPluginImages.DESC_PACKAGE_OBJ); - } else if (element instanceof IInstallableUnit) { - IInstallableUnit iu = (IInstallableUnit) element; + } else if (element instanceof IInstallableUnit iu) { if (QueryUtil.isGroup(iu)) return labelProvider.get(PDEPluginImages.DESC_FEATURE_OBJ); return labelProvider.get(PDEPluginImages.DESC_PLUGIN_OBJ); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dialogs/FilteredPluginArtifactsSelectionDialog.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dialogs/FilteredPluginArtifactsSelectionDialog.java index 8adc8b0890..890000d551 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dialogs/FilteredPluginArtifactsSelectionDialog.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dialogs/FilteredPluginArtifactsSelectionDialog.java @@ -112,27 +112,23 @@ public String getText(Object object) { if (object instanceof IPluginBase) return ((IPluginBase) object).getId(); - if (object instanceof IPluginImport) { - IPluginImport dep = (IPluginImport) object; + if (object instanceof IPluginImport dep) { return dep.getId() + " - " //$NON-NLS-1$ + dep.getPluginBase().getId(); } - if (object instanceof IPluginExtension) { - IPluginExtension extension = (IPluginExtension) object; + if (object instanceof IPluginExtension extension) { return extension.getPoint() + " - " + extension.getPluginBase().getId(); //$NON-NLS-1$ } if (object instanceof IPluginExtensionPoint) return ((IPluginExtensionPoint) object).getFullId(); - if (object instanceof ExportPackageDescription) { - ExportPackageDescription epd = (ExportPackageDescription) object; + if (object instanceof ExportPackageDescription epd) { return epd.getName() + ' ' + '(' + epd.getVersion() + ')'; } - if (object instanceof IFeatureModel) { - IFeatureModel fModel = (IFeatureModel) object; + if (object instanceof IFeatureModel fModel) { IFeature feature = fModel.getFeature(); return feature.getId() + ' ' + '(' + feature.getVersion() + ')'; } @@ -147,8 +143,7 @@ public Image decorateImage(Image image, Object element) { @Override public String decorateText(String text, Object element) { - if (element instanceof ExportPackageDescription) { - ExportPackageDescription epd = (ExportPackageDescription) element; + if (element instanceof ExportPackageDescription epd) { return text.concat(" - " + epd.getSupplier().getSymbolicName()); //$NON-NLS-1$ } return text; @@ -190,23 +185,18 @@ private class DetailedLabelProvider extends LabelProvider { @Override public Image getImage(Object element) { - if (element instanceof IPluginModelBase) { - IPluginModelBase model = (IPluginModelBase) element; + if (element instanceof IPluginModelBase model) { return getImage(model.getInstallLocation()); - } else if (element instanceof IPluginExtensionPoint) { - IPluginExtensionPoint model = (IPluginExtensionPoint) element; + } else if (element instanceof IPluginExtensionPoint model) { return getImage(model.getModel().getInstallLocation()); - } else if (element instanceof IPluginExtension) { - IPluginExtension model = (IPluginExtension) element; + } else if (element instanceof IPluginExtension model) { return getImage(model.getModel().getInstallLocation()); - } else if (element instanceof ExportPackageDescription) { - ExportPackageDescription model = (ExportPackageDescription) element; + } else if (element instanceof ExportPackageDescription model) { String id = model.getSupplier().getName(); String version = model.getSupplier().getVersion().toString(); IPluginModelBase base = getModel(id, version); return getImage(base.getInstallLocation()); - } else if (element instanceof IFeatureModel) { - IFeatureModel model = (IFeatureModel) element; + } else if (element instanceof IFeatureModel model) { return getImage(model.getInstallLocation()); } return null; @@ -214,23 +204,18 @@ public Image getImage(Object element) { @Override public String getText(Object element) { - if (element instanceof IPluginModelBase) { - IPluginModelBase model = (IPluginModelBase) element; + if (element instanceof IPluginModelBase model) { return model.getInstallLocation(); - } else if (element instanceof IPluginExtensionPoint) { - IPluginExtensionPoint model = (IPluginExtensionPoint) element; + } else if (element instanceof IPluginExtensionPoint model) { return model.getModel().getInstallLocation(); - } else if (element instanceof IPluginExtension) { - IPluginExtension model = (IPluginExtension) element; + } else if (element instanceof IPluginExtension model) { return model.getModel().getInstallLocation(); - } else if (element instanceof ExportPackageDescription) { - ExportPackageDescription model = (ExportPackageDescription) element; + } else if (element instanceof ExportPackageDescription model) { String id = model.getSupplier().getName(); String version = model.getSupplier().getVersion().toString(); IPluginModelBase base = getModel(id, version); return base.getInstallLocation(); - } else if (element instanceof IFeatureModel) { - IFeatureModel model = (IFeatureModel) element; + } else if (element instanceof IFeatureModel model) { return model.getInstallLocation(); } return null; @@ -481,20 +466,15 @@ protected IDialogSettings getDialogSettings() { @Override public String getElementName(Object item) { - if (item instanceof IPluginModelBase) { - IPluginModelBase model = (IPluginModelBase) item; + if (item instanceof IPluginModelBase model) { return model.getPluginBase().getId(); - } else if (item instanceof IPluginExtensionPoint) { - IPluginExtensionPoint model = (IPluginExtensionPoint) item; + } else if (item instanceof IPluginExtensionPoint model) { return model.getFullId(); - } else if (item instanceof IPluginExtension) { - IPluginExtension model = (IPluginExtension) item; + } else if (item instanceof IPluginExtension model) { return model.getPoint(); - } else if (item instanceof ExportPackageDescription) { - ExportPackageDescription model = (ExportPackageDescription) item; + } else if (item instanceof ExportPackageDescription model) { return model.getName(); - } else if (item instanceof IFeatureModel) { - IFeatureModel model = (IFeatureModel) item; + } else if (item instanceof IFeatureModel model) { return model.getFeature().getId(); } return null; @@ -650,31 +630,26 @@ protected IPluginModelBase getModel(IMemento memento) { @Override protected void storeItemToMemento(Object item, IMemento memento) { - if (item instanceof IPluginModelBase) { - IPluginModelBase model = (IPluginModelBase) item; + if (item instanceof IPluginModelBase model) { memento.putInteger(M_TYPE, TYPE_PLUGIN); memento.putString(M_PLUGIN_ID, model.getPluginBase().getId()); memento.putString(M_PLUGIN_VERSION, model.getPluginBase().getVersion()); - } else if (item instanceof IPluginExtensionPoint) { - IPluginExtensionPoint model = (IPluginExtensionPoint) item; + } else if (item instanceof IPluginExtensionPoint model) { memento.putInteger(M_TYPE, TYPE_EXTENSION_POINT); memento.putString(M_ID, model.getFullId()); memento.putString(M_PLUGIN_ID, model.getPluginBase().getId()); memento.putString(M_PLUGIN_VERSION, model.getPluginBase().getVersion()); - } else if (item instanceof IPluginExtension) { - IPluginExtension model = (IPluginExtension) item; + } else if (item instanceof IPluginExtension model) { memento.putInteger(M_TYPE, TYPE_EXTENSION); memento.putString(M_ID, model.getPoint()); memento.putString(M_PLUGIN_ID, model.getPluginBase().getId()); memento.putString(M_PLUGIN_VERSION, model.getPluginBase().getVersion()); - } else if (item instanceof ExportPackageDescription) { - ExportPackageDescription model = (ExportPackageDescription) item; + } else if (item instanceof ExportPackageDescription model) { memento.putInteger(M_TYPE, TYPE_EXPORTED_PACKAGE); memento.putString(M_ID, model.getName()); memento.putString(M_PLUGIN_ID, model.getSupplier().getSymbolicName()); memento.putString(M_PLUGIN_VERSION, model.getSupplier().getVersion().toString()); - } else if (item instanceof IFeatureModel) { - IFeatureModel model = (IFeatureModel) item; + } else if (item instanceof IFeatureModel model) { memento.putInteger(M_TYPE, TYPE_FEATURE); memento.putString(M_ID, model.getFeature().getId()); memento.putString(M_PLUGIN_VERSION, model.getFeature().getVersion()); @@ -703,20 +678,15 @@ public boolean isConsistentItem(Object item) { @Override public boolean matchItem(Object item) { String id = null; - if (item instanceof IPluginModelBase) { - IPluginModelBase model = (IPluginModelBase) item; + if (item instanceof IPluginModelBase model) { id = model.getPluginBase().getId(); - } else if (item instanceof IPluginExtensionPoint) { - IPluginExtensionPoint model = (IPluginExtensionPoint) item; + } else if (item instanceof IPluginExtensionPoint model) { id = model.getFullId(); - } else if (item instanceof IPluginExtension) { - IPluginExtension model = (IPluginExtension) item; + } else if (item instanceof IPluginExtension model) { id = model.getPoint(); - } else if (item instanceof ExportPackageDescription) { - ExportPackageDescription model = (ExportPackageDescription) item; + } else if (item instanceof ExportPackageDescription model) { id = model.getName(); - } else if (item instanceof IFeatureModel) { - IFeatureModel model = (IFeatureModel) item; + } else if (item instanceof IFeatureModel model) { id = model.getFeature().getId(); } @@ -774,32 +744,27 @@ private int getId(Object element) { } private int compareSimilarObjects(Object o1, Object o2) { - if (o1 instanceof IPluginModelBase && o2 instanceof IPluginModelBase) { - IPluginModelBase ipmb1 = (IPluginModelBase) o1; + if (o1 instanceof IPluginModelBase ipmb1 && o2 instanceof IPluginModelBase) { IPluginModelBase ipmb2 = (IPluginModelBase) o2; return comparePlugins(ipmb1.getPluginBase(), ipmb2.getPluginBase()); - } else if (o1 instanceof IPluginExtensionPoint && o2 instanceof IPluginExtensionPoint) { - IPluginExtensionPoint ipep1 = (IPluginExtensionPoint) o1; + } else if (o1 instanceof IPluginExtensionPoint ipep1 && o2 instanceof IPluginExtensionPoint) { IPluginExtensionPoint ipep2 = (IPluginExtensionPoint) o2; return compareExtensionPoints(ipep1, ipep2); - } else if (o1 instanceof IPluginExtension && o2 instanceof IPluginExtension) { - IPluginExtension ipe1 = (IPluginExtension) o1; + } else if (o1 instanceof IPluginExtension ipe1 && o2 instanceof IPluginExtension) { IPluginExtension ipe2 = (IPluginExtension) o2; int comparePointsResult = ipe1.getPoint().compareTo(ipe2.getPoint()); if (comparePointsResult == 0) return comparePlugins(ipe1.getPluginBase(), ipe2.getPluginBase()); // else return comparePointsResult; - } else if (o1 instanceof ExportPackageDescription && o2 instanceof ExportPackageDescription) { - ExportPackageDescription epd1 = (ExportPackageDescription) o1; + } else if (o1 instanceof ExportPackageDescription epd1 && o2 instanceof ExportPackageDescription) { ExportPackageDescription epd2 = (ExportPackageDescription) o2; int compareNamesResult = epd1.getName().compareTo(epd2.getName()); if (compareNamesResult == 0) return compareBundleDescriptions(epd1.getSupplier(), epd2.getSupplier()); // else return compareNamesResult; - } else if (o1 instanceof IFeatureModel && o2 instanceof IFeatureModel) { - IFeatureModel ifm1 = (IFeatureModel) o1; + } else if (o1 instanceof IFeatureModel ifm1 && o2 instanceof IFeatureModel) { IFeatureModel ifm2 = (IFeatureModel) o2; return compareFeatures(ifm1, ifm2); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dialogs/PluginArtifactSearchHandler.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dialogs/PluginArtifactSearchHandler.java index 62987bd93c..5e81ee9f28 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dialogs/PluginArtifactSearchHandler.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/search/dialogs/PluginArtifactSearchHandler.java @@ -48,8 +48,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException { FeatureEditor.openFeatureEditor((IFeatureModel) object); } else { IEditorPart editorPart = ManifestEditor.open(object, true); - if (editorPart != null && editorPart instanceof ManifestEditor) { - ManifestEditor editor = (ManifestEditor) editorPart; + if (editorPart != null && editorPart instanceof ManifestEditor editor) { InputContext context = getInputContext(object, editor); IDocument document = context.getDocumentProvider().getDocument(context.getInput()); IRegion region = ManifestEditorOpener.getAttributeMatch(editor, object, document); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/BundleContainerFactory.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/BundleContainerFactory.java index f7f68b300a..6e4f7e6591 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/BundleContainerFactory.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/BundleContainerFactory.java @@ -31,8 +31,7 @@ public class BundleContainerFactory implements IAdapterFactory, ITargetLocationH @Override public T getAdapter(Object adaptableObject, Class adapterType) { - if (adaptableObject instanceof AbstractBundleContainer) { - AbstractBundleContainer bundleContainer = (AbstractBundleContainer) adaptableObject; + if (adaptableObject instanceof AbstractBundleContainer bundleContainer) { if (isValidTargetLocation(bundleContainer)) { if (adapterType == ITargetLocationHandler.class) { return adapterType.cast(this); @@ -50,8 +49,7 @@ public Class[] getAdapterList() { @Override public boolean canEdit(ITargetDefinition target, TreePath path) { Object root = path.getLastSegment(); - if (root instanceof ITargetLocation) { - ITargetLocation location = (ITargetLocation) root; + if (root instanceof ITargetLocation location) { return isValidTargetLocation(location); } return false; @@ -60,8 +58,7 @@ public boolean canEdit(ITargetDefinition target, TreePath path) { @Override public IWizard getEditWizard(ITargetDefinition target, TreePath path) { Object root = path.getFirstSegment(); - if (root instanceof ITargetLocation) { - ITargetLocation location = (ITargetLocation) root; + if (root instanceof ITargetLocation location) { if (isValidTargetLocation(location)) { return new EditBundleContainerWizard(target, location); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/EditTargetContainerPage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/EditTargetContainerPage.java index ecbc2d6ffc..326b269b7c 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/EditTargetContainerPage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/EditTargetContainerPage.java @@ -212,8 +212,7 @@ private String[] getLocationComboItems() { } } ITargetHandle handle = targetDefinition.getHandle(); - if (handle instanceof WorkspaceFileTargetHandle) { - WorkspaceFileTargetHandle wsHandle = (WorkspaceFileTargetHandle) handle; + if (handle instanceof WorkspaceFileTargetHandle wsHandle) { String name = wsHandle.getTargetFile().getProject().getName(); previousLocations.add(String.format("file:${project_loc:/%s}/", name)); //$NON-NLS-1$ diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/IUFactory.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/IUFactory.java index f63b27915f..8069bb1e0b 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/IUFactory.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/IUFactory.java @@ -103,8 +103,7 @@ public IStatus update(ITargetDefinition target, TreePath[] treePaths, IProgressM Object lastSegment = path.getLastSegment(); if (lastSegment instanceof IUBundleContainer) { containers.add((IUBundleContainer) lastSegment); - } else if (lastSegment instanceof IUWrapper) { - IUWrapper wrapper = (IUWrapper) lastSegment; + } else if (lastSegment instanceof IUWrapper wrapper) { wrappersMap.computeIfAbsent(wrapper.getParent(), k -> new HashSet<>()).add(wrapper.getIU().getId()); } } @@ -155,10 +154,9 @@ public IStatus remove(ITargetDefinition target, TreePath[] treePaths) { if (segment instanceof IUBundleContainer) { // nothing to do but force reload the target forceReload = true; - } else if (segment instanceof IUWrapper) { + } else if (segment instanceof IUWrapper wrapper) { // TODO check if we need to force-reload here (at least in // planner mode!) - IUWrapper wrapper = (IUWrapper) segment; wrapper.getParent().removeInstallableUnit(wrapper.getIU()); } } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/LegacyAdapterFactory.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/LegacyAdapterFactory.java index d5cfbcd6f7..08a104c553 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/LegacyAdapterFactory.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/LegacyAdapterFactory.java @@ -31,8 +31,7 @@ public class LegacyAdapterFactory implements IAdapterFactory { @Override public T getAdapter(Object adaptableObject, Class adapterType) { - if (adaptableObject instanceof ITargetLocation) { - ITargetLocation location = (ITargetLocation) adaptableObject; + if (adaptableObject instanceof ITargetLocation location) { if (adapterType == ITargetLocationHandler.class) { LegacyProxy proxy = new LegacyProxy(location); if (proxy.editor != null || proxy.updater != null) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/StyledBundleLabelProvider.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/StyledBundleLabelProvider.java index 7dc44352ce..2eed00b2ef 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/StyledBundleLabelProvider.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/StyledBundleLabelProvider.java @@ -100,9 +100,8 @@ protected StyledString getStyledString(Object element) { .ofNullable(Adapters.adapt(element, DelegatingStyledCellLabelProvider.IStyledLabelProvider.class)) .map(styleProvider -> styleProvider.getStyledText(element)).or(() -> { return Optional.ofNullable(Adapters.adapt(element, ILabelProvider.class)).map(provider -> { - if (provider instanceof StyledBundleLabelProvider) { + if (provider instanceof StyledBundleLabelProvider bundleLabelProvider) { // just in case someone return this class itself... - StyledBundleLabelProvider bundleLabelProvider = (StyledBundleLabelProvider) provider; return bundleLabelProvider.getInternalStyledString(element); } String text = provider.getText(element); @@ -132,8 +131,7 @@ private StyledString getInternalStyledString(Object element) { } else if (element instanceof NameVersionDescriptor) { appendBundleInfo(styledString, new BundleInfo(((NameVersionDescriptor) element).getId(), ((NameVersionDescriptor) element).getVersion(), null, BundleInfo.NO_LEVEL, false)); - } else if (element instanceof TargetBundle) { - TargetBundle bundle = ((TargetBundle) element); + } else if (element instanceof TargetBundle bundle) { if (bundle.getStatus().isOK()) { appendBundleInfo(styledString, bundle.getBundleInfo()); } else { @@ -148,8 +146,7 @@ private StyledString getInternalStyledString(Object element) { // Use a bundle info to reuse existing code appendBundleInfo(styledString, new BundleInfo(((TargetFeature) element).getId(), ((TargetFeature) element).getVersion(), null, BundleInfo.NO_LEVEL, false)); - } else if (element instanceof FeatureBundleContainer) { - FeatureBundleContainer container = (FeatureBundleContainer) element; + } else if (element instanceof FeatureBundleContainer container) { styledString.append(container.getFeatureId()); String version = container.getFeatureVersion(); if (version != null) { @@ -163,8 +160,7 @@ private StyledString getInternalStyledString(Object element) { } appendLocation(styledString, container, false); appendBundleCount(styledString, container); - } else if (element instanceof DirectoryBundleContainer) { - DirectoryBundleContainer container = (DirectoryBundleContainer) element; + } else if (element instanceof DirectoryBundleContainer container) { try { styledString.append(container.getLocation(false)); } catch (CoreException e) { @@ -174,8 +170,7 @@ private StyledString getInternalStyledString(Object element) { appendLocation(styledString, container, true); } appendBundleCount(styledString, container); - } else if (element instanceof ProfileBundleContainer) { - ProfileBundleContainer container = (ProfileBundleContainer) element; + } else if (element instanceof ProfileBundleContainer container) { try { styledString.append(container.getLocation(false)); } catch (CoreException e) { @@ -185,8 +180,7 @@ private StyledString getInternalStyledString(Object element) { appendLocation(styledString, container, true); } appendBundleCount(styledString, container); - } else if (element instanceof IUBundleContainer) { - IUBundleContainer container = (IUBundleContainer) element; + } else if (element instanceof IUBundleContainer container) { URI[] repos = container.getRepositories(); if (repos == null || repos.length == 0) { styledString.append(Messages.BundleContainerTable_8); @@ -196,8 +190,7 @@ private StyledString getInternalStyledString(Object element) { appendBundleCount(styledString, container); } else if (element instanceof IUWrapper) { styledString = getStyledString(((IUWrapper) element).getIU()); - } else if (element instanceof IInstallableUnit) { - IInstallableUnit iu = (IInstallableUnit) element; + } else if (element instanceof IInstallableUnit iu) { String name = fTranslations.getIUProperty(iu, IInstallableUnit.PROP_NAME); if (name == null) { name = iu.getId(); @@ -297,9 +290,8 @@ public Image getImage(Object element) { .map(styleProvider -> styleProvider.getImage(element)).or(() -> { return Optional.ofNullable(Adapters.adapt(element, ILabelProvider.class)).map(provider -> { - if (provider instanceof StyledBundleLabelProvider) { + if (provider instanceof StyledBundleLabelProvider styleLabelProvider) { // just in case someone return this class itself... - StyledBundleLabelProvider styleLabelProvider = (StyledBundleLabelProvider) provider; return styleLabelProvider.getInternalImage(element); } Image image = provider.getImage(element); @@ -319,8 +311,7 @@ public Image getImage(Object element) { * @return an image for some PDE specific objects */ private Image getInternalImage(Object element) { - if (element instanceof TargetBundle) { - TargetBundle bundle = (TargetBundle) element; + if (element instanceof TargetBundle bundle) { int flag = 0; if (bundle.getStatus().getSeverity() == IStatus.WARNING || bundle.getStatus().getSeverity() == IStatus.INFO) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/TargetContentsGroup.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/TargetContentsGroup.java index acbd5bcb09..024afb8e86 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/TargetContentsGroup.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/TargetContentsGroup.java @@ -1016,8 +1016,7 @@ private Object[] getBundleChildren(Object parent) { result = fAllBundles.toArray(); } else if (fFeaureModeButton.getSelection() && parent == OTHER_CATEGORY) { result = fTargetDefinition.getOtherBundles(); - } else if (fGrouping == GROUP_BY_CONTAINER && parent instanceof ITargetLocation) { - ITargetLocation container = (ITargetLocation) parent; + } else if (fGrouping == GROUP_BY_CONTAINER && parent instanceof ITargetLocation container) { result = container.getBundles(); } else if (fGrouping == GROUP_BY_FILE_LOC && parent instanceof IPath) { List bundles = getFileBundleMapping().get(parent); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/TargetLocationContentProvider.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/TargetLocationContentProvider.java index e1517750a9..39c506d64a 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/TargetLocationContentProvider.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/TargetLocationContentProvider.java @@ -41,8 +41,7 @@ public Object[] getChildren(Object parentElement) { if (parentElement instanceof ITargetDefinition) { ITargetLocation[] containers = ((ITargetDefinition) parentElement).getTargetLocations(); return containers != null ? containers : new Object[0]; - } else if (parentElement instanceof ITargetLocation) { - ITargetLocation location = (ITargetLocation) parentElement; + } else if (parentElement instanceof ITargetLocation location) { if (location.isResolved()) { IStatus status = location.getStatus(); if (!status.isOK() && !status.isMultiStatus()) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/TargetReferenceBundleContainerAdapterFactory.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/TargetReferenceBundleContainerAdapterFactory.java index 418f159f20..603d9bc945 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/TargetReferenceBundleContainerAdapterFactory.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/shared/target/TargetReferenceBundleContainerAdapterFactory.java @@ -48,8 +48,7 @@ public class TargetReferenceBundleContainerAdapterFactory implements IAdapterFac @Override public String getText(Object element) { - if (element instanceof TargetReferenceBundleContainer) { - TargetReferenceBundleContainer container = (TargetReferenceBundleContainer) element; + if (element instanceof TargetReferenceBundleContainer container) { String name = container.targetDefinition().map(ITargetDefinition::getName).orElse(null); if (name != null && !name.isBlank()) { return name; @@ -90,8 +89,7 @@ public void dispose() { @Override public IStatus reload(ITargetDefinition target, ITargetLocation[] targetLocations, IProgressMonitor monitor) { for (ITargetLocation location : targetLocations) { - if (location instanceof TargetReferenceBundleContainer) { - TargetReferenceBundleContainer targetRefrenceBundleContainer = (TargetReferenceBundleContainer) location; + if (location instanceof TargetReferenceBundleContainer targetRefrenceBundleContainer) { targetRefrenceBundleContainer.reload(); } } @@ -123,8 +121,7 @@ public boolean hasChildren(Object element) { if (element instanceof TargetReferenceBundleContainer) { return true; } - if (element instanceof TargetLocationWrapper) { - TargetLocationWrapper wrapper = (TargetLocationWrapper) element; + if (element instanceof TargetLocationWrapper wrapper) { return wrapper.as(ITreeContentProvider.class).map(provider -> provider.hasChildren(wrapper.wrappedItem)) .orElse(Boolean.FALSE); } @@ -143,16 +140,14 @@ public Object[] getElements(Object inputElement) { @Override public Object[] getChildren(Object parentElement) { - if (parentElement instanceof TargetReferenceBundleContainer) { - TargetReferenceBundleContainer container = (TargetReferenceBundleContainer) parentElement; + if (parentElement instanceof TargetReferenceBundleContainer container) { ITargetLocation[] targetLocations = container.targetDefinition() .map(ITargetDefinition::getTargetLocations).orElse(null); if (targetLocations != null && targetLocations.length > 0) { return Arrays.stream(targetLocations).map(TargetLocationWrapper::new).toArray(); } } - if (parentElement instanceof TargetLocationWrapper) { - TargetLocationWrapper wrapper = (TargetLocationWrapper) parentElement; + if (parentElement instanceof TargetLocationWrapper wrapper) { return wrapper.as(ITreeContentProvider.class).map(provider -> provider.getChildren(wrapper.wrappedItem)) .stream().flatMap(Arrays::stream).map(TargetLocationWrapper::new).toArray(); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/util/ExtensionsFilterUtil.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/util/ExtensionsFilterUtil.java index d546f1906e..b74fc81ad3 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/util/ExtensionsFilterUtil.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/util/ExtensionsFilterUtil.java @@ -138,8 +138,7 @@ public static String getElementPath(IPluginElement pluginElement) { while (element.getParent() != null && !(element.getParent() instanceof PluginNode)) { element = element.getParent(); } - if (element instanceof IPluginExtension) { - IPluginExtension extension = (IPluginExtension) element; + if (element instanceof IPluginExtension extension) { return extension.getPoint() + '.' + pluginElement.getName(); } return null; @@ -156,8 +155,7 @@ public static String getFilterRelatedPattern(IStructuredSelection selection) { Set filterPatterns = new HashSet<>(); while (it.hasNext()) { Object treeElement = it.next(); - if (treeElement instanceof IPluginElement) { - IPluginElement pluginElement = (IPluginElement) treeElement; + if (treeElement instanceof IPluginElement pluginElement) { Set customAttributes = getCustomRelations(pluginElement); if (customAttributes.isEmpty()) { for (String property : RELATED_ATTRIBUTES) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/util/PDEModelUtility.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/util/PDEModelUtility.java index 89c88242cd..f8053f3ead 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/util/PDEModelUtility.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/util/PDEModelUtility.java @@ -117,8 +117,7 @@ public static void disconnect(PDEFormEditor editor) { // getCommonProject will return null when project is deleted with editor open - bug 226788 // Solution is to use editor input if it is a FileEditorInput. IEditorInput input = editor.getEditorInput(); - if (input != null && input instanceof FileEditorInput) { - FileEditorInput fei = (FileEditorInput) input; + if (input != null && input instanceof FileEditorInput fei) { IFile file = fei.getFile(); project = file.getProject(); } @@ -538,8 +537,7 @@ private static IModelTextChangeListener[] gatherListeners(IBaseModel editModel) IModelTextChangeListener[] listeners = new IModelTextChangeListener[0]; if (editModel instanceof AbstractEditingModel) listeners = new IModelTextChangeListener[] {((AbstractEditingModel) editModel).getLastTextChangeListener()}; - if (editModel instanceof IBundlePluginModelBase) { - IBundlePluginModelBase modelBase = (IBundlePluginModelBase) editModel; + if (editModel instanceof IBundlePluginModelBase modelBase) { listeners = new IModelTextChangeListener[2]; listeners[F_Bi] = gatherListener(modelBase.getBundleModel()); listeners[F_Xi] = gatherListener(modelBase.getExtensionsModel()); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/util/PersistablePluginObject.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/util/PersistablePluginObject.java index 1c9c38ec28..784352eccb 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/util/PersistablePluginObject.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/util/PersistablePluginObject.java @@ -68,8 +68,7 @@ public T getAdapter(Class adapter) { return (T) getPluginContainmentAdapter(); if (adapter.equals(IJavaElement.class)) { IResource res = getResource(); - if (res instanceof IProject) { - IProject project = (IProject) res; + if (res instanceof IProject project) { try { if (project.hasNature(JavaCore.NATURE_ID)) return (T) JavaCore.create(project); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/dependencies/CalleesContentProvider.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/dependencies/CalleesContentProvider.java index 27df867bd5..4b80f86761 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/dependencies/CalleesContentProvider.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/dependencies/CalleesContentProvider.java @@ -42,8 +42,7 @@ protected Object[] findCallees(IPluginModelBase model) { fFragmentDescription = desc; Object[] fragmentDependencies = getDependencies(desc); BaseDescription host = spec.getSupplier(); - if (host instanceof BundleDescription) { - BundleDescription hostDesc = (BundleDescription) host; + if (host instanceof BundleDescription hostDesc) { // check to see if the host is already included as a dependency. If so, we don't need to include the host manually. for (Object fragmentDependency : fragmentDependencies) { BundleDescription dependency = null; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/dependencies/DependenciesLabelProvider.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/dependencies/DependenciesLabelProvider.java index db1246fcdc..2bb1b4b29a 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/dependencies/DependenciesLabelProvider.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/dependencies/DependenciesLabelProvider.java @@ -92,8 +92,7 @@ public String getObjectText(BundleDescription obj) { public Image getImage(Object obj) { int flags = 0; String id = null; - if (obj instanceof IPluginImport) { - IPluginImport iobj = (IPluginImport) obj; + if (obj instanceof IPluginImport iobj) { id = iobj.getId(); if (fShowReexport && iobj.isReexported()) flags = SharedLabelProvider.F_EXPORT; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/dependencies/DependenciesViewPage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/dependencies/DependenciesViewPage.java index 626b44d4a9..0a2bf60af6 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/dependencies/DependenciesViewPage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/dependencies/DependenciesViewPage.java @@ -189,8 +189,7 @@ private void fillContextMenu(IMenuManager manager) { Object input = fViewer.getInput(); if (input instanceof IPluginBase) input = ((IPluginBase) input).getModel(); - if (input instanceof IPluginModelBase) { - IPluginModelBase base = (IPluginModelBase) input; + if (input instanceof IPluginModelBase base) { IResource res = base.getUnderlyingResource(); if (res != null) manager.add(new DependencyExtentAction(res.getProject(), id)); @@ -281,8 +280,7 @@ private void handleFocusOn(Object newFocus) { if (newFocus instanceof IPluginBase) { fView.openTo(((IPluginBase) newFocus).getModel()); } - if (newFocus instanceof IPluginImport) { - IPluginImport pluginImport = ((IPluginImport) newFocus); + if (newFocus instanceof IPluginImport pluginImport) { String id = pluginImport.getId(); IPluginModelBase model = PluginRegistry.findModel(id); if (model != null) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/dependencies/OpenDependenciesAction.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/dependencies/OpenDependenciesAction.java index 6b6bba6ba6..b65a2cfe5f 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/dependencies/OpenDependenciesAction.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/dependencies/OpenDependenciesAction.java @@ -31,8 +31,7 @@ public class OpenDependenciesAction extends AbstractHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { ISelection selection = HandlerUtil.getCurrentSelection(event); - if (selection instanceof IStructuredSelection) { - IStructuredSelection ssel = (IStructuredSelection) selection; + if (selection instanceof IStructuredSelection ssel) { openDependencies(ssel.getFirstElement()); } return null; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/support/FeatureSupport.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/support/FeatureSupport.java index e96cd8d4f1..fd2354031c 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/support/FeatureSupport.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/support/FeatureSupport.java @@ -25,13 +25,11 @@ public class FeatureSupport { public IFeatureModel toFeatureModel(Object obj) { if (obj instanceof IFeatureModel) { return (IFeatureModel) obj; - } else if (obj instanceof IIdentifiable) { - IIdentifiable featureOrChild = (IIdentifiable) obj; + } else if (obj instanceof IIdentifiable featureOrChild) { return getManager().findFeatureModel(featureOrChild.getId()); } else if (obj instanceof IProject) { return getManager().getFeatureModel((IProject) obj); - } else if (obj instanceof IProductFeature) { - IProductFeature productFeature = (IProductFeature) obj; + } else if (obj instanceof IProductFeature productFeature) { return getManager().findFeatureModel(productFeature.getId()); } else { return null; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/support/PluginSupport.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/support/PluginSupport.java index 77dbad99e5..667cc99836 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/support/PluginSupport.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/support/PluginSupport.java @@ -36,11 +36,9 @@ public IPluginModelBase toSinglePluginModel(IStructuredSelection selection) { public IPluginModelBase toPluginModel(Object obj) { if (obj instanceof IPluginModelBase) { return (IPluginModelBase) obj; - } else if (obj instanceof IFeaturePlugin) { - IFeaturePlugin featurePlugin = (IFeaturePlugin) obj; + } else if (obj instanceof IFeaturePlugin featurePlugin) { return getManager().findModel(featurePlugin.getId()); - } else if (obj instanceof IProductPlugin) { - IProductPlugin productPlugin = (IProductPlugin) obj; + } else if (obj instanceof IProductPlugin productPlugin) { return getManager().findModel(productPlugin.getId()); } else if (obj instanceof IProject) { return getManager().findModel((IProject) obj); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/support/ProductSupport.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/support/ProductSupport.java index 0c636bfc84..938daf4b70 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/support/ProductSupport.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/support/ProductSupport.java @@ -47,8 +47,7 @@ public void openProductEditor(IProductModel productModel) { } public IProductModel toProductModel(Object obj) { - if (obj instanceof IProduct) { - IProduct product = (IProduct) obj; + if (obj instanceof IProduct product) { return getManager().findProductModel(product.getId()); } else if (obj instanceof IProductModel) { return (IProductModel) obj; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/viewer/AbstractFeatureTreeContentProvider.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/viewer/AbstractFeatureTreeContentProvider.java index 3a139e2275..5f90538135 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/viewer/AbstractFeatureTreeContentProvider.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/viewer/AbstractFeatureTreeContentProvider.java @@ -76,8 +76,7 @@ public boolean hasChildren(Object element) { @Override public Object[] getElements(Object inputElement) { - if (inputElement instanceof DeferredFeaturesViewInput) { - DeferredFeaturesViewInput deferredFeaturesViewInput = (DeferredFeaturesViewInput) inputElement; + if (inputElement instanceof DeferredFeaturesViewInput deferredFeaturesViewInput) { return deferredFeaturesViewInput.isInitialized() ? deferredFeaturesViewInput.getChildren(inputElement) : fDeferredTreeContentManager.getChildren(inputElement); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/viewer/FeatureChildViewerFilter.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/viewer/FeatureChildViewerFilter.java index 395bfe6f82..6f959546a2 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/viewer/FeatureChildViewerFilter.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/viewer/FeatureChildViewerFilter.java @@ -21,8 +21,7 @@ public class FeatureChildViewerFilter extends ViewerFilter { @Override public boolean select(Viewer viewer, Object parentElement, Object element) { - if (parentElement instanceof DeferredFeaturesViewInput && element instanceof IFeatureModel) { - DeferredFeaturesViewInput input = (DeferredFeaturesViewInput) parentElement; + if (parentElement instanceof DeferredFeaturesViewInput input && element instanceof IFeatureModel) { IFeatureModel featureModel = (IFeatureModel) element; boolean showProducts = input.getFeaturesViewInput().isIncludeProducts(); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/viewer/FeatureTreeCalleesContentProvider.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/viewer/FeatureTreeCalleesContentProvider.java index 7e7faecfa0..61e61e566c 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/viewer/FeatureTreeCalleesContentProvider.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/viewer/FeatureTreeCalleesContentProvider.java @@ -31,9 +31,7 @@ public FeatureTreeCalleesContentProvider(FeaturesViewInput featuresViewInput) { @Override public Object[] getChildren(Object parentElement) { - if (parentElement instanceof IProductModel) { - IProductModel productModel = (IProductModel) parentElement; - + if (parentElement instanceof IProductModel productModel) { Object[] features = productModel.getProduct().getFeatures(); Object[] plugins = productModel.getProduct().getPlugins(); @@ -42,9 +40,7 @@ public Object[] getChildren(Object parentElement) { all.addAll(Arrays.asList(plugins)); return all.toArray(); - } else if (parentElement instanceof IFeatureModel) { - IFeatureModel featureModel = (IFeatureModel) parentElement; - + } else if (parentElement instanceof IFeatureModel featureModel) { Object[] features = featureModel.getFeature().getIncludedFeatures(); Object[] plugins = featureModel.getFeature().getPlugins(); @@ -53,12 +49,10 @@ public Object[] getChildren(Object parentElement) { all.addAll(Arrays.asList(plugins)); return all.toArray(); - } else if (parentElement instanceof IFeatureChild) { - IFeatureChild featureChild = (IFeatureChild) parentElement; + } else if (parentElement instanceof IFeatureChild featureChild) { IFeatureModel featureModel = fFeatureModelManager.findFeatureModel(featureChild.getId()); return getChildren(featureModel); - } else if (parentElement instanceof IProductFeature) { - IProductFeature productFeature = (IProductFeature) parentElement; + } else if (parentElement instanceof IProductFeature productFeature) { IFeatureModel featureModel = fFeatureModelManager.findFeatureModel(productFeature.getId()); return getChildren(featureModel); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/viewer/FeatureTreeCallersContentProvider.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/viewer/FeatureTreeCallersContentProvider.java index f151a887ca..3d2cd155bf 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/viewer/FeatureTreeCallersContentProvider.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/viewer/FeatureTreeCallersContentProvider.java @@ -29,8 +29,7 @@ public FeatureTreeCallersContentProvider(FeaturesViewInput featuresViewInput) { @Override public Object[] getChildren(Object parentElement) { - if (parentElement instanceof IFeatureModel) { - IFeatureModel featureModel = (IFeatureModel) parentElement; + if (parentElement instanceof IFeatureModel featureModel) { String featureId = featureModel.getFeature().getId(); Collection features = fInput.getFeaturesViewInput().getIncludingFeatures(featureId); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/viewer/FeatureViewerComparator.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/viewer/FeatureViewerComparator.java index eef44dae89..e97a481e4b 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/viewer/FeatureViewerComparator.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/features/viewer/FeatureViewerComparator.java @@ -42,8 +42,7 @@ public int category(Object element) { if (element instanceof IProductModel) { return 0; - } else if (element instanceof IFeatureModel) { - IFeatureModel featureModel = (IFeatureModel) element; + } else if (element instanceof IFeatureModel featureModel) { return (featureModel.isEditable() ? 1 : 2); } else if (element instanceof IFeaturePlugin || element instanceof IProductPlugin) { return 4; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/plugins/ImportActionGroup.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/plugins/ImportActionGroup.java index 10ce293b6d..f947c04d62 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/plugins/ImportActionGroup.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/plugins/ImportActionGroup.java @@ -74,8 +74,7 @@ public void run() { public void fillContextMenu(IMenuManager menu) { ActionContext context = getContext(); ISelection selection = context.getSelection(); - if (!selection.isEmpty() && selection instanceof IStructuredSelection) { - IStructuredSelection sSelection = (IStructuredSelection) selection; + if (!selection.isEmpty() && selection instanceof IStructuredSelection sSelection) { String menuName = null; if (sSelection.getFirstElement() instanceof IPluginExtension || sSelection.getFirstElement() instanceof IPluginExtensionPoint) menuName = PDEUIMessages.ImportActionGroup_importContributingPlugin; @@ -163,9 +162,8 @@ private static IPluginModelBase getModel(Object next) { if (desc != null) { model = PDECore.getDefault().getModelManager().findModel(desc); } - } else if (next instanceof IPackageFragmentRoot) { + } else if (next instanceof IPackageFragmentRoot root) { // Required for context menu on PDE classpath container entries - IPackageFragmentRoot root = (IPackageFragmentRoot) next; if (root.isExternal()) { String path = root.getPath().toOSString(); IPluginModelBase[] externalModels = PDECore.getDefault().getModelManager().getExternalModels(); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/plugins/JavaSearchActionGroup.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/plugins/JavaSearchActionGroup.java index 358543fad6..8dd4573bf7 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/plugins/JavaSearchActionGroup.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/plugins/JavaSearchActionGroup.java @@ -70,9 +70,7 @@ public void run() { public void fillContextMenu(IMenuManager menu) { ActionContext context = getContext(); ISelection selection = context.getSelection(); - if (!selection.isEmpty() && selection instanceof IStructuredSelection) { - IStructuredSelection sSelection = (IStructuredSelection) selection; - + if (!selection.isEmpty() && selection instanceof IStructuredSelection sSelection) { boolean addSeparator = false; if (canDoJavaSearchOperation(sSelection, true)) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/plugins/PluginsContentProvider.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/plugins/PluginsContentProvider.java index ae03313649..1343314766 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/plugins/PluginsContentProvider.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/plugins/PluginsContentProvider.java @@ -72,8 +72,7 @@ public Object[] getChildren(Object parentElement) { Object[] children = fManager.getChildren(parentElement); return children; } - if (parentElement instanceof IPluginModelBase) { - IPluginModelBase model = (IPluginModelBase) parentElement; + if (parentElement instanceof IPluginModelBase model) { File file = new File(model.getInstallLocation()); if (!file.isFile()) { FileAdapter adapter = new ModelFileAdapter(model, file, PDECore.getDefault().getSearchablePluginsManager()); @@ -115,12 +114,10 @@ public Object getParent(Object element) { public boolean hasChildren(Object element) { if (element instanceof IDeferredWorkbenchAdapter) return fManager.mayHaveChildren(element); - if (element instanceof IPluginModelBase) { - IPluginModelBase model = (IPluginModelBase) element; + if (element instanceof IPluginModelBase model) { return model.getUnderlyingResource() == null && !new File(model.getInstallLocation()).isFile(); } - if (element instanceof FileAdapter) { - FileAdapter fileAdapter = (FileAdapter) element; + if (element instanceof FileAdapter fileAdapter) { return fileAdapter.hasChildren(); } if (element instanceof IPackageFragmentRoot || element instanceof IPackageFragment || element instanceof ICompilationUnit || element instanceof IStorage) diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/plugins/PluginsLabelProvider.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/plugins/PluginsLabelProvider.java index 83fb616fd0..c24d0e62f2 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/plugins/PluginsLabelProvider.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/plugins/PluginsLabelProvider.java @@ -105,8 +105,7 @@ public Image getImage(Object obj) { return getImage((FileAdapter) obj); } - if (obj instanceof IPackageFragmentRoot) { - IPackageFragmentRoot root = (IPackageFragmentRoot) obj; + if (obj instanceof IPackageFragmentRoot root) { boolean hasSource = false; try { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/target/StateViewPage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/target/StateViewPage.java index c20c87afff..560dce0d8d 100755 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/target/StateViewPage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/views/target/StateViewPage.java @@ -134,8 +134,7 @@ static class StateContentProvider implements ITreeContentProvider { @Override public Object[] getChildren(Object parentElement) { - if (parentElement instanceof BundleDescription) { - BundleDescription desc = (BundleDescription) parentElement; + if (parentElement instanceof BundleDescription desc) { if (desc.isResolved()) { Object[] required = getResolvedDependencies(desc.getRequiredBundles()); Object[] imported = getResolvedDependencies(desc.getImportPackages()); @@ -198,8 +197,7 @@ public void dispose() { public void update(ViewerCell cell) { Object element = cell.getElement(); StyledString styledString = new StyledString(); - if (element instanceof ImportPackageSpecification) { - ImportPackageSpecification spec = (ImportPackageSpecification) element; + if (element instanceof ImportPackageSpecification spec) { styledString.append(spec.getName()); ExportPackageDescription supplier = (ExportPackageDescription) spec.getSupplier(); if (isJREPackage(supplier)) { @@ -221,8 +219,7 @@ public void update(ViewerCell cell) { private void getElementString(Object element, StyledString styledString, boolean showLocation) { if (element instanceof BundleSpecification) { styledString.append(((BundleSpecification) element).getSupplier().toString()); - } else if (element instanceof BundleDescription) { - BundleDescription description = (BundleDescription) element; + } else if (element instanceof BundleDescription description) { styledString.append(fSharedProvider.getObjectText(description)); Version version = description.getVersion(); // Bug 183417 - Bidi3.3: Elements' labels in the extensions page in the fragment manifest characters order is incorrect @@ -259,13 +256,11 @@ public Image getImage(Object element) { @Override public String getText(Object element) { String result = element.toString(); - if (element instanceof ImportPackageSpecification) { - ImportPackageSpecification spec = (ImportPackageSpecification) element; + if (element instanceof ImportPackageSpecification spec) { result = spec.getName(); } else if (element instanceof BundleSpecification) { result = ((BundleSpecification) element).getSupplier().toString(); - } else if (element instanceof BundleDescription) { - BundleDescription description = (BundleDescription) element; + } else if (element instanceof BundleDescription description) { result = fSharedProvider.getObjectText(description); } return result; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/BaseExportWizardPage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/BaseExportWizardPage.java index 34a72801d8..81783e96da 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/BaseExportWizardPage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/BaseExportWizardPage.java @@ -193,8 +193,7 @@ protected void createViewer(Composite parent) { fExportPart.updateCounterLabel(); }); Object input = getInput(); - if (input instanceof FeatureModelManager) { - FeatureModelManager fmm = (FeatureModelManager) input; + if (input instanceof FeatureModelManager fmm) { IFeatureModel[] models = fmm.getWorkspaceModels(); for (IFeatureModel iFeatureModel : models) { if (iFeatureModel.getFeature().getId() == null) { @@ -214,8 +213,7 @@ protected void initializeViewer() { for (Object elem : fSelection.toArray()) { IProject project = null; - if (elem instanceof IFile) { - IFile file = (IFile) elem; + if (elem instanceof IFile file) { project = file.getProject(); } else if (elem instanceof IProject) { project = (IProject) elem; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/CrossPlatformExportPage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/CrossPlatformExportPage.java index 86768ceffb..1c0d5b74a4 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/CrossPlatformExportPage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/CrossPlatformExportPage.java @@ -52,8 +52,7 @@ public String toString() { @Override public boolean equals(Object obj) { - if (obj instanceof Configuration) { - Configuration config = (Configuration) obj; + if (obj instanceof Configuration config) { return os.equals(config.os) && ws.equals(config.ws) && arch.equals(config.arch); } return super.equals(obj); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/FeatureOptionsTab.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/FeatureOptionsTab.java index 90e41c4ae0..e1b33aeb4c 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/FeatureOptionsTab.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/FeatureOptionsTab.java @@ -71,8 +71,7 @@ public CategoryResourceListSelectionDialog(Shell shell, boolean multi, IContaine @Override public boolean select(Viewer viewer, Object parentElement, Object element) { IResource resource = (IResource) element; - if (resource != null && resource instanceof IFile) { - IFile file = (IFile) resource; + if (resource != null && resource instanceof IFile file) { String extension = file.getFileExtension(); return extension != null && extension.equalsIgnoreCase("xml"); //$NON-NLS-1$ } @@ -83,8 +82,7 @@ public boolean select(Viewer viewer, Object parentElement, Object element) { @Override protected IStatus validateItem(Object item) { - if (item instanceof IResource) { - IResource resource = (IResource) item; + if (item instanceof IResource resource) { if (resource instanceof IFile) { try { IFile file = (IFile) resource; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/ProductConfigurationSection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/ProductConfigurationSection.java index cad2d49f22..30adde33a4 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/ProductConfigurationSection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/exports/ProductConfigurationSection.java @@ -129,16 +129,14 @@ protected void initialize(IStructuredSelection selection, IDialogSettings settin if (!selection.isEmpty()) { Object object = selection.getFirstElement(); - if (object instanceof IFile) { - IFile file = (IFile) object; + if (object instanceof IFile file) { if ("product".equals(file.getFileExtension())) { //$NON-NLS-1$ String entry = file.getFullPath().toString(); if (fProductCombo.indexOf(entry) == -1) fProductCombo.add(entry, 0); fProductCombo.setText(entry); } - } else if (object instanceof IContainer) { - IContainer container = (IContainer) object; + } else if (object instanceof IContainer container) { try { if (container.isAccessible()) { IResource[] resources = container.members(); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/extension/NewExtensionWizard.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/extension/NewExtensionWizard.java index 0831a79b0e..39645543ba 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/extension/NewExtensionWizard.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/extension/NewExtensionWizard.java @@ -61,12 +61,10 @@ public WizardCollectionElement getTemplates() { private void collectTemplates(Object[] children, WizardCollectionElement list) { for (Object child : children) { - if (child instanceof WizardCollectionElement) { - WizardCollectionElement element = (WizardCollectionElement) child; + if (child instanceof WizardCollectionElement element) { collectTemplates(element.getChildren(), list); collectTemplates(element.getWizards().getChildren(), list); - } else if (child instanceof WizardElement) { - WizardElement wizard = (WizardElement) child; + } else if (child instanceof WizardElement wizard) { if (wizard.isTemplate()) list.getWizards().add(wizard); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/extension/PointSelectionPage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/extension/PointSelectionPage.java index 9f954dd306..182a64d2ca 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/extension/PointSelectionPage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/extension/PointSelectionPage.java @@ -177,8 +177,7 @@ public boolean select(Viewer viewer, Object parentElement, Object element) { class TemplateContentProvider implements IStructuredContentProvider { @Override public Object[] getElements(Object inputElement) { - if (inputElement instanceof IPluginExtensionPoint) { - IPluginExtensionPoint point = (IPluginExtensionPoint) inputElement; + if (inputElement instanceof IPluginExtensionPoint point) { String pointID = IdUtil.getFullId(point, fModel); ArrayList result = new ArrayList<>(); if (fTemplateCollection.getWizards() != null) { @@ -498,8 +497,7 @@ public boolean finish() { ISchemaElement schemaElement = null; // Get the extension's schema Object object = extension.getSchema(); - if ((object != null) && (object instanceof Schema)) { - Schema schema = (Schema) object; + if ((object != null) && (object instanceof Schema schema)) { if (extension instanceof PluginExtensionNode) { // Get the extension's XML element name String elementName = ((PluginExtensionNode) extension).getXMLTagName(); @@ -539,8 +537,7 @@ protected void initialize() { @Override public void selectionChanged(SelectionChangedEvent event) { ISelection selection = event.getSelection(); - if (selection instanceof IStructuredSelection) { - IStructuredSelection ssel = (IStructuredSelection) selection; + if (selection instanceof IStructuredSelection ssel) { if (!ssel.isEmpty()) { Object element = ssel.getFirstElement(); if (element instanceof WizardElement) diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/imports/BaseImportWizardSecondPage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/imports/BaseImportWizardSecondPage.java index 88c42ef138..a6f3c67572 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/imports/BaseImportWizardSecondPage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/imports/BaseImportWizardSecondPage.java @@ -224,8 +224,7 @@ protected void addPluginAndDependencies(IPluginModelBase model, ArrayList result, boolean addFragments) { ISharedPluginModel sharedModel = model.getPluginBase().getModel(); - if (sharedModel instanceof BundlePluginModel) { - BundlePluginModel bundleModel = (BundlePluginModel) sharedModel; + if (sharedModel instanceof BundlePluginModel bundleModel) { ImportPackageSpecification[] importPackages = bundleModel.getBundleDescription().getImportPackages(); for (ImportPackageSpecification importPackageSpecification : importPackages) { IPluginModelBase found = findModel(importPackageSpecification.getName(), null); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportLabelProvider.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportLabelProvider.java index fbf3306799..b7b24c3722 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportLabelProvider.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportLabelProvider.java @@ -52,8 +52,7 @@ public void update(ViewerCell cell) { private StyledString getStyledText(Object element) { StyledString styledString = new StyledString(); - if (element instanceof IPluginModelBase) { - IPluginModelBase plugin = (IPluginModelBase) element; + if (element instanceof IPluginModelBase plugin) { String symbolicName = plugin.getBundleDescription().getSymbolicName(); Version version = plugin.getBundleDescription().getVersion(); styledString.append(symbolicName); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportWizard.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportWizard.java index 221fe4c949..9d33a555f5 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportWizard.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportWizard.java @@ -75,8 +75,7 @@ public void init(IWorkbench workbench, IStructuredSelection selection) { public void createPageControls(Composite pageContainer) { super.createPageControls(pageContainer); IWizardContainer container = getContainer(); - if (container instanceof WizardDialog) { - WizardDialog dialog = (WizardDialog) container; + if (container instanceof WizardDialog dialog) { dialog.addPageChangingListener(this); } } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportWizardExpressPage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportWizardExpressPage.java index 75f954a2dd..99c930dc5d 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportWizardExpressPage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/imports/PluginImportWizardExpressPage.java @@ -201,8 +201,7 @@ private void initialize() { if (item instanceof IJavaProject) { item = ((IJavaProject) item).getProject(); } - if (item instanceof IProject) { - IProject project = (IProject) item; + if (item instanceof IProject project) { if (WorkspaceModelManager.isPluginProject(project) && !WorkspaceModelManager.isBinaryProject(project)) { IPluginModelBase model = PluginRegistry.findModel(project); if (model != null) diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/plugin/LibraryPluginJarsPage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/plugin/LibraryPluginJarsPage.java index 23fa6d7107..4b3c0329a3 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/plugin/LibraryPluginJarsPage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/plugin/LibraryPluginJarsPage.java @@ -135,8 +135,7 @@ public void createControl(Composite parent) { public String getText(Object obj) { String name; String location; - if (obj instanceof IFile) { - IFile jarFile = (IFile) obj; + if (obj instanceof IFile jarFile) { name = jarFile.getName(); location = jarFile.getParent().getFullPath().toString().substring(1); } else { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/plugin/NewProjectCreationOperation.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/plugin/NewProjectCreationOperation.java index b4223ff50a..9751b00607 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/plugin/NewProjectCreationOperation.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/plugin/NewProjectCreationOperation.java @@ -222,13 +222,11 @@ private void createManifest(IProject project) throws CoreException { pluginBase.setVersion(fData.getVersion()); pluginBase.setName(fData.getName()); pluginBase.setProviderName(fData.getProvider()); - if (fModel instanceof IBundlePluginModelBase) { - IBundlePluginModelBase bmodel = ((IBundlePluginModelBase) fModel); + if (fModel instanceof IBundlePluginModelBase bmodel) { ((IBundlePluginBase) bmodel.getPluginBase()).setTargetVersion(targetVersion); bmodel.getBundleModel().getBundle().setHeader(Constants.BUNDLE_MANIFESTVERSION, "2"); //$NON-NLS-1$ } - if (pluginBase instanceof IFragment) { - IFragment fragment = (IFragment) pluginBase; + if (pluginBase instanceof IFragment fragment) { IFragmentFieldData data = (IFragmentFieldData) fData; fragment.setPluginId(data.getPluginId()); fragment.setPluginVersion(data.getPluginVersion()); @@ -398,9 +396,7 @@ protected void execute(IProgressMonitor monitor) throws CoreException, Invocatio setClasspath(project, fData); subMonitor.worked(1); } - if (fData instanceof PluginFieldData) { - PluginFieldData data = (PluginFieldData) fData; - + if (fData instanceof PluginFieldData data) { // generate top-level Java class if that option is selected if (data.doGenerateClass()) { generateTopLevelPluginClass(project, subMonitor.split(1)); @@ -581,8 +577,7 @@ protected int getNumberOfWorkUnits() { int numUnits = 4; if (fData.hasBundleStructure()) numUnits++; - if (fData instanceof IPluginFieldData) { - IPluginFieldData data = (IPluginFieldData) fData; + if (fData instanceof IPluginFieldData data) { if (data.doGenerateClass()) numUnits++; if (fContentWizard != null) diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/product/BaseManifestOperation.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/product/BaseManifestOperation.java index 938da2e770..a2d0e69210 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/product/BaseManifestOperation.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/product/BaseManifestOperation.java @@ -78,13 +78,11 @@ protected void updateSingleton(IProgressMonitor monitor) throws CoreException { ModelModification mod = new ModelModification(file) { @Override protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws CoreException { - if (!(model instanceof IBundlePluginModelBase)) + if (!(model instanceof IBundlePluginModelBase modelBase)) return; - IBundlePluginModelBase modelBase = (IBundlePluginModelBase) model; IBundle bundle = modelBase.getBundleModel().getBundle(); IManifestHeader header = bundle.getManifestHeader(Constants.BUNDLE_SYMBOLICNAME); - if (header instanceof BundleSymbolicNameHeader) { - BundleSymbolicNameHeader symbolic = (BundleSymbolicNameHeader) header; + if (header instanceof BundleSymbolicNameHeader symbolic) { if (!symbolic.isSingleton()) symbolic.setSingleton(true); } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/product/ProductIntroOperation.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/product/ProductIntroOperation.java index 4086b00af7..3a987a7e49 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/product/ProductIntroOperation.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/product/ProductIntroOperation.java @@ -164,9 +164,8 @@ private void modifyExistingFile(IFile file, IProgressMonitor monitor) throws Cor ModelModification mod = new ModelModification(file) { @Override protected void modifyModel(IBaseModel model, IProgressMonitor monitor) throws CoreException { - if (!(model instanceof IPluginModelBase)) + if (!(model instanceof IPluginModelBase pluginModel)) return; - IPluginModelBase pluginModel = (IPluginModelBase) model; IPluginExtension extension = getExtension(pluginModel, INTRO_POINT); if (extension == null) { extension = createIntroExtension(pluginModel); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/product/RemoveSplashHandlerBindingAction.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/product/RemoveSplashHandlerBindingAction.java index 2f07f99195..ca3988a628 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/product/RemoveSplashHandlerBindingAction.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/product/RemoveSplashHandlerBindingAction.java @@ -161,8 +161,7 @@ private IPluginElement[] findProductBindingElements(IPluginExtension extension) IPluginObject[] pluginObjects = extension.getChildren(); // Process all children for (IPluginObject pluginObject : pluginObjects) { - if (pluginObject instanceof IPluginElement) { - IPluginElement element = (IPluginElement) pluginObject; + if (pluginObject instanceof IPluginElement element) { // Find product binding elements if (element.getName().equals(F_ELEMENT_PRODUCT_BINDING)) { elements.add(element); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/product/UpdateSplashHandlerAction.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/product/UpdateSplashHandlerAction.java index 8bf7d86c5a..8a39667d47 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/product/UpdateSplashHandlerAction.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/product/UpdateSplashHandlerAction.java @@ -362,8 +362,7 @@ private void removeMatchingProductBindingElements(IPluginExtension extension) th IPluginObject[] pluginObjects = extension.getChildren(); // Process all children for (IPluginObject pluginObject : pluginObjects) { - if (pluginObject instanceof IPluginElement) { - IPluginElement element = (IPluginElement) pluginObject; + if (pluginObject instanceof IPluginElement element) { // Find splash handler elements if (element.getName().equals(F_ELEMENT_PRODUCT_BINDING)) { // Get the splash ID attribute @@ -395,8 +394,7 @@ private IPluginElement findSplashHandlerElement(IPluginExtension extension) { IPluginObject[] pluginObjects = extension.getChildren(); // Process all children for (IPluginObject pluginObject : pluginObjects) { - if (pluginObject instanceof IPluginElement) { - IPluginElement element = (IPluginElement) pluginObject; + if (pluginObject instanceof IPluginElement element) { // Find splash handler elements if (element.getName().equals(F_ELEMENT_SPLASH_HANDLER)) { // Get the id attribute @@ -445,8 +443,7 @@ private IPluginElement findProductBindingElement(IPluginExtension extension) { IPluginObject[] pluginObjects = extension.getChildren(); // Process all children for (IPluginObject pluginObject : pluginObjects) { - if (pluginObject instanceof IPluginElement) { - IPluginElement element = (IPluginElement) pluginObject; + if (pluginObject instanceof IPluginElement element) { // Find product binding elements if (element.getName().equals(F_ELEMENT_PRODUCT_BINDING)) { // Get the id attribute diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/tools/ConvertProjectsAction.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/tools/ConvertProjectsAction.java index f4555c028b..10f57cf4c8 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/tools/ConvertProjectsAction.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/tools/ConvertProjectsAction.java @@ -55,8 +55,7 @@ public void run(IAction action) { for (Object elem : elems) { IProject project = null; - if (elem instanceof IFile) { - IFile file = (IFile) elem; + if (elem instanceof IFile file) { project = file.getProject(); } else if (elem instanceof IProject) { project = (IProject) elem; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/tools/OrganizeManifest.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/tools/OrganizeManifest.java index 126fa3ab7e..a2905d0ed4 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/tools/OrganizeManifest.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/tools/OrganizeManifest.java @@ -165,8 +165,7 @@ public static void organizeExportPackages(IBundle bundle, IProject project, bool if (ManifestUtils.isImmediateRoot(root)) { IJavaElement[] elements = root.getChildren(); for (IJavaElement element : elements) - if (element instanceof IPackageFragment) { - IPackageFragment fragment = (IPackageFragment) element; + if (element instanceof IPackageFragment fragment) { String name = fragment.getElementName(); if (name.length() == 0) name = "."; //$NON-NLS-1$ diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/tools/OrganizeManifestsAction.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/tools/OrganizeManifestsAction.java index 891794c8d8..fe45446058 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/tools/OrganizeManifestsAction.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/tools/OrganizeManifestsAction.java @@ -57,8 +57,7 @@ public void runOrganizeManfestsAction(ISelection selection) { if (!PlatformUI.getWorkbench().saveAllEditors(true)) return; - if (selection instanceof IStructuredSelection) { - IStructuredSelection ssel = (IStructuredSelection) selection; + if (selection instanceof IStructuredSelection ssel) { Iterator it = ssel.iterator(); ArrayList projects = new ArrayList<>(); while (it.hasNext()) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/tools/UpdateClasspathAction.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/tools/UpdateClasspathAction.java index 1c50bef670..8845bdce5a 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/tools/UpdateClasspathAction.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/wizards/tools/UpdateClasspathAction.java @@ -55,8 +55,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException { for (Object elem : elems) { IProject project = null; - if (elem instanceof IFile) { - IFile file = (IFile) elem; + if (elem instanceof IFile file) { project = file.getProject(); } else if (elem instanceof IProject) { project = (IProject) elem; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/ui/launcher/EclipseLaunchShortcut.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/ui/launcher/EclipseLaunchShortcut.java index 4ee94a1acd..627503ed56 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/ui/launcher/EclipseLaunchShortcut.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/ui/launcher/EclipseLaunchShortcut.java @@ -81,8 +81,7 @@ public void launch(IEditorPart editor, String mode) { @Override public void launch(ISelection selection, String mode) { IPluginModelBase model = null; - if (selection instanceof IStructuredSelection) { - IStructuredSelection ssel = (IStructuredSelection) selection; + if (selection instanceof IStructuredSelection ssel) { if (!ssel.isEmpty()) { Object object = ssel.getFirstElement(); IProject project = null; diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/ui/templates/AbstractTemplateSection.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/ui/templates/AbstractTemplateSection.java index 8caebba096..215608e92c 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/ui/templates/AbstractTemplateSection.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/ui/templates/AbstractTemplateSection.java @@ -769,9 +769,8 @@ protected boolean hasBundleManifest() { private IBundle getBundleFromModel() { // Do early exit checks - if (model != null && (model instanceof IBundlePluginModelBase)) { + if (model != null && (model instanceof IBundlePluginModelBase bundlePModel)) { - IBundlePluginModelBase bundlePModel = (IBundlePluginModelBase) model; IBundleModel bundleModel = bundlePModel.getBundleModel(); if (bundleModel != null) { diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/ui/templates/OptionTemplateWizardPage.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/ui/templates/OptionTemplateWizardPage.java index c4c9081819..bc84c79e47 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/ui/templates/OptionTemplateWizardPage.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/ui/templates/OptionTemplateWizardPage.java @@ -94,8 +94,7 @@ public void createControl(Composite composite) { public void setVisible(boolean visible) { if (visible && section.isDependentOnParentWizard()) { IWizard wizard = getWizard(); - if (wizard instanceof AbstractNewPluginTemplateWizard) { - AbstractNewPluginTemplateWizard templateWizard = (AbstractNewPluginTemplateWizard) wizard; + if (wizard instanceof AbstractNewPluginTemplateWizard templateWizard) { section.initializeFields(templateWizard.getData()); } } diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/ui/templates/PluginReference.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/ui/templates/PluginReference.java index 862cd58e34..8bebe3f15c 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/ui/templates/PluginReference.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/ui/templates/PluginReference.java @@ -67,8 +67,7 @@ public PluginReference(String id, String version, int match) { @Override public boolean equals(Object object) { - if (object instanceof IPluginReference) { - IPluginReference source = (IPluginReference) object; + if (object instanceof IPluginReference source) { if (id == null) return false; return id.equals(source.getId()) && ((version == null && source.getVersion() == null) || version.equals(source.getVersion())); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/ui/internal/views/log/jdt/ShowErrorInStackTraceConsoleHandler.java b/ui/org.eclipse.pde.ui/src/org/eclipse/ui/internal/views/log/jdt/ShowErrorInStackTraceConsoleHandler.java index 8ad0147ba0..8b80c0cf56 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/ui/internal/views/log/jdt/ShowErrorInStackTraceConsoleHandler.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/ui/internal/views/log/jdt/ShowErrorInStackTraceConsoleHandler.java @@ -54,8 +54,7 @@ public boolean isEnabled() { @Override public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchPart activePart = HandlerUtil.getActivePart(event); - if (activePart instanceof LogView) { - LogView logView = (LogView) activePart; + if (activePart instanceof LogView logView) { if (logView.getSelectedStack() != null) { if (fFactory == null) { fFactory = new JavaStackTraceConsoleFactory(); diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/ui/internal/views/log/jdt/ShowInConsolePropertyTester.java b/ui/org.eclipse.pde.ui/src/org/eclipse/ui/internal/views/log/jdt/ShowInConsolePropertyTester.java index f80a84e3a3..d53231880a 100644 --- a/ui/org.eclipse.pde.ui/src/org/eclipse/ui/internal/views/log/jdt/ShowInConsolePropertyTester.java +++ b/ui/org.eclipse.pde.ui/src/org/eclipse/ui/internal/views/log/jdt/ShowInConsolePropertyTester.java @@ -25,8 +25,7 @@ public class ShowInConsolePropertyTester extends PropertyTester { @Override public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { if (HAS_SELECTED_STACK_PROPERTY.equals(property)) { - if (receiver instanceof LogView) { - LogView logView = (LogView) receiver; + if (receiver instanceof LogView logView) { if (logView.getSelectedStack() != null) { return true; } diff --git a/ui/org.eclipse.pde.ui/src_samples/org/eclipse/pde/internal/ui/samples/SampleEditor.java b/ui/org.eclipse.pde.ui/src_samples/org/eclipse/pde/internal/ui/samples/SampleEditor.java index ca57a5097d..7096af899f 100644 --- a/ui/org.eclipse.pde.ui/src_samples/org/eclipse/pde/internal/ui/samples/SampleEditor.java +++ b/ui/org.eclipse.pde.ui/src_samples/org/eclipse/pde/internal/ui/samples/SampleEditor.java @@ -83,8 +83,7 @@ public void resourceChanged(IResourceChangeEvent event) { @Override public boolean visit(IResourceDelta delta) throws CoreException { IResource resource = delta.getResource(); - if (resource instanceof IFile) { - IFile file = (IFile) resource; + if (resource instanceof IFile file) { if (file.equals(((IFileEditorInput) getEditorInput()).getFile())) { if (delta.getKind() == IResourceDelta.REMOVED || delta.getKind() == IResourceDelta.REPLACED) close();