From b5e1c78cc61f5425ca5f4bd06e08c68264c03ba5 Mon Sep 17 00:00:00 2001 From: azerr Date: Mon, 12 Aug 2024 17:13:22 +0200 Subject: [PATCH] fix: @ConfigProperty for java.util.Duration with defaultValue flagged as error Fixes #1207 Signed-off-by: azerr --- .../java/MicroProfileConfigASTValidator.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/config/java/MicroProfileConfigASTValidator.java b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/config/java/MicroProfileConfigASTValidator.java index 1a214ef16..6126f0956 100644 --- a/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/config/java/MicroProfileConfigASTValidator.java +++ b/src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/config/java/MicroProfileConfigASTValidator.java @@ -31,9 +31,11 @@ import org.eclipse.lsp4mp.commons.utils.AntPathMatcher; import java.text.MessageFormat; +import java.time.Duration; import java.util.List; import java.util.logging.Logger; import java.util.regex.Pattern; +import java.util.stream.Stream; import static com.redhat.devtools.intellij.lsp4mp4ij.psi.core.MicroProfileConfigConstants.*; import static com.redhat.devtools.intellij.lsp4mp4ij.psi.core.utils.AnnotationUtils.getAnnotationMemberValueExpression; @@ -274,7 +276,24 @@ private static boolean isAssignable(String typeFqn, String value, Module javaPro return PsiTypeUtils.findType(javaProject, value) != null; case "java.lang.String": return true; + case "java.time.Duration": + try { + Duration.parse(value); + return true; + } + catch(Exception e) { + return false; + } default: + PsiClass type = PsiTypeUtils.findType(javaProject, typeFqn); + if (type != null) { + if (type.isEnum()) { + return Stream.of(type.getFields()) + .anyMatch(e -> e.getName().equals(value)); + + + } + } return false; } } catch (NumberFormatException e) {