Skip to content

Commit 659c6c6

Browse files
committed
I added more comments and corrected the indentation issue.
1 parent 283a777 commit 659c6c6

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/core/java/validators/annotations/AnnotationValidator.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,16 @@ public void unregisterRule(AnnotationRule rule) {
9090
*/
9191
public String validate(String value, AnnotationAttributeRule rule) {
9292
return ExceptionUtil.executeWithExceptionHandling(
93-
() -> {
94-
if (rule == null) {
95-
return null;
96-
}
97-
return rule.validate(value);
98-
},
99-
e -> {
100-
LOGGER.log(Level.WARNING, e.getLocalizedMessage(), e);
93+
() -> {
94+
if (rule == null) {
10195
return null;
10296
}
97+
return rule.validate(value);
98+
},
99+
e -> {
100+
LOGGER.log(Level.WARNING, e.getLocalizedMessage(), e);
101+
return null;
102+
}
103103
);
104104
}
105105

src/main/java/io/openliberty/tools/intellij/lsp4mp4ij/psi/internal/faulttolerance/java/MicroProfileFaultToleranceASTValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ private void validateAsynchronousAnnotation(PsiMethod node, PsiAnnotation annota
159159
},
160160
e -> {
161161
LOGGER.log(Level.WARNING, "An error occurred", e);
162-
return null;
162+
return null;
163163
}
164164
);
165165

src/main/java/io/openliberty/tools/intellij/util/ExceptionUtil.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import com.intellij.openapi.project.IndexNotReadyException;
1414

1515
import java.util.concurrent.CancellationException;
16-
import java.util.function.Consumer;
1716
import java.util.function.Function;
1817
import java.util.function.Supplier;
1918
import io.openliberty.tools.intellij.lsp4mp4ij.psi.core.java.codeaction.JavaCodeActionResolveContext;
@@ -23,8 +22,20 @@
2322
import java.util.logging.Level;
2423
import java.util.logging.Logger;
2524

25+
/**
26+
* This class is intended for cases where exception handling is repetitive
27+
*/
2628
public class ExceptionUtil {
2729

30+
/**
31+
* Executes a supplied action with structured exception handling, allowing
32+
* the caller to specify a fallback function in case of an exception.
33+
*
34+
* @param action the main operation to execute, represented by a Supplier
35+
* @param fallback a function to handle exceptions and provide a safe return value
36+
* @param <T> the type of result expected from the action
37+
* @return the result of the action or the fallback value in case of an exception
38+
*/
2839
public static <T> T executeWithExceptionHandling(Supplier<T> action, Function<Exception, T> fallback) {
2940
try {
3041
return action.get();
@@ -40,6 +51,15 @@ public static <T> T executeWithExceptionHandling(Supplier<T> action, Function<Ex
4051
}
4152
}
4253

54+
/**
55+
* Executes a workspace edit operation, handling any errors by logging them.
56+
*
57+
* @param context the context required to convert a correction proposal to a workspace edit
58+
* @param proposal the proposed correction to be applied
59+
* @param toResolve the code action to be resolved with the edit
60+
* @param logger a logger instance for logging exceptions if they occur
61+
* @param logMessage a message to log if an exception is encountered
62+
*/
4363
public static void executeWithWorkspaceEditHandling(JavaCodeActionResolveContext context, ChangeCorrectionProposal proposal, CodeAction toResolve, Logger logger, String logMessage) {
4464
executeWithExceptionHandling(
4565
() -> {

0 commit comments

Comments
 (0)