Fixed a case where the new index for a message field gets calculated and
set twice, resulting in a value of max+2 instead of max+1
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/semicolon/SmartSemicolonHandler.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/semicolon/SmartSemicolonHandler.java
index da489b5..f3d607a 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/semicolon/SmartSemicolonHandler.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/semicolon/SmartSemicolonHandler.java
@@ -41,6 +41,7 @@
import com.google.eclipse.protobuf.model.util.Protobufs;
import com.google.eclipse.protobuf.model.util.Resources;
import com.google.eclipse.protobuf.protobuf.FieldOption;
+import com.google.eclipse.protobuf.protobuf.IndexedElement;
import com.google.eclipse.protobuf.protobuf.Literal;
import com.google.eclipse.protobuf.protobuf.MessageField;
import com.google.eclipse.protobuf.protobuf.Protobuf;
@@ -119,7 +120,7 @@
}
if (model instanceof MessageField) {
MessageField field = (MessageField) model;
- if (shouldCalculateIndex(field, MESSAGE_FIELD__INDEX)) {
+ if (shouldCalculateIndex(field)) {
long index = indexedElements.calculateNewIndexFor(field);
field.setIndex(index);
updateIndexInCommentOfParent(field, index, document);
@@ -142,6 +143,10 @@
INode node = nodes.firstNodeForFeature(target, indexAttribute);
return node == null || isEmpty(node.getText());
}
+
+ private boolean shouldCalculateIndex(IndexedElement target) {
+ return indexedElements.indexOf(target) <= 0;
+ }
private EObject modelFrom(ContentAssistContext c) {
EObject current = c.getCurrentModel();