Fixed: [Issue 104] Update "Next Id" comment when generating a the tag
number of a field or literal
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 a0a43f5..6e3ba10 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
@@ -31,6 +31,7 @@
import com.google.eclipse.protobuf.grammar.CommonKeyword;
import com.google.eclipse.protobuf.protobuf.*;
import com.google.eclipse.protobuf.protobuf.Enum;
+import com.google.eclipse.protobuf.ui.preferences.pages.editor.numerictag.*;
import com.google.eclipse.protobuf.ui.util.*;
import com.google.eclipse.protobuf.util.ModelNodes;
import com.google.inject.Inject;
@@ -53,6 +54,7 @@
@Inject private HighlightingReconciler highlightingReconciler;
@Inject private Literals literals;
@Inject private ModelNodes nodes;
+ @Inject private NumericTagPreferencesFactory preferencesFactory;
@Inject private ParserBasedContentAssistContextFactory contextFactory;
private static final String SEMICOLON = CommonKeyword.SEMICOLON.toString();
@@ -166,17 +168,20 @@
private void updateIndexInCommentOfParent(EObject o, int index, IXtextDocument document) {
EObject parent = o.eContainer();
if (parent == null) return;
- String pattern = "Next[\\s]+Id:[\\s]+[\\d]+";
- Pair<INode, Matcher> match = commentNodesFinder.matchingCommentNode(parent, pattern);
- if (match == null) return;
- String original = match.getSecond().group();
- String replacement = NUMBERS_PATTERN.matcher(original).replaceFirst(String.valueOf(index + 1));
- INode node = match.getFirst();
- int offset = node.getTotalOffset() + node.getText().indexOf(original);
- try {
- document.replace(offset, original.length(), replacement);
- } catch (BadLocationException e) {
- logger.error("Unable to update comment tracking next tag number", e);
+ NumericTagPreferences preferences = preferencesFactory.preferences();
+ for (String pattern : preferences.patterns()) {
+ Pair<INode, Matcher> match = commentNodesFinder.matchingCommentNode(parent, pattern);
+ if (match == null) return;
+ String original = match.getSecond().group();
+ String replacement = NUMBERS_PATTERN.matcher(original).replaceFirst(String.valueOf(index + 1));
+ INode node = match.getFirst();
+ int offset = node.getTotalOffset() + node.getText().indexOf(original);
+ try {
+ document.replace(offset, original.length(), replacement);
+ } catch (BadLocationException e) {
+ String format = "Unable to update comment tracking next tag number using pattern '%s'";
+ logger.error(String.format(format, pattern), e);
+ }
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferences.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferences.java
new file mode 100644
index 0000000..cd13a7b
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferences.java
@@ -0,0 +1,31 @@
+/*
+ * 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.preferences.pages.editor.numerictag;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+
+import java.util.List;
+
+/**
+ * "Numeric tag" preferences, retrieved from an <code>{@link IPreferenceStore}</code>.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class NumericTagPreferences {
+
+ private final List<String> patterns;
+
+ NumericTagPreferences(RawPreferences preferences) {
+ patterns = preferences.patterns().value();
+ }
+
+ public List<String> patterns() {
+ return patterns;
+ }
+}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferencesFactory.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferencesFactory.java
new file mode 100644
index 0000000..5c22c08
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferencesFactory.java
@@ -0,0 +1,29 @@
+/*
+ * 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.preferences.pages.editor.numerictag;
+
+import com.google.inject.Inject;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.xtext.ui.editor.preferences.IPreferenceStoreAccess;
+
+/**
+ * Factory of <code>{@link NumericTagPreferences}</code>.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class NumericTagPreferencesFactory {
+
+ @Inject private IPreferenceStoreAccess storeAccess;
+
+ public NumericTagPreferences preferences() {
+ IPreferenceStore store = storeAccess.getWritablePreferenceStore();
+ return new NumericTagPreferences(new RawPreferences(store));
+ }
+}