Added "quick fix" for duplicated field tag number and negative tag
number.
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/quickfix/Messages.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/quickfix/Messages.java
index 03ea039..f0a5f22 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/quickfix/Messages.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/quickfix/Messages.java
@@ -1,10 +1,10 @@
/*
* Copyright (c) 2011 Google Inc.
- *
+ *
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
- *
+ *
* http://www.eclipse.org/legal/epl-v10.html
*/
package com.google.eclipse.protobuf.ui.quickfix;
@@ -15,10 +15,12 @@
* @author alruiz@google.com (Alex Ruiz)
*/
public class Messages extends NLS {
-
+
public static String changeToProto2;
public static String changeToProto2Label;
-
+ public static String regenerateTagNumber;
+ public static String regenerateTagNumberLabel;
+
static {
Class<Messages> targetType = Messages.class;
NLS.initializeMessages(targetType.getName(), targetType);
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/quickfix/Messages.properties b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/quickfix/Messages.properties
index 54e5126..5436a9a 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/quickfix/Messages.properties
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/quickfix/Messages.properties
@@ -1,2 +1,4 @@
-changeToProto2=Change syntax to "proto2".
+changeToProto2=Change syntax to "proto2."
changeToProto2Label=Change syntax to "proto2"
+regenerateTagNumber=Regenerate tag number.
+regenerateTagNumberLabel=Regenerate tag number
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/quickfix/ProtobufQuickfixProvider.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/quickfix/ProtobufQuickfixProvider.java
index 04f7973..ff3ff07 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/quickfix/ProtobufQuickfixProvider.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/quickfix/ProtobufQuickfixProvider.java
@@ -1,35 +1,37 @@
/*
* Copyright (c) 2011 Google Inc.
- *
+ *
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
- *
+ *
* http://www.eclipse.org/legal/epl-v10.html
*/
package com.google.eclipse.protobuf.ui.quickfix;
import static com.google.eclipse.protobuf.ui.quickfix.Messages.*;
-import static com.google.eclipse.protobuf.validation.ProtobufJavaValidator.SYNTAX_IS_NOT_PROTO2_ERROR_CODE;
-
-import com.google.eclipse.protobuf.protobuf.Syntax;
-import com.google.eclipse.protobuf.ui.labeling.Images;
-import com.google.inject.Inject;
+import static com.google.eclipse.protobuf.validation.ProtobufJavaValidator.*;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.ui.editor.model.edit.*;
import org.eclipse.xtext.ui.editor.quickfix.*;
import org.eclipse.xtext.validation.Issue;
+import com.google.eclipse.protobuf.protobuf.*;
+import com.google.eclipse.protobuf.ui.labeling.Images;
+import com.google.eclipse.protobuf.ui.util.Fields;
+import com.google.inject.Inject;
+
/**
* @author alruiz@google.com (Alex Ruiz)
*/
public class ProtobufQuickfixProvider extends DefaultQuickfixProvider {
+ @Inject private Fields fields;
@Inject private Images images;
-
- @Fix(SYNTAX_IS_NOT_PROTO2_ERROR_CODE)
- public void makeSyntaxProto2(final Issue issue, IssueResolutionAcceptor acceptor) {
+
+ @Fix(SYNTAX_IS_NOT_PROTO2_ERROR_CODE)
+ public void makeSyntaxProto2(Issue issue, IssueResolutionAcceptor acceptor) {
String image = images.imageFor(Syntax.class);
acceptor.accept(issue, changeToProto2Label, changeToProto2, image, new ISemanticModification() {
public void apply(EObject element, IModificationContext context) throws Exception {
@@ -39,4 +41,16 @@
}
});
}
+
+ @Fix(INVALID_FIELD_TAG_NUMBER_ERROR_CODE)
+ public void regenerateTagNumver(Issue issue, IssueResolutionAcceptor acceptor) {
+ acceptor.accept(issue, regenerateTagNumberLabel, regenerateTagNumber, "property.gif", new ISemanticModification() {
+ public void apply(EObject element, IModificationContext context) throws Exception {
+ if (!(element instanceof Field)) return;
+ Field field = (Field) element;
+ long tagNumber = fields.calculateTagNumberOf(field);
+ field.setIndex(tagNumber);
+ }
+ });
+ }
}
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 1ede6e7..f33f52a 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
@@ -15,8 +15,7 @@
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.xtext.naming.IQualifiedNameProvider;
-import org.eclipse.xtext.naming.QualifiedName;
+import org.eclipse.xtext.naming.*;
import org.eclipse.xtext.scoping.impl.ImportUriResolver;
import org.eclipse.xtext.validation.Check;
@@ -31,13 +30,13 @@
public class ProtobufJavaValidator extends AbstractProtobufJavaValidator {
public static final String SYNTAX_IS_NOT_PROTO2_ERROR_CODE = "syntaxIsNotProto2";
- public static final String TAG_NUMBER_IS_NOT_UNIQUE_ERROR_CODE = "tagNumberIsNotUnique";
+ public static final String INVALID_FIELD_TAG_NUMBER_ERROR_CODE = "invalidFieldTagNumber";
@Inject private FieldOptions fieldOptions;
@Inject private ImportUriResolver uriResolver;
@Inject private IQualifiedNameProvider qualifiedNameProvider;
@Inject private Properties properties;
-
+
@Check public void checkDefaultValueType(FieldOption option) {
if (!fieldOptions.isDefaultValueOption(option)) return;
Property property = (Property) option.eContainer();
@@ -90,7 +89,7 @@
if (other.getIndex() != index) continue;
QualifiedName messageName = qualifiedNameProvider.getFullyQualifiedName(message);
String msg = format(fieldNumberAlreadyUsed, index, messageName.toString(), other.getName());
- error(msg, field, FIELD__INDEX, TAG_NUMBER_IS_NOT_UNIQUE_ERROR_CODE);
+ error(msg, field, FIELD__INDEX, INVALID_FIELD_TAG_NUMBER_ERROR_CODE);
break;
}
}
@@ -101,7 +100,7 @@
long index = field.getIndex();
if (index > 0) return;
String msg = (index == 0) ? fieldNumbersMustBePositive : expectedFieldNumber;
- error(msg, FIELD__INDEX);
+ error(msg, field, FIELD__INDEX, INVALID_FIELD_TAG_NUMBER_ERROR_CODE);
}
@Check public void checkOnlyOnePackageDefinition(Package aPackage) {