In progress: [Issue 164] Validate that the default value of a field
matches the type of such field.
Forgot to consider hexadecimal numbers as integers.
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/DataTypeValidator.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/DataTypeValidator.java
index 4d1b8bf..dde430a 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/DataTypeValidator.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/DataTypeValidator.java
@@ -63,7 +63,7 @@
private boolean validateFloatingPointNumber(FieldOption option, MessageField field) {
if (!messageFields.isFloatingPointNumber(field)) return false;
Value value = option.getValue();
- if (!(value instanceof DoubleLink) && !(value instanceof LongLink)) {
+ if (!(value instanceof DoubleLink) && !isInteger(value)) {
error(expectedNumber, FIELD_OPTION__VALUE);
}
return true;
@@ -72,7 +72,7 @@
private boolean validateInteger(FieldOption option, MessageField field) {
if (!messageFields.isInteger(field)) return false;
Value value = option.getValue();
- if (!(value instanceof LongLink)) {
+ if (!isInteger(value)) {
error(expectedInteger, FIELD_OPTION__VALUE);
return true;
}
@@ -85,6 +85,10 @@
return true;
}
+ private boolean isInteger(Value value) {
+ return value instanceof LongLink || value instanceof HexNumberLink;
+ }
+
private boolean validateString(FieldOption option, MessageField field) {
if (!messageFields.isBytes(field) && !messageFields.isString(field)) return false;
Value value = option.getValue();