From e663b582b562ca474c59ed40c13c16a02a8a3bf6 Mon Sep 17 00:00:00 2001 From: vaisakhkannan <133869023+vaisakhkannan@users.noreply.github.com> Date: Tue, 6 Aug 2024 17:19:11 +0530 Subject: [PATCH 01/21] Fix Multi catch exception --- .../lsp4jakarta/lsp4ij/AnnotationUtil.java | 6 ++++- .../PostConstructReturnTypeQuickFix.java | 6 ++++- .../BeanValidationQuickFix.java | 12 ++++++++-- .../ManagedBeanNoArgConstructorQuickFix.java | 6 ++++- .../lsp4ij/cdi/ManagedBeanQuickFix.java | 6 ++++- .../InsertAnnotationMissingQuickFix.java | 6 ++++- .../quickfix/InsertAnnotationQuickFix.java | 6 ++++- .../RemoveAnnotationConflictQuickFix.java | 6 ++++- .../RemoveMethodParametersQuickFix.java | 6 ++++- .../RemoveModifierConflictQuickFix.java | 6 ++++- .../RemoveParamAnnotationQuickFix.java | 6 ++++- .../NoResourcePublicConstructorQuickFix.java | 6 ++++- .../NonPublicResourceMethodQuickFix.java | 6 ++++- ...rceMethodMultipleEntityParamsQuickFix.java | 6 ++++- .../PersistenceAnnotationQuickFix.java | 6 ++++- .../PersistenceEntityQuickFix.java | 6 ++++- .../CompleteFilterAnnotationQuickFix.java | 12 ++++++++-- .../CompleteServletAnnotationQuickFix.java | 12 ++++++++-- .../servlet/FilterImplementationQuickFix.java | 6 ++++- .../lsp4ij/servlet/HttpServletQuickFix.java | 6 ++++- .../ListenerImplementationQuickFix.java | 6 ++++- .../InsertAnnotationAttributeQuickFix.java | 6 ++++- .../InsertAnnotationMissingQuickFix.java | 6 ++++- .../annotations/AnnotationValidator.java | 6 ++++- .../completion/JavaCompletionDefinition.java | 14 +++++++---- .../JavaDiagnosticsDefinition.java | 24 +++++++++++++++---- ...icroProfileFaultToleranceASTValidator.java | 6 ++++- .../java/ImplementHealthCheckQuickFix.java | 6 ++++- ...cationScopedAnnotationMissingQuickFix.java | 6 ++++- .../MicroProfileGenerateOpenAPIOperation.java | 6 ++++- 30 files changed, 185 insertions(+), 39 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AnnotationUtil.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AnnotationUtil.java index 8bdcc526c..182d951b9 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AnnotationUtil.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AnnotationUtil.java @@ -38,7 +38,11 @@ public static List getScopeAnnotations(PsiClass type, Set scopes // recognised annotations found in scopes. return Arrays.stream(type.getAnnotations()).map(annotation -> annotation.getNameReferenceElement().getQualifiedName()) .filter(scopes::contains).distinct().collect(Collectors.toList()); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { return Collections.emptyList(); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/annotations/PostConstructReturnTypeQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/annotations/PostConstructReturnTypeQuickFix.java index eaca420e5..4048b0237 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/annotations/PostConstructReturnTypeQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/annotations/PostConstructReturnTypeQuickFix.java @@ -77,7 +77,11 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { try { WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); toResolve.setEdit(we); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to change return type to void", e); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/beanvalidation/BeanValidationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/beanvalidation/BeanValidationQuickFix.java index 7429e4d04..41f819d08 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/beanvalidation/BeanValidationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/beanvalidation/BeanValidationQuickFix.java @@ -114,7 +114,11 @@ private void resolveRemoveConstraintAnnotationsCodeAction(JavaCodeActionResolveC try { WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); toResolve.setEdit(we); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to remove constraint annotation", e); @@ -137,7 +141,11 @@ private void resolveStaticModifierCodeAction(JavaCodeActionResolveContext contex try { WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); toResolve.setEdit(we); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to remove static modifier", e); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/cdi/ManagedBeanNoArgConstructorQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/cdi/ManagedBeanNoArgConstructorQuickFix.java index c131cc87f..60cfa1884 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/cdi/ManagedBeanNoArgConstructorQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/cdi/ManagedBeanNoArgConstructorQuickFix.java @@ -77,7 +77,11 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { try { WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); toResolve.setEdit(we); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to create workspace edit for code actions to add constructors", e); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/cdi/ManagedBeanQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/cdi/ManagedBeanQuickFix.java index 2707f34a5..46a6ffaef 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/cdi/ManagedBeanQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/cdi/ManagedBeanQuickFix.java @@ -77,7 +77,11 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { try { WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); toResolve.setEdit(we); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action.", e); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationMissingQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationMissingQuickFix.java index 5254ef960..5e0d71a3f 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationMissingQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationMissingQuickFix.java @@ -93,7 +93,11 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { try { WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); toResolve.setEdit(we); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action.", e); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java index 5dbc73014..94e1d8eba 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java @@ -96,7 +96,11 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { try { WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); toResolve.setEdit(we); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action " + label, e); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveAnnotationConflictQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveAnnotationConflictQuickFix.java index 0fd04e40d..d5c493885 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveAnnotationConflictQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveAnnotationConflictQuickFix.java @@ -120,7 +120,11 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { try { WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); toResolve.setEdit(we); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to remove annotation", e); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveMethodParametersQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveMethodParametersQuickFix.java index 66c47ded8..76bafaca7 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveMethodParametersQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveMethodParametersQuickFix.java @@ -78,7 +78,11 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { try { WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); toResolve.setEdit(we); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action", e); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveModifierConflictQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveModifierConflictQuickFix.java index 36d1963ef..7bfc0f050 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveModifierConflictQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveModifierConflictQuickFix.java @@ -111,7 +111,11 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { try { WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); toResolve.setEdit(we); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action " + label, e); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveParamAnnotationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveParamAnnotationQuickFix.java index 45afcc066..d3af72e49 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveParamAnnotationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveParamAnnotationQuickFix.java @@ -124,7 +124,11 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { try { WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); toResolve.setEdit(we); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to extend the HttpServlet class.", e); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/NoResourcePublicConstructorQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/NoResourcePublicConstructorQuickFix.java index 807d6d36b..fc426dc5e 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/NoResourcePublicConstructorQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/NoResourcePublicConstructorQuickFix.java @@ -106,7 +106,11 @@ public void convertWorkspaceEdit(ChangeCorrectionProposal proposal, String warni try { WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); context.getUnresolved().setEdit(we); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, warningMessage, e); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/NonPublicResourceMethodQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/NonPublicResourceMethodQuickFix.java index 27b4edea0..9e73f0130 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/NonPublicResourceMethodQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/NonPublicResourceMethodQuickFix.java @@ -80,7 +80,11 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { try { WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); toResolve.setEdit(we); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to make method public", e); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/ResourceMethodMultipleEntityParamsQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/ResourceMethodMultipleEntityParamsQuickFix.java index d27c0740e..d8a62b79b 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/ResourceMethodMultipleEntityParamsQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/ResourceMethodMultipleEntityParamsQuickFix.java @@ -132,7 +132,11 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { try { WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); toResolve.setEdit(we); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action", e); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/persistence/PersistenceAnnotationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/persistence/PersistenceAnnotationQuickFix.java index fa891bf63..5092828e1 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/persistence/PersistenceAnnotationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/persistence/PersistenceAnnotationQuickFix.java @@ -78,7 +78,11 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { try { WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); toResolve.setEdit(we); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action.", e); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/persistence/PersistenceEntityQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/persistence/PersistenceEntityQuickFix.java index 7bab08d4e..f2c234999 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/persistence/PersistenceEntityQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/persistence/PersistenceEntityQuickFix.java @@ -96,7 +96,11 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { try { WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); toResolve.setEdit(we); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to create workspace edit for code actions to add constructors", e); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/CompleteFilterAnnotationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/CompleteFilterAnnotationQuickFix.java index 2de17b474..4f8c58cd3 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/CompleteFilterAnnotationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/CompleteFilterAnnotationQuickFix.java @@ -105,7 +105,11 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { try { WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); toResolve.setEdit(we); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action.", e); @@ -125,7 +129,11 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { try { WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); toResolve.setEdit(we); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action.", e); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/CompleteServletAnnotationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/CompleteServletAnnotationQuickFix.java index 0c8323a71..a72602edd 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/CompleteServletAnnotationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/CompleteServletAnnotationQuickFix.java @@ -104,7 +104,11 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { try { WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); toResolve.setEdit(we); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action.", e); @@ -123,7 +127,11 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { try { WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); toResolve.setEdit(we); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action.", e); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/FilterImplementationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/FilterImplementationQuickFix.java index dcb777194..fc9d22577 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/FilterImplementationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/FilterImplementationQuickFix.java @@ -81,7 +81,11 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { try { WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); toResolve.setEdit(we); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to filter implementation", e); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/HttpServletQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/HttpServletQuickFix.java index 5411064d1..08f869038 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/HttpServletQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/HttpServletQuickFix.java @@ -98,7 +98,11 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { try { WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); toResolve.setEdit(we); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to extend the HttpServlet class.", e); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/ListenerImplementationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/ListenerImplementationQuickFix.java index 7801b91f4..a87b70d93 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/ListenerImplementationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/ListenerImplementationQuickFix.java @@ -102,7 +102,11 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { try { WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); toResolve.setEdit(we); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to listener implementation", e); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationAttributeQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationAttributeQuickFix.java index 27ceabb17..419041a07 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationAttributeQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationAttributeQuickFix.java @@ -83,7 +83,11 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { annotation, 0, context.getSource().getCompilationUnit(), attributeName); try { toResolve.setEdit(context.convertToWorkspaceEdit(proposal)); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to resolve code action edit for inserting an attribute value", e); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationMissingQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationMissingQuickFix.java index f9f6608ed..520d5cf44 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationMissingQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationMissingQuickFix.java @@ -105,7 +105,11 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { try { WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); toResolve.setEdit(we); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to insert missing annotation", e); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java index d39d1d5e2..877306afd 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java @@ -93,7 +93,11 @@ public String validate(String value, AnnotationAttributeRule rule) { return null; } return rule.validate(value); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, e.getLocalizedMessage(), e); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/completion/JavaCompletionDefinition.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/completion/JavaCompletionDefinition.java index ab969ccf7..3baa5cb71 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/completion/JavaCompletionDefinition.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/completion/JavaCompletionDefinition.java @@ -52,8 +52,11 @@ public final class JavaCompletionDefinition extends BaseKeyedLazyInstance collectCompletionItems(JavaCompletionContext context) { try { return getInstance().collectCompletionItems(context); - } - catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java index 1a32519cd..8a21847eb 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java @@ -52,7 +52,11 @@ public final class JavaDiagnosticsDefinition extends BaseKeyedLazyInstance collectDiagnostics(JavaDiagnosticsContext context) { try { List diagnostics = getInstance().collectDiagnostics(context); return diagnostics != null ? diagnostics : Collections.emptyList(); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Error while calling collectDiagnostics", e); @@ -88,7 +100,11 @@ public List collectDiagnostics(JavaDiagnosticsContext context) { public void endDiagnostics(JavaDiagnosticsContext context) { try { getInstance().endDiagnostics(context); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Error while calling endDiagnostics", e); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java index ce3de6aa2..bd8aa2840 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java @@ -156,7 +156,11 @@ private void validateAsynchronousAnnotation(PsiMethod node, PsiAnnotation annota String methodReturnTypeString; try { methodReturnTypeString = methodReturnType.getCanonicalText(); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { throw e; diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/health/java/ImplementHealthCheckQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/health/java/ImplementHealthCheckQuickFix.java index 2769fc303..c17078727 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/health/java/ImplementHealthCheckQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/health/java/ImplementHealthCheckQuickFix.java @@ -87,7 +87,11 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { context.getSource().getCompilationUnit()); try { toResolve.setEdit(context.convertToWorkspaceEdit(proposal)); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Unable to create workspace edit to make the class implement @HealthCheck", e); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/metrics/java/ApplicationScopedAnnotationMissingQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/metrics/java/ApplicationScopedAnnotationMissingQuickFix.java index 003de920a..c12329360 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/metrics/java/ApplicationScopedAnnotationMissingQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/metrics/java/ApplicationScopedAnnotationMissingQuickFix.java @@ -103,7 +103,11 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { REMOVE_ANNOTATION_NAMES); try { toResolve.setEdit(context.convertToWorkspaceEdit(proposal)); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { LOGGER.log(Level.WARNING, "Failed to create workspace edit to replace bean scope annotation", e); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/openapi/java/MicroProfileGenerateOpenAPIOperation.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/openapi/java/MicroProfileGenerateOpenAPIOperation.java index c2df79979..4bc88c676 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/openapi/java/MicroProfileGenerateOpenAPIOperation.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/openapi/java/MicroProfileGenerateOpenAPIOperation.java @@ -125,7 +125,11 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { try { toResolve.setEdit(context.convertToWorkspaceEdit(proposal)); - } catch (IndexNotReadyException | ProcessCanceledException | CancellationException e) { + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 + throw e; + } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { } From aa9d11d49d66bb5fe9aa067d9c08371559d489bc Mon Sep 17 00:00:00 2001 From: vaisakhkannan <133869023+vaisakhkannan@users.noreply.github.com> Date: Tue, 6 Aug 2024 19:04:21 +0530 Subject: [PATCH 02/21] Updated header year --- .../tools/intellij/lsp4jakarta/lsp4ij/AnnotationUtil.java | 2 +- .../core/java/codeaction/InsertAnnotationAttributeQuickFix.java | 2 +- .../core/java/codeaction/InsertAnnotationMissingQuickFix.java | 2 +- .../core/java/validators/annotations/AnnotationValidator.java | 2 +- .../core/java/corrections/JavaDiagnosticsDefinition.java | 2 +- .../java/MicroProfileFaultToleranceASTValidator.java | 2 +- .../psi/internal/health/java/ImplementHealthCheckQuickFix.java | 2 +- .../java/ApplicationScopedAnnotationMissingQuickFix.java | 2 +- .../openapi/java/MicroProfileGenerateOpenAPIOperation.java | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AnnotationUtil.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AnnotationUtil.java index 182d951b9..d4151be75 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AnnotationUtil.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AnnotationUtil.java @@ -1,4 +1,4 @@ -/* Copyright (c) 2022 IBM Corporation, Lidia Ataupillco Ramos and others. +/* Copyright (c) 2022, 2024 IBM Corporation, Lidia Ataupillco Ramos and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationAttributeQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationAttributeQuickFix.java index 419041a07..d8ce79bd7 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationAttributeQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationAttributeQuickFix.java @@ -1,5 +1,5 @@ /******************************************************************************* -* Copyright (c) 2021 Red Hat Inc. and others. +* Copyright (c) 2021, 2024 Red Hat Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationMissingQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationMissingQuickFix.java index 520d5cf44..3e9d27c04 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationMissingQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationMissingQuickFix.java @@ -1,5 +1,5 @@ /******************************************************************************* -* Copyright (c) 2020 Red Hat Inc. and others. +* Copyright (c) 2020, 2024 Red Hat Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java index 877306afd..9b729aab1 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java @@ -1,5 +1,5 @@ /******************************************************************************* -* Copyright (c) 2021 Red Hat Inc. and others. +* Copyright (c) 2021, 2024 Red Hat Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java index 8a21847eb..2ba8135da 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2020, 2023 Red Hat Inc. and others. + * Copyright (c) 2020, 2024 Red Hat Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java index bd8aa2840..d03d74c21 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2021 Red Hat Inc. and others. + * Copyright (c) 2021, 2024 Red Hat Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/health/java/ImplementHealthCheckQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/health/java/ImplementHealthCheckQuickFix.java index c17078727..0473435de 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/health/java/ImplementHealthCheckQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/health/java/ImplementHealthCheckQuickFix.java @@ -1,5 +1,5 @@ /******************************************************************************* -* Copyright (c) 2020 Red Hat Inc. and others. +* Copyright (c) 2020, 2024 Red Hat Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/metrics/java/ApplicationScopedAnnotationMissingQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/metrics/java/ApplicationScopedAnnotationMissingQuickFix.java index c12329360..de3997302 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/metrics/java/ApplicationScopedAnnotationMissingQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/metrics/java/ApplicationScopedAnnotationMissingQuickFix.java @@ -1,5 +1,5 @@ /******************************************************************************* -* Copyright (c) 2020 IBM Corporation and others. +* Copyright (c) 2020, 2024 IBM Corporation and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/openapi/java/MicroProfileGenerateOpenAPIOperation.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/openapi/java/MicroProfileGenerateOpenAPIOperation.java index 4bc88c676..99c9f12c1 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/openapi/java/MicroProfileGenerateOpenAPIOperation.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/openapi/java/MicroProfileGenerateOpenAPIOperation.java @@ -1,5 +1,5 @@ /******************************************************************************* -* Copyright (c) 2020 Red Hat Inc. and others. +* Copyright (c) 2020, 2024 Red Hat Inc. and others. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at From 54aae6cfafc6fee079fd925c4d5a62134b20d54e Mon Sep 17 00:00:00 2001 From: vaisakhkannan <133869023+vaisakhkannan@users.noreply.github.com> Date: Tue, 22 Oct 2024 10:57:23 +0530 Subject: [PATCH 03/21] Added common class for exception handling --- .../PostConstructReturnTypeQuickFix.java | 27 +++++------ .../BeanValidationQuickFix.java | 46 +++++++++---------- .../tools/intellij/util/ExceptionUtil.java | 35 ++++++++++++++ 3 files changed, 68 insertions(+), 40 deletions(-) create mode 100644 src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/annotations/PostConstructReturnTypeQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/annotations/PostConstructReturnTypeQuickFix.java index 4048b0237..9785908bc 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/annotations/PostConstructReturnTypeQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/annotations/PostConstructReturnTypeQuickFix.java @@ -12,11 +12,8 @@ *******************************************************************************/ package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.annotations; -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiMethod; -import com.intellij.psi.PsiPrimitiveType; import com.intellij.psi.PsiTypes; import com.intellij.psi.util.PsiTreeUtil; import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.JDTUtils; @@ -26,13 +23,13 @@ import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.WorkspaceEdit; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.CancellationException; import java.util.logging.Level; import java.util.logging.Logger; @@ -74,17 +71,17 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { assert parentType != null; ChangeCorrectionProposal proposal = new ModifyReturnTypeProposal(TITLE_MESSAGE, context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, 0, PsiTypes.voidType()); - try { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to change return type to void", e); + + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); + toResolve.setEdit(we); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to change return type to void", e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/beanvalidation/BeanValidationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/beanvalidation/BeanValidationQuickFix.java index 41f819d08..d2a57c371 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/beanvalidation/BeanValidationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/beanvalidation/BeanValidationQuickFix.java @@ -12,8 +12,6 @@ *******************************************************************************/ package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.beanvalidation; -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.JDTUtils; @@ -23,13 +21,13 @@ import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.IJavaCodeActionParticipant; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.WorkspaceEdit; import org.eclipse.lsp4mp.commons.codeaction.CodeActionResolveData; import java.util.*; -import java.util.concurrent.CancellationException; import java.util.logging.Level; import java.util.logging.Logger; @@ -111,17 +109,16 @@ private void resolveRemoveConstraintAnnotationsCodeAction(JavaCodeActionResolveC final RemoveAnnotationsProposal proposal = new RemoveAnnotationsProposal(name, context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, 0, Collections.singletonList(annotationToRemove.get()), isFormatRequired); - try { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to remove constraint annotation", e); + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); + toResolve.setEdit(we); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to remove constraint annotation", e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } } } @@ -138,17 +135,16 @@ private void resolveStaticModifierCodeAction(JavaCodeActionResolveContext contex context.getASTRoot(), parentType, 0, modifierListOwner.getModifierList(), Collections.emptyList(), Collections.singletonList("static")); - try { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to remove static modifier", e); + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); + toResolve.setEdit(we); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to remove static modifier", e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } } diff --git a/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java b/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java new file mode 100644 index 000000000..9c3fd93fb --- /dev/null +++ b/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2024 IBM Corporation. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + ******************************************************************************/ +package io.openliberty.tools.intellij.util; + +import com.intellij.openapi.progress.ProcessCanceledException; +import com.intellij.openapi.project.IndexNotReadyException; + +import java.util.concurrent.CancellationException; +import java.util.function.Consumer; +import java.util.function.Supplier; + +public class ExceptionUtil { + + public static T executeWithExceptionHandling(Supplier action, Consumer logger) { + try { + return action.get(); + } catch (ProcessCanceledException e) { + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multi-catch to keep backward compatibility + throw e; + } catch (IndexNotReadyException | CancellationException e) { + throw e; + } catch (Exception e) { + // Log the exception using the provided logger + logger.accept(e); + return null; // Return null to indicate failure + } + } +} \ No newline at end of file From 973a051e6e91c3e56f3c0095047eaa92cbe2baf6 Mon Sep 17 00:00:00 2001 From: vaisakhkannan <133869023+vaisakhkannan@users.noreply.github.com> Date: Tue, 22 Oct 2024 11:30:23 +0530 Subject: [PATCH 04/21] Updated AnnotationUtil.java --- .../lsp4jakarta/lsp4ij/AnnotationUtil.java | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AnnotationUtil.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AnnotationUtil.java index d4151be75..d0adb0005 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AnnotationUtil.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AnnotationUtil.java @@ -22,6 +22,7 @@ import java.util.concurrent.CancellationException; import java.util.stream.Collectors; import java.util.Collections; +import java.util.function.Supplier; /** * Returns the list of recognised defining annotations applied to a @@ -33,19 +34,28 @@ */ public class AnnotationUtil { public static List getScopeAnnotations(PsiClass type, Set scopes) { + return executeWithExceptionHandling(() -> + // Construct a stream of only the annotations applied to the type that are also + // recognised annotations found in scopes. + Arrays.stream(type.getAnnotations()) + .map(annotation -> annotation.getNameReferenceElement().getQualifiedName()) + .filter(scopes::contains) + .distinct() + .collect(Collectors.toList()), + Collections::emptyList + ); + } + + private static T executeWithExceptionHandling(Supplier action, Supplier fallback) { try { - // Construct a stream of only the annotations applied to the type that are also - // recognised annotations found in scopes. - return Arrays.stream(type.getAnnotations()).map(annotation -> annotation.getNameReferenceElement().getQualifiedName()) - .filter(scopes::contains).distinct().collect(Collectors.toList()); + return action.get(); } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 + //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multi-catch to keep backward compatibility throw e; } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { - return Collections.emptyList(); + return fallback.get(); // Return fallback value } } } From c4e4425a06a9ad5b9f0565851acd4621f035e4e7 Mon Sep 17 00:00:00 2001 From: vaisakhkannan <133869023+vaisakhkannan@users.noreply.github.com> Date: Tue, 22 Oct 2024 12:08:45 +0530 Subject: [PATCH 05/21] Refactored code to use common exception class --- .../ManagedBeanNoArgConstructorQuickFix.java | 25 ++++++++---------- .../lsp4ij/cdi/ManagedBeanQuickFix.java | 25 ++++++++---------- .../InsertAnnotationMissingQuickFix.java | 26 +++++++++---------- .../quickfix/InsertAnnotationQuickFix.java | 26 +++++++++---------- .../RemoveAnnotationConflictQuickFix.java | 25 ++++++++---------- .../RemoveMethodParametersQuickFix.java | 26 +++++++++---------- 6 files changed, 69 insertions(+), 84 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/cdi/ManagedBeanNoArgConstructorQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/cdi/ManagedBeanNoArgConstructorQuickFix.java index 60cfa1884..d790cf120 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/cdi/ManagedBeanNoArgConstructorQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/cdi/ManagedBeanNoArgConstructorQuickFix.java @@ -13,8 +13,6 @@ package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.cdi; -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; import com.intellij.psi.util.PsiTreeUtil; @@ -25,6 +23,7 @@ import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.WorkspaceEdit; @@ -32,7 +31,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.concurrent.CancellationException; import java.util.logging.Level; import java.util.logging.Logger; @@ -74,17 +72,16 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, 0, constructorName.equals(Messages.getMessage("AddProtectedConstructor")) ? "protected" : "public"); - try { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Unable to create workspace edit for code actions to add constructors", e); + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); + toResolve.setEdit(we); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code actions to add constructors", e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } return toResolve; diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/cdi/ManagedBeanQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/cdi/ManagedBeanQuickFix.java index 46a6ffaef..4a264fac5 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/cdi/ManagedBeanQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/cdi/ManagedBeanQuickFix.java @@ -15,8 +15,6 @@ package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.cdi; -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiModifierListOwner; import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.JDTUtils; @@ -26,13 +24,13 @@ import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ReplaceAnnotationProposal; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.WorkspaceEdit; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.CancellationException; import java.util.logging.Level; import java.util.logging.Logger; @@ -74,17 +72,16 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { context.getASTRoot(), parentType, 0, ADD_ANNOTATION, context.getSource().getCompilationUnit(), REMOVE_ANNOTATION_NAMES); - try { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action.", e); + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); + toResolve.setEdit(we); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action", e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationMissingQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationMissingQuickFix.java index 5e0d71a3f..cedfd253a 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationMissingQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationMissingQuickFix.java @@ -14,8 +14,6 @@ *******************************************************************************/ package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.codeAction.proposal.quickfix; -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.JDTUtils; @@ -25,12 +23,12 @@ import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.InsertAnnotationProposal; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.WorkspaceEdit; import java.util.*; -import java.util.concurrent.CancellationException; import java.util.logging.Level; import java.util.logging.Logger; @@ -90,17 +88,17 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { ChangeCorrectionProposal proposal = new InsertAnnotationProposal(name, context.getCompilationUnit(), context.getASTRoot(), parentType, 0, context.getSource().getCompilationUnit(), annotations); - try { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action.", e); + + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); + toResolve.setEdit(we); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action.", e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java index 94e1d8eba..7ec9a35fb 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java @@ -13,8 +13,6 @@ *******************************************************************************/ package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.codeAction.proposal.quickfix; -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.psi.PsiAnnotation; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; @@ -27,6 +25,7 @@ import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.WorkspaceEdit; @@ -34,7 +33,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.concurrent.CancellationException; import java.util.logging.Level; import java.util.logging.Logger; @@ -93,17 +91,17 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { String label = getLabel(this.annotation, attributes); ChangeCorrectionProposal proposal = new ModifyAnnotationProposal(label, context.getSource().getCompilationUnit(), context.getASTRoot(), binding, annotationNode, 0, this.annotation, Arrays.asList(attributes)); - try { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action " + label, e); + + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); + toResolve.setEdit(we); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action", e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveAnnotationConflictQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveAnnotationConflictQuickFix.java index d5c493885..f9a2cb769 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveAnnotationConflictQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveAnnotationConflictQuickFix.java @@ -14,8 +14,6 @@ *******************************************************************************/ package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.codeAction.proposal.quickfix; -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; @@ -30,6 +28,7 @@ import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.WorkspaceEdit; @@ -41,7 +40,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.concurrent.CancellationException; import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Collectors; @@ -117,17 +115,16 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { ChangeCorrectionProposal proposal = new DeleteAnnotationProposal(name, context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, 0, declaringNode, resolveAnnotationsArray); - try { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to remove annotation", e); + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); + toResolve.setEdit(we); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to remove annotation", e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveMethodParametersQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveMethodParametersQuickFix.java index 76bafaca7..b77e33031 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveMethodParametersQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveMethodParametersQuickFix.java @@ -13,8 +13,6 @@ package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.codeAction.proposal.quickfix; -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiMethod; @@ -27,6 +25,7 @@ import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.WorkspaceEdit; @@ -34,7 +33,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.concurrent.CancellationException; import java.util.logging.Level; import java.util.logging.Logger; @@ -75,17 +73,17 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { final PsiParameterList parameterList = parentMethod.getParameterList(); ChangeCorrectionProposal proposal = new RemoveParamsProposal(NAME, context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, 0, Arrays.asList(parameterList.getParameters()), false); - try { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action", e); + + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); + toResolve.setEdit(we); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action", e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } return toResolve; } From b4fd07f0329f7b97c2092841e1e34d437807e53f Mon Sep 17 00:00:00 2001 From: vaisakhkannan <133869023+vaisakhkannan@users.noreply.github.com> Date: Tue, 22 Oct 2024 13:29:07 +0530 Subject: [PATCH 06/21] Refactored quickfix code to use common exception class --- .../RemoveModifierConflictQuickFix.java | 25 +++++----- .../RemoveParamAnnotationQuickFix.java | 26 +++++----- .../NoResourcePublicConstructorQuickFix.java | 25 +++++----- .../NonPublicResourceMethodQuickFix.java | 26 +++++----- ...rceMethodMultipleEntityParamsQuickFix.java | 25 +++++----- .../PersistenceAnnotationQuickFix.java | 27 +++++------ .../PersistenceEntityQuickFix.java | 26 +++++----- .../CompleteFilterAnnotationQuickFix.java | 48 +++++++++---------- .../CompleteServletAnnotationQuickFix.java | 48 +++++++++---------- .../servlet/FilterImplementationQuickFix.java | 26 +++++----- .../lsp4ij/servlet/HttpServletQuickFix.java | 26 +++++----- .../ListenerImplementationQuickFix.java | 26 +++++----- .../InsertAnnotationAttributeQuickFix.java | 27 +++++------ .../InsertAnnotationMissingQuickFix.java | 26 +++++----- .../JavaDiagnosticsDefinition.java | 39 ++++++++------- .../java/ImplementHealthCheckQuickFix.java | 25 +++++----- ...cationScopedAnnotationMissingQuickFix.java | 24 +++++----- .../MicroProfileGenerateOpenAPIOperation.java | 26 +++++----- 18 files changed, 242 insertions(+), 279 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveModifierConflictQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveModifierConflictQuickFix.java index 7bfc0f050..da33f388b 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveModifierConflictQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveModifierConflictQuickFix.java @@ -13,8 +13,6 @@ package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.codeAction.proposal.quickfix; -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.JDTUtils; @@ -23,6 +21,7 @@ import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.IJavaCodeActionParticipant; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.WorkspaceEdit; @@ -31,7 +30,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.concurrent.CancellationException; import java.util.logging.Level; import java.util.logging.Logger; @@ -108,17 +106,16 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { ModifyModifiersProposal proposal = new ModifyModifiersProposal(label, context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, 0, modifierListOwner.getModifierList(), Collections.emptyList(), Arrays.asList(modifiers), false); - try { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action " + label, e); + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); + toResolve.setEdit(we); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action " + label, e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveParamAnnotationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveParamAnnotationQuickFix.java index d3af72e49..bc4bd2543 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveParamAnnotationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveParamAnnotationQuickFix.java @@ -12,8 +12,6 @@ *******************************************************************************/ package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.codeAction.proposal.quickfix; - import com.intellij.openapi.progress.ProcessCanceledException; - import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.JDTUtils; @@ -22,13 +20,13 @@ import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.IJavaCodeActionParticipant; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext; + import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.WorkspaceEdit; import org.eclipse.lsp4mp.commons.codeaction.CodeActionResolveData; import java.util.*; - import java.util.concurrent.CancellationException; import java.util.logging.Logger; import java.util.logging.Level; @@ -121,17 +119,17 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { String label = getLabel(parameter, annotationsToRemove); RemoveAnnotationsProposal proposal = new RemoveAnnotationsProposal(label, context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, 0, psiAnnotationsToRemove); - try { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to extend the HttpServlet class.", e); + + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); + toResolve.setEdit(we); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to extend the HttpServlet class", e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/NoResourcePublicConstructorQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/NoResourcePublicConstructorQuickFix.java index fc426dc5e..f656c95d6 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/NoResourcePublicConstructorQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/NoResourcePublicConstructorQuickFix.java @@ -13,8 +13,6 @@ package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.jax_rs; -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiMethod; @@ -27,6 +25,7 @@ import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.WorkspaceEdit; @@ -34,7 +33,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.concurrent.CancellationException; import java.util.logging.Level; import java.util.logging.Logger; @@ -103,17 +101,16 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { } public void convertWorkspaceEdit(ChangeCorrectionProposal proposal, String warningMessage, JavaCodeActionResolveContext context) { - try { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - context.getUnresolved().setEdit(we); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, warningMessage, e); + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); + context.getUnresolved().setEdit(we); + return true; + }, + e -> LOGGER.log(Level.WARNING, warningMessage, e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } } } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/NonPublicResourceMethodQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/NonPublicResourceMethodQuickFix.java index 9e73f0130..c25a94f32 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/NonPublicResourceMethodQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/NonPublicResourceMethodQuickFix.java @@ -13,8 +13,6 @@ package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.jax_rs; -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiMethod; @@ -26,13 +24,13 @@ import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.WorkspaceEdit; import java.util.Collections; import java.util.List; -import java.util.concurrent.CancellationException; import java.util.logging.Level; import java.util.logging.Logger; @@ -77,17 +75,17 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { assert parentMethod != null; ChangeCorrectionProposal proposal = new ModifyModifiersProposal(TITLE_MESSAGE, context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, 0, parentMethod.getModifierList(), Collections.singletonList("public")); - try { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to make method public", e); + + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); + toResolve.setEdit(we); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to make method public", e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/ResourceMethodMultipleEntityParamsQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/ResourceMethodMultipleEntityParamsQuickFix.java index d8a62b79b..c60594fcb 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/ResourceMethodMultipleEntityParamsQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/ResourceMethodMultipleEntityParamsQuickFix.java @@ -13,8 +13,6 @@ package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.jax_rs; -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.JDTUtils; @@ -24,13 +22,13 @@ import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.WorkspaceEdit; import org.eclipse.lsp4mp.commons.codeaction.CodeActionResolveData; import java.util.*; -import java.util.concurrent.CancellationException; import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Collectors; @@ -129,17 +127,16 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { ChangeCorrectionProposal proposal = new RemoveParamsProposal(title, context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, 0, entityParams, false); - try { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action", e); + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); + toResolve.setEdit(we); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action", e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/persistence/PersistenceAnnotationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/persistence/PersistenceAnnotationQuickFix.java index 5092828e1..de0f5d5e4 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/persistence/PersistenceAnnotationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/persistence/PersistenceAnnotationQuickFix.java @@ -12,9 +12,6 @@ *******************************************************************************/ package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.persistence; - -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.psi.*; import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.JDTUtils; import io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.Messages; @@ -23,6 +20,7 @@ import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.WorkspaceEdit; @@ -30,7 +28,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.concurrent.CancellationException; import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Collectors; @@ -75,17 +72,17 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { for (PsiAnnotation annotationNode : annotationNodes) { ChangeCorrectionProposal proposal = new ModifyAnnotationProposal(name, context.getSource().getCompilationUnit(), context.getASTRoot(), binding, annotationNode, 0, attributes, this.getAnnotations()); - try { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action.", e); + + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); + toResolve.setEdit(we); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action.", e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/persistence/PersistenceEntityQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/persistence/PersistenceEntityQuickFix.java index f2c234999..54772eda0 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/persistence/PersistenceEntityQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/persistence/PersistenceEntityQuickFix.java @@ -12,9 +12,6 @@ *******************************************************************************/ package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.persistence; - -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; import com.intellij.psi.util.PsiTreeUtil; @@ -25,13 +22,13 @@ import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.WorkspaceEdit; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.CancellationException; import java.util.logging.Level; import java.util.logging.Logger; @@ -93,17 +90,16 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, 0, constructorName.equals(Messages.getMessage("AddNoArgProtectedConstructor")) ? "protected" : "public"); - try { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Unable to create workspace edit for code actions to add constructors", e); + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); + toResolve.setEdit(we); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code actions to add constructors", e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/CompleteFilterAnnotationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/CompleteFilterAnnotationQuickFix.java index 4f8c58cd3..c6ff06d4d 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/CompleteFilterAnnotationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/CompleteFilterAnnotationQuickFix.java @@ -14,8 +14,6 @@ package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.servlet; -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.psi.PsiAnnotation; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiModifierListOwner; @@ -27,6 +25,7 @@ import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.WorkspaceEdit; @@ -36,7 +35,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.CancellationException; import java.util.logging.Level; import java.util.logging.Logger; @@ -102,17 +100,17 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { String name = toResolve.getTitle(); ChangeCorrectionProposal proposal = new ModifyAnnotationProposal(name, context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, annotationNode, 0, annotation, attributesToAdd); - try { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action.", e); + + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); + toResolve.setEdit(we); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action.", e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } } @@ -126,17 +124,17 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { String name = toResolve.getTitle(); ChangeCorrectionProposal proposal = new ModifyAnnotationProposal(name, context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, annotationNode, 0, annotation, new ArrayList(), attributesToRemove); - try { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action.", e); + + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); + toResolve.setEdit(we); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action.", e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } } return toResolve; diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/CompleteServletAnnotationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/CompleteServletAnnotationQuickFix.java index a72602edd..01bacb506 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/CompleteServletAnnotationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/CompleteServletAnnotationQuickFix.java @@ -14,8 +14,6 @@ package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.servlet; -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.psi.PsiAnnotation; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiModifierListOwner; @@ -27,6 +25,7 @@ import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.WorkspaceEdit; @@ -36,7 +35,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.CancellationException; import java.util.logging.Level; import java.util.logging.Logger; @@ -101,17 +99,17 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { String name = toResolve.getTitle(); ChangeCorrectionProposal proposal = new ModifyAnnotationProposal(name, context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, annotationNode, 0, annotation, attributesToAdd); - try { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action.", e); + + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); + toResolve.setEdit(we); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action.", e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } } if (diagnosticCode.equals(ServletConstants.DIAGNOSTIC_CODE_DUPLICATE_ATTRIBUTES)) { @@ -124,17 +122,17 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { String name = toResolve.getTitle(); ChangeCorrectionProposal proposal = new ModifyAnnotationProposal(name, context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, annotationNode, 0, annotation, new ArrayList(), attributesToRemove); - try { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action.", e); + + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); + toResolve.setEdit(we); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action.", e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/FilterImplementationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/FilterImplementationQuickFix.java index fc9d22577..e27267c59 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/FilterImplementationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/FilterImplementationQuickFix.java @@ -14,8 +14,6 @@ *******************************************************************************/ package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.servlet; -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; import com.intellij.psi.util.PsiTreeUtil; @@ -26,13 +24,13 @@ import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ImplementInterfaceProposal; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.WorkspaceEdit; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.CancellationException; import java.util.logging.Level; import java.util.logging.Logger; @@ -78,17 +76,17 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { ChangeCorrectionProposal proposal = new ImplementInterfaceProposal( context.getCompilationUnit(), parentType, context.getASTRoot(), "jakarta.servlet.Filter", 0, context.getSource().getCompilationUnit()); - try { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to filter implementation", e); + + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); + toResolve.setEdit(we); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to filter implementation", e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/HttpServletQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/HttpServletQuickFix.java index 08f869038..5a9803296 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/HttpServletQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/HttpServletQuickFix.java @@ -15,8 +15,6 @@ package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.servlet; -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; import com.intellij.psi.util.PsiTreeUtil; @@ -27,13 +25,13 @@ import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.WorkspaceEdit; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.CancellationException; import java.util.logging.Level; import java.util.logging.Logger; @@ -95,17 +93,17 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { ChangeCorrectionProposal proposal = new ExtendClassProposal(title, context.getCompilationUnit(), context.getSource().getCompilationUnit(), parentType, "jakarta.servlet.http.HttpServlet", 0); - try { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to extend the HttpServlet class.", e); + + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); + toResolve.setEdit(we); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to extend the HttpServlet class.", e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/ListenerImplementationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/ListenerImplementationQuickFix.java index a87b70d93..4352458fd 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/ListenerImplementationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/ListenerImplementationQuickFix.java @@ -15,8 +15,6 @@ package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.servlet; -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; import com.intellij.psi.util.PsiTreeUtil; @@ -27,6 +25,7 @@ import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ImplementInterfaceProposal; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; import org.eclipse.lsp4j.WorkspaceEdit; @@ -36,7 +35,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.CancellationException; import java.util.logging.Level; import java.util.logging.Logger; @@ -99,17 +97,17 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { ChangeCorrectionProposal proposal = new ImplementInterfaceProposal( context.getCompilationUnit(), parentType, context.getASTRoot(), interfaceType, 0, context.getSource().getCompilationUnit()); - try { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to listener implementation", e); + + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); + toResolve.setEdit(we); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to listener implementation", e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationAttributeQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationAttributeQuickFix.java index d8ce79bd7..cfc18eb21 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationAttributeQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationAttributeQuickFix.java @@ -13,13 +13,13 @@ *******************************************************************************/ package io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction; -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; + import com.intellij.psi.PsiAnnotation; import com.intellij.psi.PsiElement; import com.intellij.psi.util.PsiTreeUtil; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.InsertAnnotationAttributeProposal; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.CodeActionKind; import org.eclipse.lsp4j.Diagnostic; @@ -27,11 +27,10 @@ import org.eclipse.lsp4mp.commons.codeaction.MicroProfileCodeActionId; import java.text.MessageFormat; -import java.util.ArrayList; + import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.concurrent.CancellationException; import java.util.logging.Level; import java.util.logging.Logger; @@ -81,16 +80,16 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { String name = getLabel(attributeName); ChangeCorrectionProposal proposal = new InsertAnnotationAttributeProposal(name, context.getCompilationUnit(), annotation, 0, context.getSource().getCompilationUnit(), attributeName); - try { - toResolve.setEdit(context.convertToWorkspaceEdit(proposal)); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Unable to resolve code action edit for inserting an attribute value", e); + + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + toResolve.setEdit(context.convertToWorkspaceEdit(proposal)); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Unable to resolve code action edit for inserting an attribute value", e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationMissingQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationMissingQuickFix.java index 3e9d27c04..b0cfd4c89 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationMissingQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationMissingQuickFix.java @@ -19,12 +19,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.CancellationException; import java.util.logging.Level; import java.util.logging.Logger; -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiModifierListOwner; @@ -32,6 +29,7 @@ import com.intellij.psi.util.PsiTreeUtil; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.InsertAnnotationProposal; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.CodeActionKind; import org.eclipse.lsp4j.Diagnostic; @@ -102,17 +100,17 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { ChangeCorrectionProposal proposal = new InsertAnnotationProposal(name, context.getCompilationUnit(), context.getASTRoot(), parentType, 0, context.getSource().getCompilationUnit(), resolveAnnotationsArray); - try { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to insert missing annotation", e); + + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); + toResolve.setEdit(we); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to insert missing annotation", e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } return toResolve; diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java index 2ba8135da..4d4468d19 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java @@ -21,6 +21,7 @@ import com.intellij.util.xmlb.annotations.Attribute; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.diagnostics.IJavaDiagnosticsParticipant; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.diagnostics.JavaDiagnosticsContext; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.Diagnostic; import org.jetbrains.annotations.Nullable; @@ -66,16 +67,15 @@ public boolean isAdaptedForDiagnostics(JavaDiagnosticsContext context) { @Override public void beginDiagnostics(JavaDiagnosticsContext context) { - try { - getInstance().beginDiagnostics(context); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Error while calling beginDiagnostics", e); + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + getInstance().beginDiagnostics(context); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Error while calling beginDiagnostics", e) + ); + if (success == null || !success) { + System.out.println("An error occurred"); } } @@ -98,16 +98,15 @@ public List collectDiagnostics(JavaDiagnosticsContext context) { @Override public void endDiagnostics(JavaDiagnosticsContext context) { - try { - getInstance().endDiagnostics(context); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Error while calling endDiagnostics", e); + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + getInstance().endDiagnostics(context); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Error while calling endDiagnostics", e) + ); + if (success == null || !success) { + System.out.println("An error occurred"); } } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/health/java/ImplementHealthCheckQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/health/java/ImplementHealthCheckQuickFix.java index 0473435de..39fc7c27c 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/health/java/ImplementHealthCheckQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/health/java/ImplementHealthCheckQuickFix.java @@ -13,11 +13,8 @@ *******************************************************************************/ package io.openliberty.tools.intellij.lsp4mp4ij.psi.internal.health.java; -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiModifierListOwner; import com.intellij.psi.PsiNamedElement; import com.intellij.psi.PsiVariable; import com.intellij.psi.util.PsiTreeUtil; @@ -28,6 +25,7 @@ import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ImplementInterfaceProposal; import io.openliberty.tools.intellij.lsp4mp4ij.psi.internal.health.MicroProfileHealthConstants; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.CodeActionKind; import org.eclipse.lsp4j.Diagnostic; @@ -36,7 +34,6 @@ import java.util.Collections; import java.util.List; -import java.util.concurrent.CancellationException; import java.util.logging.Level; import java.util.logging.Logger; @@ -85,16 +82,16 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { ChangeCorrectionProposal proposal = new ImplementInterfaceProposal(context.getCompilationUnit(), parentType, context.getASTRoot(), MicroProfileHealthConstants.HEALTH_CHECK_INTERFACE, 0, context.getSource().getCompilationUnit()); - try { - toResolve.setEdit(context.convertToWorkspaceEdit(proposal)); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Unable to create workspace edit to make the class implement @HealthCheck", e); + + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + toResolve.setEdit(context.convertToWorkspaceEdit(proposal)); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit to make the class implement @HealthCheck", e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } } return context.getUnresolved(); diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/metrics/java/ApplicationScopedAnnotationMissingQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/metrics/java/ApplicationScopedAnnotationMissingQuickFix.java index de3997302..2e18347d0 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/metrics/java/ApplicationScopedAnnotationMissingQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/metrics/java/ApplicationScopedAnnotationMissingQuickFix.java @@ -13,8 +13,6 @@ *******************************************************************************/ package io.openliberty.tools.intellij.lsp4mp4ij.psi.internal.metrics.java; -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiModifierListOwner; @@ -28,6 +26,7 @@ import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ReplaceAnnotationProposal; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.utils.PsiTypeUtils; import io.openliberty.tools.intellij.lsp4mp4ij.psi.internal.metrics.MicroProfileMetricsConstants; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.CodeActionKind; import org.eclipse.lsp4j.Diagnostic; @@ -36,7 +35,6 @@ import java.util.Collections; import java.util.List; -import java.util.concurrent.CancellationException; import java.util.logging.Level; import java.util.logging.Logger; @@ -101,16 +99,16 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { ChangeCorrectionProposal proposal = new ReplaceAnnotationProposal(name, context.getCompilationUnit(), context.getASTRoot(), parentType, 0, addAnnotation, context.getSource().getCompilationUnit(), REMOVE_ANNOTATION_NAMES); - try { - toResolve.setEdit(context.convertToWorkspaceEdit(proposal)); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Failed to create workspace edit to replace bean scope annotation", e); + + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + toResolve.setEdit(context.convertToWorkspaceEdit(proposal)); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Failed to create workspace edit to replace bean scope annotation", e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } return toResolve; diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/openapi/java/MicroProfileGenerateOpenAPIOperation.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/openapi/java/MicroProfileGenerateOpenAPIOperation.java index 99c9f12c1..0df69c2c1 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/openapi/java/MicroProfileGenerateOpenAPIOperation.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/openapi/java/MicroProfileGenerateOpenAPIOperation.java @@ -14,8 +14,6 @@ package io.openliberty.tools.intellij.lsp4mp4ij.psi.internal.openapi.java; import com.intellij.openapi.module.Module; -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiFile; import com.intellij.psi.util.PsiTreeUtil; @@ -26,6 +24,7 @@ import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.utils.PsiTypeUtils; import io.openliberty.tools.intellij.lsp4mp4ij.psi.internal.openapi.MicroProfileOpenAPIConstants; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.apache.commons.lang3.StringUtils; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.CodeActionKind; @@ -35,7 +34,8 @@ import java.text.MessageFormat; import java.util.*; -import java.util.concurrent.CancellationException; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Generate OpenAPI annotations by the "Source" kind code action. @@ -47,6 +47,8 @@ public class MicroProfileGenerateOpenAPIOperation implements IJavaCodeActionPart private final static String MESSAGE = "Generate OpenAPI Annotations for ''{0}''"; + private static final Logger LOGGER = Logger.getLogger(MicroProfileGenerateOpenAPIOperation.class.getName()); + private final static String TYPE_NAME_KEY = "type"; @Override @@ -123,15 +125,15 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { typeDeclaration, MicroProfileOpenAPIConstants.OPERATION_ANNOTATION, 0, context.getSource().getCompilationUnit()); - try { - toResolve.setEdit(context.convertToWorkspaceEdit(proposal)); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { + Boolean success = ExceptionUtil.executeWithExceptionHandling( + () -> { + toResolve.setEdit(context.convertToWorkspaceEdit(proposal)); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action", e) + ); + if (success == null || !success) { + System.out.println("An error occurred during the code action resolution."); } return toResolve; From 59632c6f9ff516cb4299b6c6269f45064ad07030 Mon Sep 17 00:00:00 2001 From: vaisakhkannan <133869023+vaisakhkannan@users.noreply.github.com> Date: Tue, 22 Oct 2024 13:46:34 +0530 Subject: [PATCH 07/21] Updated warning message --- .../codeAction/proposal/quickfix/InsertAnnotationQuickFix.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java index 7ec9a35fb..eb45dd670 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java @@ -98,7 +98,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { toResolve.setEdit(we); return true; }, - e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action", e) + e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action " + label, e) ); if (success == null || !success) { System.out.println("An error occurred during the code action resolution."); From 7d0d98be26e52f92b91e7174205fe3d828d2dd34 Mon Sep 17 00:00:00 2001 From: vaisakhkannan <133869023+vaisakhkannan@users.noreply.github.com> Date: Tue, 22 Oct 2024 14:49:30 +0530 Subject: [PATCH 08/21] Added code for MicroProfileFaultToleranceASTValidator to use common class --- ...icroProfileFaultToleranceASTValidator.java | 27 ++++++++----------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java index d03d74c21..1562ddc19 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java @@ -14,13 +14,12 @@ package io.openliberty.tools.intellij.lsp4mp4ij.psi.internal.faulttolerance.java; import com.intellij.openapi.module.Module; -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.psi.*; import com.intellij.psi.util.PsiTreeUtil; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.utils.PsiTypeUtils; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.diagnostics.JavaDiagnosticsContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.validators.JavaASTValidator; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.DiagnosticSeverity; import java.text.MessageFormat; @@ -31,7 +30,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; -import java.util.concurrent.CancellationException; +import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -152,19 +151,15 @@ private void validateFallbackAnnotation(PsiMethod node, PsiAnnotation annotation * @param annotation The @Asynchronous annotation */ private void validateAsynchronousAnnotation(PsiMethod node, PsiAnnotation annotation) { - PsiType methodReturnType = node.getReturnType(); - String methodReturnTypeString; - try { - methodReturnTypeString = methodReturnType.getCanonicalText(); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - throw e; - } + // Use lambda expression to avoid code duplication + String methodReturnTypeString = ExceptionUtil.executeWithExceptionHandling( + () -> { + PsiType methodReturnType = node.getReturnType(); + return methodReturnType.getCanonicalText(); + }, + e -> LOGGER.log(Level.WARNING, "An error occurred", e) + ); + if ((!isAllowedReturnTypeForAsynchronousAnnotation(methodReturnTypeString))) { String allowedTypes = allowedReturnTypesForAsynchronousAnnotation.stream() .collect(Collectors.joining("', '", "'", "'")); From f6609f563f3a6a7f6ffe0d88399c48949287a17f Mon Sep 17 00:00:00 2001 From: vaisakhkannan <133869023+vaisakhkannan@users.noreply.github.com> Date: Sun, 27 Oct 2024 14:11:12 +0530 Subject: [PATCH 09/21] done more refactoring --- .../PostConstructReturnTypeQuickFix.java | 14 +--------- .../BeanValidationQuickFix.java | 26 ++----------------- .../ManagedBeanNoArgConstructorQuickFix.java | 14 +--------- .../lsp4ij/cdi/ManagedBeanQuickFix.java | 14 +--------- .../InsertAnnotationMissingQuickFix.java | 14 +--------- .../quickfix/InsertAnnotationQuickFix.java | 14 +--------- .../RemoveAnnotationConflictQuickFix.java | 14 +--------- .../RemoveMethodParametersQuickFix.java | 14 +--------- .../RemoveModifierConflictQuickFix.java | 14 +--------- .../RemoveParamAnnotationQuickFix.java | 13 +--------- .../NoResourcePublicConstructorQuickFix.java | 15 ++--------- .../NonPublicResourceMethodQuickFix.java | 14 +--------- ...rceMethodMultipleEntityParamsQuickFix.java | 14 +--------- .../PersistenceAnnotationQuickFix.java | 14 +--------- .../PersistenceEntityQuickFix.java | 14 +--------- .../CompleteFilterAnnotationQuickFix.java | 26 ++----------------- .../CompleteServletAnnotationQuickFix.java | 26 ++----------------- .../servlet/FilterImplementationQuickFix.java | 14 +--------- .../lsp4ij/servlet/HttpServletQuickFix.java | 14 +--------- .../ListenerImplementationQuickFix.java | 14 +--------- .../InsertAnnotationAttributeQuickFix.java | 12 +-------- .../InsertAnnotationMissingQuickFix.java | 14 +--------- .../JavaDiagnosticsDefinition.java | 6 ----- .../java/ImplementHealthCheckQuickFix.java | 12 +-------- ...cationScopedAnnotationMissingQuickFix.java | 12 +-------- .../MicroProfileGenerateOpenAPIOperation.java | 13 +--------- .../tools/intellij/util/ExceptionUtil.java | 20 ++++++++++++++ 27 files changed, 49 insertions(+), 356 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/annotations/PostConstructReturnTypeQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/annotations/PostConstructReturnTypeQuickFix.java index 9785908bc..b00f72dde 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/annotations/PostConstructReturnTypeQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/annotations/PostConstructReturnTypeQuickFix.java @@ -26,11 +26,9 @@ import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; -import org.eclipse.lsp4j.WorkspaceEdit; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; import java.util.logging.Logger; /** @@ -72,17 +70,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { ChangeCorrectionProposal proposal = new ModifyReturnTypeProposal(TITLE_MESSAGE, context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, 0, PsiTypes.voidType()); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to change return type to void", e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit for code action to change return type to void"); return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/beanvalidation/BeanValidationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/beanvalidation/BeanValidationQuickFix.java index d2a57c371..89a3635c6 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/beanvalidation/BeanValidationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/beanvalidation/BeanValidationQuickFix.java @@ -24,11 +24,9 @@ import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; -import org.eclipse.lsp4j.WorkspaceEdit; import org.eclipse.lsp4mp.commons.codeaction.CodeActionResolveData; import java.util.*; -import java.util.logging.Level; import java.util.logging.Logger; /** @@ -109,17 +107,7 @@ private void resolveRemoveConstraintAnnotationsCodeAction(JavaCodeActionResolveC final RemoveAnnotationsProposal proposal = new RemoveAnnotationsProposal(name, context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, 0, Collections.singletonList(annotationToRemove.get()), isFormatRequired); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to remove constraint annotation", e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit for code action to remove constraint annotation"); } } } @@ -135,17 +123,7 @@ private void resolveStaticModifierCodeAction(JavaCodeActionResolveContext contex context.getASTRoot(), parentType, 0, modifierListOwner.getModifierList(), Collections.emptyList(), Collections.singletonList("static")); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to remove static modifier", e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit for code action to remove static modifier"); } private void removeStaticModifierCodeActions(Diagnostic diagnostic, JavaCodeActionContext context, diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/cdi/ManagedBeanNoArgConstructorQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/cdi/ManagedBeanNoArgConstructorQuickFix.java index d790cf120..d62c3ce56 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/cdi/ManagedBeanNoArgConstructorQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/cdi/ManagedBeanNoArgConstructorQuickFix.java @@ -26,12 +26,10 @@ import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; -import org.eclipse.lsp4j.WorkspaceEdit; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.logging.Level; import java.util.logging.Logger; /** @@ -72,17 +70,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, 0, constructorName.equals(Messages.getMessage("AddProtectedConstructor")) ? "protected" : "public"); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code actions to add constructors", e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit for code actions to add constructors"); return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/cdi/ManagedBeanQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/cdi/ManagedBeanQuickFix.java index 4a264fac5..239303fd9 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/cdi/ManagedBeanQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/cdi/ManagedBeanQuickFix.java @@ -27,11 +27,9 @@ import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; -import org.eclipse.lsp4j.WorkspaceEdit; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; import java.util.logging.Logger; import static io.openliberty.tools.intellij.lsp4jakarta.lsp4ij.cdi.ManagedBeanConstants.SCOPE_FQ_NAMES; @@ -72,17 +70,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { context.getASTRoot(), parentType, 0, ADD_ANNOTATION, context.getSource().getCompilationUnit(), REMOVE_ANNOTATION_NAMES); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action", e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit for code action"); return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationMissingQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationMissingQuickFix.java index cedfd253a..c2683e005 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationMissingQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationMissingQuickFix.java @@ -26,10 +26,8 @@ import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; -import org.eclipse.lsp4j.WorkspaceEdit; import java.util.*; -import java.util.logging.Level; import java.util.logging.Logger; /** @@ -89,17 +87,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { context.getASTRoot(), parentType, 0, context.getSource().getCompilationUnit(), annotations); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action.", e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit for code action."); return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java index eb45dd670..dc19ca9e7 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/InsertAnnotationQuickFix.java @@ -28,12 +28,10 @@ import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; -import org.eclipse.lsp4j.WorkspaceEdit; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.logging.Level; import java.util.logging.Logger; /** @@ -92,17 +90,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { ChangeCorrectionProposal proposal = new ModifyAnnotationProposal(label, context.getSource().getCompilationUnit(), context.getASTRoot(), binding, annotationNode, 0, this.annotation, Arrays.asList(attributes)); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action " + label, e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit for code action " + label); return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveAnnotationConflictQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveAnnotationConflictQuickFix.java index f9a2cb769..5121ac425 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveAnnotationConflictQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveAnnotationConflictQuickFix.java @@ -31,7 +31,6 @@ import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; -import org.eclipse.lsp4j.WorkspaceEdit; import org.eclipse.lsp4mp.commons.codeaction.CodeActionResolveData; import java.util.HashMap; @@ -40,7 +39,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Collectors; @@ -115,17 +113,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { ChangeCorrectionProposal proposal = new DeleteAnnotationProposal(name, context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, 0, declaringNode, resolveAnnotationsArray); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to remove annotation", e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit for code action to remove annotation"); return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveMethodParametersQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveMethodParametersQuickFix.java index b77e33031..91f0b4296 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveMethodParametersQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveMethodParametersQuickFix.java @@ -28,12 +28,10 @@ import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; -import org.eclipse.lsp4j.WorkspaceEdit; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.logging.Level; import java.util.logging.Logger; /** @@ -74,17 +72,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { ChangeCorrectionProposal proposal = new RemoveParamsProposal(NAME, context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, 0, Arrays.asList(parameterList.getParameters()), false); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action", e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit for code action"); return toResolve; } } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveModifierConflictQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveModifierConflictQuickFix.java index da33f388b..01ec25ddb 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveModifierConflictQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveModifierConflictQuickFix.java @@ -24,13 +24,11 @@ import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; -import org.eclipse.lsp4j.WorkspaceEdit; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.logging.Level; import java.util.logging.Logger; /** @@ -106,17 +104,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { ModifyModifiersProposal proposal = new ModifyModifiersProposal(label, context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, 0, modifierListOwner.getModifierList(), Collections.emptyList(), Arrays.asList(modifiers), false); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action " + label, e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit for code action " + label); return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveParamAnnotationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveParamAnnotationQuickFix.java index bc4bd2543..1c9c606ed 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveParamAnnotationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/codeAction/proposal/quickfix/RemoveParamAnnotationQuickFix.java @@ -23,7 +23,6 @@ import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; - import org.eclipse.lsp4j.WorkspaceEdit; import org.eclipse.lsp4mp.commons.codeaction.CodeActionResolveData; import java.util.*; @@ -120,17 +119,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { RemoveAnnotationsProposal proposal = new RemoveAnnotationsProposal(label, context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, 0, psiAnnotationsToRemove); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to extend the HttpServlet class", e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit for code action to extend the HttpServlet class"); return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/NoResourcePublicConstructorQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/NoResourcePublicConstructorQuickFix.java index f656c95d6..cdff757be 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/NoResourcePublicConstructorQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/NoResourcePublicConstructorQuickFix.java @@ -28,12 +28,10 @@ import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; -import org.eclipse.lsp4j.WorkspaceEdit; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.logging.Level; import java.util.logging.Logger; /** @@ -101,16 +99,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { } public void convertWorkspaceEdit(ChangeCorrectionProposal proposal, String warningMessage, JavaCodeActionResolveContext context) { - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - context.getUnresolved().setEdit(we); - return true; - }, - e -> LOGGER.log(Level.WARNING, warningMessage, e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + final CodeAction toResolve = context.getUnresolved(); + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, warningMessage); } } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/NonPublicResourceMethodQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/NonPublicResourceMethodQuickFix.java index c25a94f32..815776b9b 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/NonPublicResourceMethodQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/NonPublicResourceMethodQuickFix.java @@ -27,11 +27,9 @@ import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; -import org.eclipse.lsp4j.WorkspaceEdit; import java.util.Collections; import java.util.List; -import java.util.logging.Level; import java.util.logging.Logger; /** @@ -76,17 +74,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { ChangeCorrectionProposal proposal = new ModifyModifiersProposal(TITLE_MESSAGE, context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, 0, parentMethod.getModifierList(), Collections.singletonList("public")); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to make method public", e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit for code action to make method public"); return toResolve; } } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/ResourceMethodMultipleEntityParamsQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/ResourceMethodMultipleEntityParamsQuickFix.java index c60594fcb..57b6d5162 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/ResourceMethodMultipleEntityParamsQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/jax_rs/ResourceMethodMultipleEntityParamsQuickFix.java @@ -25,11 +25,9 @@ import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; -import org.eclipse.lsp4j.WorkspaceEdit; import org.eclipse.lsp4mp.commons.codeaction.CodeActionResolveData; import java.util.*; -import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Collectors; @@ -127,17 +125,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { ChangeCorrectionProposal proposal = new RemoveParamsProposal(title, context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, 0, entityParams, false); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action", e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit for code action"); return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/persistence/PersistenceAnnotationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/persistence/PersistenceAnnotationQuickFix.java index de0f5d5e4..5d02f8170 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/persistence/PersistenceAnnotationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/persistence/PersistenceAnnotationQuickFix.java @@ -23,12 +23,10 @@ import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; -import org.eclipse.lsp4j.WorkspaceEdit; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.logging.Level; import java.util.logging.Logger; import java.util.stream.Collectors; @@ -73,17 +71,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { ChangeCorrectionProposal proposal = new ModifyAnnotationProposal(name, context.getSource().getCompilationUnit(), context.getASTRoot(), binding, annotationNode, 0, attributes, this.getAnnotations()); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action.", e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit for code action."); } return toResolve; diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/persistence/PersistenceEntityQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/persistence/PersistenceEntityQuickFix.java index 54772eda0..d8c324e93 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/persistence/PersistenceEntityQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/persistence/PersistenceEntityQuickFix.java @@ -25,11 +25,9 @@ import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; -import org.eclipse.lsp4j.WorkspaceEdit; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; import java.util.logging.Logger; /** @@ -90,17 +88,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, 0, constructorName.equals(Messages.getMessage("AddNoArgProtectedConstructor")) ? "protected" : "public"); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code actions to add constructors", e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit for code actions to add constructors"); return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/CompleteFilterAnnotationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/CompleteFilterAnnotationQuickFix.java index c6ff06d4d..48d88491e 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/CompleteFilterAnnotationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/CompleteFilterAnnotationQuickFix.java @@ -28,14 +28,12 @@ import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; -import org.eclipse.lsp4j.WorkspaceEdit; import org.eclipse.lsp4mp.commons.codeaction.CodeActionResolveData; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.logging.Level; import java.util.logging.Logger; /** @@ -101,17 +99,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { ChangeCorrectionProposal proposal = new ModifyAnnotationProposal(name, context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, annotationNode, 0, annotation, attributesToAdd); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action.", e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit for code action."); } if (diagnosticCode.equals(ServletConstants.DIAGNOSTIC_CODE_FILTER_DUPLICATE_ATTRIBUTES)) { @@ -125,17 +113,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { ChangeCorrectionProposal proposal = new ModifyAnnotationProposal(name, context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, annotationNode, 0, annotation, new ArrayList(), attributesToRemove); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action.", e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit for code action."); } return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/CompleteServletAnnotationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/CompleteServletAnnotationQuickFix.java index 01bacb506..d50a53469 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/CompleteServletAnnotationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/CompleteServletAnnotationQuickFix.java @@ -28,14 +28,12 @@ import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; -import org.eclipse.lsp4j.WorkspaceEdit; import org.eclipse.lsp4mp.commons.codeaction.CodeActionResolveData; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.logging.Level; import java.util.logging.Logger; /** @@ -100,17 +98,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { ChangeCorrectionProposal proposal = new ModifyAnnotationProposal(name, context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, annotationNode, 0, annotation, attributesToAdd); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action.", e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit for code action."); } if (diagnosticCode.equals(ServletConstants.DIAGNOSTIC_CODE_DUPLICATE_ATTRIBUTES)) { node = context.getCoveringNode(); @@ -123,17 +111,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { ChangeCorrectionProposal proposal = new ModifyAnnotationProposal(name, context.getSource().getCompilationUnit(), context.getASTRoot(), parentType, annotationNode, 0, annotation, new ArrayList(), attributesToRemove); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action.", e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit for code action."); } return toResolve; diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/FilterImplementationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/FilterImplementationQuickFix.java index e27267c59..ea727581d 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/FilterImplementationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/FilterImplementationQuickFix.java @@ -27,11 +27,9 @@ import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; -import org.eclipse.lsp4j.WorkspaceEdit; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; import java.util.logging.Logger; /** @@ -77,17 +75,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { context.getCompilationUnit(), parentType, context.getASTRoot(), "jakarta.servlet.Filter", 0, context.getSource().getCompilationUnit()); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to filter implementation", e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit for code action to filter implementation"); return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/HttpServletQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/HttpServletQuickFix.java index 5a9803296..eb1b3ae56 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/HttpServletQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/HttpServletQuickFix.java @@ -28,11 +28,9 @@ import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; -import org.eclipse.lsp4j.WorkspaceEdit; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; import java.util.logging.Logger; /** @@ -94,17 +92,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { context.getSource().getCompilationUnit(), parentType, "jakarta.servlet.http.HttpServlet", 0); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to extend the HttpServlet class.", e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit for code action to extend the HttpServlet class."); return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/ListenerImplementationQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/ListenerImplementationQuickFix.java index 4352458fd..e8db20899 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/ListenerImplementationQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/servlet/ListenerImplementationQuickFix.java @@ -28,14 +28,12 @@ import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.Diagnostic; -import org.eclipse.lsp4j.WorkspaceEdit; import org.eclipse.lsp4mp.commons.codeaction.CodeActionResolveData; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.logging.Level; import java.util.logging.Logger; /** @@ -98,17 +96,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { context.getCompilationUnit(), parentType, context.getASTRoot(), interfaceType, 0, context.getSource().getCompilationUnit()); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to listener implementation", e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit for code action to listener implementation"); return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationAttributeQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationAttributeQuickFix.java index cfc18eb21..8c0109dab 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationAttributeQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationAttributeQuickFix.java @@ -31,7 +31,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.logging.Level; import java.util.logging.Logger; /** @@ -81,16 +80,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { ChangeCorrectionProposal proposal = new InsertAnnotationAttributeProposal(name, context.getCompilationUnit(), annotation, 0, context.getSource().getCompilationUnit(), attributeName); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - toResolve.setEdit(context.convertToWorkspaceEdit(proposal)); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Unable to resolve code action edit for inserting an attribute value", e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to resolve code action edit for inserting an attribute value"); return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationMissingQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationMissingQuickFix.java index b0cfd4c89..daa81cd75 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationMissingQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/codeaction/InsertAnnotationMissingQuickFix.java @@ -19,7 +19,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.logging.Level; import java.util.logging.Logger; import com.intellij.psi.PsiClass; @@ -33,7 +32,6 @@ import org.eclipse.lsp4j.CodeAction; import org.eclipse.lsp4j.CodeActionKind; import org.eclipse.lsp4j.Diagnostic; -import org.eclipse.lsp4j.WorkspaceEdit; import org.eclipse.lsp4mp.commons.codeaction.CodeActionResolveData; import org.eclipse.lsp4mp.commons.codeaction.ICodeActionId; @@ -101,17 +99,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { context.getASTRoot(), parentType, 0, context.getSource().getCompilationUnit(), resolveAnnotationsArray); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); - toResolve.setEdit(we); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action to insert missing annotation", e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit for code action to insert missing annotation"); return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java index 4d4468d19..423e5a42e 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java @@ -74,9 +74,6 @@ public void beginDiagnostics(JavaDiagnosticsContext context) { }, e -> LOGGER.log(Level.WARNING, "Error while calling beginDiagnostics", e) ); - if (success == null || !success) { - System.out.println("An error occurred"); - } } @Override @@ -105,9 +102,6 @@ public void endDiagnostics(JavaDiagnosticsContext context) { }, e -> LOGGER.log(Level.WARNING, "Error while calling endDiagnostics", e) ); - if (success == null || !success) { - System.out.println("An error occurred"); - } } public @Nullable String getGroup() { diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/health/java/ImplementHealthCheckQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/health/java/ImplementHealthCheckQuickFix.java index 39fc7c27c..9c0375a34 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/health/java/ImplementHealthCheckQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/health/java/ImplementHealthCheckQuickFix.java @@ -34,7 +34,6 @@ import java.util.Collections; import java.util.List; -import java.util.logging.Level; import java.util.logging.Logger; /** @@ -83,16 +82,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { context.getASTRoot(), MicroProfileHealthConstants.HEALTH_CHECK_INTERFACE, 0, context.getSource().getCompilationUnit()); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - toResolve.setEdit(context.convertToWorkspaceEdit(proposal)); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit to make the class implement @HealthCheck", e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit to make the class implement @HealthCheck"); } return context.getUnresolved(); } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/metrics/java/ApplicationScopedAnnotationMissingQuickFix.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/metrics/java/ApplicationScopedAnnotationMissingQuickFix.java index 2e18347d0..c41547b2f 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/metrics/java/ApplicationScopedAnnotationMissingQuickFix.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/metrics/java/ApplicationScopedAnnotationMissingQuickFix.java @@ -35,7 +35,6 @@ import java.util.Collections; import java.util.List; -import java.util.logging.Level; import java.util.logging.Logger; /** @@ -100,16 +99,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { context.getASTRoot(), parentType, 0, addAnnotation, context.getSource().getCompilationUnit(), REMOVE_ANNOTATION_NAMES); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - toResolve.setEdit(context.convertToWorkspaceEdit(proposal)); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Failed to create workspace edit to replace bean scope annotation", e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Failed to create workspace edit to replace bean scope annotation"); return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/openapi/java/MicroProfileGenerateOpenAPIOperation.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/openapi/java/MicroProfileGenerateOpenAPIOperation.java index 0df69c2c1..250582021 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/openapi/java/MicroProfileGenerateOpenAPIOperation.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/openapi/java/MicroProfileGenerateOpenAPIOperation.java @@ -34,7 +34,6 @@ import java.text.MessageFormat; import java.util.*; -import java.util.logging.Level; import java.util.logging.Logger; /** @@ -125,17 +124,7 @@ public CodeAction resolveCodeAction(JavaCodeActionResolveContext context) { typeDeclaration, MicroProfileOpenAPIConstants.OPERATION_ANNOTATION, 0, context.getSource().getCompilationUnit()); - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - toResolve.setEdit(context.convertToWorkspaceEdit(proposal)); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Unable to create workspace edit for code action", e) - ); - if (success == null || !success) { - System.out.println("An error occurred during the code action resolution."); - } - + ExceptionUtil.executeWithWorkspaceEditHandling(context, proposal, toResolve, LOGGER, "Unable to create workspace edit for code action"); return toResolve; } diff --git a/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java b/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java index 9c3fd93fb..e0c59a997 100644 --- a/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java +++ b/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java @@ -15,6 +15,12 @@ import java.util.concurrent.CancellationException; import java.util.function.Consumer; import java.util.function.Supplier; +import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext; +import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal; +import org.eclipse.lsp4j.CodeAction; +import org.eclipse.lsp4j.WorkspaceEdit; +import java.util.logging.Level; +import java.util.logging.Logger; public class ExceptionUtil { @@ -32,4 +38,18 @@ public static T executeWithExceptionHandling(Supplier action, Consumer { + int a =10; + int b = 0; + int c = a / b; + WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); + toResolve.setEdit(we); + return true; + }, + e -> logger.log(Level.WARNING, logMessage, e) + ); + } } \ No newline at end of file From d642c67328721b4d0ba0ad0a8fbbebf403869b61 Mon Sep 17 00:00:00 2001 From: vaisakhkannan <133869023+vaisakhkannan@users.noreply.github.com> Date: Mon, 28 Oct 2024 12:08:43 +0530 Subject: [PATCH 10/21] Added more refactored code --- .../annotations/AnnotationValidator.java | 1 - .../completion/JavaCompletionDefinition.java | 2 -- .../JavaDiagnosticsDefinition.java | 26 +++++++++---------- ...icroProfileFaultToleranceASTValidator.java | 10 +++---- .../tools/intellij/util/ExceptionUtil.java | 5 +--- 5 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java index 9b729aab1..5fed3937f 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java @@ -95,7 +95,6 @@ public String validate(String value, AnnotationAttributeRule rule) { return rule.validate(value); } catch (ProcessCanceledException e) { //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 throw e; } catch (IndexNotReadyException | CancellationException e) { throw e; diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/completion/JavaCompletionDefinition.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/completion/JavaCompletionDefinition.java index 3baa5cb71..9ba5225aa 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/completion/JavaCompletionDefinition.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/completion/JavaCompletionDefinition.java @@ -54,7 +54,6 @@ public boolean isAdaptedForCompletion(JavaCompletionContext context) { return getInstance().isAdaptedForCompletion(context); } catch (ProcessCanceledException e) { //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 throw e; } catch (IndexNotReadyException | CancellationException e) { throw e; @@ -71,7 +70,6 @@ public List collectCompletionItems(JavaCompletionConte return getInstance().collectCompletionItems(context); } catch (ProcessCanceledException e) { //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 throw e; } catch (IndexNotReadyException | CancellationException e) { throw e; diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java index 423e5a42e..1440ee4a9 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java @@ -55,7 +55,6 @@ public boolean isAdaptedForDiagnostics(JavaDiagnosticsContext context) { return getInstance().isAdaptedForDiagnostics(context); } catch (ProcessCanceledException e) { //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 throw e; } catch (IndexNotReadyException | CancellationException e) { throw e; @@ -67,12 +66,12 @@ public boolean isAdaptedForDiagnostics(JavaDiagnosticsContext context) { @Override public void beginDiagnostics(JavaDiagnosticsContext context) { - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - getInstance().beginDiagnostics(context); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Error while calling beginDiagnostics", e) + ExceptionUtil.executeWithExceptionHandling( + () -> { + getInstance().beginDiagnostics(context); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Error while calling beginDiagnostics", e) ); } @@ -83,7 +82,6 @@ public List collectDiagnostics(JavaDiagnosticsContext context) { return diagnostics != null ? diagnostics : Collections.emptyList(); } catch (ProcessCanceledException e) { //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - //TODO delete block when minimum required version is 2024.2 throw e; } catch (IndexNotReadyException | CancellationException e) { throw e; @@ -95,12 +93,12 @@ public List collectDiagnostics(JavaDiagnosticsContext context) { @Override public void endDiagnostics(JavaDiagnosticsContext context) { - Boolean success = ExceptionUtil.executeWithExceptionHandling( - () -> { - getInstance().endDiagnostics(context); - return true; - }, - e -> LOGGER.log(Level.WARNING, "Error while calling endDiagnostics", e) + ExceptionUtil.executeWithExceptionHandling( + () -> { + getInstance().endDiagnostics(context); + return true; + }, + e -> LOGGER.log(Level.WARNING, "Error while calling endDiagnostics", e) ); } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java index 1562ddc19..57306a55d 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java @@ -153,11 +153,11 @@ private void validateFallbackAnnotation(PsiMethod node, PsiAnnotation annotation private void validateAsynchronousAnnotation(PsiMethod node, PsiAnnotation annotation) { // Use lambda expression to avoid code duplication String methodReturnTypeString = ExceptionUtil.executeWithExceptionHandling( - () -> { - PsiType methodReturnType = node.getReturnType(); - return methodReturnType.getCanonicalText(); - }, - e -> LOGGER.log(Level.WARNING, "An error occurred", e) + () -> { + PsiType methodReturnType = node.getReturnType(); + return methodReturnType.getCanonicalText(); + }, + e -> LOGGER.log(Level.WARNING, "An error occurred", e) ); if ((!isAllowedReturnTypeForAsynchronousAnnotation(methodReturnTypeString))) { diff --git a/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java b/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java index e0c59a997..12b9e40ed 100644 --- a/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java +++ b/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java @@ -40,11 +40,8 @@ public static T executeWithExceptionHandling(Supplier action, Consumer { - int a =10; - int b = 0; - int c = a / b; WorkspaceEdit we = context.convertToWorkspaceEdit(proposal); toResolve.setEdit(we); return true; From de487846103b16e7c3e11a973be8a2778395837f Mon Sep 17 00:00:00 2001 From: vaisakhkannan <133869023+vaisakhkannan@users.noreply.github.com> Date: Fri, 1 Nov 2024 16:04:53 +0530 Subject: [PATCH 11/21] Refactored some code --- .../JavaDiagnosticsDefinition.java | 23 +++++++++---------- ...icroProfileFaultToleranceASTValidator.java | 1 + .../tools/intellij/util/ExceptionUtil.java | 6 ++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java index 1440ee4a9..d489d8532 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java @@ -71,26 +71,24 @@ public void beginDiagnostics(JavaDiagnosticsContext context) { getInstance().beginDiagnostics(context); return true; }, + null, e -> LOGGER.log(Level.WARNING, "Error while calling beginDiagnostics", e) ); } @Override public List collectDiagnostics(JavaDiagnosticsContext context) { - try { - List diagnostics = getInstance().collectDiagnostics(context); - return diagnostics != null ? diagnostics : Collections.emptyList(); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, "Error while calling collectDiagnostics", e); - return Collections.emptyList(); - } + return ExceptionUtil.executeWithExceptionHandling( + () -> { + List diagnostics = getInstance().collectDiagnostics(context); + return diagnostics != null ? diagnostics : Collections.emptyList(); + }, + Collections::emptyList, + e -> LOGGER.log(Level.WARNING, "Error while calling collectDiagnostics", e) + ); } + @Override public void endDiagnostics(JavaDiagnosticsContext context) { ExceptionUtil.executeWithExceptionHandling( @@ -98,6 +96,7 @@ public void endDiagnostics(JavaDiagnosticsContext context) { getInstance().endDiagnostics(context); return true; }, + null, e -> LOGGER.log(Level.WARNING, "Error while calling endDiagnostics", e) ); } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java index 57306a55d..52f5fad55 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java @@ -157,6 +157,7 @@ private void validateAsynchronousAnnotation(PsiMethod node, PsiAnnotation annota PsiType methodReturnType = node.getReturnType(); return methodReturnType.getCanonicalText(); }, + null, e -> LOGGER.log(Level.WARNING, "An error occurred", e) ); diff --git a/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java b/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java index 12b9e40ed..3dc05023e 100644 --- a/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java +++ b/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java @@ -24,7 +24,7 @@ public class ExceptionUtil { - public static T executeWithExceptionHandling(Supplier action, Consumer logger) { + public static T executeWithExceptionHandling(Supplier action, Supplier fallback, Consumer logger) { try { return action.get(); } catch (ProcessCanceledException e) { @@ -33,9 +33,8 @@ public static T executeWithExceptionHandling(Supplier action, Consumer logger.log(Level.WARNING, logMessage, e) ); } From 5568f5431d8ea9572bd6da6bff301dde3bb91e41 Mon Sep 17 00:00:00 2001 From: vaisakhkannan <133869023+vaisakhkannan@users.noreply.github.com> Date: Fri, 1 Nov 2024 16:22:20 +0530 Subject: [PATCH 12/21] Modified code in AnnotationUtil.java class --- .../lsp4jakarta/lsp4ij/AnnotationUtil.java | 38 ++++++------------- .../JavaDiagnosticsDefinition.java | 16 +++----- 2 files changed, 17 insertions(+), 37 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AnnotationUtil.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AnnotationUtil.java index d0adb0005..8cfd30cf4 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AnnotationUtil.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AnnotationUtil.java @@ -12,17 +12,16 @@ package io.openliberty.tools.intellij.lsp4jakarta.lsp4ij; -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.psi.PsiClass; +import io.openliberty.tools.intellij.util.ExceptionUtil; import java.util.Arrays; import java.util.List; import java.util.Set; -import java.util.concurrent.CancellationException; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.Collections; -import java.util.function.Supplier; /** * Returns the list of recognised defining annotations applied to a @@ -33,29 +32,16 @@ * @return list of recognised defining annotations applied to a class */ public class AnnotationUtil { + private static final Logger LOGGER = Logger.getLogger(AnnotationUtil.class.getName()); public static List getScopeAnnotations(PsiClass type, Set scopes) { - return executeWithExceptionHandling(() -> - // Construct a stream of only the annotations applied to the type that are also - // recognised annotations found in scopes. - Arrays.stream(type.getAnnotations()) - .map(annotation -> annotation.getNameReferenceElement().getQualifiedName()) - .filter(scopes::contains) - .distinct() - .collect(Collectors.toList()), - Collections::emptyList + return ExceptionUtil.executeWithExceptionHandling( + () -> Arrays.stream(type.getAnnotations()) + .map(annotation -> annotation.getNameReferenceElement().getQualifiedName()) + .filter(scopes::contains) + .distinct() + .collect(Collectors.toList()), + Collections::emptyList, // Fallback value in case of exception + e -> LOGGER.log(Level.WARNING, "Error while calling getScopeAnnotations", e) ); } - - private static T executeWithExceptionHandling(Supplier action, Supplier fallback) { - try { - return action.get(); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multi-catch to keep backward compatibility - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - return fallback.get(); // Return fallback value - } - } } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java index d489d8532..5e78c14f8 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java @@ -51,17 +51,11 @@ public final class JavaDiagnosticsDefinition extends BaseKeyedLazyInstance getInstance().isAdaptedForDiagnostics(context), + () -> false, // Fallback value in case of exception + e -> LOGGER.log(Level.WARNING, "Error while calling isAdaptedForDiagnostics", e) + ); } @Override From b048a86f46decffdb91be7bf0d9f85fef9b88df1 Mon Sep 17 00:00:00 2001 From: vaisakhkannan <133869023+vaisakhkannan@users.noreply.github.com> Date: Fri, 1 Nov 2024 16:40:38 +0530 Subject: [PATCH 13/21] Completed whole refactoring --- .../annotations/AnnotationValidator.java | 25 ++++++------ .../completion/JavaCompletionDefinition.java | 38 ++++++------------- .../tools/intellij/util/ExceptionUtil.java | 1 + 3 files changed, 23 insertions(+), 41 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java index 5fed3937f..7614cb00b 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java @@ -16,6 +16,7 @@ import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.project.IndexNotReadyException; +import io.openliberty.tools.intellij.util.ExceptionUtil; import java.util.Collection; import java.util.HashMap; @@ -88,20 +89,16 @@ public void unregisterRule(AnnotationRule rule) { * @return the error message of the validation result of the attribute value and null otherwise. */ public String validate(String value, AnnotationAttributeRule rule) { - try { - if (rule == null) { - return null; - } - return rule.validate(value); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } catch (Exception e) { - LOGGER.log(Level.WARNING, e.getLocalizedMessage(), e); - return null; - } + return ExceptionUtil.executeWithExceptionHandling( + () -> { + if (rule == null) { + return null; + } + return rule.validate(value); + }, + null, // Fallback value in case of exception + e -> LOGGER.log(Level.WARNING, e.getLocalizedMessage(), e) + ); } /** diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/completion/JavaCompletionDefinition.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/completion/JavaCompletionDefinition.java index 9ba5225aa..5c670e72b 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/completion/JavaCompletionDefinition.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/completion/JavaCompletionDefinition.java @@ -15,18 +15,16 @@ package io.openliberty.tools.intellij.lsp4mp4ij.psi.internal.core.java.completion; import com.intellij.openapi.extensions.ExtensionPointName; -import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.serviceContainer.BaseKeyedLazyInstance; import com.intellij.util.xmlb.annotations.Attribute; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.completion.IJavaCompletionParticipant; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.completion.JavaCompletionContext; +import io.openliberty.tools.intellij.util.ExceptionUtil; import org.eclipse.lsp4j.CompletionItem; import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.List; -import java.util.concurrent.CancellationException; import java.util.logging.Level; import java.util.logging.Logger; @@ -50,34 +48,20 @@ public final class JavaCompletionDefinition extends BaseKeyedLazyInstance getInstance().isAdaptedForCompletion(context), + () -> false, // Fallback value in case of exception + e -> LOGGER.log(Level.WARNING, "Error while calling isAdaptedForCompletion", e) + ); } @Override public List collectCompletionItems(JavaCompletionContext context) { - try { - return getInstance().collectCompletionItems(context); - } catch (ProcessCanceledException e) { - //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multicatch to keep backward compatibility - throw e; - } catch (IndexNotReadyException | CancellationException e) { - throw e; - } - catch (Exception e) { - LOGGER.log(Level.WARNING, "Error while calling collectCompletionItems", e); - return Collections.emptyList(); - } + return ExceptionUtil.executeWithExceptionHandling( + () -> getInstance().collectCompletionItems(context), + Collections::emptyList, // Fallback value in case of exception + e -> LOGGER.log(Level.WARNING, "Error while calling collectCompletionItems", e) + ); } public @Nullable String getGroup() { diff --git a/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java b/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java index 3dc05023e..73bc4f208 100644 --- a/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java +++ b/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java @@ -29,6 +29,7 @@ public static T executeWithExceptionHandling(Supplier action, Supplier return action.get(); } catch (ProcessCanceledException e) { //Since 2024.2 ProcessCanceledException extends CancellationException so we can't use multi-catch to keep backward compatibility + //TODO delete block when minimum required version is 2024.2 throw e; } catch (IndexNotReadyException | CancellationException e) { throw e; From f7a720f69763be3d06533718ce48e36fe91f998f Mon Sep 17 00:00:00 2001 From: vaisakhkannan <133869023+vaisakhkannan@users.noreply.github.com> Date: Tue, 5 Nov 2024 08:51:37 +0530 Subject: [PATCH 14/21] Replaced null with () -> null for the fallback value --- .../core/java/validators/annotations/AnnotationValidator.java | 2 +- .../core/java/corrections/JavaDiagnosticsDefinition.java | 4 ++-- .../io/openliberty/tools/intellij/util/ExceptionUtil.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java index 7614cb00b..131e2b688 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java @@ -96,7 +96,7 @@ public String validate(String value, AnnotationAttributeRule rule) { } return rule.validate(value); }, - null, // Fallback value in case of exception + () -> null, // Fallback value supplier in case of exception e -> LOGGER.log(Level.WARNING, e.getLocalizedMessage(), e) ); } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java index 5e78c14f8..9c7c32f1d 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java @@ -65,7 +65,7 @@ public void beginDiagnostics(JavaDiagnosticsContext context) { getInstance().beginDiagnostics(context); return true; }, - null, + () -> null, // Fallback value supplier in case of exception e -> LOGGER.log(Level.WARNING, "Error while calling beginDiagnostics", e) ); } @@ -90,7 +90,7 @@ public void endDiagnostics(JavaDiagnosticsContext context) { getInstance().endDiagnostics(context); return true; }, - null, + () -> null, // Fallback value supplier in case of exception e -> LOGGER.log(Level.WARNING, "Error while calling endDiagnostics", e) ); } diff --git a/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java b/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java index 73bc4f208..1eff96f3b 100644 --- a/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java +++ b/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java @@ -46,7 +46,7 @@ public static void executeWithWorkspaceEditHandling(JavaCodeActionResolveContext toResolve.setEdit(we); return true; }, - null, + () -> null, // Fallback value supplier in case of exception e -> logger.log(Level.WARNING, logMessage, e) ); } From 283a777ba51adfc729b97eba6314a317a82d7b1d Mon Sep 17 00:00:00 2001 From: vaisakhkannan <133869023+vaisakhkannan@users.noreply.github.com> Date: Tue, 5 Nov 2024 10:37:18 +0530 Subject: [PATCH 15/21] Did change on method executeWithExceptionHandling --- .../lsp4jakarta/lsp4ij/AnnotationUtil.java | 6 +++-- .../annotations/AnnotationValidator.java | 6 +++-- .../completion/JavaCompletionDefinition.java | 12 ++++++---- .../JavaDiagnosticsDefinition.java | 24 ++++++++++++------- ...icroProfileFaultToleranceASTValidator.java | 6 +++-- .../tools/intellij/util/ExceptionUtil.java | 13 ++++++---- 6 files changed, 44 insertions(+), 23 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AnnotationUtil.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AnnotationUtil.java index 8cfd30cf4..c700dd0ec 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AnnotationUtil.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AnnotationUtil.java @@ -40,8 +40,10 @@ public static List getScopeAnnotations(PsiClass type, Set scopes .filter(scopes::contains) .distinct() .collect(Collectors.toList()), - Collections::emptyList, // Fallback value in case of exception - e -> LOGGER.log(Level.WARNING, "Error while calling getScopeAnnotations", e) + e -> { + LOGGER.log(Level.WARNING, "Error while calling getScopeAnnotations", e); + return Collections.emptyList(); + } ); } } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java index 131e2b688..d8747d057 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java @@ -96,8 +96,10 @@ public String validate(String value, AnnotationAttributeRule rule) { } return rule.validate(value); }, - () -> null, // Fallback value supplier in case of exception - e -> LOGGER.log(Level.WARNING, e.getLocalizedMessage(), e) + e -> { + LOGGER.log(Level.WARNING, e.getLocalizedMessage(), e); + return null; + } ); } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/completion/JavaCompletionDefinition.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/completion/JavaCompletionDefinition.java index 5c670e72b..b1f39de33 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/completion/JavaCompletionDefinition.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/completion/JavaCompletionDefinition.java @@ -50,8 +50,10 @@ public final class JavaCompletionDefinition extends BaseKeyedLazyInstance getInstance().isAdaptedForCompletion(context), - () -> false, // Fallback value in case of exception - e -> LOGGER.log(Level.WARNING, "Error while calling isAdaptedForCompletion", e) + e -> { + LOGGER.log(Level.WARNING, "Error while calling isAdaptedForCompletion", e); + return false; + } ); } @@ -59,8 +61,10 @@ public boolean isAdaptedForCompletion(JavaCompletionContext context) { public List collectCompletionItems(JavaCompletionContext context) { return ExceptionUtil.executeWithExceptionHandling( () -> getInstance().collectCompletionItems(context), - Collections::emptyList, // Fallback value in case of exception - e -> LOGGER.log(Level.WARNING, "Error while calling collectCompletionItems", e) + e -> { + LOGGER.log(Level.WARNING, "Error while calling collectCompletionItems", e); + return Collections.emptyList(); + } ); } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java index 9c7c32f1d..fe3f8f6cd 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java @@ -53,8 +53,10 @@ public final class JavaDiagnosticsDefinition extends BaseKeyedLazyInstance getInstance().isAdaptedForDiagnostics(context), - () -> false, // Fallback value in case of exception - e -> LOGGER.log(Level.WARNING, "Error while calling isAdaptedForDiagnostics", e) + e -> { + LOGGER.log(Level.WARNING, "Error while calling isAdaptedForDiagnostics", e); + return false; + } ); } @@ -65,8 +67,10 @@ public void beginDiagnostics(JavaDiagnosticsContext context) { getInstance().beginDiagnostics(context); return true; }, - () -> null, // Fallback value supplier in case of exception - e -> LOGGER.log(Level.WARNING, "Error while calling beginDiagnostics", e) + e -> { + LOGGER.log(Level.WARNING, "Error while calling beginDiagnostics", e); + return null; + } ); } @@ -77,8 +81,10 @@ public List collectDiagnostics(JavaDiagnosticsContext context) { List diagnostics = getInstance().collectDiagnostics(context); return diagnostics != null ? diagnostics : Collections.emptyList(); }, - Collections::emptyList, - e -> LOGGER.log(Level.WARNING, "Error while calling collectDiagnostics", e) + e -> { + LOGGER.log(Level.WARNING, "Error while calling collectDiagnostics", e); + return Collections.emptyList(); + } ); } @@ -90,8 +96,10 @@ public void endDiagnostics(JavaDiagnosticsContext context) { getInstance().endDiagnostics(context); return true; }, - () -> null, // Fallback value supplier in case of exception - e -> LOGGER.log(Level.WARNING, "Error while calling endDiagnostics", e) + e -> { + LOGGER.log(Level.WARNING, "Error while calling endDiagnostics", e); + return null; + } ); } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java index 52f5fad55..baf7179ff 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java @@ -157,8 +157,10 @@ private void validateAsynchronousAnnotation(PsiMethod node, PsiAnnotation annota PsiType methodReturnType = node.getReturnType(); return methodReturnType.getCanonicalText(); }, - null, - e -> LOGGER.log(Level.WARNING, "An error occurred", e) + e -> { + LOGGER.log(Level.WARNING, "An error occurred", e); + return null; + } ); if ((!isAllowedReturnTypeForAsynchronousAnnotation(methodReturnTypeString))) { diff --git a/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java b/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java index 1eff96f3b..744b06f3d 100644 --- a/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java +++ b/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java @@ -14,6 +14,7 @@ import java.util.concurrent.CancellationException; import java.util.function.Consumer; +import java.util.function.Function; import java.util.function.Supplier; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.corrections.proposal.ChangeCorrectionProposal; @@ -24,7 +25,7 @@ public class ExceptionUtil { - public static T executeWithExceptionHandling(Supplier action, Supplier fallback, Consumer logger) { + public static T executeWithExceptionHandling(Supplier action, Function fallback) { try { return action.get(); } catch (ProcessCanceledException e) { @@ -34,8 +35,8 @@ public static T executeWithExceptionHandling(Supplier action, Supplier } catch (IndexNotReadyException | CancellationException e) { throw e; } catch (Exception e) { - logger.accept(e); - return fallback.get(); // Return the fallback value in case of failure + // Invoke the fallback function with the exception to generate a safe return value. + return fallback.apply(e); } } @@ -46,8 +47,10 @@ public static void executeWithWorkspaceEditHandling(JavaCodeActionResolveContext toResolve.setEdit(we); return true; }, - () -> null, // Fallback value supplier in case of exception - e -> logger.log(Level.WARNING, logMessage, e) + e -> { + logger.log(Level.WARNING, logMessage, e); + return null; + } ); } } \ No newline at end of file From 659c6c6a828145363da2efb4f9d4561d86b8e6ac Mon Sep 17 00:00:00 2001 From: vaisakhkannan <133869023+vaisakhkannan@users.noreply.github.com> Date: Tue, 5 Nov 2024 10:53:50 +0530 Subject: [PATCH 16/21] I added more comments and corrected the indentation issue. --- .../annotations/AnnotationValidator.java | 16 +++++++------- ...icroProfileFaultToleranceASTValidator.java | 2 +- .../tools/intellij/util/ExceptionUtil.java | 22 ++++++++++++++++++- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java index d8747d057..d58d8219f 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java @@ -90,16 +90,16 @@ public void unregisterRule(AnnotationRule rule) { */ public String validate(String value, AnnotationAttributeRule rule) { return ExceptionUtil.executeWithExceptionHandling( - () -> { - if (rule == null) { - return null; - } - return rule.validate(value); - }, - e -> { - LOGGER.log(Level.WARNING, e.getLocalizedMessage(), e); + () -> { + if (rule == null) { return null; } + return rule.validate(value); + }, + e -> { + LOGGER.log(Level.WARNING, e.getLocalizedMessage(), e); + return null; + } ); } diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java index baf7179ff..9a34a68db 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java @@ -159,7 +159,7 @@ private void validateAsynchronousAnnotation(PsiMethod node, PsiAnnotation annota }, e -> { LOGGER.log(Level.WARNING, "An error occurred", e); - return null; + return null; } ); diff --git a/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java b/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java index 744b06f3d..84177a88e 100644 --- a/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java +++ b/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java @@ -13,7 +13,6 @@ import com.intellij.openapi.project.IndexNotReadyException; import java.util.concurrent.CancellationException; -import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext; @@ -23,8 +22,20 @@ import java.util.logging.Level; import java.util.logging.Logger; +/** + * This class is intended for cases where exception handling is repetitive + */ public class ExceptionUtil { + /** + * Executes a supplied action with structured exception handling, allowing + * the caller to specify a fallback function in case of an exception. + * + * @param action the main operation to execute, represented by a Supplier + * @param fallback a function to handle exceptions and provide a safe return value + * @param the type of result expected from the action + * @return the result of the action or the fallback value in case of an exception + */ public static T executeWithExceptionHandling(Supplier action, Function fallback) { try { return action.get(); @@ -40,6 +51,15 @@ public static T executeWithExceptionHandling(Supplier action, Function { From 92388f0e8af7305d5ae0df668c85d3bf4976b1d9 Mon Sep 17 00:00:00 2001 From: vaisakhkannan <133869023+vaisakhkannan@users.noreply.github.com> Date: Tue, 5 Nov 2024 10:55:23 +0530 Subject: [PATCH 17/21] Added comment back --- .../tools/intellij/lsp4jakarta/lsp4ij/AnnotationUtil.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AnnotationUtil.java b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AnnotationUtil.java index c700dd0ec..5f5fc1e6e 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AnnotationUtil.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4jakarta/lsp4ij/AnnotationUtil.java @@ -35,6 +35,8 @@ public class AnnotationUtil { private static final Logger LOGGER = Logger.getLogger(AnnotationUtil.class.getName()); public static List getScopeAnnotations(PsiClass type, Set scopes) { return ExceptionUtil.executeWithExceptionHandling( + // Construct a stream of only the annotations applied to the type that are also + // recognised annotations found in scopes. () -> Arrays.stream(type.getAnnotations()) .map(annotation -> annotation.getNameReferenceElement().getQualifiedName()) .filter(scopes::contains) From 5aa8e99d382baa3a46bfc65812a1a01b8db7b19a Mon Sep 17 00:00:00 2001 From: vaisakhkannan <133869023+vaisakhkannan@users.noreply.github.com> Date: Thu, 7 Nov 2024 14:52:04 +0530 Subject: [PATCH 18/21] Replaced null --- .../java/MicroProfileFaultToleranceASTValidator.java | 2 +- .../java/io/openliberty/tools/intellij/util/ExceptionUtil.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java index 9a34a68db..863214eae 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java @@ -159,7 +159,7 @@ private void validateAsynchronousAnnotation(PsiMethod node, PsiAnnotation annota }, e -> { LOGGER.log(Level.WARNING, "An error occurred", e); - return null; + throw new RuntimeException("Failed to validate asynchronous annotation", e); } ); diff --git a/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java b/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java index 84177a88e..a6d33b40a 100644 --- a/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java +++ b/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java @@ -69,7 +69,7 @@ public static void executeWithWorkspaceEditHandling(JavaCodeActionResolveContext }, e -> { logger.log(Level.WARNING, logMessage, e); - return null; + return false; } ); } From 3255846232d8ed4a3eb7326cb2342308aed3ff12 Mon Sep 17 00:00:00 2001 From: vaisakhkannan <133869023+vaisakhkannan@users.noreply.github.com> Date: Thu, 7 Nov 2024 14:57:35 +0530 Subject: [PATCH 19/21] Replaced null with false --- .../core/java/corrections/JavaDiagnosticsDefinition.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java index fe3f8f6cd..ef344f4e4 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/core/java/corrections/JavaDiagnosticsDefinition.java @@ -69,7 +69,7 @@ public void beginDiagnostics(JavaDiagnosticsContext context) { }, e -> { LOGGER.log(Level.WARNING, "Error while calling beginDiagnostics", e); - return null; + return false; } ); } @@ -98,7 +98,7 @@ public void endDiagnostics(JavaDiagnosticsContext context) { }, e -> { LOGGER.log(Level.WARNING, "Error while calling endDiagnostics", e); - return null; + return false; } ); } From d5a1c00f91d7507fda1d2ec5b0cebd0028f735e4 Mon Sep 17 00:00:00 2001 From: vaisakhkannan <133869023+vaisakhkannan@users.noreply.github.com> Date: Thu, 7 Nov 2024 20:52:36 +0530 Subject: [PATCH 20/21] Changed to RuntimeException --- .../io/openliberty/tools/intellij/util/ExceptionUtil.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java b/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java index a6d33b40a..1cc860363 100644 --- a/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java +++ b/src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java @@ -36,7 +36,7 @@ public class ExceptionUtil { * @param the type of result expected from the action * @return the result of the action or the fallback value in case of an exception */ - public static T executeWithExceptionHandling(Supplier action, Function fallback) { + public static T executeWithExceptionHandling(Supplier action, Function fallback) { try { return action.get(); } catch (ProcessCanceledException e) { @@ -45,7 +45,7 @@ public static T executeWithExceptionHandling(Supplier action, Function Date: Thu, 7 Nov 2024 21:55:14 +0530 Subject: [PATCH 21/21] back to re-throw exception --- .../java/MicroProfileFaultToleranceASTValidator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java index 863214eae..0a7d23823 100644 --- a/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java +++ b/src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java @@ -159,7 +159,7 @@ private void validateAsynchronousAnnotation(PsiMethod node, PsiAnnotation annota }, e -> { LOGGER.log(Level.WARNING, "An error occurred", e); - throw new RuntimeException("Failed to validate asynchronous annotation", e); + throw e; } );