In progress: [Issue 104] Update "Next Id" comment when generating a the
tag number of a field or literal.
Code cleanup.
diff --git a/com.google.eclipse.protobuf.ui/OSGI-INF/l10n/bundle.properties b/com.google.eclipse.protobuf.ui/OSGI-INF/l10n/bundle.properties
index 66f116e..b0aca08 100644
--- a/com.google.eclipse.protobuf.ui/OSGI-INF/l10n/bundle.properties
+++ b/com.google.eclipse.protobuf.ui/OSGI-INF/l10n/bundle.properties
@@ -9,7 +9,7 @@
page.name.3 = Import Paths
page.name.4 = Editor
page.name.5 = Save Actions
-page.name.6 = Tag Number Patterns
+page.name.6 = Numeric Tags
keyword.label = Protocol Buffer
command.description = Trigger expensive validation
command.name = Validate
diff --git a/com.google.eclipse.protobuf.ui/plugin.xml b/com.google.eclipse.protobuf.ui/plugin.xml
index 667dbd2..4e44ea8 100644
--- a/com.google.eclipse.protobuf.ui/plugin.xml
+++ b/com.google.eclipse.protobuf.ui/plugin.xml
@@ -78,8 +78,8 @@
<keywordReference id="com.google.eclipse.protobuf.ui.keyword_Protobuf" />
</page>
<page category="com.google.eclipse.protobuf.ui.preferences.pages.editor"
- class="com.google.eclipse.protobuf.ui.ProtobufExecutableExtensionFactory:com.google.eclipse.protobuf.ui.preferences.pages.editor.tagpatterns.TagPatternsPreferencePage"
- id="com.google.eclipse.protobuf.ui.preferences.pages.editor.tagpatterns.TagPatternsPreferencePage" name="%page.name.6">
+ class="com.google.eclipse.protobuf.ui.ProtobufExecutableExtensionFactory:com.google.eclipse.protobuf.ui.preferences.pages.editor.numerictag.NumericTagPreferencePage"
+ id="com.google.eclipse.protobuf.ui.preferences.pages.editor.numerictag.NumericTagPreferencePage" name="%page.name.6">
<keywordReference id="com.google.eclipse.protobuf.ui.keyword_Protobuf" />
</page>
</extension>
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 3583a3b..a0a43f5 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
@@ -11,7 +11,7 @@
import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.*;
import static org.eclipse.xtext.util.Strings.isEmpty;
-import java.util.regex.Matcher;
+import java.util.regex.*;
import org.apache.log4j.Logger;
import org.eclipse.emf.ecore.EObject;
@@ -44,6 +44,8 @@
*/
public class SmartSemicolonHandler extends SmartInsertHandler {
+ private static final Pattern NUMBERS_PATTERN = Pattern.compile("[\\d]+");
+
private static Logger logger = Logger.getLogger(SmartSemicolonHandler.class);
@Inject private CommentNodesFinder commentNodesFinder;
@@ -66,9 +68,8 @@
ContentToInsert newContent = ContentToInsert.RETRY;
int retryCount = 2;
for (int i = 0; i < retryCount; i++) {
- if (newContent.equals(ContentToInsert.RETRY)) {
- newContent = newContent(editor, styledText, line);
- }
+ if (!newContent.equals(ContentToInsert.RETRY)) break;
+ newContent = newContent(editor, styledText, line);
if (newContent.equals(ContentToInsert.NONE)) return;
if (newContent.equals(ContentToInsert.INSERT_TAG_NUMBER)) {
refreshHighlighting(editor);
@@ -89,9 +90,9 @@
ContentToInsert contentToInsert = ContentToInsert.NONE;
try {
contentToInsert = document.modify(new IUnitOfWork<ContentToInsert, XtextResource>() {
- public ContentToInsert exec(XtextResource state) {
+ public ContentToInsert exec(XtextResource resource) {
int offset = styledText.getCaretOffset();
- ContentAssistContext[] context = contextFactory.create(editor.getInternalSourceViewer(), offset, state);
+ ContentAssistContext[] context = contextFactory.create(editor.getInternalSourceViewer(), offset, resource);
for (ContentAssistContext c : context) {
if (isCommentOrString(c.getCurrentNode())) continue;
EObject model = c.getCurrentModel();
@@ -168,12 +169,12 @@
String pattern = "Next[\\s]+Id:[\\s]+[\\d]+";
Pair<INode, Matcher> match = commentNodesFinder.matchingCommentNode(parent, pattern);
if (match == null) return;
- String originalText = match.getSecond().group();
- String replacement = originalText.replaceFirst("[\\d]+", String.valueOf(index + 1));
+ 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(originalText);
+ int offset = node.getTotalOffset() + node.getText().indexOf(original);
try {
- document.replace(offset, originalText.length(), replacement);
+ document.replace(offset, original.length(), replacement);
} catch (BadLocationException e) {
logger.error("Unable to update comment tracking next tag number", e);
}
@@ -181,8 +182,8 @@
private void refreshHighlighting(XtextEditor editor) {
editor.getDocument().readOnly(new IUnitOfWork.Void<XtextResource>() {
- @Override public void process(XtextResource state) throws Exception {
- highlightingReconciler.modelChanged(state);
+ @Override public void process(XtextResource resource) {
+ highlightingReconciler.modelChanged(resource);
}
});
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/PreferenceAndPropertyPage.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/PreferenceAndPropertyPage.java
index b1a8690..48d1831 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/PreferenceAndPropertyPage.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/PreferenceAndPropertyPage.java
@@ -46,7 +46,7 @@
private final PreferenceBinder preferenceBinder = new PreferenceBinder();
- @Override protected final Control createContents(Composite parent) {
+ @Override protected Control createContents(Composite parent) {
Composite contents = contentParent(parent);
doCreateContents(contents);
if (isPropertyPage()) setupBindingOfBtnEnabledProjectSettings();
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/tagpatterns/TagPatternsPreferencePage.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferencePage.java
similarity index 84%
rename from com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/tagpatterns/TagPatternsPreferencePage.java
rename to com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferencePage.java
index 6e40ca6..dfb2a51 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/tagpatterns/TagPatternsPreferencePage.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferencePage.java
@@ -6,47 +6,47 @@
*
* http://www.eclipse.org/legal/epl-v10.html
*/
-package com.google.eclipse.protobuf.ui.preferences.pages.editor.tagpatterns;
+package com.google.eclipse.protobuf.ui.preferences.pages.editor.numerictag;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.viewers.ListViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
import com.google.eclipse.protobuf.ui.preferences.BooleanPreference;
import com.google.eclipse.protobuf.ui.preferences.binding.PreferenceBinder;
import com.google.eclipse.protobuf.ui.preferences.pages.PreferenceAndPropertyPage;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.*;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.jface.viewers.ListViewer;
-
/**
* Preference page where users can specify the patterns to use to match comments where "the next id" is being tracked.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
-public class TagPatternsPreferencePage extends PreferenceAndPropertyPage {
-
+public class NumericTagPreferencePage extends PreferenceAndPropertyPage {
+ public NumericTagPreferencePage() {
+ }
+
private List lstPaths;
private Button btnAdd;
@Override protected void doCreateContents(Composite parent) {
- Label lblDescription = new Label(parent, SWT.NONE);
- GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
- // gridData.horizontalSpan = 3;
+ Label lblDescription = new Label(parent, SWT.WRAP);
+ GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, false, false, 3, 1);
gridData.widthHint = 150; // only expand further if anyone else requires it
lblDescription.setLayoutData(gridData);
lblDescription.setText("Patterns to match the comments that track the next available tag number in message fields and enum literals.");
-
+
ListViewer lstVwrPaths = new ListViewer(parent, SWT.BORDER | SWT.V_SCROLL);
lstPaths = lstVwrPaths.getList();
- gridData = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
+ gridData = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
gridData.heightHint = 121;
lstPaths.setLayoutData(gridData);
-
+
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false, 1, 1));
composite.setLayout(new GridLayout(1, false));
-
+
btnAdd = new Button(composite, SWT.NONE);
btnAdd.setSize(88, 29);
btnAdd.setText("&Add");
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/save/Messages.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/save/Messages.java
new file mode 100644
index 0000000..bb07e69
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/save/Messages.java
@@ -0,0 +1,26 @@
+/*
+ * 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.save;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class Messages extends NLS {
+
+ public static String removeTrailingWhitespace;
+
+ static {
+ Class<Messages> clazz = Messages.class;
+ NLS.initializeMessages(clazz.getName(), clazz);
+ }
+
+ private Messages() {}
+}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/save/Messages.properties b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/save/Messages.properties
new file mode 100644
index 0000000..2161910
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/save/Messages.properties
@@ -0,0 +1 @@
+removeTrailingWhitespace=Remove trailing &whitespace
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/save/SaveActionsPreferencePage.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/save/SaveActionsPreferencePage.java
index 4116204..7b1e989 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/save/SaveActionsPreferencePage.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/save/SaveActionsPreferencePage.java
@@ -1,30 +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.save;
import static com.google.eclipse.protobuf.ui.preferences.binding.BindingToButtonSelection.bindSelectionOf;
-import com.google.eclipse.protobuf.ui.preferences.binding.*;
-import com.google.inject.Inject;
-
import org.eclipse.jface.preference.*;
-import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.*;
import org.eclipse.xtext.ui.editor.preferences.IPreferenceStoreAccess;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
+
+import com.google.eclipse.protobuf.ui.preferences.binding.PreferenceBinder;
+import com.google.inject.Inject;
/**
* "Save Actions" preference page.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class SaveActionsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
@@ -42,8 +41,8 @@
Composite contents = new Composite(parent, NONE);
contents.setLayout(new GridLayout(1, false));
btnRemoveTrailingwhitespace = new Button(contents, SWT.CHECK);
- btnRemoveTrailingwhitespace.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
- btnRemoveTrailingwhitespace.setText("Remove trailing &whitespace");
+ btnRemoveTrailingwhitespace.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, false, 1, 1));
+ btnRemoveTrailingwhitespace.setText(Messages.removeTrailingWhitespace);
setUpBinding();
preferenceBinder.applyValues();
return contents;
@@ -56,10 +55,6 @@
);
}
- /**
- * Returns the preference store of this preference page.
- * @return the preference store.
- */
@Override protected final IPreferenceStore doGetPreferenceStore() {
return preferenceStoreAccess.getWritablePreferenceStore();
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/validation/Validation.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/validation/Validation.java
index d8186de..39901c3 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/validation/Validation.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/validation/Validation.java
@@ -61,18 +61,17 @@
private static void validate(XtextEditor editor) {
final IXtextDocument document = editor.getDocument();
if (!(document instanceof XtextDocument)) return;
- document.readOnly(new IUnitOfWork<Void, XtextResource>() {
- public java.lang.Void exec(XtextResource resource) throws Exception {
+ document.readOnly(new IUnitOfWork.Void<XtextResource>() {
+ @Override public void process(XtextResource resource) {
EObject root = rootOf(resource);
- if (root == null) return null;
+ if (root == null) return;
resetImports(root);
resource.getLinker().linkModel(root, new ListBasedDiagnosticConsumer());
((XtextDocument) document).checkAndUpdateAnnotations();
- return null;
}
});
}
-
+
private static EObject rootOf(XtextResource resource) {
if (resource == null) return null;
return resource.getParseResult().getRootASTElement();