diff --git a/projects/lsp4mp/projects/maven/config-quickstart/src/main/java/org/acme/config/DefaultValueResource.java b/projects/lsp4mp/projects/maven/config-quickstart/src/main/java/org/acme/config/DefaultValueResource.java index dcf264ce3..34c8e330f 100644 --- a/projects/lsp4mp/projects/maven/config-quickstart/src/main/java/org/acme/config/DefaultValueResource.java +++ b/projects/lsp4mp/projects/maven/config-quickstart/src/main/java/org/acme/config/DefaultValueResource.java @@ -3,6 +3,8 @@ import javax.ws.rs.Path; import org.eclipse.microprofile.config.inject.ConfigProperty; +import java.time.Duration; + @Path("/greeting") public class DefaultValueResource { @@ -35,4 +37,30 @@ public class DefaultValueResource { @ConfigProperty(name = "greeting10", defaultValue="AB") char greeting10; + + @ConfigProperty(name = "greeting11", defaultValue="AB") + char greeting11; + + @ConfigProperty(name = "greeting1_1", defaultValue="1") + int greeting1_1; + + @ConfigProperty(name = "greeting2_1", defaultValue="1") + Integer greeting2_1; + + public static enum Profile { + admin, + user + } + + @ConfigProperty(name = "app.duration", defaultValue = "PT15M") + Duration duration; + + @ConfigProperty(name = "app.duration", defaultValue = "PT15") + Duration durationWithError; + + @ConfigProperty(name = "profile", defaultValue = "user") + Profile profile; + + @ConfigProperty(name = "profile", defaultValue = "userXXX") + Profile profileWithError; } 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) {