Skip to content

Commit 2a285f9

Browse files
committed
@ConfigProperty for java.util.Duration with defaultValue flagged as fix:
error Fixes #1207 Signed-off-by: azerr <[email protected]>
1 parent 869ead4 commit 2a285f9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/main/java/com/redhat/devtools/intellij/lsp4mp4ij/psi/internal/config/java/MicroProfileConfigASTValidator.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131
import org.eclipse.lsp4mp.commons.utils.AntPathMatcher;
3232

3333
import java.text.MessageFormat;
34+
import java.time.Duration;
3435
import java.util.List;
3536
import java.util.logging.Logger;
3637
import java.util.regex.Pattern;
38+
import java.util.stream.Stream;
3739

3840
import static com.redhat.devtools.intellij.lsp4mp4ij.psi.core.MicroProfileConfigConstants.*;
3941
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
274276
return PsiTypeUtils.findType(javaProject, value) != null;
275277
case "java.lang.String":
276278
return true;
279+
case "java.time.Duration":
280+
try {
281+
Duration.parse(value);
282+
return true;
283+
}
284+
catch(Exception e) {
285+
return false;
286+
}
277287
default:
288+
PsiClass type = PsiTypeUtils.findType(javaProject, typeFqn);
289+
if (type != null) {
290+
if (type.isEnum()) {
291+
return Stream.of(type.getFields())
292+
.anyMatch(e -> e.getName().equals(value));
293+
294+
295+
}
296+
}
278297
return false;
279298
}
280299
} catch (NumberFormatException e) {

0 commit comments

Comments
 (0)