Upgraded to Xtext 2.2.1.
diff --git a/com.google.eclipse.protobuf.feature/feature.xml b/com.google.eclipse.protobuf.feature/feature.xml
index 6a6e436..b84e30b 100644
--- a/com.google.eclipse.protobuf.feature/feature.xml
+++ b/com.google.eclipse.protobuf.feature/feature.xml
@@ -39,7 +39,7 @@
<import plugin="org.eclipse.emf.databinding"/>
<import plugin="org.eclipse.core.resources"/>
<import plugin="org.eclipse.core.filesystem" version="1.3.100" match="greaterOrEqual"/>
- <import plugin="org.eclipse.xtext" version="2.1.1" match="greaterOrEqual"/>
+ <import plugin="org.eclipse.xtext" version="2.2.1" match="greaterOrEqual"/>
<import plugin="org.eclipse.compare.core" version="3.5.200" match="greaterOrEqual"/>
<import plugin="org.eclipse.ui.workbench.texteditor"/>
</requires>
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/junit/IEObjectDescriptions.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/junit/IEObjectDescriptions.java
index cb1b5ce..4cbff1e 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/junit/IEObjectDescriptions.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/junit/IEObjectDescriptions.java
@@ -8,6 +8,7 @@
*/
package com.google.eclipse.protobuf.junit;
+import static com.google.common.collect.Maps.newLinkedHashMap;
import static java.util.Collections.unmodifiableSet;
import java.util.*;
@@ -30,7 +31,7 @@
return new IEObjectDescriptions(elements);
}
- private final Map<String, IEObjectDescription> descriptions = new LinkedHashMap<String, IEObjectDescription>();
+ private final Map<String, IEObjectDescription> descriptions = newLinkedHashMap();
private IEObjectDescriptions(Iterable<IEObjectDescription> elements) {
for (IEObjectDescription d : elements) {
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/junit/matchers/ContainAllFields.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/junit/matchers/ContainAllFields.java
index ca4c976..bb6827b 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/junit/matchers/ContainAllFields.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/junit/matchers/ContainAllFields.java
@@ -8,11 +8,15 @@
*/
package com.google.eclipse.protobuf.junit.matchers;
-import java.util.*;
+import static com.google.common.collect.Collections2.transform;
+import static com.google.common.collect.Lists.newArrayList;
+
+import java.util.Collection;
import org.eclipse.emf.ecore.EObject;
import org.hamcrest.*;
+import com.google.common.base.Function;
import com.google.eclipse.protobuf.junit.IEObjectDescriptions;
import com.google.eclipse.protobuf.protobuf.MessageField;
@@ -21,7 +25,7 @@
*/
public class ContainAllFields extends BaseMatcher<IEObjectDescriptions> {
- private final Collection<MessageField> fields = new ArrayList<MessageField>();
+ private final Collection<MessageField> fields = newArrayList();
public static ContainAllFields containAll(Collection<MessageField> fields) {
return new ContainAllFields(fields);
@@ -50,10 +54,11 @@
}
@Override public void describeTo(Description description) {
- List<String> names = new ArrayList<String>();
- for (MessageField field : fields) {
- names.add(field.getName());
- }
+ Collection<String> names = transform(fields, new Function<MessageField, String>() {
+ @Override public String apply(MessageField input) {
+ return input.getName();
+ }
+ });
description.appendValue(names);
}
}
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/junit/matchers/ContainAllFieldsInMessage.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/junit/matchers/ContainAllFieldsInMessage.java
index 2f53cd3..1d55270 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/junit/matchers/ContainAllFieldsInMessage.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/junit/matchers/ContainAllFieldsInMessage.java
@@ -8,6 +8,7 @@
*/
package com.google.eclipse.protobuf.junit.matchers;
+import static com.google.common.collect.Collections2.transform;
import static org.eclipse.xtext.EcoreUtil2.getAllContentsOfType;
import java.util.*;
@@ -15,6 +16,7 @@
import org.eclipse.emf.ecore.EObject;
import org.hamcrest.*;
+import com.google.common.base.Function;
import com.google.eclipse.protobuf.junit.IEObjectDescriptions;
import com.google.eclipse.protobuf.protobuf.*;
@@ -57,10 +59,12 @@
}
@Override public void describeTo(Description description) {
- List<String> names = new ArrayList<String>();
- for (IndexedElement e : allIndexedElements()) {
- names.add(nameOf(e));
- }
+ List<IndexedElement> allIndexedElements = allIndexedElements();
+ Collection<String> names = transform(allIndexedElements, new Function<IndexedElement, String>() {
+ @Override public String apply(IndexedElement input) {
+ return nameOf(input);
+ }
+ });
description.appendValue(names);
}
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/junit/matchers/ContainAllLiteralsInEnum.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/junit/matchers/ContainAllLiteralsInEnum.java
index 6fd2fdb..4a667e0 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/junit/matchers/ContainAllLiteralsInEnum.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/junit/matchers/ContainAllLiteralsInEnum.java
@@ -8,6 +8,7 @@
*/
package com.google.eclipse.protobuf.junit.matchers;
+import static com.google.common.collect.Collections2.transform;
import static org.eclipse.xtext.EcoreUtil2.getAllContentsOfType;
import java.util.*;
@@ -15,6 +16,7 @@
import org.eclipse.emf.ecore.EObject;
import org.hamcrest.*;
+import com.google.common.base.Function;
import com.google.eclipse.protobuf.junit.IEObjectDescriptions;
import com.google.eclipse.protobuf.protobuf.*;
import com.google.eclipse.protobuf.protobuf.Enum;
@@ -54,11 +56,11 @@
}
@Override public void describeTo(Description description) {
- List<String> names = new ArrayList<String>();
- for (Literal literal : allLiterals()) {
- String name = literal.getName();
- names.add(name);
- }
+ Collection<String> names = transform(allLiterals(), new Function<Literal, String>() {
+ @Override public String apply(Literal input) {
+ return input.getName();
+ }
+ });
description.appendValue(names);
}
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/junit/matchers/ContainAllNames.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/junit/matchers/ContainAllNames.java
index c818b62..3103edf 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/junit/matchers/ContainAllNames.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/junit/matchers/ContainAllNames.java
@@ -8,6 +8,8 @@
*/
package com.google.eclipse.protobuf.junit.matchers;
+import static com.google.common.collect.Lists.newArrayList;
+
import java.util.*;
import org.hamcrest.*;
@@ -34,7 +36,7 @@
return false;
}
IEObjectDescriptions descriptions = (IEObjectDescriptions) arg;
- List<String> names = new ArrayList<String>(descriptions.names());
+ List<String> names = newArrayList(descriptions.names());
if (names.size() != expectedNames.length) {
return false;
}
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtoDescriptor_availableOptionsFor_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtoDescriptor_availableOptionsFor_Test.java
index e2df747..82c21e3 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtoDescriptor_availableOptionsFor_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtoDescriptor_availableOptionsFor_Test.java
@@ -8,6 +8,7 @@
*/
package com.google.eclipse.protobuf.scoping;
+import static com.google.common.collect.Maps.newHashMap;
import static com.google.eclipse.protobuf.junit.core.Setups.integrationTestSetup;
import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
import static com.google.eclipse.protobuf.junit.matchers.FieldHasType.*;
@@ -77,7 +78,7 @@
}
private static class Options {
- private final Map<String, MessageField> optionsByName = new HashMap<String, MessageField>();
+ private final Map<String, MessageField> optionsByName = newHashMap();
void mapByName(Collection<MessageField> options) {
optionsByName.clear();
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/TestSourceReader.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/TestSourceReader.java
index 418e23b..a370b6d 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/TestSourceReader.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/TestSourceReader.java
@@ -9,6 +9,8 @@
*/
package com.google.eclipse.protobuf.junit.core;
+import static com.google.common.collect.Lists.newArrayList;
+import static com.google.common.collect.Maps.newHashMap;
import static java.io.File.separator;
import java.io.*;
@@ -25,7 +27,7 @@
private static final String COMMENT_START = "//";
- private final Map<String, List<String>> comments = new HashMap<String, List<String>>();
+ private final Map<String, List<String>> comments = newHashMap();
private final CommentProcessor processor = new CommentProcessor();
private boolean initialized;
@@ -63,7 +65,7 @@
String classFile = fqn + ".java";
File file = new File("src" + separator + classFile);
Scanner scanner = null;
- List<String> allComments = new ArrayList<String>();
+ List<String> allComments = newArrayList();
MultiLineTextBuilder comment = new MultiLineTextBuilder();
try {
scanner = new Scanner(new FileInputStream(file));
@@ -87,7 +89,7 @@
}
if (testName != null) {
comments.put(testName, allComments);
- allComments = new ArrayList<String>();
+ allComments = newArrayList();
}
}
} catch (IOException e) {
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/matchers/EnumHasLiterals.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/matchers/EnumHasLiterals.java
index 6f5c274..92656ec 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/matchers/EnumHasLiterals.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/matchers/EnumHasLiterals.java
@@ -8,12 +8,15 @@
*/
package com.google.eclipse.protobuf.junit.matchers;
+import static com.google.common.collect.Collections2.transform;
+import static com.google.common.collect.Lists.newArrayList;
import static org.eclipse.xtext.EcoreUtil2.getAllContentsOfType;
import java.util.*;
import org.hamcrest.*;
+import com.google.common.base.Function;
import com.google.eclipse.protobuf.protobuf.*;
import com.google.eclipse.protobuf.protobuf.Enum;
@@ -37,19 +40,20 @@
return false;
}
Enum anEnum = (Enum) arg;
- List<String> actualNames = literalNames(anEnum);
+ List<String> actualNames = newArrayList(literalNames(anEnum));
for (String name : literalNames) {
actualNames.remove(name);
}
return actualNames.isEmpty();
}
- private List<String> literalNames(Enum anEnum) {
- List<String> names = new ArrayList<String>();
- for (Literal literal : getAllContentsOfType(anEnum, Literal.class)) {
- names.add(literal.getName());
- }
- return names;
+ private Collection<String> literalNames(Enum anEnum) {
+ List<Literal> allLiterals = getAllContentsOfType(anEnum, Literal.class);
+ return transform(allLiterals, new Function<Literal, String>() {
+ @Override public String apply(Literal input) {
+ return input.getName();
+ }
+ });
}
@Override public void describeTo(Description description) {
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/resources/FileStub.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/resources/FileStub.java
index ada60de..d6edac2 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/resources/FileStub.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/resources/FileStub.java
@@ -8,6 +8,8 @@
*/
package com.google.eclipse.protobuf.junit.stubs.resources;
+import static com.google.common.collect.Lists.newArrayList;
+import static com.google.common.collect.Maps.newHashMap;
import static java.util.Collections.*;
import java.io.*;
@@ -24,7 +26,7 @@
*/
public class FileStub implements IFile {
- private final Map<String, List<MarkerStub>> markersByType = new HashMap<String, List<MarkerStub>>();
+ private final Map<String, List<MarkerStub>> markersByType = newHashMap();
private IPath location;
/** {@inheritDoc} */
@@ -537,7 +539,7 @@
String type = marker.getType();
List<MarkerStub> markers = markersByType.get(type);
if (markers == null) {
- markers = new ArrayList<MarkerStub>();
+ markers = newArrayList();
markersByType.put(type, markers);
}
markers.add(marker);
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/resources/MarkerStub.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/resources/MarkerStub.java
index b90a24e..f3a7c2b 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/resources/MarkerStub.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/resources/MarkerStub.java
@@ -8,19 +8,23 @@
*/
package com.google.eclipse.protobuf.junit.stubs.resources;
-import static com.google.eclipse.protobuf.util.Objects.*;
+import static com.google.common.base.Objects.equal;
+import static com.google.common.collect.Lists.newArrayList;
+import static com.google.common.collect.Maps.newHashMap;
import static java.util.Collections.unmodifiableMap;
import java.util.*;
import org.eclipse.core.resources.*;
+import com.google.common.base.Objects;
+
/**
* @author alruiz@google.com (Alex Ruiz)
*/
public class MarkerStub implements IMarker {
- private final Map<String, Object> attributes = new HashMap<String, Object>();
+ private final Map<String, Object> attributes = newHashMap();
private final String type;
private final long creationTime;
@@ -91,7 +95,7 @@
/** {@inheritDoc} */
@Override public Object[] getAttributes(String[] attributeNames) {
- List<Object> values = new ArrayList<Object>();
+ List<Object> values = newArrayList();
for (String name : attributeNames) {
values.add(attributes.get(name));
}
@@ -168,18 +172,14 @@
return false;
}
MarkerStub other = (MarkerStub) obj;
- if (!areEqual(attributes, other.attributes)) {
+ if (!equal(attributes, other.attributes)) {
return false;
}
- return areEqual(type, other.type);
+ return equal(type, other.type);
}
@Override public int hashCode() {
- final int prime = HASH_CODE_PRIME;
- int result = 1;
- result = prime * result + hashCodeOf(attributes);
- result = prime * result + hashCodeOf(type);
- return result;
+ return Objects.hashCode(attributes, type);
}
@Override public String toString() {
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_localExtensionsFrom_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_localExtensionsFrom_Test.java
index 3832a9e..b81d23e 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_localExtensionsFrom_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/ModelFinder_localExtensionsFrom_Test.java
@@ -8,11 +8,12 @@
*/
package com.google.eclipse.protobuf.model.util;
+import static com.google.common.collect.Lists.newArrayList;
import static com.google.eclipse.protobuf.junit.core.Setups.unitTestSetup;
import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
import static org.junit.Assert.assertSame;
-import java.util.*;
+import java.util.List;
import org.junit.*;
@@ -43,7 +44,7 @@
// extend Person {}
@Test public void should_return_extensions_of_message() {
Message m = xtext.find("Person", " {", Message.class);
- List<TypeExtension> extensions = new ArrayList<TypeExtension>(finder.localExtensionsOf(m));
+ List<TypeExtension> extensions = newArrayList(finder.localExtensionsOf(m));
Message referred = (Message) extensions.get(0).getType().getTarget();
assertSame(m, referred);
}
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/contentassist/IEObjectDescriptionChooser_shortestQualifiedNamesIn_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/contentassist/IEObjectDescriptionChooser_shortestQualifiedNamesIn_Test.java
index c665c58..f13c218 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/contentassist/IEObjectDescriptionChooser_shortestQualifiedNamesIn_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/contentassist/IEObjectDescriptionChooser_shortestQualifiedNamesIn_Test.java
@@ -8,6 +8,7 @@
*/
package com.google.eclipse.protobuf.ui.contentassist;
+import static com.google.common.collect.Lists.newArrayList;
import static com.google.eclipse.protobuf.ui.contentassist.IEObjectDescriptionsHaveNames.containOnly;
import static java.util.Collections.emptyMap;
import static org.junit.Assert.assertThat;
@@ -36,7 +37,7 @@
@Before public void setUp() {
userData = emptyMap();
chooser = new IEObjectDescriptionChooser();
- descriptions = new ArrayList<IEObjectDescription>();
+ descriptions = newArrayList();
describe(mock(Message.class), QualifiedName.create("com", "google", "test", "Phone"));
describe(mock(Message.class), QualifiedName.create("com", "google", "test", "EMail"));
}
@@ -54,7 +55,7 @@
*/
private void describe(EObject e, QualifiedName name) {
int count = name.getSegmentCount();
- List<String> segments = new ArrayList<String>();
+ List<String> segments = newArrayList();
for (int i = count - 1; i >= 0; i--) {
segments.add(0, name.getSegment(i));
QualifiedName newName = QualifiedName.create(segments.toArray(new String[segments.size()]));
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/contentassist/IEObjectDescriptionsHaveNames.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/contentassist/IEObjectDescriptionsHaveNames.java
index bce9d0b..7227d79 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/contentassist/IEObjectDescriptionsHaveNames.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/contentassist/IEObjectDescriptionsHaveNames.java
@@ -8,7 +8,7 @@
*/
package com.google.eclipse.protobuf.ui.contentassist;
-import static java.util.Arrays.asList;
+import static com.google.common.collect.Lists.newArrayList;
import java.util.*;
@@ -28,7 +28,7 @@
}
private IEObjectDescriptionsHaveNames(String[] qualifiedNames) {
- this.qualifiedNames = new ArrayList<String>(asList(qualifiedNames));
+ this.qualifiedNames = newArrayList(qualifiedNames);
}
/** {@inheritDoc} */
@@ -38,7 +38,7 @@
return false;
}
Collection<IEObjectDescription> descriptions = (Collection<IEObjectDescription>) arg;
- List<String> copyOfNames = new ArrayList<String>(qualifiedNames);
+ List<String> copyOfNames = newArrayList(qualifiedNames);
if (copyOfNames.size() != descriptions.size()) {
return false;
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtobufBuildParticipant.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtobufBuildParticipant.java
index 9843e2f..65c51c9 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtobufBuildParticipant.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtobufBuildParticipant.java
@@ -8,6 +8,7 @@
*/
package com.google.eclipse.protobuf.ui.builder.protoc;
+import static com.google.common.collect.Lists.newArrayList;
import static com.google.eclipse.protobuf.ui.exception.CoreExceptions.error;
import static com.google.eclipse.protobuf.ui.preferences.compiler.core.CompilerPreferences.compilerPreferences;
import static com.google.eclipse.protobuf.ui.util.CommaSeparatedValues.splitCsv;
@@ -16,7 +17,7 @@
import static org.eclipse.core.resources.IResource.DEPTH_INFINITE;
import java.io.*;
-import java.util.*;
+import java.util.List;
import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.*;
@@ -75,7 +76,7 @@
}
private List<String> importRoots(IProject project) {
- List<String> paths = new ArrayList<String>();
+ List<String> paths = newArrayList();
PathsPreferences preferences = new PathsPreferences(storeAccess, project);
if (preferences.filesInMultipleDirectories().getValue()) {
String directoryPaths = preferences.directoryPaths().getValue();
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/CommentNodesFinder.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/CommentNodesFinder.java
index 5541f16..9f80cbb 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/CommentNodesFinder.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/CommentNodesFinder.java
@@ -8,13 +8,14 @@
*/
package com.google.eclipse.protobuf.ui.commands;
+import static com.google.common.collect.Lists.newArrayList;
import static com.google.eclipse.protobuf.util.SystemProperties.lineSeparator;
import static java.util.regex.Pattern.CASE_INSENSITIVE;
import static org.eclipse.xtext.nodemodel.util.NodeModelUtils.getNode;
import static org.eclipse.xtext.util.Strings.isEmpty;
import static org.eclipse.xtext.util.Tuples.pair;
-import java.util.*;
+import java.util.List;
import java.util.regex.*;
import org.eclipse.emf.ecore.EObject;
@@ -58,7 +59,7 @@
}
private List<Pattern> compile(String[] patterns, EObject target) {
- List<Pattern> compiled = new ArrayList<Pattern>();
+ List<Pattern> compiled = newArrayList();
for (final String s : patterns) {
Pattern p = cache.get(s, target.eResource(), new Provider<Pattern>() {
@Override public Pattern get() {
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/IEObjectDescriptionChooser.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/IEObjectDescriptionChooser.java
index e2adf8d..a0b0cc0 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/IEObjectDescriptionChooser.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/IEObjectDescriptionChooser.java
@@ -8,6 +8,7 @@
*/
package com.google.eclipse.protobuf.ui.contentassist;
+import static com.google.common.collect.Maps.newHashMap;
import static java.util.Collections.*;
import java.util.*;
@@ -24,7 +25,7 @@
if (descriptions.isEmpty()) {
return emptySet();
}
- Map<EObject, IEObjectDescription> shortestOnes = new HashMap<EObject, IEObjectDescription>();
+ Map<EObject, IEObjectDescription> shortestOnes = newHashMap();
for (IEObjectDescription d : descriptions) {
EObject e = d.getEObjectOrProxy();
IEObjectDescription stored = shortestOnes.get(e);
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/ProtobufProposalProvider.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/ProtobufProposalProvider.java
index d818d01..5b9790a 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/ProtobufProposalProvider.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/contentassist/ProtobufProposalProvider.java
@@ -8,6 +8,7 @@
*/
package com.google.eclipse.protobuf.ui.contentassist;
+import static com.google.common.collect.Lists.newArrayList;
import static com.google.eclipse.protobuf.grammar.CommonKeyword.*;
import static com.google.eclipse.protobuf.protobuf.Modifier.*;
import static com.google.eclipse.protobuf.ui.grammar.CompoundElement.*;
@@ -380,7 +381,7 @@
if (allFieldOptions.isEmpty()) {
return emptyList();
}
- List<String> optionNames = new ArrayList<String>();
+ List<String> optionNames = newArrayList();
for (FieldOption option : allFieldOptions) {
optionNames.add(options.nameOf(option));
}
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
index edc776e..8b5d3f7 100644
--- 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
@@ -8,6 +8,8 @@
*/
package com.google.eclipse.protobuf.ui.documentation;
+import static com.google.common.collect.Lists.newArrayList;
+
import java.util.*;
import java.util.regex.Pattern;
@@ -19,7 +21,7 @@
return new Patterns(patterns);
}
- private final List<Pattern> patterns = new ArrayList<Pattern>();
+ private final List<Pattern> patterns = newArrayList();
private Patterns(String[] patterns) {
for (String s : patterns) {
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/documentation/ProtobufDocumentationProvider.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/documentation/ProtobufDocumentationProvider.java
index b6a13da..4e1425c 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/documentation/ProtobufDocumentationProvider.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/documentation/ProtobufDocumentationProvider.java
@@ -8,9 +8,10 @@
*/
package com.google.eclipse.protobuf.ui.documentation;
+import static com.google.common.collect.Lists.newArrayList;
import static org.eclipse.xtext.util.Strings.isEmpty;
-import java.util.*;
+import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.documentation.IEObjectDocumentationProvider;
@@ -24,11 +25,10 @@
* @author alruiz@google.com (Alex Ruiz)
*/
@Singleton public class ProtobufDocumentationProvider implements IEObjectDocumentationProvider {
- private final List<IEObjectDocumentationProvider> delegates = new ArrayList<IEObjectDocumentationProvider>();
+ private final List<IEObjectDocumentationProvider> delegates;
@Inject public ProtobufDocumentationProvider(SLCommentDocumentationProvider p1, MLCommentDocumentationProvider p2) {
- delegates.add(p1);
- delegates.add(p2);
+ delegates = newArrayList(p1, p2);
}
/** {@inheritDoc} */
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/UriEditorInput.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/UriEditorInput.java
index 4fd19b7..f371b52 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/UriEditorInput.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/UriEditorInput.java
@@ -8,13 +8,15 @@
*/
package com.google.eclipse.protobuf.ui.editor;
-import static com.google.eclipse.protobuf.util.Objects.*;
+import static com.google.common.base.Objects.equal;
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.*;
+import com.google.common.base.Objects;
+
/**
* @author alruiz@google.com (Alex Ruiz)
*/
@@ -64,17 +66,13 @@
return false;
}
UriEditorInput other = (UriEditorInput) obj;
- if (!areEqual(name, other.name)) {
+ if (!equal(name, other.name)) {
return false;
}
- return areEqual(fileUri, other.fileUri);
+ return equal(fileUri, other.fileUri);
}
@Override public int hashCode() {
- final int prime = HASH_CODE_PRIME;
- int result = 1;
- result = prime * result + hashCodeOf(name);
- result = prime * result + hashCodeOf(fileUri);
- return result;
+ return Objects.hashCode(name, fileUri);
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/DocumentContentsFactoryRegistry.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/DocumentContentsFactoryRegistry.java
index 88856e3..dac5e07 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/DocumentContentsFactoryRegistry.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/DocumentContentsFactoryRegistry.java
@@ -8,22 +8,22 @@
*/
package com.google.eclipse.protobuf.ui.editor.model;
-import java.util.*;
+import java.util.List;
import org.eclipse.ui.IEditorInput;
+import com.google.common.collect.Lists;
import com.google.inject.Inject;
/**
* @author alruiz@google.com (Alex Ruiz)
*/
class DocumentContentsFactoryRegistry {
- private final List<DocumentContentsFactory> factories = new ArrayList<DocumentContentsFactory>();
+ private final List<DocumentContentsFactory> factories;
@Inject
- DocumentContentsFactoryRegistry(FileStoreDocumentContentsFactory factory1, UriDocumentContentsFactory factory2) {
- factories.add(factory1);
- factories.add(factory2);
+ DocumentContentsFactoryRegistry(FileStoreDocumentContentsFactory f1, UriDocumentContentsFactory f2) {
+ factories = Lists.newArrayList(f1, f2);
}
DocumentContentsFactory findFactory(Object element) {
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/labeling/Images.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/labeling/Images.java
index ce2ad49..95ca2e7 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/labeling/Images.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/labeling/Images.java
@@ -8,6 +8,7 @@
*/
package com.google.eclipse.protobuf.ui.labeling;
+import static com.google.common.collect.Maps.newHashMap;
import static com.google.eclipse.protobuf.protobuf.Modifier.*;
import static java.util.Arrays.asList;
@@ -29,14 +30,14 @@
private static final String GIF_EXTENSION = ".gif";
private static final String DEFAULT_IMAGE = "empty.gif";
- private static final Map<Modifier, String> IMAGES_BY_MODIFIER = new HashMap<Modifier, String>();
+ private static final Map<Modifier, String> IMAGES_BY_MODIFIER = newHashMap();
static {
IMAGES_BY_MODIFIER.put(OPTIONAL, "field-opt.gif");
IMAGES_BY_MODIFIER.put(REPEATED, "field-rep.gif");
IMAGES_BY_MODIFIER.put(REQUIRED, "field-req.gif");
}
- private static final Map<Class<?>, String> IMAGES_BY_TYPE = new HashMap<Class<?>, String>();
+ private static final Map<Class<?>, String> IMAGES_BY_TYPE = newHashMap();
static {
IMAGES_BY_TYPE.put(Enum.class, "enum.gif");
IMAGES_BY_TYPE.put(TypeExtension.class, "extend.gif");
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/outline/OutlineViewModel.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/outline/OutlineViewModel.java
index 3833a4a..af198a3 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/outline/OutlineViewModel.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/outline/OutlineViewModel.java
@@ -8,7 +8,7 @@
*/
package com.google.eclipse.protobuf.ui.outline;
-import static com.google.inject.internal.Maps.newLinkedHashMap;
+import static com.google.common.collect.Maps.newLinkedHashMap;
import static java.util.Collections.unmodifiableList;
import java.util.*;
@@ -21,7 +21,6 @@
/**
* @author alruiz@google.com (Alex Ruiz)
*/
-@SuppressWarnings("restriction")
class OutlineViewModel {
private static final Class<?>[] GROUP_TYPES = { Package.class, Import.class, ProtobufElement.class };
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/outline/ProtobufOutlineTreeProvider.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/outline/ProtobufOutlineTreeProvider.java
index 1ceec4b..c61e6a6 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/outline/ProtobufOutlineTreeProvider.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/outline/ProtobufOutlineTreeProvider.java
@@ -8,9 +8,10 @@
*/
package com.google.eclipse.protobuf.ui.outline;
+import static com.google.common.collect.Lists.newArrayList;
import static com.google.eclipse.protobuf.ui.outline.Messages.importDeclarations;
-import java.util.*;
+import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.ui.editor.outline.IOutlineNode;
@@ -25,7 +26,7 @@
* @author alruiz@google.com (Alex Ruiz)
*/
public class ProtobufOutlineTreeProvider extends DefaultOutlineTreeProvider {
- private static final List<Class<? extends EObject>> IGNORED_ELEMENT_TYPES = new ArrayList<Class<? extends EObject>>();
+ private static final List<Class<? extends EObject>> IGNORED_ELEMENT_TYPES = newArrayList();
static {
IGNORED_ELEMENT_TYPES.add(BooleanLink.class);
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/editor/save/page/SaveActionsPreferencePage.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/editor/save/page/SaveActionsPreferencePage.java
index 220b39a..0e4b1d9 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/editor/save/page/SaveActionsPreferencePage.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/editor/save/page/SaveActionsPreferencePage.java
@@ -84,20 +84,20 @@
private void updateContents() {
boolean enabled = btnRemoveTrailingwhitespace.getSelection();
- btnInEditedLines.setEnabled(enabled);
btnInAllLines.setEnabled(enabled);
+ btnInEditedLines.setEnabled(enabled);
}
- @Override protected final IPreferenceStore doGetPreferenceStore() {
+ @Override protected IPreferenceStore doGetPreferenceStore() {
return preferenceStoreAccess.getWritablePreferenceStore();
}
- @Override public final boolean performOk() {
+ @Override public boolean performOk() {
preferenceBinder.saveValues();
return true;
}
- @Override protected final void performDefaults() {
+ @Override protected void performDefaults() {
preferenceBinder.applyDefaults();
super.performDefaults();
updateContents();
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/binding/PreferenceBinder.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/binding/PreferenceBinder.java
index 5fcab9b..8ba6f42 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/binding/PreferenceBinder.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/binding/PreferenceBinder.java
@@ -8,7 +8,9 @@
*/
package com.google.eclipse.protobuf.ui.preferences.pages.binding;
-import java.util.*;
+import static com.google.common.collect.Lists.newArrayList;
+
+import java.util.List;
/**
* Binds preference values to properties in UI controls.
@@ -16,7 +18,7 @@
* @author alruiz@google.com (Alex Ruiz)
*/
public class PreferenceBinder {
- private final List<Binding> allBindings = new ArrayList<Binding>();
+ private final List<Binding> allBindings = newArrayList();
/**
* Adds all the given bindings to this binder.
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/page/PathsPreferencePage.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/page/PathsPreferencePage.java
index acfb64c..f2c97cb 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/page/PathsPreferencePage.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/paths/page/PathsPreferencePage.java
@@ -8,6 +8,7 @@
*/
package com.google.eclipse.protobuf.ui.preferences.paths.page;
+import static com.google.common.collect.Lists.newArrayList;
import static com.google.eclipse.protobuf.ui.ProtobufUiModule.PLUGIN_ID;
import static com.google.eclipse.protobuf.ui.preferences.pages.ButtonGroup.with;
import static com.google.eclipse.protobuf.ui.preferences.pages.binding.BindingToButtonSelection.bindSelectionOf;
@@ -18,7 +19,6 @@
import static org.eclipse.core.runtime.jobs.Job.BUILD;
import static org.eclipse.xtext.util.Strings.*;
-import java.util.*;
import java.util.List;
import org.apache.log4j.Logger;
@@ -145,12 +145,11 @@
}
private void setDirectoryPaths(String directoryPaths) {
- List<String> paths = new ArrayList<String>();
+ List<String> paths = newArrayList();
for (String path : split(directoryPaths, COMMA_DELIMITER)) {
- if (isEmpty(path)) {
- continue;
+ if (!isEmpty(path)) {
+ paths.add(path);
}
- paths.add(path);
}
directoryPathsEditor.directoryPaths(unmodifiableList(paths));
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/quickfix/ProtobufQuickAssistProcessor.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/quickfix/ProtobufQuickAssistProcessor.java
index 4968f34..26325d9 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/quickfix/ProtobufQuickAssistProcessor.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/quickfix/ProtobufQuickAssistProcessor.java
@@ -9,10 +9,11 @@
*/
package com.google.eclipse.protobuf.ui.quickfix;
+import static com.google.common.collect.Lists.newArrayList;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
-import java.util.*;
+import java.util.List;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext;
@@ -28,7 +29,7 @@
@Inject private SpellingCorrectionProcessor spellingCorrectionProcessor;
@Override public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext context) {
- List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
+ List<ICompletionProposal> proposals = newArrayList();
proposals.addAll(spellingFixes(context));
proposals.addAll(asList(super.computeQuickAssistProposals(context)));
return proposals.toArray(new ICompletionProposal[proposals.size()]);
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/MultipleDirectoriesFileResolver.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/MultipleDirectoriesFileResolver.java
index da52eb4..d71c808 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/MultipleDirectoriesFileResolver.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/MultipleDirectoriesFileResolver.java
@@ -8,9 +8,10 @@
*/
package com.google.eclipse.protobuf.ui.scoping;
+import static com.google.common.collect.Lists.newArrayList;
import static com.google.eclipse.protobuf.ui.util.CommaSeparatedValues.splitCsv;
-import java.util.*;
+import java.util.List;
import org.eclipse.core.filesystem.*;
import org.eclipse.core.filesystem.URIUtil;
@@ -35,7 +36,7 @@
/** {@inheritDoc} */
@Override public String resolveUri(String importUri, URI declaringResourceUri, PathsPreferences preferences) {
String directoryPaths = preferences.directoryPaths().getValue();
- List<String> fileSystemDirectories = new ArrayList<String>();
+ List<String> fileSystemDirectories = newArrayList();
for (String importRoot : splitCsv(directoryPaths)) {
DirectoryPath path = DirectoryPath.parse(importRoot, preferences.getProject());
String resolved = resolveUri(importUri, path);
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolver.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolver.java
index a40386a..6ff0ba4 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolver.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolver.java
@@ -8,9 +8,11 @@
*/
package com.google.eclipse.protobuf.ui.scoping;
+import static com.google.common.collect.Lists.newArrayList;
+import static java.util.Collections.*;
import static org.eclipse.emf.common.util.URI.createURI;
-import java.util.*;
+import java.util.List;
import org.eclipse.emf.common.util.URI;
@@ -63,12 +65,13 @@
// first is always "platform" and last is the file name (both unnecessary)
private static List<String> removeFirstAndLast(URI declaringResourceUri) {
- List<String> segments = new ArrayList<String>(declaringResourceUri.segmentsList());
- if (segments.isEmpty()) {
- return segments;
+ List<String> originalSegments = declaringResourceUri.segmentsList();
+ if (originalSegments.isEmpty()) {
+ return emptyList();
}
+ List<String> segments = newArrayList(originalSegments);
segments.remove(0);
segments.remove(segments.size() - 1);
- return segments;
+ return unmodifiableList(segments);
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/editor/Editors.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/editor/Editors.java
index 5c52f1f..34d1378 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/editor/Editors.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/editor/Editors.java
@@ -9,6 +9,7 @@
*/
package com.google.eclipse.protobuf.ui.util.editor;
+import static com.google.common.collect.Lists.newArrayList;
import static com.google.eclipse.protobuf.ui.ProtobufUiModule.PLUGIN_ID;
import static com.google.eclipse.protobuf.ui.util.editor.Messages.*;
import static org.eclipse.compare.rangedifferencer.RangeDifferencer.findDifferences;
@@ -17,7 +18,7 @@
import static org.eclipse.core.runtime.Status.OK_STATUS;
import static org.eclipse.core.runtime.SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK;
-import java.util.*;
+import java.util.List;
import org.apache.log4j.Logger;
import org.eclipse.compare.rangedifferencer.RangeDifference;
@@ -71,7 +72,7 @@
*/
private IRegion[] getChangedLineRegions(IDocument old) {
RangeDifference[] differences = differencesWith(old);
- List<IRegion> regions = new ArrayList<IRegion>();
+ List<IRegion> regions = newArrayList();
int numberOfLines = current.getNumberOfLines();
for (RangeDifference difference : differences) {
if (difference.kind() == RangeDifference.CHANGE) {
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/validation/ValidationTrigger.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/validation/ValidationTrigger.java
index 4fff51d..aa07a44 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/validation/ValidationTrigger.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/validation/ValidationTrigger.java
@@ -8,8 +8,8 @@
*/
package com.google.eclipse.protobuf.ui.validation;
+import static com.google.common.base.Objects.equal;
import static com.google.eclipse.protobuf.ui.validation.Validation.validate;
-import static com.google.eclipse.protobuf.util.Objects.areEqual;
import java.net.URI;
@@ -61,6 +61,6 @@
}
URI uri1 = p1.getLocationURI();
URI uri2 = p2.getLocationURI();
- return areEqual(uri1, uri2);
+ return equal(uri1, uri2);
}
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/ProtobufRuntimeModule.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/ProtobufRuntimeModule.java
index 46a5254..585e0e2 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/ProtobufRuntimeModule.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/ProtobufRuntimeModule.java
@@ -11,6 +11,7 @@
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.xtext.conversion.IValueConverterService;
import org.eclipse.xtext.naming.IQualifiedNameProvider;
+import org.eclipse.xtext.parser.IParser;
import org.eclipse.xtext.parser.antlr.ISyntaxErrorMessageProvider;
import org.eclipse.xtext.resource.*;
import org.eclipse.xtext.scoping.impl.ImportUriResolver;
@@ -28,7 +29,7 @@
/**
* Use this class to register components to be used at runtime / without the Equinox extension registry.
*/
-public class ProtobufRuntimeModule extends com.google.eclipse.protobuf.AbstractProtobufRuntimeModule {
+public class ProtobufRuntimeModule extends AbstractProtobufRuntimeModule {
public Class<? extends IGlobalServiceProvider> bindIGlobalServiceProvider() {
return ResourceServiceProvider.class;
}
@@ -37,7 +38,7 @@
return ProtobufImportUriResolver.class;
}
- @Override public Class<? extends org.eclipse.xtext.parser.IParser> bindIParser() {
+ @Override public Class<? extends IParser> bindIParser() {
return Proto2OnlyParser.class;
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/DOUBLEValueConverter.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/DOUBLEValueConverter.java
index a85cae5..d3dff91 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/DOUBLEValueConverter.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/DOUBLEValueConverter.java
@@ -8,10 +8,11 @@
*/
package com.google.eclipse.protobuf.conversion;
+import static com.google.common.collect.Maps.newHashMap;
import static java.lang.Double.*;
import static org.eclipse.xtext.util.Strings.isEmpty;
-import java.util.*;
+import java.util.Map;
import org.eclipse.xtext.conversion.ValueConverterException;
import org.eclipse.xtext.conversion.impl.AbstractLexerBasedConverter;
@@ -23,7 +24,7 @@
* @author alruiz@google.com (Alex Ruiz)
*/
public class DOUBLEValueConverter extends AbstractLexerBasedConverter<Double> {
- private static final Map<String, Double> PREDEFINED_VALUES = new HashMap<String, Double>();
+ private static final Map<String, Double> PREDEFINED_VALUES = newHashMap();
static {
PREDEFINED_VALUES.put("nan", NaN);
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/linking/ProtobufDiagnostic.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/linking/ProtobufDiagnostic.java
index 1d4a3c7..80a5387 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/linking/ProtobufDiagnostic.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/linking/ProtobufDiagnostic.java
@@ -8,13 +8,15 @@
*/
package com.google.eclipse.protobuf.linking;
-import static com.google.eclipse.protobuf.util.Objects.*;
+import static com.google.common.base.Objects.equal;
import static java.util.Arrays.copyOf;
import static org.eclipse.xtext.util.Arrays.contains;
import org.eclipse.xtext.diagnostics.*;
import org.eclipse.xtext.nodemodel.INode;
+import com.google.common.base.Objects;
+
/**
* <code>{@link Diagnostic}</code> that supports appending text to its message.
*
@@ -72,11 +74,7 @@
}
@Override public int hashCode() {
- final int prime = HASH_CODE_PRIME;
- int result = 1;
- result = prime * result + hashCodeOf(message);
- result = prime * result + hashCodeOf(node);
- return result;
+ return Objects.hashCode(message, node);
}
@Override public boolean equals(Object obj) {
@@ -87,9 +85,9 @@
return false;
}
ProtobufDiagnostic other = (ProtobufDiagnostic) obj;
- if (!areEqual(message, other.message)) {
+ if (!equal(message, other.message)) {
return false;
}
- return areEqual(node, other.node);
+ return equal(node, other.node);
}
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/ModelFinder.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/ModelFinder.java
index 2bc2312..976c5d6 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/ModelFinder.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/ModelFinder.java
@@ -8,6 +8,7 @@
*/
package com.google.eclipse.protobuf.model.util;
+import static com.google.common.collect.Lists.newArrayList;
import static java.util.Collections.unmodifiableList;
import static org.eclipse.emf.ecore.util.EcoreUtil.getAllContents;
import static org.eclipse.xtext.EcoreUtil2.getAllContentsOfType;
@@ -153,7 +154,7 @@
* @return all the import definitions in the given proto.
*/
public List<Import> importsIn(Protobuf root) {
- List<Import> imports = new ArrayList<Import>();
+ List<Import> imports = newArrayList();
for (ProtobufElement e : root.getElements()) {
if (e instanceof Import) {
imports.add((Import) e);
@@ -168,7 +169,7 @@
* @return all the public import definitions in the given proto.
*/
public List<Import> publicImportsIn(Protobuf root) {
- List<Import> imports = new ArrayList<Import>();
+ List<Import> imports = newArrayList();
for (ProtobufElement e : root.getElements()) {
if (e instanceof PublicImport) {
imports.add((Import) e);
@@ -201,7 +202,7 @@
}
public Collection<MessageField> propertiesOf(Message message) {
- List<MessageField> properties = new ArrayList<MessageField>();
+ List<MessageField> properties = newArrayList();
for (MessageElement e : message.getElements()) {
if (e instanceof MessageField) {
properties.add((MessageField) e);
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Packages.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Packages.java
index 977a953..158ff1b 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Packages.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Packages.java
@@ -8,6 +8,7 @@
*/
package com.google.eclipse.protobuf.model.util;
+import static com.google.common.collect.Lists.newArrayList;
import static java.util.Collections.*;
import static org.eclipse.xtext.util.Strings.isEmpty;
@@ -70,7 +71,7 @@
if (segmentCount <= 1) {
return emptyList();
}
- List<QualifiedName> allNames = new ArrayList<QualifiedName>();
+ List<QualifiedName> allNames = newArrayList();
for (int i = segmentCount - 1; i > 0; i--) {
current = QualifiedName.create(segments.get(i)).append(current);
allNames.add(current);
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/QualifiedNames.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/QualifiedNames.java
index adf5053..353105b 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/QualifiedNames.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/QualifiedNames.java
@@ -8,7 +8,9 @@
*/
package com.google.eclipse.protobuf.model.util;
-import java.util.*;
+import static com.google.common.collect.Lists.newArrayList;
+
+import java.util.List;
import org.eclipse.xtext.naming.QualifiedName;
@@ -32,7 +34,7 @@
if (name.getFirstSegment().equals("")) {
return name;
}
- List<String> segments = new ArrayList<String>();
+ List<String> segments = newArrayList();
segments.addAll(name.getSegments());
segments.add(0, "");
return QualifiedName.create(segments.toArray(new String[segments.size()]));
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/LocalNamesProvider.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/LocalNamesProvider.java
index 474c68e..0ffc30d 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/LocalNamesProvider.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/LocalNamesProvider.java
@@ -8,12 +8,13 @@
*/
package com.google.eclipse.protobuf.naming;
+import static com.google.common.collect.Lists.newArrayList;
import static com.google.eclipse.protobuf.naming.Naming.NamingUsage.*;
import static java.util.Collections.*;
import static org.eclipse.xtext.util.Strings.isEmpty;
import static org.eclipse.xtext.util.Tuples.pair;
-import java.util.*;
+import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.naming.*;
@@ -77,7 +78,7 @@
Pair<EObject, String> key = pair(e, "localFqns");
return cache.get(key, e.eResource(), new Provider<List<QualifiedName>>() {
@Override public List<QualifiedName> get() {
- List<QualifiedName> allNames = new ArrayList<QualifiedName>();
+ List<QualifiedName> allNames = newArrayList();
EObject current = e;
String name = naming.nameOf(e, usage);
if (isEmpty(name)) {
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/LiteralDescriptions.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/LiteralDescriptions.java
index 0b8cb63..3aed188 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/LiteralDescriptions.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/LiteralDescriptions.java
@@ -8,6 +8,7 @@
*/
package com.google.eclipse.protobuf.scoping;
+import static com.google.common.collect.Lists.newArrayList;
import static java.util.Collections.emptyList;
import static org.eclipse.xtext.EcoreUtil2.getAllContentsOfType;
import static org.eclipse.xtext.resource.EObjectDescription.create;
@@ -27,7 +28,7 @@
if (anEnum == null) {
return emptyList();
}
- List<IEObjectDescription> descriptions = new ArrayList<IEObjectDescription>();
+ List<IEObjectDescription> descriptions = newArrayList();
for (Literal literal : getAllContentsOfType(anEnum, Literal.class)) {
String name = literal.getName();
descriptions.add(create(name, literal));
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/NativeOptionDescriptions.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/NativeOptionDescriptions.java
index 9cdd03c..cc5366d 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/NativeOptionDescriptions.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/NativeOptionDescriptions.java
@@ -8,7 +8,8 @@
*/
package com.google.eclipse.protobuf.scoping;
-import static java.util.Collections.emptyList;
+import static com.google.common.collect.Lists.newArrayList;
+import static java.util.Collections.*;
import static org.eclipse.xtext.resource.EObjectDescription.create;
import java.util.*;
@@ -34,11 +35,11 @@
}
private Collection<IEObjectDescription> describe(Collection<MessageField> fields) {
- List<IEObjectDescription> descriptions = new ArrayList<IEObjectDescription>();
+ List<IEObjectDescription> descriptions = newArrayList();
for (MessageField field : fields) {
String name = field.getName();
descriptions.add(create(name, field));
}
- return descriptions;
+ return unmodifiableList(descriptions);
}
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/OptionType.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/OptionType.java
index 9b40452..bcb0cfd 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/OptionType.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/OptionType.java
@@ -8,6 +8,8 @@
*/
package com.google.eclipse.protobuf.scoping;
+import static com.google.common.collect.Maps.newHashMap;
+
import java.util.*;
import java.util.Map.Entry;
@@ -23,7 +25,7 @@
FILE("FileOptions"), MESSAGE("MessageOptions"), FIELD("FieldOptions"), ENUM("EnumOptions"),
LITERAL("EnumValueOptions"), SERVICE("ServiceOptions"), RPC("MethodOptions");
- private static final Map<Class<?>, OptionType> OPTION_TYPES_BY_CONTAINER = new HashMap<Class<?>, OptionType>();
+ private static final Map<Class<?>, OptionType> OPTION_TYPES_BY_CONTAINER = newHashMap();
static {
OPTION_TYPES_BY_CONTAINER.put(Protobuf.class, FILE);
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/PackageIntersectionDescriptions.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/PackageIntersectionDescriptions.java
index 5163a9f..380a0dc 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/PackageIntersectionDescriptions.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/PackageIntersectionDescriptions.java
@@ -8,6 +8,7 @@
*/
package com.google.eclipse.protobuf.scoping;
+import static com.google.common.collect.Lists.newArrayList;
import static java.util.Collections.emptySet;
import static org.eclipse.xtext.resource.EObjectDescription.create;
@@ -58,7 +59,7 @@
}
Set<IEObjectDescription> descriptions = new HashSet<IEObjectDescription>();
QualifiedName fqn = nameProvider.getFullyQualifiedName(e);
- List<String> segments = new ArrayList<String>(fqn.getSegments());
+ List<String> segments = newArrayList(fqn.getSegments());
for (int i = 0; i < start; i++) {
segments.remove(0);
descriptions.add(create(fqn(segments), e));
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtoDescriptor.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtoDescriptor.java
index 83c3a7e..2b01604 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtoDescriptor.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtoDescriptor.java
@@ -8,6 +8,8 @@
*/
package com.google.eclipse.protobuf.scoping;
+import static com.google.common.collect.Lists.newArrayList;
+import static com.google.common.collect.Maps.newHashMap;
import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.MESSAGE_FIELD__TYPE;
import static com.google.eclipse.protobuf.scoping.OptionType.findOptionTypeForLevelOf;
import static com.google.eclipse.protobuf.util.Closeables.closeQuietly;
@@ -38,7 +40,7 @@
* @author alruiz@google.com (Alex Ruiz)
*/
public class ProtoDescriptor {
- private static final Map<String, OptionType> OPTION_DEFINITION_BY_NAME = new HashMap<String, OptionType>();
+ private static final Map<String, OptionType> OPTION_DEFINITION_BY_NAME = newHashMap();
static {
populateMap();
@@ -50,9 +52,9 @@
}
}
- private final List<ComplexType> allTypes = new ArrayList<ComplexType>();
- private final Map<OptionType, Map<String, MessageField>> optionsByType = new HashMap<OptionType, Map<String, MessageField>>();
- private final Map<String, Enum> enumsByName = new HashMap<String, Enum>();
+ private final List<ComplexType> allTypes = newArrayList();
+ private final Map<OptionType, Map<String, MessageField>> optionsByType = newHashMap();
+ private final Map<String, Enum> enumsByName = newHashMap();
private Protobuf root;
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtoDescriptorProvider.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtoDescriptorProvider.java
index a7887bc..dcc1d20 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtoDescriptorProvider.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtoDescriptorProvider.java
@@ -8,6 +8,7 @@
*/
package com.google.eclipse.protobuf.scoping;
+import static com.google.common.collect.Maps.newLinkedHashMap;
import static java.util.Collections.unmodifiableCollection;
import static org.eclipse.xtext.util.Strings.isEmpty;
@@ -63,7 +64,7 @@
private void ensureProtoDescriptorsAreCreated() {
synchronized (lock) {
if (descriptors == null) {
- descriptors = new LinkedHashMap<String, ProtoDescriptor>();
+ descriptors = newLinkedHashMap();
ensureProtoDescriptorInfosAreCreated();
for (Entry<String, URI> entry : descriptorInfos.entrySet()) {
String importUri = entry.getKey();
@@ -91,7 +92,7 @@
private void ensureProtoDescriptorInfosAreCreated() {
synchronized (lock) {
if (descriptorInfos == null) {
- descriptorInfos = new LinkedHashMap<String, URI>();
+ descriptorInfos = newLinkedHashMap();
add(defaultDescriptorInfo());
add(descriptorInfoFromExtensionPoint());
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/QualifiedNameDescriptions.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/QualifiedNameDescriptions.java
index bebb638..60c1cc4 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/QualifiedNameDescriptions.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/QualifiedNameDescriptions.java
@@ -8,6 +8,8 @@
*/
package com.google.eclipse.protobuf.scoping;
+import static com.google.common.collect.Lists.newArrayList;
+import static java.util.Collections.unmodifiableList;
import static org.eclipse.xtext.resource.EObjectDescription.create;
import java.util.*;
@@ -38,9 +40,9 @@
}
private Collection<IEObjectDescription> allQualifiedNames(EObject e, QualifiedName fqn) {
- List<IEObjectDescription> descriptions = new ArrayList<IEObjectDescription>();
+ List<IEObjectDescription> descriptions = newArrayList();
descriptions.add(create(fqn, e));
descriptions.add(create(qualifiedNames.addLeadingDot(fqn), e));
- return descriptions;
+ return unmodifiableList(descriptions);
}
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Objects.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Objects.java
deleted file mode 100644
index 254c314..0000000
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Objects.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.util;
-
-/**
- * Utility methods related to objects.
- *
- * @author alruiz@google.com (Alex Ruiz)
- */
-public final class Objects {
- /** Prime number used to calculate the hash code of objects. */
- public static final int HASH_CODE_PRIME = 31;
-
- /**
- * Returns {@code true} if the given objects are equal or if both objects are {@code null}.
- * @param o1 one of the objects to compare.
- * @param o2 one of the objects to compare.
- * @return {@code true} if the given objects are equal or if both objects are {@code null}.
- */
- public static boolean areEqual(Object o1, Object o2) {
- if (o1 == null) {
- return o2 == null;
- }
- return o1.equals(o2);
- }
-
- /**
- * Returns the hash code for the given object. If the object is {@code null}, this method returns zero. Otherwise
- * calls the method {@code hashCode} of the given object.
- * @param o the given object.
- * @return the hash code for the given object
- */
- public static int hashCodeOf(Object o) {
- return o != null ? o.hashCode() : 0;
- }
-
- private Objects() {}
-}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ImportValidator.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ImportValidator.java
index 70b921e..bddd692 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ImportValidator.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ImportValidator.java
@@ -8,6 +8,7 @@
*/
package com.google.eclipse.protobuf.validation;
+import static com.google.common.collect.Lists.newArrayList;
import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.IMPORT__IMPORT_URI;
import static com.google.eclipse.protobuf.validation.Messages.importingNonProto2;
import static org.eclipse.xtext.util.Tuples.pair;
@@ -51,7 +52,7 @@
}
ResourceSet resourceSet = resource.getResourceSet();
boolean hasNonProto2 = false;
- List<Pair<Import, Resource>> resourcesToCheck = new ArrayList<Pair<Import, Resource>>();
+ List<Pair<Import, Resource>> resourcesToCheck = newArrayList();
Set<URI> checked = new HashSet<URI>();
checked.add(resource.getURI());
for (Import anImport : finder.importsIn(root)) {
@@ -80,7 +81,7 @@
if (!protobufs.isProto2(root)) {
return false;
}
- List<Pair<Import, Resource>> resourcesToCheck = new ArrayList<Pair<Import, Resource>>();
+ List<Pair<Import, Resource>> resourcesToCheck = newArrayList();
for (Import anImport : finder.importsIn(root)) {
Resource imported = resources.importedResource(anImport, resourceSet);
if (checked.contains(imported.getURI())) {