[yaml] numeric value validation
[idea/community.git] / plugins / yaml / src / org / jetbrains / yaml / meta / model / YamlIntegerType.java
index 7d76d5779c06540d1035de14e5c4095c1cf5807e..10f0727bfa858b3a78b28db9537ca9099b7ee267 100644 (file)
@@ -3,7 +3,10 @@
  */
 package org.jetbrains.yaml.meta.model;
 
+import com.intellij.codeInspection.ProblemsHolder;
 import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.yaml.psi.YAMLScalar;
 
 @ApiStatus.Experimental
 public class YamlIntegerType extends YamlScalarType {
@@ -17,4 +20,15 @@ public class YamlIntegerType extends YamlScalarType {
     super("yaml:integer");
     setDisplayName("integer");
   }
+
+  @Override
+  protected void validateScalarValue(@NotNull YAMLScalar scalarValue, @NotNull ProblemsHolder holder) {
+    try {
+      //noinspection ResultOfMethodCallIgnored
+      Integer.parseInt(scalarValue.getTextValue());
+    }
+    catch (NumberFormatException e) {
+      holder.registerProblem(scalarValue, "Integer value expected");
+    }
+  }
 }