Code cleanup.
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/CommentProcessor.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/CommentProcessor.java
index acdf358..51bf47d 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/CommentProcessor.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/CommentProcessor.java
@@ -9,6 +9,7 @@
package com.google.eclipse.protobuf.junit.core;
import static com.google.eclipse.protobuf.junit.core.GeneratedProtoFiles.*;
+import static java.util.regex.Pattern.compile;
import java.io.*;
import java.util.Scanner;
@@ -19,7 +20,7 @@
*/
class CommentProcessor {
- private static final Pattern CREATE_FILE_PATTERN = Pattern.compile("// Create file (.*)");
+ private static final Pattern CREATE_FILE_PATTERN = compile("// Create file (.*)");
Object processComment(String comment) {
Scanner scanner = new Scanner(comment);
@@ -49,7 +50,7 @@
}
return file;
}
-
+
private void closeQuietly(Writer out) {
if (out == null) return;
try {
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/CodeGenerationErrorParser.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/CodeGenerationErrorParser.java
index b0c74e3..2237fce 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/CodeGenerationErrorParser.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/CodeGenerationErrorParser.java
@@ -8,6 +8,8 @@
*/
package com.google.eclipse.protobuf.ui.builder;
+import static java.util.regex.Pattern.compile;
+
import java.util.regex.*;
import org.eclipse.core.runtime.CoreException;
@@ -25,9 +27,9 @@
* *: whitespace
* 2: description
*/
- private static final Pattern ERROR_PATTERN = Pattern.compile("(.*):\\s*(--.*)");
+ private static final Pattern ERROR_PATTERN = compile("(.*):\\s*(--.*)");
- @Override
+ @Override
public boolean parseAndAddMarkerIfNecessary(String line, ProtocMarkerFactory markerFactory) throws CoreException {
Matcher errorMatcher = ERROR_PATTERN.matcher(line);
if (!errorMatcher.matches()) return false;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/LineSpecificErrorParser.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/LineSpecificErrorParser.java
index aab727b..49ea2cf 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/LineSpecificErrorParser.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/LineSpecificErrorParser.java
@@ -9,6 +9,7 @@
package com.google.eclipse.protobuf.ui.builder;
import static java.lang.Integer.parseInt;
+import static java.util.regex.Pattern.compile;
import java.util.regex.*;
@@ -29,9 +30,9 @@
* *: whitespace
* 4: description
*/
- private static final Pattern ERROR_PATTERN = Pattern.compile("(.*):(\\d+):(\\d+):\\s*(.*)");
+ private static final Pattern ERROR_PATTERN = compile("(.*):(\\d+):(\\d+):\\s*(.*)");
- @Override
+ @Override
public boolean parseAndAddMarkerIfNecessary(String line, ProtocMarkerFactory markerFactory) throws CoreException {
Matcher errorMatcher = ERROR_PATTERN.matcher(line);
if (!errorMatcher.matches()) return false;
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 5f17c9a..2cd4148 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
@@ -9,14 +9,10 @@
package com.google.eclipse.protobuf.ui.commands;
import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.*;
+import static java.util.regex.Pattern.compile;
import static org.eclipse.xtext.util.Strings.isEmpty;
-import com.google.eclipse.protobuf.grammar.CommonKeyword;
-import com.google.eclipse.protobuf.model.util.INodes;
-import com.google.eclipse.protobuf.protobuf.*;
-import com.google.eclipse.protobuf.ui.preferences.pages.editor.numerictag.*;
-import com.google.eclipse.protobuf.ui.util.*;
-import com.google.inject.Inject;
+import java.util.regex.*;
import org.apache.log4j.Logger;
import org.eclipse.emf.ecore.EObject;
@@ -31,7 +27,12 @@
import org.eclipse.xtext.util.Pair;
import org.eclipse.xtext.util.concurrent.IUnitOfWork;
-import java.util.regex.*;
+import com.google.eclipse.protobuf.grammar.CommonKeyword;
+import com.google.eclipse.protobuf.model.util.INodes;
+import com.google.eclipse.protobuf.protobuf.*;
+import com.google.eclipse.protobuf.ui.preferences.pages.editor.numerictag.*;
+import com.google.eclipse.protobuf.ui.util.*;
+import com.google.inject.Inject;
/**
* Inserts a semicolon at the end of a line, regardless of the current position of the caret in the editor. If the
@@ -42,7 +43,7 @@
*/
public class SmartSemicolonHandler extends SmartInsertHandler {
- private static final Pattern NUMBERS_PATTERN = Pattern.compile("[\\d]+");
+ private static final Pattern NUMBERS_PATTERN = compile("[\\d]+");
private static Logger logger = Logger.getLogger(SmartSemicolonHandler.class);
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/documentation/MLCommentDocumentationProvider.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/documentation/MLCommentDocumentationProvider.java
index 4917b06..07fefb2 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/documentation/MLCommentDocumentationProvider.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/documentation/MLCommentDocumentationProvider.java
@@ -8,40 +8,30 @@
*/
package com.google.eclipse.protobuf.ui.documentation;
+import static com.google.eclipse.protobuf.ui.documentation.Patterns.compileAll;
+import static java.util.regex.Pattern.compile;
import static org.eclipse.xtext.nodemodel.util.NodeModelUtils.getNode;
+import java.util.regex.Pattern;
+
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.documentation.IEObjectDocumentationProvider;
import org.eclipse.xtext.nodemodel.*;
-import java.util.*;
-import java.util.regex.Pattern;
-
import com.google.eclipse.protobuf.model.util.INodes;
import com.google.inject.*;
/**
- * Provides single line comments of a protobuf element as its documentation when hovered.
+ * Provides multiple-line comments of a protobuf element as its documentation when hovered.
*
* @author alruiz@google.com (Alex Ruiz)
*/
@Singleton
public class MLCommentDocumentationProvider implements IEObjectDocumentationProvider {
- private static final Pattern COMMENT = Pattern.compile("(?s)/\\*\\*?.*");
-
- private static final List<Pattern> CLEAN_UP = new ArrayList<Pattern>();
-
- static {
- addToCleanUp("\\A/\\*\\*?", "\\*/\\z", "(?m)^( |\\t)*\\** ?", "(?m)( |\\t)*\\**( |\\t)*$");
- }
-
- private static void addToCleanUp(String...patterns) {
- for (String p : patterns) {
- CLEAN_UP.add(Pattern.compile(p));
- }
- }
-
+ private static final Pattern COMMENT = compile("(?s)/\\*\\*?.*");
+ private static final Patterns CLEAN_UP = compileAll("\\A/\\*\\*?", "\\*/\\z", "(?m)^( |\\t)*\\** ?", "(?m)( |\\t)*\\**( |\\t)*$");
+
@Inject private INodes nodes;
@Override public String getDocumentation(EObject o) {
@@ -64,7 +54,7 @@
}
return returnValue;
}
-
+
private String cleanUp(String comment) {
String clean = comment;
for (Pattern pattern : CLEAN_UP) {
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/documentation/Patterns.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/documentation/Patterns.java
new file mode 100644
index 0000000..14c7075
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/documentation/Patterns.java
@@ -0,0 +1,34 @@
+/*
+ * 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.documentation;
+
+import java.util.*;
+import java.util.regex.Pattern;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+class Patterns implements Iterable<Pattern> {
+
+ static Patterns compileAll(String...patterns) {
+ return new Patterns(patterns);
+ }
+
+ private final List<Pattern> patterns = new ArrayList<Pattern>();
+
+ private Patterns(String[] patterns) {
+ for (String s : patterns) {
+ this.patterns.add(Pattern.compile(s));
+ }
+ }
+
+ @Override public Iterator<Pattern> iterator() {
+ return patterns.iterator();
+ }
+}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/documentation/SLCommentDocumentationProvider.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/documentation/SLCommentDocumentationProvider.java
index eaab068..43a0409 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/documentation/SLCommentDocumentationProvider.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/documentation/SLCommentDocumentationProvider.java
@@ -8,40 +8,31 @@
*/
package com.google.eclipse.protobuf.ui.documentation;
+import static com.google.eclipse.protobuf.ui.documentation.Patterns.compileAll;
import static com.google.eclipse.protobuf.util.CommonWords.space;
+import static java.util.regex.Pattern.compile;
import static org.eclipse.xtext.nodemodel.util.NodeModelUtils.getNode;
+import java.util.regex.Pattern;
+
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.documentation.IEObjectDocumentationProvider;
import org.eclipse.xtext.nodemodel.*;
-import java.util.*;
-import java.util.regex.Pattern;
-
import com.google.eclipse.protobuf.model.util.*;
import com.google.eclipse.protobuf.protobuf.*;
import com.google.inject.*;
/**
- * Provides single line comments of a protobuf element as its documentation when hovered.
+ * Provides single-line comments of a protobuf element as its documentation when hovered.
*
* @author alruiz@google.com (Alex Ruiz)
*/
@Singleton
public class SLCommentDocumentationProvider implements IEObjectDocumentationProvider {
- private static final Pattern COMMENT_START = Pattern.compile("//\\s*"); // "//" plus any whitespace
- private static final List<Pattern> NEW_LINE = new ArrayList<Pattern>();
-
- static {
- addToNewLine("\\r\\n", "\\n");
- }
-
- private static void addToNewLine(String...patterns) {
- for (String p : patterns) {
- NEW_LINE.add(Pattern.compile(p));
- }
- }
+ private static final Pattern COMMENT_START = compile("//\\s*"); // "//" plus any whitespace
+ private static final Patterns NEW_LINE = compileAll("\\r\\n", "\\n");
@Inject private FieldOptions fieldOptions;
@Inject private INodes nodes;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPath.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPath.java
index 1aeb5bb..81c9400 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPath.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPath.java
@@ -9,9 +9,9 @@
package com.google.eclipse.protobuf.ui.preferences.pages.paths;
import static com.google.eclipse.protobuf.ui.preferences.pages.paths.ProjectVariable.useProjectName;
+import static java.util.regex.Pattern.compile;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+import java.util.regex.*;
import org.eclipse.core.filesystem.*;
import org.eclipse.core.resources.*;
@@ -24,7 +24,7 @@
*/
public class DirectoryPath {
- private static final Pattern WORKSPACE_PATH_PATTERN = Pattern.compile("\\$\\{workspace_loc:(.*)\\}");
+ private static final Pattern WORKSPACE_PATH_PATTERN = compile("\\$\\{workspace_loc:(.*)\\}");
private final String value;
private final boolean isWorkspacePath;
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/STRINGValueConverter.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/STRINGValueConverter.java
index 8e4f192..e3af982 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/STRINGValueConverter.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/STRINGValueConverter.java
@@ -8,14 +8,15 @@
*/
package com.google.eclipse.protobuf.conversion;
+import static java.util.regex.Pattern.compile;
import static org.eclipse.xtext.util.Strings.*;
+import java.util.regex.Pattern;
+
import org.eclipse.xtext.conversion.ValueConverterException;
import org.eclipse.xtext.conversion.impl.AbstractLexerBasedConverter;
import org.eclipse.xtext.nodemodel.INode;
-import java.util.regex.Pattern;
-
/**
* Converts multi-line strings to {@code String}s.
*
@@ -23,8 +24,8 @@
*/
public class STRINGValueConverter extends AbstractLexerBasedConverter<String> {
- private static final Pattern LINE_BREAK = Pattern.compile("\"[\t\r\n]+\"|'[\t\r\n]+'");
-
+ private static final Pattern LINE_BREAK = compile("\"[\t\r\n]+\"|'[\t\r\n]+'");
+
@Override
protected String toEscapedString(String value) {
if (value == null) return null;