Fixed: [Issue 106] Syntax error when specifying default values larger
than 2147483647.
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/conversion/HEXValueConverter_toValue_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/conversion/HEXValueConverter_toValue_Test.java
index e70c158..c435cfd 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/conversion/HEXValueConverter_toValue_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/conversion/HEXValueConverter_toValue_Test.java
@@ -34,18 +34,18 @@
@Rule public XtextRule xtext = new XtextRule();
private final String input;
- private final Integer expected;
+ private final Long expected;
@Parameters
public static Collection<Object[]> parameters() {
return asList(new Object[][] {
- { "0x1", 1 },
- { "0xA", 10 },
- { "0xFF", 255 }
+ { "0x1", 1L },
+ { "0xA", 10L },
+ { "0xFF", 255L }
});
}
- public HEXValueConverter_toValue_Test(String input, Integer expected) {
+ public HEXValueConverter_toValue_Test(String input, Long expected) {
this.input = input;
this.expected = expected;
}
@@ -59,7 +59,7 @@
}
@Test public void should_parse_hexadecimal_number() {
- Integer value = converter.toValue(input, node);
+ Long value = converter.toValue(input, node);
assertThat(value, equalTo(expected));
}
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/conversion/HEXValueConverter_toValue_withInvalidInput_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/conversion/HEXValueConverter_toValue_withInvalidInput_Test.java
index 9a01e03..7696359 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/conversion/HEXValueConverter_toValue_withInvalidInput_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/conversion/HEXValueConverter_toValue_withInvalidInput_Test.java
@@ -41,25 +41,25 @@
@Test public void should_throw_error_if_input_is_null() {
thrown.expect(ValueConverterException.class);
- thrown.expectMessage("Couldn't convert empty string to int.");
+ thrown.expectMessage("Couldn't convert empty string to long.");
converter.toValue(null, node);
}
@Test public void should_throw_error_if_input_is_empty() {
thrown.expect(ValueConverterException.class);
- thrown.expectMessage("Couldn't convert empty string to int.");
+ thrown.expectMessage("Couldn't convert empty string to long.");
converter.toValue("", node);
}
@Test public void should_throw_error_if_input_has_less_than_three_characters() {
thrown.expect(ValueConverterException.class);
- thrown.expectMessage("Couldn't convert '0x' to int.");
+ thrown.expectMessage("Couldn't convert '0x' to long.");
converter.toValue("0x", node);
}
@Test public void should_throw_error_if_input_does_not_start_with_0x() {
thrown.expect(ValueConverterException.class);
- thrown.expectMessage("Couldn't convert '65' to int.");
+ thrown.expectMessage("Couldn't convert '65' to long.");
converter.toValue("65", node);
}
@@ -68,7 +68,7 @@
converter.toValue("0xZ", node);
fail("Expecting a " + ValueConverterException.class.getName());
} catch (ValueConverterException e) {
- assertThat(e.getMessage(), equalTo("Couldn't convert '0xZ' to int."));
+ assertThat(e.getMessage(), equalTo("Couldn't convert '0xZ' to long."));
assertThat(e.getCause(), instanceOf(NumberFormatException.class));
}
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/conversion/INTValueConverter_toValue_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/conversion/LONGValueConverter_toValue_Test.java
similarity index 75%
rename from com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/conversion/INTValueConverter_toValue_Test.java
rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/conversion/LONGValueConverter_toValue_Test.java
index af29dea..7e6220c 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/conversion/INTValueConverter_toValue_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/conversion/LONGValueConverter_toValue_Test.java
@@ -25,32 +25,32 @@
import com.google.eclipse.protobuf.junit.core.XtextRule;
/**
- * Tests for <code>{@link INTValueConverter#toString()}</code>.
+ * Tests for <code>{@link LONGValueConverter#toString()}</code>.
*
* @author alruiz@google.com (Alex Ruiz)
*/
-public class INTValueConverter_toValue_Test {
+public class LONGValueConverter_toValue_Test {
@Rule public XtextRule xtext = new XtextRule();
@Rule public ExpectedException thrown = none();
- private INTValueConverter converter;
+ private LONGValueConverter converter;
private INode node;
@Before public void setUp() {
node = mock(INode.class);
- converter = xtext.injector().getInstance(INTValueConverter.class);
+ converter = xtext.injector().getInstance(LONGValueConverter.class);
}
@Test public void should_throw_error_if_input_is_null() {
thrown.expect(ValueConverterException.class);
- thrown.expectMessage("Couldn't convert empty string to int.");
+ thrown.expectMessage("Couldn't convert empty string to long.");
converter.toValue(null, node);
}
@Test public void should_throw_error_if_input_is_empty() {
thrown.expect(ValueConverterException.class);
- thrown.expectMessage("Couldn't convert empty string to int.");
+ thrown.expectMessage("Couldn't convert empty string to long.");
converter.toValue("", node);
}
@@ -59,16 +59,16 @@
converter.toValue("abc", node);
fail("Expecting a " + ValueConverterException.class.getName());
} catch (ValueConverterException e) {
- assertThat(e.getMessage(), equalTo("Couldn't convert 'abc' to int."));
+ assertThat(e.getMessage(), equalTo("Couldn't convert 'abc' to long."));
assertThat(e.getCause(), instanceOf(NumberFormatException.class));
}
}
- @Test public void should_parse_integer() {
- assertThat(converter.toValue("68", node), equalTo(68));
+ @Test public void should_parse_long() {
+ assertThat(converter.toValue("68", node), equalTo(68L));
}
- @Test public void should_parse_negative_integer() {
- assertThat(converter.toValue("-2", node), equalTo(-2));
+ @Test public void should_parse_negative_long() {
+ assertThat(converter.toValue("-2", node), equalTo(-2L));
}
}
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Fields_calculateTagNumberOf_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Fields_calculateTagNumberOf_Test.java
index a045b1d..6c2238a 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Fields_calculateTagNumberOf_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Fields_calculateTagNumberOf_Test.java
@@ -40,8 +40,8 @@
.append("} ");
Protobuf root = xtext.parse(proto);
Property name = findProperty("name", root);
- int index = fields.calculateTagNumberOf(name);
- assertThat(index, equalTo(1));
+ long index = fields.calculateTagNumberOf(name);
+ assertThat(index, equalTo(1L));
}
@Test public void should_return_max_tag_number_value_plus_one_for_new_property() {
@@ -52,7 +52,7 @@
.append("} ");
Protobuf root = xtext.parse(proto);
Property id = findProperty("id", root);
- int index = fields.calculateTagNumberOf(id);
- assertThat(index, equalTo(7));
+ long index = fields.calculateTagNumberOf(id);
+ assertThat(index, equalTo(7L));
}
}
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Literals_calculateIndexOf_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Literals_calculateIndexOf_Test.java
index be5b537..40cf01a 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Literals_calculateIndexOf_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Literals_calculateIndexOf_Test.java
@@ -41,8 +41,8 @@
.append("} ");
Protobuf root = xtext.parse(proto);
Literal mobile = findLiteral("MOBILE", root);
- int index = literals.calculateIndexOf(mobile);
- assertThat(index, equalTo(0));
+ long index = literals.calculateIndexOf(mobile);
+ assertThat(index, equalTo(0L));
}
@Test public void should_return_max_index_value_plus_one_for_new_literal() {
@@ -54,7 +54,7 @@
.append("} ");
Protobuf root = xtext.parse(proto);
Literal work = findLiteral("WORK", root);
- int index = literals.calculateIndexOf(work);
- assertThat(index, equalTo(6));
+ long index = literals.calculateIndexOf(work);
+ assertThat(index, equalTo(6L));
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/SmartSemicolonHandler.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/SmartSemicolonHandler.java
index 6e3ba10..c013f20 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/SmartSemicolonHandler.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/SmartSemicolonHandler.java
@@ -110,7 +110,7 @@
Literal literal = (Literal) model;
ContentToInsert content = newContent(literal);
if (content.equals(ContentToInsert.INSERT_TAG_NUMBER)) {
- int index = literals.calculateIndexOf(literal);
+ long index = literals.calculateIndexOf(literal);
literal.setIndex(index);
updateIndexInCommentOfParent(literal, index, document);
}
@@ -120,7 +120,7 @@
Property property = (Property) model;
ContentToInsert content = newContent(property);
if (content.equals(ContentToInsert.INSERT_TAG_NUMBER)) {
- int index = fields.calculateTagNumberOf(property);
+ long index = fields.calculateTagNumberOf(property);
property.setIndex(index);
updateIndexInCommentOfParent(property, index, document);
}
@@ -165,7 +165,7 @@
return hasIndex ? new ContentToInsert(SEMICOLON, Location.END) : ContentToInsert.INSERT_TAG_NUMBER;
}
- private void updateIndexInCommentOfParent(EObject o, int index, IXtextDocument document) {
+ private void updateIndexInCommentOfParent(EObject o, long index, IXtextDocument document) {
EObject parent = o.eContainer();
if (parent == null) return;
NumericTagPreferences preferences = preferencesFactory.preferences();
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/ProtobufProposalProvider.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/ProtobufProposalProvider.java
index 0dfce9e..57b1b1a 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/ProtobufProposalProvider.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/ProtobufProposalProvider.java
@@ -257,7 +257,7 @@
@Override public void completeLiteral_Index(EObject model, Assignment assignment, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
- int index = literals.calculateIndexOf((Literal) model);
+ long index = literals.calculateIndexOf((Literal) model);
proposeIndex(index, context, acceptor);
}
@@ -267,11 +267,11 @@
@Override public void completeProperty_Index(EObject model, Assignment assignment, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
- int index = fields.calculateTagNumberOf((Property) model);
+ long index = fields.calculateTagNumberOf((Property) model);
proposeIndex(index, context, acceptor);
}
- private void proposeIndex(int index, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
+ private void proposeIndex(long index, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
proposeAndAccept(valueOf(index), context, acceptor);
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Fields.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Fields.java
index 47e35fd..9fe4b74 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Fields.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Fields.java
@@ -41,8 +41,8 @@
* @param f the given field.
* @return the calculated value for the tag number of the given field.
*/
- public int calculateTagNumberOf(Field f) {
- int index = 0;
+ public long calculateTagNumberOf(Field f) {
+ long index = 0;
for (EObject o : f.eContainer().eContents()) {
if (o == f || !(o instanceof Field)) continue;
index = max(index, ((Field) o).getIndex());
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Literals.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Literals.java
index b4238e9..eea1cac 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Literals.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Literals.java
@@ -42,8 +42,8 @@
* @param l the given literal.
* @return the calculated index value.
*/
- public int calculateIndexOf(Literal l) {
- int index = -1;
+ public long calculateIndexOf(Literal l) {
+ long index = -1;
List<Literal> allLiterals = getAllContentsOfType(l.eContainer(), Literal.class);
for (Literal c : allLiterals) {
if (c == l) continue;
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext
index 3c3a1bd..df250b8 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext
@@ -62,16 +62,16 @@
'extensions' ranges+=Range (',' ranges+=Range)* ';';
Range:
- from=INT ('to' to=RangeMax)?;
+ from=LONG ('to' to=RangeMax)?;
RangeMax:
- INT | 'max';
+ LONG | 'max';
Field:
Property | Group;
Group:
- modifier=Modifier 'group' name=Name '=' index=(INT | HEX)
+ modifier=Modifier 'group' name=Name '=' index=(LONG | HEX)
('[' (fieldOptions+=FieldOption (',' fieldOptions+=FieldOption)*) ']')? '{'
elements+=GroupElement*
'}' (';')?;
@@ -80,7 +80,7 @@
Field | Option | Enum;
Property:
- modifier=Modifier type=AbstractTypeRef name=Name '=' index=(INT | HEX)
+ modifier=Modifier type=AbstractTypeRef name=Name '=' index=(LONG | HEX)
('[' fieldOptions+=FieldOption (',' fieldOptions+=FieldOption)* ']')? ';';
enum Modifier:
@@ -128,15 +128,15 @@
| false;
NumberRef:
- HexRef | IntRef | FloatRef;
+ HexRef | LongRef | FloatRef;
HexRef:
hex=HEX;
-IntRef:
- int=INT;
+LongRef:
+ long=LONG;
-terminal INT returns ecore::EInt:
+terminal LONG returns ecore::ELong:
('-')? (NUMBER)+;
FloatRef:
@@ -166,7 +166,7 @@
Option | Literal;
Literal:
- name=Name '=' index=(INT | HEX)
+ name=Name '=' index=(LONG | HEX)
('[' fieldOptions+=FieldOption (',' fieldOptions+=FieldOption)* ']')? ';';
FieldOption:
@@ -178,7 +178,7 @@
CustomFieldOption:
'(' name=QualifiedName ')' '=' value=ValueRef;
-terminal HEX returns ecore::EInt:
+terminal HEX returns ecore::ELong:
'0x' (NUMBER | 'a'..'f' | 'A'..'F')+;
terminal NUMBER:
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/HEXValueConverter.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/HEXValueConverter.java
index 8f26d41..1abde7b 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/HEXValueConverter.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/HEXValueConverter.java
@@ -15,11 +15,11 @@
import org.eclipse.xtext.nodemodel.INode;
/**
- * Converts hexadecimal numbers to {@code int}s.
+ * Converts hexadecimal numbers to {@code long}s.
*
* @author alruiz@google.com (Alex Ruiz)
*/
-public class HEXValueConverter extends AbstractLexerBasedConverter<Integer> {
+public class HEXValueConverter extends AbstractLexerBasedConverter<Long> {
/**
* Creates an {@code int} from the given input, if the given input represents an hexadecimal number.
@@ -29,14 +29,14 @@
* @throws ValueConverterException if the given input is {@code null}, empty or does not represent an hexadecimal
* number.
*/
- public Integer toValue(String string, INode node) throws ValueConverterException {
- if (isEmpty(string)) throw new ValueConverterException("Couldn't convert empty string to int.", node, null);
+ public Long toValue(String string, INode node) throws ValueConverterException {
+ if (isEmpty(string)) throw new ValueConverterException("Couldn't convert empty string to long.", node, null);
int length = string.length();
if (length < 3) throw parsingError(string, node);
if (!string.substring(0, 2).equalsIgnoreCase("0x")) throw parsingError(string, node);
String val = string.substring(2, length);
try {
- return Integer.parseInt(val, 16);
+ return Long.parseLong(val, 16);
} catch (NumberFormatException e) {
throw parsingError(string, node, e);
}
@@ -47,6 +47,6 @@
}
private ValueConverterException parsingError(String string, INode node, Exception cause) {
- return new ValueConverterException("Couldn't convert '" + string + "' to int.", node, cause);
+ return new ValueConverterException("Couldn't convert '" + string + "' to long.", node, cause);
}
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/INTValueConverter.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/LONGValueConverter.java
similarity index 79%
rename from com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/INTValueConverter.java
rename to com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/LONGValueConverter.java
index 2538d52..986b90b 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/INTValueConverter.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/LONGValueConverter.java
@@ -15,11 +15,11 @@
import org.eclipse.xtext.nodemodel.INode;
/**
- * Converts integer numbers to {@code int}s.
+ * Converts integer numbers to {@code long}s.
*
* @author alruiz@google.com (Alex Ruiz)
*/
-public class INTValueConverter extends AbstractLexerBasedConverter<Integer> {
+public class LONGValueConverter extends AbstractLexerBasedConverter<Long> {
/**
* Creates an {@code int} from the given input, if the given input represents an integer number.
@@ -28,16 +28,16 @@
* @return the new {@code int}.
* @throws ValueConverterException if the given input is {@code null}, empty or does not represent an integer number.
*/
- public Integer toValue(String string, INode node) throws ValueConverterException {
- if (isEmpty(string)) throw new ValueConverterException("Couldn't convert empty string to int.", node, null);
+ public Long toValue(String string, INode node) throws ValueConverterException {
+ if (isEmpty(string)) throw new ValueConverterException("Couldn't convert empty string to long.", node, null);
try {
- return Integer.parseInt(string, 10);
+ return Long.parseLong(string, 10);
} catch (NumberFormatException e) {
throw parsingError(string, node, e);
}
}
private ValueConverterException parsingError(String string, INode node, Exception cause) {
- return new ValueConverterException("Couldn't convert '" + string + "' to int.", node, cause);
+ return new ValueConverterException("Couldn't convert '" + string + "' to long.", node, cause);
}
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/ProtobufTerminalConverters.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/ProtobufTerminalConverters.java
index 9a6af27..e4ac026 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/ProtobufTerminalConverters.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/ProtobufTerminalConverters.java
@@ -20,7 +20,7 @@
@Inject private FLOATValueConverter floatValueConverter;
@Inject private HEXValueConverter hexValueConverter;
- @Inject private INTValueConverter intValueConverter;
+ @Inject private LONGValueConverter longValueConverter;
@Inject private STRINGValueConverter stringValueConverter;
@ValueConverter(rule = "FLOAT")
@@ -29,13 +29,13 @@
}
@ValueConverter(rule = "HEX")
- public IValueConverter<Integer> HEX() {
+ public IValueConverter<Long> HEX() {
return hexValueConverter;
}
- @ValueConverter(rule = "INT")
- @Override public IValueConverter<Integer> INT() {
- return intValueConverter;
+ @ValueConverter(rule = "LONG")
+ public IValueConverter<Long> LONG() {
+ return longValueConverter;
}
@ValueConverter(rule = "STRING")
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator.java
index fae683b..443c974 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator.java
@@ -77,7 +77,7 @@
@Check public void checkTagNumberIsUnique(Field field) {
if (isNameNull(field)) return; // we already show an error if name is null, no need to go further.
- int index = field.getIndex();
+ long index = field.getIndex();
EObject container = field.eContainer();
if (container instanceof Message) {
Message message = (Message) container;
@@ -96,7 +96,7 @@
@Check public void checkTagNumberIsGreaterThanZero(Field field) {
if (isNameNull(field)) return; // we already show an error if name is null, no need to go further.
- int index = field.getIndex();
+ long index = field.getIndex();
if (index > 0) return;
String msg = (index == 0) ? fieldNumbersMustBePositive : expectedFieldNumber;
error(msg, FIELD__INDEX);