Major cleanup.
diff --git a/com.google.eclipse.protobuf.feature/feature.xml b/com.google.eclipse.protobuf.feature/feature.xml
index bf5e092..90368a9 100644
--- a/com.google.eclipse.protobuf.feature/feature.xml
+++ b/com.google.eclipse.protobuf.feature/feature.xml
@@ -22,7 +22,6 @@
</url>
<requires>
- <import plugin="org.eclipse.xtext"/>
<import plugin="org.eclipse.xtext.util"/>
<import plugin="org.eclipse.emf.ecore"/>
<import plugin="org.eclipse.emf.common"/>
@@ -37,9 +36,12 @@
<import plugin="org.eclipse.ui"/>
<import plugin="org.eclipse.xtext.builder"/>
<import plugin="com.ibm.icu"/>
+ <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.emf.databinding"/>
+ <import plugin="org.eclipse.xtext" version="2.1.1" match="greaterOrEqual"/>
+ <import plugin="org.eclipse.compare.core" version="3.5.200" match="greaterOrEqual"/>
+ <import plugin="org.eclipse.ui.workbench.texteditor"/>
</requires>
<plugin
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/bugs/Issue161_PackageScoping_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/bugs/Issue161_PackageScoping_Test.java
index 9fcddc5..db4e3fc 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/bugs/Issue161_PackageScoping_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/bugs/Issue161_PackageScoping_Test.java
@@ -15,17 +15,17 @@
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
-import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.protobuf.*;
-import com.google.eclipse.protobuf.scoping.ProtobufScopeProvider;
-
import org.eclipse.emf.ecore.EReference;
import org.eclipse.xtext.scoping.IScope;
import org.junit.*;
+import com.google.eclipse.protobuf.junit.core.XtextRule;
+import com.google.eclipse.protobuf.protobuf.*;
+import com.google.eclipse.protobuf.scoping.ProtobufScopeProvider;
+
/**
* Tests fix for <a href="http://code.google.com/p/protobuf-dt/issues/detail?id=161">Issue 161</a>.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class Issue161_PackageScoping_Test {
@@ -53,7 +53,7 @@
// ONE = 1;
// TWO = 2;
// }
-
+
// syntax = "proto2";
// package com.google.proto.project.shared;
//
@@ -65,7 +65,7 @@
@Test public void should_include_package_intersection() {
MessageField field = xtext.find("type", " =", MessageField.class);
IScope scope = provider.scope_ComplexTypeLink_target((ComplexTypeLink) field.getType(), reference);
- assertThat(descriptionsIn(scope), contain("base.shared.Type", "proto.base.shared.Type",
+ assertThat(descriptionsIn(scope), contain("base.shared.Type", "proto.base.shared.Type",
"google.proto.base.shared.Type", "com.google.proto.base.shared.Type"));
}
}
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/bugs/Issue167_PackageScopingWithNestedTypes_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/bugs/Issue167_PackageScopingWithNestedTypes_Test.java
index 311a01e..19637f7 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/bugs/Issue167_PackageScopingWithNestedTypes_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/bugs/Issue167_PackageScopingWithNestedTypes_Test.java
@@ -15,17 +15,17 @@
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
-import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.protobuf.*;
-import com.google.eclipse.protobuf.scoping.ProtobufScopeProvider;
-
import org.eclipse.emf.ecore.EReference;
import org.eclipse.xtext.scoping.IScope;
import org.junit.*;
+import com.google.eclipse.protobuf.junit.core.XtextRule;
+import com.google.eclipse.protobuf.protobuf.*;
+import com.google.eclipse.protobuf.scoping.ProtobufScopeProvider;
+
/**
* Tests fix for <a href="http://code.google.com/p/protobuf-dt/issues/detail?id=167">Issue 167</a>.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class Issue167_PackageScopingWithNestedTypes_Test {
@@ -48,14 +48,14 @@
//
// syntax = 'proto2';
// package com.google.proto.base.shared;
- //
+ //
// message Outer {
// enum Type {
// ONE = 1;
// TWO = 2;
// }
// }
-
+
// syntax = "proto2";
// package com.google.proto.project.shared;
//
@@ -67,8 +67,8 @@
@Test public void should_include_package_intersection() {
MessageField field = xtext.find("type", " =", MessageField.class);
IScope scope = provider.scope_ComplexTypeLink_target((ComplexTypeLink) field.getType(), reference);
- assertThat(descriptionsIn(scope), contain("base.shared.Outer.Type", "proto.base.shared.Outer.Type",
- "google.proto.base.shared.Outer.Type",
+ assertThat(descriptionsIn(scope), contain("base.shared.Outer.Type", "proto.base.shared.Outer.Type",
+ "google.proto.base.shared.Outer.Type",
"com.google.proto.base.shared.Outer.Type"));
}
}
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 69253ee..ca4c976 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
@@ -1,9 +1,9 @@
/*
* 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.junit.matchers;
@@ -32,13 +32,19 @@
}
@Override public boolean matches(Object arg) {
- if (!(arg instanceof IEObjectDescriptions)) return false;
+ if (!(arg instanceof IEObjectDescriptions)) {
+ return false;
+ }
IEObjectDescriptions descriptions = (IEObjectDescriptions) arg;
- if (descriptions.size() != fields.size()) return false;
+ if (descriptions.size() != fields.size()) {
+ return false;
+ }
for (MessageField field : fields) {
String name = field.getName();
EObject described = descriptions.objectDescribedAs(name);
- if (described != field) return false;
+ if (described != field) {
+ return false;
+ }
}
return true;
}
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 ac3fa14..2f53cd3 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
@@ -1,9 +1,9 @@
/*
* 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.junit.matchers;
@@ -38,14 +38,20 @@
}
@Override public boolean matches(Object arg) {
- if (!(arg instanceof IEObjectDescriptions)) return false;
+ if (!(arg instanceof IEObjectDescriptions)) {
+ return false;
+ }
IEObjectDescriptions descriptions = (IEObjectDescriptions) arg;
List<IndexedElement> elements = allIndexedElements();
- if (descriptions.size() != elements.size()) return false;
+ if (descriptions.size() != elements.size()) {
+ return false;
+ }
for (IndexedElement e : elements) {
String name = nameOf(e);
EObject described = descriptions.objectDescribedAs(name);
- if (described != e) return false;
+ if (described != e) {
+ return false;
+ }
}
return true;
}
@@ -63,7 +69,9 @@
}
private String nameOf(IndexedElement e) {
- if (e == null) return null;
+ if (e == null) {
+ return null;
+ }
return (e instanceof Group) ? ((Group) e).getName() : ((MessageField) e).getName();
}
}
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 7fcad3f..6fd2fdb 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
@@ -1,9 +1,9 @@
/*
* 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.junit.matchers;
@@ -35,14 +35,20 @@
}
@Override public boolean matches(Object arg) {
- if (!(arg instanceof IEObjectDescriptions)) return false;
+ if (!(arg instanceof IEObjectDescriptions)) {
+ return false;
+ }
IEObjectDescriptions descriptions = (IEObjectDescriptions) arg;
List<Literal> literals = allLiterals();
- if (descriptions.size() != literals.size()) return false;
+ if (descriptions.size() != literals.size()) {
+ return false;
+ }
for (Literal literal : literals) {
String name = literal.getName();
EObject described = descriptions.objectDescribedAs(name);
- if (described != literal) return false;
+ if (described != literal) {
+ return false;
+ }
}
return true;
}
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 f40ca20..c818b62 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
@@ -1,9 +1,9 @@
/*
* 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.junit.matchers;
@@ -30,13 +30,19 @@
}
@Override public boolean matches(Object arg) {
- if (!(arg instanceof IEObjectDescriptions)) return false;
+ if (!(arg instanceof IEObjectDescriptions)) {
+ return false;
+ }
IEObjectDescriptions descriptions = (IEObjectDescriptions) arg;
List<String> names = new ArrayList<String>(descriptions.names());
- if (names.size() != expectedNames.length) return false;
+ if (names.size() != expectedNames.length) {
+ return false;
+ }
for (String name : expectedNames) {
boolean removed = names.remove(name);
- if (!removed) return false;
+ if (!removed) {
+ return false;
+ }
}
return names.isEmpty();
}
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/junit/matchers/ContainNames.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/junit/matchers/ContainNames.java
index 24503f6..a6f9ee8 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/junit/matchers/ContainNames.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/junit/matchers/ContainNames.java
@@ -1,16 +1,16 @@
/*
* 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.junit.matchers;
import static java.util.Arrays.asList;
-import java.util.*;
+import java.util.List;
import org.hamcrest.*;
@@ -32,7 +32,9 @@
}
@Override public boolean matches(Object arg) {
- if (!(arg instanceof IEObjectDescriptions)) return false;
+ if (!(arg instanceof IEObjectDescriptions)) {
+ return false;
+ }
IEObjectDescriptions descriptions = (IEObjectDescriptions) arg;
return descriptions.names().containsAll(expectedNames);
}
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_sourceOf_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_sourceOf_Test.java
index bb6e9c0..84a5083 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_sourceOf_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/model/util/Options_sourceOf_Test.java
@@ -13,14 +13,14 @@
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
+import org.junit.*;
+
import com.google.eclipse.protobuf.junit.core.XtextRule;
import com.google.eclipse.protobuf.protobuf.*;
-import org.junit.*;
-
/**
* Tests for <code>{@link Options#sourceOf(CustomOption)}</code>
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class Options_sourceOf_Test {
diff --git a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_FieldName_target_with_ExtensionFieldName_Test.java b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_FieldName_target_with_ExtensionFieldName_Test.java
index ad04200..0e1c5bc 100644
--- a/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_FieldName_target_with_ExtensionFieldName_Test.java
+++ b/com.google.eclipse.protobuf.integration.test/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider_scope_FieldName_target_with_ExtensionFieldName_Test.java
@@ -15,16 +15,16 @@
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
-import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.protobuf.*;
-
import org.eclipse.emf.ecore.EReference;
import org.eclipse.xtext.scoping.IScope;
import org.junit.*;
+import com.google.eclipse.protobuf.junit.core.XtextRule;
+import com.google.eclipse.protobuf.protobuf.*;
+
/**
* Tests for <code>{@link ProtobufScopeProvider#scope_FieldName_target(FieldName, EReference)}</code>.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class ProtobufScopeProvider_scope_FieldName_target_with_ExtensionFieldName_Test {
@@ -54,7 +54,7 @@
// optional google.protobuf.FileOptions file = 2;
// }
//
- // extend google.protobuf.FileOptions {
+ // extend google.protobuf.FileOptions {
// optional Aggregate fileopt = 15478479;
// }
//
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/bugs/Issue154_AllowMultipleSemicolons_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/bugs/Issue154_AllowMultipleSemicolons_Test.java
index ca6de14..8ff3e4b 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/bugs/Issue154_AllowMultipleSemicolons_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/bugs/Issue154_AllowMultipleSemicolons_Test.java
@@ -12,25 +12,25 @@
import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
import static org.junit.Assert.assertNotNull;
-import com.google.eclipse.protobuf.junit.core.XtextRule;
-
import org.junit.*;
+import com.google.eclipse.protobuf.junit.core.XtextRule;
+
/**
* Tests fix for <a href="http://code.google.com/p/protobuf-dt/issues/detail?id=154">Issue 154</a>.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class Issue154_AllowMultipleSemicolons_Test {
@Rule public XtextRule xtext = createWith(unitTestSetup());
-
+
// syntax = "proto2";
- //
+ //
// message Foo {
// optional double bar = 1 [deprecated = true];;
// }
@Test public void should_allow_multiple_semicolons_at_the_end_of_field() {
assertNotNull(xtext.root());
- }
+ }
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/bugs/Issue165_Support64BitNumbers_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/bugs/Issue165_Support64BitNumbers_Test.java
index 225f943..b2cc4cd 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/bugs/Issue165_Support64BitNumbers_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/bugs/Issue165_Support64BitNumbers_Test.java
@@ -14,12 +14,12 @@
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
-import com.google.eclipse.protobuf.conversion.LONGValueConverter;
-import com.google.eclipse.protobuf.junit.core.XtextRule;
-
import org.eclipse.xtext.nodemodel.INode;
import org.junit.*;
+import com.google.eclipse.protobuf.conversion.LONGValueConverter;
+import com.google.eclipse.protobuf.junit.core.XtextRule;
+
/**
* Tests fix for <a href="http://code.google.com/p/protobuf-dt/issues/detail?id=165">Issue 165</a>.
*
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/bugs/Issue166_SupportOptionalDecimals_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/bugs/Issue166_SupportOptionalDecimals_Test.java
index 09732ef..fc9d409 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/bugs/Issue166_SupportOptionalDecimals_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/bugs/Issue166_SupportOptionalDecimals_Test.java
@@ -13,11 +13,11 @@
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
+import org.junit.*;
+
import com.google.eclipse.protobuf.junit.core.XtextRule;
import com.google.eclipse.protobuf.protobuf.*;
-import org.junit.*;
-
/**
* Tests fix for <a href="http://code.google.com/p/protobuf-dt/issues/detail?id=166">Issue 166</a>.
*
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/bugs/Issue168_GroupsCanHaveMessagesAndExtensions_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/bugs/Issue168_GroupsCanHaveMessagesAndExtensions_Test.java
index 088c366..c170026 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/bugs/Issue168_GroupsCanHaveMessagesAndExtensions_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/bugs/Issue168_GroupsCanHaveMessagesAndExtensions_Test.java
@@ -11,10 +11,10 @@
import static com.google.eclipse.protobuf.junit.core.Setups.unitTestSetup;
import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
-import com.google.eclipse.protobuf.junit.core.*;
-
import org.junit.*;
+import com.google.eclipse.protobuf.junit.core.XtextRule;
+
/**
* Tests fix for <a href="http://code.google.com/p/protobuf-dt/issues/detail?id=168">Issue 168</a>.
*
@@ -23,7 +23,7 @@
public class Issue168_GroupsCanHaveMessagesAndExtensions_Test {
@Rule public XtextRule xtext = createWith(unitTestSetup());
-
+
// syntax = "proto2";
//
// message TopMessage {
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/conversion/LONGValueConverter_toValue_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/conversion/LONGValueConverter_toValue_Test.java
index 39ad8a1..3e3bf22 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/conversion/LONGValueConverter_toValue_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/conversion/LONGValueConverter_toValue_Test.java
@@ -12,23 +12,20 @@
import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
import static org.junit.rules.ExpectedException.none;
import static org.mockito.Mockito.mock;
import org.eclipse.xtext.conversion.ValueConverterException;
import org.eclipse.xtext.nodemodel.INode;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.*;
import org.junit.rules.ExpectedException;
import com.google.eclipse.protobuf.junit.core.XtextRule;
/**
* Tests for <code>{@link LONGValueConverter#toString()}</code>.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class LONGValueConverter_toValue_Test {
@@ -43,7 +40,7 @@
node = mock(INode.class);
converter = xtext.injector().getInstance(LONGValueConverter.class);
}
-
+
@Test public void should_throw_error_if_input_is_null() {
thrown.expect(ValueConverterException.class);
thrown.expectMessage("Couldn't convert empty string to long.");
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/grammar/Keywords_isKeyword_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/grammar/Keywords_isKeyword_Test.java
index dc3f22b..e7a2378 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/grammar/Keywords_isKeyword_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/grammar/Keywords_isKeyword_Test.java
@@ -20,7 +20,7 @@
/**
* Tests for <code>{@link Keywords#isKeyword(String)}</code>.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class Keywords_isKeyword_Test {
@@ -29,18 +29,18 @@
private IGrammarAccess grammarAccess;
private Keywords keywords;
-
+
@Before public void setUp() {
grammarAccess = xtext.getInstanceOf(IGrammarAccess.class);
keywords = xtext.getInstanceOf(Keywords.class);
}
-
+
@Test public void should_return_true_if_given_String_is_keyword() {
for (String s : getAllKeywords(grammarAccess.getGrammar())) {
assertTrue(keywords.isKeyword(s));
}
}
-
+
@Test public void should_return_false_if_given_String_is_not_keyword() {
assertFalse(keywords.isKeyword("Google"));
}
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 0ebc1c8..99d16c0 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
@@ -28,7 +28,9 @@
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
Matcher matcher = CREATE_FILE_PATTERN.matcher(line);
- if (!matcher.matches()) return comment;
+ if (!matcher.matches()) {
+ return comment;
+ }
fileName = matcher.group(1);
break;
}
@@ -38,7 +40,9 @@
private File createFile(String fileName, String contents) {
ensureParentDirectoryExists();
File file = protoFile(fileName);
- if (file.isFile()) file.delete();
+ if (file.isFile()) {
+ file.delete();
+ }
Writer out = null;
try {
out = new OutputStreamWriter(new FileOutputStream(file));
@@ -52,7 +56,9 @@
}
private void closeQuietly(Writer out) {
- if (out == null) return;
+ if (out == null) {
+ return;
+ }
try {
out.close();
} catch (IOException e) {}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/Finder.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/Finder.java
index 17d8723..e3e8f50 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/Finder.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/Finder.java
@@ -53,13 +53,17 @@
while (iterator.hasNext()) {
AbstractNode node = iterator.next();
int nodeOffset = node.getOffset();
- if (nodeOffset > offset || (nodeOffset + node.getLength()) <= offset) continue;
+ if (nodeOffset > offset || (nodeOffset + node.getLength()) <= offset) {
+ continue;
+ }
EObject e = node.getSemanticElement();
if (isDefaultValueFieldOption(name, type, e)) {
return type.cast(e);
}
if (type.isInstance(e)) {
- if (areNamesEqual(name, e, options)) return type.cast(e);
+ if (areNamesEqual(name, e, options)) {
+ return type.cast(e);
+ }
}
}
String format = "Unable to find element. Text: '%s', count: %d, type: %s, options: %s";
@@ -78,17 +82,25 @@
realExpected = qualifiedName.getLastSegment();
}
String actual = nameOf(e);
- if (options.contains(IGNORE_CASE)) return realExpected.equalsIgnoreCase(actual);
+ if (options.contains(IGNORE_CASE)) {
+ return realExpected.equalsIgnoreCase(actual);
+ }
return realExpected.equals(actual);
}
-
+
private String nameOf(Object o) {
- if (!(o instanceof EObject)) return null;
+ if (!(o instanceof EObject)) {
+ return null;
+ }
EObject e = (EObject) o;
for (String name : FEATURE_NAMES) {
Object value = feature(e, name);
- if (value instanceof String) return (String) value;
- if (value != null) return nameOf(value);
+ if (value instanceof String) {
+ return (String) value;
+ }
+ if (value != null) {
+ return nameOf(value);
+ }
}
return null;
}
@@ -102,9 +114,13 @@
BidiTreeIterator<AbstractNode> iterator = root.basicIterator();
while (iterator.hasNext()) {
AbstractNode node = iterator.next();
- if (!(node instanceof ILeafNode)) continue;
+ if (!(node instanceof ILeafNode)) {
+ continue;
+ }
String nodeText = clean(node.getText());
- if (text.equals(nodeText)) return (ILeafNode) node;
+ if (text.equals(nodeText)) {
+ return (ILeafNode) node;
+ }
}
String format = "Unable to find node. Text: '%s'";
throw new AssertionError(String.format(format, text));
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/GeneratedProtoFiles.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/GeneratedProtoFiles.java
index 0980053..8aac327 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/GeneratedProtoFiles.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/GeneratedProtoFiles.java
@@ -19,17 +19,17 @@
final class GeneratedProtoFiles {
private static final String PARENT_DIRECTORY_NAME = "test-protos";
-
+
static File protoFile(String fileName) {
return new File(PARENT_DIRECTORY_NAME + separator + fileName);
}
-
+
static void ensureParentDirectoryExists() {
File parent = new File(PARENT_DIRECTORY_NAME);
if (!parent.isDirectory()) {
assertTrue(parent.mkdir());
}
}
-
+
private GeneratedProtoFiles() {}
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/IntegrationTestSetup.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/IntegrationTestSetup.java
index 90f239a..0935741 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/IntegrationTestSetup.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/IntegrationTestSetup.java
@@ -11,14 +11,14 @@
import static com.google.eclipse.protobuf.junit.core.GeneratedProtoFiles.protoFile;
import static org.eclipse.xtext.util.Strings.isEmpty;
-import com.google.eclipse.protobuf.*;
-import com.google.eclipse.protobuf.scoping.IFileUriResolver;
-import com.google.inject.*;
+import java.io.File;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
-import java.io.File;
+import com.google.eclipse.protobuf.*;
+import com.google.eclipse.protobuf.scoping.IFileUriResolver;
+import com.google.inject.*;
/**
* @author alruiz@google.com (Alex Ruiz)
@@ -26,25 +26,30 @@
public class IntegrationTestSetup extends ProtobufStandaloneSetup {
IntegrationTestSetup() {}
-
+
@Override
public Injector createInjector() {
return Guice.createInjector(new Module());
}
-
+
private static class Module extends ProtobufRuntimeModule {
@SuppressWarnings("unused")
public Class<? extends IFileUriResolver> bindFileUriResolver() {
return FileUriResolver.class;
}
}
-
+
private static class FileUriResolver implements IFileUriResolver {
@Override public String resolveUri(String importUri, Resource declaringResource) {
URI uri = URI.createURI(importUri);
- if (!isEmpty(uri.scheme())) return importUri; // already resolved.
+ if (!isEmpty(uri.scheme()))
+ {
+ return importUri; // already resolved.
+ }
File file = protoFile(importUri);
- if (!file.exists()) throw new IllegalArgumentException("File: " + importUri + " does not exist.");
+ if (!file.exists()) {
+ throw new IllegalArgumentException("File: " + importUri + " does not exist.");
+ }
return file.toURI().toString();
}
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/Setups.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/Setups.java
index 8209403..04503df 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/Setups.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/Setups.java
@@ -18,10 +18,10 @@
public static ISetup unitTestSetup() {
return new UnitTestSetup();
}
-
+
public static ISetup integrationTestSetup() {
return new IntegrationTestSetup();
}
-
+
private Setups() {}
}
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 5add2bd..418e23b 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
@@ -1,22 +1,22 @@
/*
* 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.junit.core;
import static java.io.File.separator;
-import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
+import java.io.*;
+import java.util.*;
import org.junit.runners.model.FrameworkMethod;
-import java.io.*;
-import java.util.*;
+import com.google.eclipse.protobuf.junit.util.MultiLineTextBuilder;
/**
* @author alruiz@google.com (Alex Ruiz)
@@ -27,30 +27,36 @@
private final Map<String, List<String>> comments = new HashMap<String, List<String>>();
private final CommentProcessor processor = new CommentProcessor();
-
+
private boolean initialized;
-
+
private final Object lock = new Object();
-
+
String commentsIn(FrameworkMethod method) {
synchronized (lock) {
ensureCommentsAreRead(method.getMethod().getDeclaringClass());
List<String> allComments = comments.get(method.getName());
- if (allComments == null || allComments.isEmpty()) return null;
+ if (allComments == null || allComments.isEmpty()) {
+ return null;
+ }
for (String comment : allComments) {
Object processed = processor.processComment(comment);
- if (processed instanceof String) return (String) processed;
+ if (processed instanceof String) {
+ return (String) processed;
+ }
}
return null;
}
}
-
+
private void ensureCommentsAreRead(Class<?> testClass) {
- if (initialized) return;
+ if (initialized) {
+ return;
+ }
doReadComments(testClass);
initialized = true;
}
-
+
private void doReadComments(Class<?> testClass) {
String fqn = testClass.getName().replace('.', '/');
fqn = fqn.indexOf("$") == -1 ? fqn : fqn.substring(0, fqn.indexOf("$"));
@@ -68,16 +74,20 @@
comment.append(line.substring(COMMENT_START.length()).trim());
continue;
}
- if (comment.isEmpty()) continue;
+ if (comment.isEmpty()) {
+ continue;
+ }
line = line.trim();
String testName = testName(line);
if (line.length() == 0 || testName != null) {
- if (!allComments.contains(comment)) allComments.add(comment.toString());
+ if (!allComments.contains(comment)) {
+ allComments.add(comment.toString());
+ }
comment = new MultiLineTextBuilder();
}
if (testName != null) {
comments.put(testName, allComments);
- allComments = new ArrayList<String>();
+ allComments = new ArrayList<String>();
}
}
} catch (IOException e) {
@@ -88,7 +98,9 @@
}
private static String testName(String line) {
- if (!line.startsWith("@Test")) return null;
+ if (!line.startsWith("@Test")) {
+ return null;
+ }
int indexOfShould = line.indexOf("should");
return (indexOfShould == -1) ? null : line.substring(indexOfShould, line.indexOf("("));
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/UnitTestSetup.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/UnitTestSetup.java
index ca4dd7b..0177a82 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/UnitTestSetup.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/UnitTestSetup.java
@@ -21,18 +21,18 @@
public class UnitTestSetup extends ProtobufStandaloneSetup {
UnitTestSetup() {}
-
+
@Override
public Injector createInjector() {
return Guice.createInjector(new Module());
}
-
+
private static class Module extends ProtobufRuntimeModule {
@Override public void configureExtensionRegistry(Binder binder) {
- binder.bind(IExtensionRegistry.class).toProvider(ExtensionRegistryProvider.class);
+ binder.bind(IExtensionRegistry.class).toProvider(ExtensionRegistryProvider.class);
}
}
-
+
private static class ExtensionRegistryProvider implements Provider<IExtensionRegistry> {
@Override public IExtensionRegistry get() {
return mock(IExtensionRegistry.class);
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/XtextRule.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/XtextRule.java
index 6cccc7e..f08dcf8 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/XtextRule.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/core/XtextRule.java
@@ -74,7 +74,9 @@
resource = resourceFrom(new StringInputStream(text));
IParseResult parseResult = resource.getParseResult();
root = (Protobuf) parseResult.getRootASTElement();
- if (ignoreSyntaxErrors) return;
+ if (ignoreSyntaxErrors) {
+ return;
+ }
if (!parseResult.hasSyntaxErrors()) {
if (root.getSyntax() == null) {
throw new IllegalStateException("Please specify 'proto2' syntax");
@@ -83,8 +85,9 @@
}
StringBuilder builder = new StringBuilder();
builder.append("Syntax errors:");
- for (INode error : parseResult.getSyntaxErrors())
+ for (INode error : parseResult.getSyntaxErrors()) {
builder.append(lineSeparator()).append("- ").append(error.getSyntaxErrorMessage());
+ }
throw new IllegalStateException(builder.toString());
}
@@ -93,7 +96,7 @@
}
private XtextResource resourceFrom(InputStream input) {
- return resourceFrom(input, createURI("mytestmodel.proto")); //$NON-NLS-1$
+ return resourceFrom(input, createURI("mytestmodel.proto"));
}
private XtextResource resourceFrom(InputStream input, URI uri) {
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 65fd42c..6f5c274 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
@@ -12,8 +12,7 @@
import java.util.*;
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
+import org.hamcrest.*;
import com.google.eclipse.protobuf.protobuf.*;
import com.google.eclipse.protobuf.protobuf.Enum;
@@ -28,16 +27,20 @@
public static EnumHasLiterals hasLiterals(String... literalNames) {
return new EnumHasLiterals(literalNames);
}
-
+
private EnumHasLiterals(String... literalNames) {
this.literalNames = literalNames;
}
-
+
@Override public boolean matches(Object arg) {
- if (!(arg instanceof Enum)) return false;
+ if (!(arg instanceof Enum)) {
+ return false;
+ }
Enum anEnum = (Enum) arg;
List<String> actualNames = literalNames(anEnum);
- for (String name : literalNames) actualNames.remove(name);
+ for (String name : literalNames) {
+ actualNames.remove(name);
+ }
return actualNames.isEmpty();
}
@@ -48,7 +51,7 @@
}
return names;
}
-
+
@Override public void describeTo(Description description) {
description.appendValue(Arrays.toString(literalNames));
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/matchers/FieldHasType.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/matchers/FieldHasType.java
index 3b31b28..341fc20 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/matchers/FieldHasType.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/matchers/FieldHasType.java
@@ -36,14 +36,18 @@
}
@Override public boolean matches(Object arg) {
- if (!(arg instanceof MessageField)) return false;
+ if (!(arg instanceof MessageField)) {
+ return false;
+ }
MessageField field = (MessageField) arg;
return typeName.equals(typeNameOf(field));
}
private String typeNameOf(MessageField field) {
TypeLink link = field.getType();
- if (link instanceof ScalarTypeLink) return ((ScalarTypeLink) link).getTarget().getName();
+ if (link instanceof ScalarTypeLink) {
+ return ((ScalarTypeLink) link).getTarget().getName();
+ }
if (link instanceof ComplexTypeLink) {
ComplexType type = ((ComplexTypeLink) link).getTarget();
return type == null ? null : type.getName();
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 67ede73..ada60de 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
@@ -138,7 +138,9 @@
/** {@inheritDoc} */
@Override public void deleteMarkers(String type, boolean includeSubtypes, int depth) {
List<MarkerStub> markers = markersByType.get(type);
- if (markers != null) markers.clear();
+ if (markers != null) {
+ markers.clear();
+ }
}
/** {@inheritDoc} */
@@ -154,7 +156,9 @@
/** {@inheritDoc} */
@Override public IMarker[] findMarkers(String type, boolean includeSubtypes, int depth) {
List<MarkerStub> markers = markersByType.get(type);
- if (markers == null) return new IMarker[0];
+ if (markers == null) {
+ return new IMarker[0];
+ }
return markers.toArray(new IMarker[markers.size()]);
}
@@ -523,7 +527,9 @@
public List<MarkerStub> markersOfType(String type) {
List<MarkerStub> markers = markersByType.get(type);
- if (markers == null) return emptyList();
+ if (markers == null) {
+ return emptyList();
+ }
return unmodifiableList(markers);
}
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 cdc7eae..b90a24e 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,6 +8,7 @@
*/
package com.google.eclipse.protobuf.junit.stubs.resources;
+import static com.google.eclipse.protobuf.util.Objects.*;
import static java.util.Collections.unmodifiableMap;
import java.util.*;
@@ -59,21 +60,27 @@
/** {@inheritDoc} */
@Override public int getAttribute(String attributeName, int defaultValue) {
Object attribute = attributes.get(attributeName);
- if (attribute instanceof Integer) return (Integer) attribute;
+ if (attribute instanceof Integer) {
+ return (Integer) attribute;
+ }
return defaultValue;
}
/** {@inheritDoc} */
@Override public String getAttribute(String attributeName, String defaultValue) {
Object attribute = attributes.get(attributeName);
- if (attribute instanceof String) return (String) attribute;
+ if (attribute instanceof String) {
+ return (String) attribute;
+ }
return defaultValue;
}
/** {@inheritDoc} */
@Override public boolean getAttribute(String attributeName, boolean defaultValue) {
Object attribute = attributes.get(attributeName);
- if (attribute instanceof Boolean) return (Boolean) attribute;
+ if (attribute instanceof Boolean) {
+ return (Boolean) attribute;
+ }
return defaultValue;
}
@@ -85,8 +92,9 @@
/** {@inheritDoc} */
@Override public Object[] getAttributes(String[] attributeNames) {
List<Object> values = new ArrayList<Object>();
- for (String name : attributeNames)
+ for (String name : attributeNames) {
values.add(attributes.get(name));
+ }
return values.toArray();
}
@@ -143,7 +151,7 @@
public int severity() {
return getAttribute(SEVERITY, -1);
}
-
+
public String message() {
return (String) getAttribute(MESSAGE);
}
@@ -153,24 +161,24 @@
}
@Override public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null) return false;
- if (getClass() != obj.getClass()) return false;
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
MarkerStub other = (MarkerStub) obj;
- if (attributes == null) {
- if (other.attributes != null) return false;
- } else if (!attributes.equals(other.attributes)) return false;
- if (type == null) {
- if (other.type != null) return false;
- } else if (!type.equals(other.type)) return false;
- return true;
+ if (!areEqual(attributes, other.attributes)) {
+ return false;
+ }
+ return areEqual(type, other.type);
}
@Override public int hashCode() {
- final int prime = 31;
+ final int prime = HASH_CODE_PRIME;
int result = 1;
- result = prime * result + ((attributes == null) ? 0 : attributes.hashCode());
- result = prime * result + ((type == null) ? 0 : type.hashCode());
+ result = prime * result + hashCodeOf(attributes);
+ result = prime * result + hashCodeOf(type);
return result;
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/resources/ResourceStub.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/resources/ResourceStub.java
index 7af740a..c5dc851 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/resources/ResourceStub.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/resources/ResourceStub.java
@@ -26,11 +26,11 @@
private URI uri;
public ResourceStub() {}
-
+
public ResourceStub(String uri) {
setURI(createURI(uri));
}
-
+
/** {@inheritDoc} */
@Override public EList<Adapter> eAdapters() {
throw new UnsupportedOperationException();
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/util/MultiLineTextBuilder.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/util/MultiLineTextBuilder.java
index f11f65d..5022fae 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/util/MultiLineTextBuilder.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/util/MultiLineTextBuilder.java
@@ -16,26 +16,26 @@
public class MultiLineTextBuilder {
private final StringBuilder builder = new StringBuilder();
-
+
public MultiLineTextBuilder() {}
-
+
public MultiLineTextBuilder(String initialContent) {
append(initialContent);
}
-
+
public MultiLineTextBuilder append(String s) {
builder.append(s).append(lineSeparator());
return this;
}
-
+
public boolean isEmpty() {
return builder.length() == 0;
}
-
+
public boolean hasContent(String s) {
return toString().equals(s);
}
-
+
@Override public String toString() {
return builder.toString();
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/linking/ProtobufDiagnostic_appendToMessage_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/linking/ProtobufDiagnostic_appendToMessage_Test.java
index 03778fe..0e7a134 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/linking/ProtobufDiagnostic_appendToMessage_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/linking/ProtobufDiagnostic_appendToMessage_Test.java
@@ -17,17 +17,17 @@
/**
* Tests for <code>{@link ProtobufDiagnostic#appendToMessage(String)}</code>
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class ProtobufDiagnostic_appendToMessage_Test {
private ProtobufDiagnostic diagnostic;
-
+
@Before public void setUp() {
diagnostic = new ProtobufDiagnostic("1000", new String[0], "Hello", mock(INode.class));
}
-
+
@Test public void should_append_text_to_message() {
diagnostic.appendToMessage(" ");
diagnostic.appendToMessage("World");
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/linking/ProtobufDiagnostic_constructor_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/linking/ProtobufDiagnostic_constructor_Test.java
index 11497b7..9d54625 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/linking/ProtobufDiagnostic_constructor_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/linking/ProtobufDiagnostic_constructor_Test.java
@@ -20,33 +20,33 @@
/**
* Tests for <code>{@link ProtobufDiagnostic#ProtobufDiagnostic(String, String[], String, INode)}</code>
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class ProtobufDiagnostic_constructor_Test {
private static INode node;
-
+
@BeforeClass public static void setUpOnce() {
node = mock(INode.class);
}
-
+
@Test(expected = NullPointerException.class)
public void should_throw_exception_if_data_is_null() {
new ProtobufDiagnostic("1000", null, "message", node);
}
-
+
@Test(expected = NullPointerException.class)
public void should_throw_exception_if_data_contains_nulls() {
new ProtobufDiagnostic("1000", new String[] { null }, "message", node);
}
-
+
@Test(expected = NullPointerException.class)
public void should_throw_exception_if_node_is_null() {
new ProtobufDiagnostic("1000", new String[0], "message", null);
}
-
- @SuppressWarnings("unchecked")
+
+ @SuppressWarnings("unchecked")
@Test public void should_create_new_instance() {
String[] data = { "abc.proto" };
ProtobufDiagnostic d = new ProtobufDiagnostic("1000", data, "message", node);
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/linking/ProtobufResource_createDiagnostic_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/linking/ProtobufResource_createDiagnostic_Test.java
index 3a08e0e..7a671c3 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/linking/ProtobufResource_createDiagnostic_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/linking/ProtobufResource_createDiagnostic_Test.java
@@ -23,25 +23,25 @@
/**
* Tests for <code>{@link ProtobufResource#createDiagnostic(Triple, DiagnosticMessage)}</code>
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class ProtobufResource_createDiagnostic_Test {
private static Triple<EObject, EReference, INode> triple;
-
+
@BeforeClass public static void setUpOnce() {
triple = Tuples.create(mock(EObject.class), mock(EReference.class), mock(INode.class));
}
-
+
private DiagnosticMessage message;
private ProtobufResource resource;
-
+
@Before public void setUp() {
message = new DiagnosticMessage("message", WARNING, "1000", new String[] { "abc.proto" });
resource = new ProtobufResource();
}
-
+
@Test public void should_create_dianostic() {
Diagnostic diagnostic = resource.createDiagnostic(triple, message);
assertThat(diagnostic, instanceOf(ProtobufDiagnostic.class));
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_firstNodeForFeature_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_firstNodeForFeature_Test.java
index a39b03b..1c5e898 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_firstNodeForFeature_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_firstNodeForFeature_Test.java
@@ -14,13 +14,13 @@
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
-import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.protobuf.MessageField;
-
import org.eclipse.emf.ecore.*;
import org.eclipse.xtext.nodemodel.INode;
import org.junit.*;
+import com.google.eclipse.protobuf.junit.core.XtextRule;
+import com.google.eclipse.protobuf.protobuf.MessageField;
+
/**
* Tests for <code>{@link INodes#firstNodeForFeature(EObject, EStructuralFeature)}</code>
*
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_isHiddenLeafNode_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_isHiddenLeafNode_Test.java
index 80993ed..c4e6a92 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_isHiddenLeafNode_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_isHiddenLeafNode_Test.java
@@ -16,17 +16,17 @@
/**
* Tests for <code>{@link INodes#isHiddenLeafNode(INode)}</code>
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class INodes_isHiddenLeafNode_Test {
private INodes nodes;
-
+
@Before public void setUp() {
nodes = new INodes();
}
-
+
@Test public void should_return_true_if_given_node_is_an_ILeafNode_and_is_hidden() {
ILeafNode node = mock(ILeafNode.class);
when(node.isHidden()).thenReturn(true);
@@ -38,7 +38,7 @@
when(node.isHidden()).thenReturn(false);
assertFalse(nodes.isHiddenLeafNode(node));
}
-
+
@Test public void should_return_false_if_given_node_is_not_an_ILeafNode() {
INode node = mock(INode.class);
assertFalse(nodes.isHiddenLeafNode(node));
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_indexFeatureOf_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_indexFeatureOf_Test.java
index a21fba2..66ff31f 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_indexFeatureOf_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_indexFeatureOf_Test.java
@@ -8,29 +8,29 @@
*/
package com.google.eclipse.protobuf.model.util;
+import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.*;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
-
-import com.google.eclipse.protobuf.protobuf.*;
+import static org.mockito.Mockito.mock;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.junit.*;
-import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.*;
+
+import com.google.eclipse.protobuf.protobuf.*;
/**
* Tests for <code>{@link IndexedElements#indexFeatureOf(IndexedElement)}</code>
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class IndexedElements_indexFeatureOf_Test {
private static IndexedElements indexedElements;
-
+
@BeforeClass public static void setUpOnce() {
indexedElements = new IndexedElements();
}
-
+
@Test public void should_return_name_of_Property() {
MessageField field = mock(MessageField.class);
EStructuralFeature expected = MESSAGE_FIELD__INDEX;
@@ -42,7 +42,7 @@
EStructuralFeature expected = GROUP__INDEX;
assertThat(indexedElements.indexFeatureOf(group), equalTo(expected));
}
-
+
@Test public void should_return_null_if_IndexedElement_is_null() {
assertNull(indexedElements.indexFeatureOf(null));
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_indexOf_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_indexOf_Test.java
index be51897..0d2dfde 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_indexOf_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_indexOf_Test.java
@@ -9,26 +9,26 @@
package com.google.eclipse.protobuf.model.util;
import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.*;
-import com.google.eclipse.protobuf.protobuf.*;
-
import org.junit.*;
+import com.google.eclipse.protobuf.protobuf.*;
+
/**
* Tests for <code>{@link IndexedElements#indexOf(IndexedElement)}</code>
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class IndexedElements_indexOf_Test {
private static IndexedElements indexedElements;
-
+
@BeforeClass public static void setUpOnce() {
indexedElements = new IndexedElements();
}
-
+
@Test public void should_return_name_of_Property() {
MessageField field = mock(MessageField.class);
when(field.getIndex()).thenReturn(6L);
@@ -42,7 +42,7 @@
assertThat(indexedElements.indexOf(group), equalTo(8L));
verify(group).getIndex();
}
-
+
@Test public void should_return_MIN_VALUE_if_IndexedElement_is_null() {
assertThat(indexedElements.indexOf(null), equalTo(Long.MIN_VALUE));
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_nameOf_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_nameOf_Test.java
index 413c94e..4c2bf4b 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_nameOf_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_nameOf_Test.java
@@ -14,26 +14,26 @@
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
-import com.google.eclipse.protobuf.junit.core.*;
-import com.google.eclipse.protobuf.protobuf.*;
-
import org.junit.*;
+import com.google.eclipse.protobuf.junit.core.XtextRule;
+import com.google.eclipse.protobuf.protobuf.*;
+
/**
* Tests for <code>{@link IndexedElements#nameOf(IndexedElement)}</code>
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class IndexedElements_nameOf_Test {
@Rule public XtextRule xtext = createWith(unitTestSetup());
-
+
private IndexedElements indexedElements;
-
+
@Before public void setUp() {
indexedElements = xtext.getInstanceOf(IndexedElements.class);
}
-
+
@Test public void should_return_name_of_Property() {
MessageField field = mock(MessageField.class);
when(field.getName()).thenReturn("foo");
@@ -47,7 +47,7 @@
assertThat(indexedElements.nameOf(group), equalTo("foo"));
verify(group).getName();
}
-
+
@Test public void should_return_null_if_IndexedElement_is_null() {
assertNull(indexedElements.nameOf(null));
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_setIndexOf_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_setIndexOf_Test.java
index 12d8f55..b636061 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_setIndexOf_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_setIndexOf_Test.java
@@ -10,23 +10,23 @@
import static org.mockito.Mockito.*;
-import com.google.eclipse.protobuf.protobuf.*;
-
import org.junit.*;
+import com.google.eclipse.protobuf.protobuf.*;
+
/**
* Tests for <code>{@link IndexedElements#setIndexTo(IndexedElement, long)}</code>
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class IndexedElements_setIndexOf_Test {
private static IndexedElements indexedElements;
-
+
@BeforeClass public static void setUpOnce() {
indexedElements = new IndexedElements();
}
-
+
@Test public void should_return_name_of_Property() {
MessageField field = mock(MessageField.class);
indexedElements.setIndexTo(field, 6L);
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/MessageFields_isPrimitive_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/MessageFields_isPrimitive_Test.java
index c1eef68..ce25b1e 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/MessageFields_isPrimitive_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/MessageFields_isPrimitive_Test.java
@@ -13,10 +13,10 @@
import static org.eclipse.xtext.EcoreUtil2.getAllContentsOfType;
import static org.junit.Assert.*;
-import org.junit.*;
-
import java.util.List;
+import org.junit.*;
+
import com.google.eclipse.protobuf.junit.core.XtextRule;
import com.google.eclipse.protobuf.protobuf.MessageField;
@@ -51,8 +51,9 @@
// }
@Test public void should_return_true_if_field_is_primitive() {
List<MessageField> allFields = getAllContentsOfType(xtext.root(), MessageField.class);
- for (MessageField field : allFields)
+ for (MessageField field : allFields) {
assertTrue(fields.isPrimitive(field));
+ }
}
// syntax = "proto2";
@@ -68,7 +69,8 @@
// }
@Test public void should_return_false_if_field_is_not_primitive() {
List<MessageField> allFields = getAllContentsOfType(xtext.root(), MessageField.class);
- for (MessageField p : allFields)
+ for (MessageField p : allFields) {
assertFalse(fields.isPrimitive(p));
+ }
}
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Options_nameForOption_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Options_nameForOption_Test.java
index 093c4b6..7a99481 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Options_nameForOption_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/Options_nameForOption_Test.java
@@ -14,39 +14,39 @@
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
+import org.junit.*;
+
import com.google.eclipse.protobuf.junit.core.XtextRule;
import com.google.eclipse.protobuf.protobuf.*;
-import org.junit.*;
-
/**
* Tests for <code>{@link Options#nameForOption(IndexedElement)}</code>
* @author alruiz@google.com (Alex Ruiz)
*/
public class Options_nameForOption_Test {
-
+
@Rule public XtextRule xtext = createWith(unitTestSetup());
private Options options;
-
+
@Before public void setUp() {
options = xtext.getInstanceOf(Options.class);
}
-
+
@Test public void should_return_unchanged_name_if_element_is_Field() {
MessageField field = mock(MessageField.class);
when(field.getName()).thenReturn("active");
assertThat(options.nameForOption(field), equalTo("active"));
verify(field).getName();
}
-
+
@Test public void should_return_name_in_lower_case_if_element_is_Group() {
Group group = mock(Group.class);
when(group.getName()).thenReturn("Person");
assertThat(options.nameForOption(group), equalTo("person"));
verify(group).getName();
}
-
+
@Test public void should_return_null_if_element_is_null() {
assertNull(options.nameForOption(null));
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/naming/LocalNamesProvider_names_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/naming/LocalNamesProvider_names_Test.java
index 2a55884..d50d44e 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/naming/LocalNamesProvider_names_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/naming/LocalNamesProvider_names_Test.java
@@ -20,7 +20,6 @@
import org.junit.*;
import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.naming.LocalNamesProvider;
import com.google.eclipse.protobuf.protobuf.Enum;
/**
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/naming/NameResolver_nameOf_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/naming/NameResolver_nameOf_Test.java
index 2466c2e..dc0d184 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/naming/NameResolver_nameOf_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/naming/NameResolver_nameOf_Test.java
@@ -22,19 +22,19 @@
/**
* Tests for <code>{@link NameResolver#nameOf(EObject)}</code>.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class NameResolver_nameOf_Test {
@Rule public XtextRule xtext = createWith(unitTestSetup());
-
+
private NameResolver resolver;
-
+
@Before public void setUp() {
resolver = xtext.getInstanceOf(NameResolver.class);
}
-
+
// syntax = "proto2";
//
// message Person {}
@@ -43,13 +43,13 @@
String name = resolver.nameOf(message);
assertThat(name, equalTo("Person"));
}
-
+
// syntax = "proto2";
//
// package com.google.proto.test;
@Test public void should_return_name_of_Package() {
Package aPackage = xtext.find("com.google.proto.test", Package.class);
String name = resolver.nameOf(aPackage);
- assertThat(name, equalTo("com.google.proto.test"));
+ assertThat(name, equalTo("com.google.proto.test"));
}
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/parser/Proto2OnlyParser_doParse_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/parser/Proto2OnlyParser_doParse_Test.java
index 6d1d335..a669172 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/parser/Proto2OnlyParser_doParse_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/parser/Proto2OnlyParser_doParse_Test.java
@@ -13,16 +13,16 @@
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.junit.Assert.assertThat;
-import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.protobuf.Protobuf;
-
import org.antlr.runtime.CharStream;
import org.eclipse.xtext.nodemodel.impl.NodeModelBuilder;
import org.junit.*;
+import com.google.eclipse.protobuf.junit.core.XtextRule;
+import com.google.eclipse.protobuf.protobuf.Protobuf;
+
/**
* Tests for <code>{@link Proto2OnlyParser#doParse(String, CharStream, NodeModelBuilder, int)}</code>.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class Proto2OnlyParser_doParse_Test {
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkSyntaxIsProto2_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkSyntaxIsProto2_Test.java
index a3b10fa..bc0f27b 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkSyntaxIsProto2_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkSyntaxIsProto2_Test.java
@@ -13,14 +13,14 @@
import static org.eclipse.xtext.validation.ValidationMessageAcceptor.INSIGNIFICANT_INDEX;
import static org.mockito.Mockito.*;
-import com.google.eclipse.protobuf.protobuf.Syntax;
-
import org.eclipse.xtext.validation.ValidationMessageAcceptor;
import org.junit.*;
+import com.google.eclipse.protobuf.protobuf.Syntax;
+
/**
* Tests for <code>{@link ProtobufJavaValidator#checkSyntaxIsProto2(Syntax)}</code>
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class ProtobufJavaValidator_checkSyntaxIsProto2_Test {
@@ -28,21 +28,21 @@
private Syntax syntax;
private ValidationMessageAcceptor messageAcceptor;
private ProtobufJavaValidator validator;
-
+
@Before public void setUp() {
syntax = mock(Syntax.class);
messageAcceptor = mock(ValidationMessageAcceptor.class);
validator = new ProtobufJavaValidator();
validator.setMessageAcceptor(messageAcceptor);
}
-
+
@Test public void should_create_error_if_syntax_is_not_proto2() {
when(syntax.getName()).thenReturn("proto1");
validator.checkSyntaxIsProto2(syntax);
String message = "Unrecognized syntax identifier \"proto1\". This parser only recognizes \"proto2\".";
verify(messageAcceptor).acceptError(message, syntax, SYNTAX__NAME, INSIGNIFICANT_INDEX, SYNTAX_IS_NOT_PROTO2_ERROR);
}
-
+
@Test public void should_not_create_error_if_syntax_is_proto2() {
when(syntax.getName()).thenReturn("proto2");
validator.checkSyntaxIsProto2(syntax);
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkTagNumberIsGreaterThanZero_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkTagNumberIsGreaterThanZero_Test.java
index 2a4c399..bd25629 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkTagNumberIsGreaterThanZero_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkTagNumberIsGreaterThanZero_Test.java
@@ -10,7 +10,7 @@
import static com.google.eclipse.protobuf.junit.core.Setups.unitTestSetup;
import static com.google.eclipse.protobuf.junit.core.XtextRule.createWith;
-import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.*;
+import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.MESSAGE_FIELD__INDEX;
import static com.google.eclipse.protobuf.validation.ProtobufJavaValidator.INVALID_FIELD_TAG_NUMBER_ERROR;
import static org.eclipse.xtext.validation.ValidationMessageAcceptor.INSIGNIFICANT_INDEX;
import static org.mockito.Mockito.*;
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkTagNumberIsUnique_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkTagNumberIsUnique_Test.java
index 5497e3a..e8fcb92 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkTagNumberIsUnique_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator_checkTagNumberIsUnique_Test.java
@@ -15,12 +15,12 @@
import static org.eclipse.xtext.validation.ValidationMessageAcceptor.INSIGNIFICANT_INDEX;
import static org.mockito.Mockito.*;
-import com.google.eclipse.protobuf.junit.core.XtextRule;
-import com.google.eclipse.protobuf.protobuf.*;
-
import org.eclipse.xtext.validation.ValidationMessageAcceptor;
import org.junit.*;
+import com.google.eclipse.protobuf.junit.core.XtextRule;
+import com.google.eclipse.protobuf.protobuf.*;
+
/**
* Tests for <code>{@link ProtobufJavaValidator#checkTagNumberIsUnique(IndexedElement)}</code>
*
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtoDescriptorPathFinder_findRootOf_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtoDescriptorPathFinder_findRootOf_Test.java
index 36ea148..53bf906 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtoDescriptorPathFinder_findRootOf_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtoDescriptorPathFinder_findRootOf_Test.java
@@ -12,8 +12,6 @@
import static org.junit.Assert.*;
import static org.junit.rules.ExpectedException.none;
-import com.google.eclipse.protobuf.ui.builder.protoc.ProtoDescriptorPathFinder;
-
import org.junit.*;
import org.junit.rules.ExpectedException;
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtocMarkerFactory_createErrorIfNecessary_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtocMarkerFactory_createErrorIfNecessary_Test.java
index 090dae6..984fe8e 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtocMarkerFactory_createErrorIfNecessary_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtocMarkerFactory_createErrorIfNecessary_Test.java
@@ -19,7 +19,6 @@
import org.junit.*;
import com.google.eclipse.protobuf.junit.stubs.resources.*;
-import com.google.eclipse.protobuf.ui.builder.protoc.ProtocMarkerFactory;
/**
* Tests for <code>{@link ProtocMarkerFactory#createErrorIfNecessary(String, String, int)}</code>.
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 501a328..c665c58 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
@@ -13,18 +13,18 @@
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
-import com.google.eclipse.protobuf.protobuf.Message;
+import java.util.*;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.resource.*;
import org.junit.*;
-import java.util.*;
+import com.google.eclipse.protobuf.protobuf.Message;
/**
* Tests for <code>{@link IEObjectDescriptionChooser#shortestQualifiedNamesIn(Collection)}</code>.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class IEObjectDescriptionChooser_shortestQualifiedNamesIn_Test {
@@ -32,7 +32,7 @@
private List<IEObjectDescription> descriptions;
private Map<String, String> userData;
private IEObjectDescriptionChooser chooser;
-
+
@Before public void setUp() {
userData = emptyMap();
chooser = new IEObjectDescriptionChooser();
@@ -43,7 +43,7 @@
/*
* Creates IEObjectDescriptions for the given EObject, one per segment in the given qualified name.
- *
+ *
* Example:
* Given the qualified name "com.google.test.Phone", this method will use these qualified names to create
* IEObjectDescriptions:
@@ -61,7 +61,7 @@
descriptions.add(new EObjectDescription(newName, e, userData));
}
}
-
+
@Test public void should_return_descriptions_with_shortest_QualifiedName() {
Collection<IEObjectDescription> chosen = chooser.shortestQualifiedNamesIn(descriptions);
assertThat(chosen, containOnly("EMail", "Phone"));
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 e6f0b4b..bce9d0b 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
@@ -26,26 +26,34 @@
public static IEObjectDescriptionsHaveNames containOnly(String...names) {
return new IEObjectDescriptionsHaveNames(names);
}
-
+
private IEObjectDescriptionsHaveNames(String[] qualifiedNames) {
this.qualifiedNames = new ArrayList<String>(asList(qualifiedNames));
}
-
+
/** {@inheritDoc} */
- @Override @SuppressWarnings("unchecked")
+ @Override @SuppressWarnings("unchecked")
public boolean matches(Object arg) {
- if (!(arg instanceof Collection)) return false;
+ if (!(arg instanceof Collection)) {
+ return false;
+ }
Collection<IEObjectDescription> descriptions = (Collection<IEObjectDescription>) arg;
List<String> copyOfNames = new ArrayList<String>(qualifiedNames);
- if (copyOfNames.size() != descriptions.size()) return false;
+ if (copyOfNames.size() != descriptions.size()) {
+ return false;
+ }
for (IEObjectDescription description : descriptions) {
QualifiedName qualifiedName = description.getName();
- if (qualifiedName == null) continue;
- if (!copyOfNames.remove(qualifiedName.toString())) return false;
+ if (qualifiedName == null) {
+ continue;
+ }
+ if (!copyOfNames.remove(qualifiedName.toString())) {
+ return false;
+ }
}
return copyOfNames.isEmpty();
}
-
+
/** {@inheritDoc} */
@Override public void describeTo(Description description) {
description.appendValue(qualifiedNames);
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/documentation/ProtobufDocumentationProvider_getDocumentation_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/documentation/ProtobufDocumentationProvider_getDocumentation_Test.java
index f12f74f..5bb4354 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/documentation/ProtobufDocumentationProvider_getDocumentation_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/documentation/ProtobufDocumentationProvider_getDocumentation_Test.java
@@ -17,28 +17,28 @@
/**
* Tests for <code>{@link ProtobufDocumentationProvider#getDocumentation(EObject)}</code>
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class ProtobufDocumentationProvider_getDocumentation_Test {
private static EObject o;
-
+
@BeforeClass public static void setUpOnce() {
o = mock(EObject.class);
}
-
+
private SLCommentDocumentationProvider delegate1;
private MLCommentDocumentationProvider delegate2;
-
+
private ProtobufDocumentationProvider provider;
-
+
@Before public void setUp() {
delegate1 = mock(SLCommentDocumentationProvider.class);
delegate2 = mock(MLCommentDocumentationProvider.class);
provider = new ProtobufDocumentationProvider(delegate1, delegate2);
}
-
+
@Test public void should_use_first_delegate_if_it_returns_comment() {
String comment = "Hello World";
when(delegate1.getDocumentation(o)).thenReturn(comment);
@@ -46,7 +46,7 @@
verify(delegate1).getDocumentation(o);
verifyZeroInteractions(delegate2);
}
-
+
@Test public void should_use_second_delegage_if_first_does_not_return_comment() {
when(delegate1.getDocumentation(o)).thenReturn("");
String comment = "Hello World";
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/editor/hyperlinking/ImportHyperlink_open_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/editor/hyperlinking/ImportHyperlink_open_Test.java
index 0ead841..c7901f0 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/editor/hyperlinking/ImportHyperlink_open_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/editor/hyperlinking/ImportHyperlink_open_Test.java
@@ -19,7 +19,7 @@
/**
* Tests for <code>{@link ImportHyperlink#open()}</code>.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class ImportHyperlink_open_Test {
@@ -29,14 +29,14 @@
@BeforeClass public static void setUpOnce() {
region = mock(IRegion.class);
}
-
+
private FileOpener fileOpener;
private ImportHyperlink hyperlink;
-
+
@Before public void setUp() {
fileOpener = mock(FileOpener.class);
}
-
+
@Test public void should_open_file_in_workspace() throws Throwable {
URI uri = createPlatformResourceURI("test.proto", false);
hyperlink = new ImportHyperlink(uri, region, fileOpener);
@@ -50,7 +50,7 @@
hyperlink.open();
verify(fileOpener).openProtoFileInPlugin(uri);
}
-
+
@Test public void should_open_file_in_file_system() throws Throwable {
URI uri = createFileURI("test.proto");
hyperlink = new ImportHyperlink(uri, region, fileOpener);
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/editor/model/ContentReader_contentsOf_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/editor/model/ContentReader_contentsOf_Test.java
index d0b00db..29988d0 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/editor/model/ContentReader_contentsOf_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/editor/model/ContentReader_contentsOf_Test.java
@@ -18,17 +18,17 @@
/**
* Tests for <code>{@link ContentReader#contentsOf(InputStream)}</code>.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class ContentReader_contentsOf_Test {
private ContentReader reader;
-
+
@Before public void setUp() {
reader = new ContentReader();
}
-
+
@Test public void should_read_InputStream() throws IOException {
String contents = "Hello \r\n World";
InputStream input = new StringInputStream(contents);
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/BooleanPreference_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/BooleanPreference_Test.java
index f349712..5f54bba 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/BooleanPreference_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/BooleanPreference_Test.java
@@ -16,34 +16,34 @@
/**
* Tests for <code>{@link BooleanPreference}</code>.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class BooleanPreference_Test {
private String name;
private IPreferenceStore store;
-
+
private BooleanPreference preference;
-
+
@Before public void setUp() {
name = "active";
store = mock(IPreferenceStore.class);
preference = new BooleanPreference(name, store);
}
-
+
@Test public void should_read_value_from_IPreferenceStore() {
when(store.getBoolean(name)).thenReturn(true);
assertTrue(preference.value());
verify(store).getBoolean(name);
}
-
+
@Test public void should_read_default_value_from_IPreferenceStore() {
when(store.getDefaultBoolean(name)).thenReturn(true);
assertTrue(preference.defaultValue());
verify(store).getDefaultBoolean(name);
}
-
+
@Test public void should_update_value_in_IPreferenceStore() {
preference.value(true);
verify(store).setValue(name, true);
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPath_parse_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPath_parse_Test.java
index bd3a501..6ad7726 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPath_parse_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPath_parse_Test.java
@@ -15,7 +15,7 @@
/**
* Tests for <code>{@link DirectoryPath#parse(String)}</code>
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class DirectoryPath_parse_Test {
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPath_toString_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPath_toString_Test.java
index 0b1d1f5..eb808f8 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPath_toString_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPath_toString_Test.java
@@ -13,11 +13,9 @@
import org.junit.Test;
-import com.google.eclipse.protobuf.ui.preferences.pages.paths.DirectoryPath;
-
/**
* Tests for <code>{@link DirectoryPath#toString()}</code>
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class DirectoryPath_toString_Test {
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/ProjectVariable_useProjectName_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/ProjectVariable_useProjectName_Test.java
index 13c59db..99606dd 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/ProjectVariable_useProjectName_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/ProjectVariable_useProjectName_Test.java
@@ -12,30 +12,28 @@
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.*;
-import com.google.eclipse.protobuf.ui.preferences.pages.paths.ProjectVariable;
-
import org.eclipse.core.resources.IProject;
import org.junit.*;
/**
* Tests for <code>{@link ProjectVariable#useProjectName(String, IProject)}</code>.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class ProjectVariable_useProjectName_Test {
private IProject project;
-
+
@Before public void setUp() {
project = mock(IProject.class);
}
-
+
@Test public void should_use_project_name_if_path_contains_variable() {
when(project.getName()).thenReturn("test");
String newPath = ProjectVariable.useProjectName("/${project}/src/test", project);
assertThat(newPath, equalTo("/test/src/test"));
}
-
+
@Test public void should_not_use_project_name_if_path_does_not_contain_variable() {
when(project.getName()).thenReturn("test");
String newPath = ProjectVariable.useProjectName("/main/src/test", project);
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/ProjectVariable_useProjectVariable_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/ProjectVariable_useProjectVariable_Test.java
index 96c9c7d..df5ce9e 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/ProjectVariable_useProjectVariable_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/ProjectVariable_useProjectVariable_Test.java
@@ -12,32 +12,30 @@
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.*;
-import com.google.eclipse.protobuf.ui.preferences.pages.paths.ProjectVariable;
-
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.*;
import org.junit.*;
/**
* Tests for <code>{@link ProjectVariable#useProjectVariable(IPath, IProject)}</code>.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class ProjectVariable_useProjectVariable_Test {
private IProject project;
-
+
@Before public void setUp() {
project = mock(IProject.class);
}
-
+
@Test public void should_use_variable_if_path_contains_project_name() {
IPath path = new Path("/test/src/test");
when(project.getName()).thenReturn("test");
IPath newPath = ProjectVariable.useProjectVariable(path, project);
assertThat(newPath.toString(), equalTo("/${project}/src/test"));
}
-
+
@Test public void should_not_use_variable_if_path_does_not_contain_project_name() {
IPath path = new Path("/main/src/test");
when(project.getName()).thenReturn("test");
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolver_resolveUri_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolver_resolveUri_Test.java
index 7ca5aff..3de99ee 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolver_resolveUri_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/scoping/SingleDirectoryFileResolver_resolveUri_Test.java
@@ -60,11 +60,11 @@
String resolved = resolver.resolveUri("src/proto/read-only/address.proto", resourceUri, preferences);
assertThat(resolved, equalTo("platform:/resource/src/proto/read-only/address.proto"));
}
-
+
private void expectResolvedPathToBelongToExistingFile() {
when(resources.fileExists(any(URI.class))).thenReturn(true);
}
-
+
@Test public void should_return_null_if_URI_cannot_be_resolved() {
when(resources.fileExists(any(URI.class))).thenReturn(false);
String resolved = resolver.resolveUri("src/proto/read-only/person.proto", resourceUri, preferences);
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Paths_segmentsOf_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Paths_segmentsOf_Test.java
index 8d5a546..b282816 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Paths_segmentsOf_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/util/Paths_segmentsOf_Test.java
@@ -25,12 +25,12 @@
public void should_throw_error_if_path_is_null() {
Paths.segmentsOf(null);
}
-
+
@Test public void should_separate_segments_using_system_file_separator() {
String path = "folder1" + separator + "folder1_1" + separator + "folder1_1_1";
assertThat(Paths.segmentsOf(path), equalTo(new String[] { "folder1" , "folder1_1", "folder1_1_1" }));
}
-
+
@Test public void should_separate_segments_for_path_ending_with_system_file_separator() {
String path = "folder1" + separator + "folder1_1" + separator;
assertThat(Paths.segmentsOf(path), equalTo(new String[] { "folder1" , "folder1_1" }));
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/validation/ProtobufResourceUIValidatorExtension_createMarkers_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/validation/ProtobufResourceUIValidatorExtension_createMarkers_Test.java
index ea86f95..2006c77 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/validation/ProtobufResourceUIValidatorExtension_createMarkers_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/validation/ProtobufResourceUIValidatorExtension_createMarkers_Test.java
@@ -12,17 +12,17 @@
import static java.util.Arrays.asList;
import static org.mockito.Mockito.*;
+import java.util.List;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.*;
import org.eclipse.xtext.ui.editor.validation.MarkerCreator;
import org.eclipse.xtext.validation.Issue;
import org.junit.*;
-import java.util.List;
-
/**
* Tests for <code>{@link ProtobufResourceUIValidatorExtension#createMarkers(IFile, List, IProgressMonitor)}</code>
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class ProtobufResourceUIValidatorExtension_createMarkers_Test {
@@ -39,13 +39,13 @@
private MarkerCreator markerCreator;
private ProtobufResourceUIValidatorExtension validator;
-
+
@Before public void setUp() {
markerCreator = mock(MarkerCreator.class);
validator = new ProtobufResourceUIValidatorExtension();
validator.markerCreator = markerCreator;
}
-
+
@Test public void should_create_markers_using_proto_editor_marker_type() throws CoreException {
validator.createMarkers(file, issues, monitor);
for (Issue issue : issues) {
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/validation/ProtobufResourceUIValidatorExtension_deleteMarkers_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/validation/ProtobufResourceUIValidatorExtension_deleteMarkers_Test.java
index 44a40a1..879bc68 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/validation/ProtobufResourceUIValidatorExtension_deleteMarkers_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/validation/ProtobufResourceUIValidatorExtension_deleteMarkers_Test.java
@@ -20,11 +20,11 @@
/**
* Tests for <code>{@link ProtobufResourceUIValidatorExtension#deleteMarkers(IFile, CheckMode, IProgressMonitor)}</code>.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class ProtobufResourceUIValidatorExtension_deleteMarkers_Test {
-
+
private static CheckMode checkMode;
private static IProgressMonitor monitor;
@@ -35,17 +35,17 @@
private IFile file;
private ProtobufResourceUIValidatorExtension validator;
-
+
@Before public void setUp() {
file = mock(IFile.class);
validator = new ProtobufResourceUIValidatorExtension();
}
-
+
@Test public void should_delete_all_xtext_and_protocol_buffer_editor_markers() throws CoreException {
validator.deleteMarkers(file, checkMode, monitor);
verifyDeletionOfMarkers(FAST_VALIDATION, NORMAL_VALIDATION, EDITOR_CHECK);
}
-
+
private void verifyDeletionOfMarkers(String...markerTypes) throws CoreException {
for (String markerType : markerTypes) {
verify(file).deleteMarkers(markerType, true, DEPTH_ZERO);
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/ProtobufUiModule.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/ProtobufUiModule.java
index 9bbaa42..1ad4743 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/ProtobufUiModule.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/ProtobufUiModule.java
@@ -29,8 +29,7 @@
import com.google.eclipse.protobuf.scoping.IFileUriResolver;
import com.google.eclipse.protobuf.ui.builder.nature.AutoAddNatureEditorCallback;
import com.google.eclipse.protobuf.ui.documentation.ProtobufDocumentationProvider;
-import com.google.eclipse.protobuf.ui.editor.FileOutsideWorkspaceIconUpdater;
-import com.google.eclipse.protobuf.ui.editor.ProtobufUriEditorOpener;
+import com.google.eclipse.protobuf.ui.editor.*;
import com.google.eclipse.protobuf.ui.editor.hyperlinking.ProtobufHyperlinkDetector;
import com.google.eclipse.protobuf.ui.editor.model.ProtobufDocumentProvider;
import com.google.eclipse.protobuf.ui.editor.spelling.ProtobufReconciler;
@@ -69,7 +68,7 @@
public Class<? extends IHighlightingConfiguration> bindHighlightingConfiguration() {
return HighlightingConfiguration.class;
}
-
+
@Override public Class<? extends IContentOutlinePage> bindIContentOutlinePage() {
return ProtobufOutlinePage.class;
}
@@ -77,19 +76,19 @@
public Class<? extends IEObjectDocumentationProvider> bindIEObjectDocumentationProvider() {
return ProtobufDocumentationProvider.class;
}
-
+
@Override public Class<? extends IHyperlinkDetector> bindIHyperlinkDetector() {
return ProtobufHyperlinkDetector.class;
}
-
+
public Class<? extends IPreferenceStoreAccess> bindIPreferenceStoreAccess() {
return PreferenceStoreAccess.class;
}
-
+
@Override public Class<? extends IReconciler> bindIReconciler() {
return ProtobufReconciler.class;
}
-
+
public Class<? extends IResourceUIValidatorExtension> bindIResourceUIValidatorExtension() {
return ProtobufResourceUIValidatorExtension.class;
}
@@ -101,7 +100,7 @@
@Override public Class<? extends IXtextEditorCallback> bindIXtextEditorCallback() {
return AutoAddNatureEditorCallback.class;
}
-
+
public Class<? extends XtextDocumentProvider> bindXtextDocumentProvider() {
return ProtobufDocumentProvider.class;
}
@@ -117,7 +116,9 @@
}
@Override public void configureLanguageSpecificURIEditorOpener(Binder binder) {
- if (!isWorkbenchRunning())return;
+ if (!isWorkbenchRunning()) {
+ return;
+ }
binder.bind(IURIEditorOpener.class)
.annotatedWith(LanguageSpecific.class)
.to(ProtobufUriEditorOpener.class);
@@ -130,7 +131,7 @@
configurePreferenceInitializer(binder, "pathsPreferences", PathsPreferenceStoreInitializer.class);
configurePreferenceInitializer(binder, "saveActionsPreferences", SaveActionsPreferenceStoreInitializer.class);
}
-
+
private void configurePreferenceInitializer(Binder binder, String name,
Class<? extends IPreferenceStoreInitializer> initializerType) {
binder.bind(IPreferenceStoreInitializer.class).annotatedWith(named(name)).to(initializerType);
@@ -143,7 +144,9 @@
}
private void setValidationTrigger(IWorkbenchWindow w, AbstractUIPlugin plugin) {
- if (w == null || !(plugin instanceof ProtobufActivator)) return;
+ if (w == null || !(plugin instanceof ProtobufActivator)) {
+ return;
+ }
w.getPartService().addPartListener(new ValidateOnActivation());
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/nature/AutoAddNatureEditorCallback.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/nature/AutoAddNatureEditorCallback.java
index cdeffa0..d3464a8 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/nature/AutoAddNatureEditorCallback.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/nature/AutoAddNatureEditorCallback.java
@@ -8,19 +8,16 @@
*/
package com.google.eclipse.protobuf.ui.builder.nature;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.xtext.builder.nature.ToggleXtextNatureAction;
-import org.eclipse.xtext.builder.nature.XtextNature;
-import org.eclipse.xtext.ui.editor.AbstractDirtyStateAwareEditorCallback;
-import org.eclipse.xtext.ui.editor.XtextEditor;
+import org.eclipse.core.resources.*;
+import org.eclipse.xtext.builder.nature.*;
+import org.eclipse.xtext.ui.editor.*;
import com.google.inject.Inject;
/**
* Automatically adds <code>{@link XtextNature}</code> to a project if needed (e.g. when opening a 'Protocol Buffer'
* editor for the first time.)
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
@SuppressWarnings("restriction")
@@ -31,9 +28,15 @@
@Override public void afterCreatePartControl(XtextEditor editor) {
super.afterCreatePartControl(editor);
IResource resource = editor.getResource();
- if (resource == null) return;
+ if (resource == null) {
+ return;
+ }
IProject project = resource.getProject();
- if (!project.isAccessible() || project.isHidden()) return;
- if (!xtext.hasNature(project)) xtext.toggleNature(project);
+ if (!project.isAccessible() || project.isHidden()) {
+ return;
+ }
+ if (!xtext.hasNature(project)) {
+ xtext.toggleNature(project);
+ }
}
}
\ No newline at end of file
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/CodeGenerationErrorParser.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/CodeGenerationErrorParser.java
index 7d1bdfa..a2a381c 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/CodeGenerationErrorParser.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/CodeGenerationErrorParser.java
@@ -32,7 +32,9 @@
@Override
public boolean parseAndAddMarkerIfNecessary(String line, ProtocMarkerFactory markerFactory) throws CoreException {
Matcher errorMatcher = ERROR_PATTERN.matcher(line);
- if (!errorMatcher.matches()) return false;
+ if (!errorMatcher.matches()) {
+ return false;
+ }
markerFactory.createErrorIfNecessary(errorMatcher.group(1), errorMatcher.group(2), -1);
return true;
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/CompoundParser.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/CompoundParser.java
index 4a6d464..0d076dd 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/CompoundParser.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/CompoundParser.java
@@ -10,21 +10,25 @@
import static java.util.Arrays.asList;
-import org.eclipse.core.runtime.CoreException;
+import java.util.List;
-import java.util.*;
+import org.eclipse.core.runtime.CoreException;
/**
* @author alruiz@google.com (Alex Ruiz)
*/
class CompoundParser implements ProtocOutputParser {
- private static final List<ProtocOutputParser> PARSERS = asList(new LineSpecificErrorParser(), new CodeGenerationErrorParser());
-
- @Override
+ private static final List<ProtocOutputParser> PARSERS =
+ asList(new LineSpecificErrorParser(), new CodeGenerationErrorParser());
+
+ @Override
public boolean parseAndAddMarkerIfNecessary(String line, ProtocMarkerFactory markerFactory) throws CoreException {
- for (ProtocOutputParser parser: PARSERS)
- if (parser.parseAndAddMarkerIfNecessary(line, markerFactory)) return true;
+ for (ProtocOutputParser parser: PARSERS) {
+ if (parser.parseAndAddMarkerIfNecessary(line, markerFactory)) {
+ return true;
+ }
+ }
return false;
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/LineSpecificErrorParser.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/LineSpecificErrorParser.java
index 18745be..0f73849 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/LineSpecificErrorParser.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/LineSpecificErrorParser.java
@@ -35,8 +35,13 @@
@Override
public boolean parseAndAddMarkerIfNecessary(String line, ProtocMarkerFactory markerFactory) throws CoreException {
Matcher errorMatcher = ERROR_PATTERN.matcher(line);
- if (!errorMatcher.matches()) return false;
- markerFactory.createErrorIfNecessary(errorMatcher.group(1), errorMatcher.group(4), parseInt(errorMatcher.group(2)));
+ if (!errorMatcher.matches()) {
+ return false;
+ }
+ String fileName = errorMatcher.group(1);
+ int lineNumber = parseInt(errorMatcher.group(2));
+ String description = errorMatcher.group(4);
+ markerFactory.createErrorIfNecessary(fileName, description, lineNumber);
return true;
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/OutputDirectories.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/OutputDirectories.java
index 3777932..3968f54 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/OutputDirectories.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/OutputDirectories.java
@@ -31,7 +31,9 @@
throws CoreException {
Map<SupportedLanguage, IFolder> outputDirectories = new HashMap<SupportedLanguage, IFolder>();
for (CodeGenerationSetting preference : preferences.allSettings()) {
- if (!preference.isEnabled()) continue;
+ if (!preference.isEnabled()) {
+ continue;
+ }
outputDirectories.put(preference.language(), findOrCreateOutputDirectory(project, preference));
}
return new OutputDirectories(outputDirectories);
@@ -48,7 +50,9 @@
for (String segment : segmentsOf(outputFolderName)) {
path.append(segment);
outputFolder = project.getFolder(path.toString());
- if (!outputFolder.exists()) outputFolder.create(true, true, NO_MONITOR);
+ if (!outputFolder.exists()) {
+ outputFolder.create(true, true, NO_MONITOR);
+ }
path.append(separator);
}
return outputFolder;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtoDescriptorPathFinder.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtoDescriptorPathFinder.java
index 0a01887..ff6e925 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtoDescriptorPathFinder.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtoDescriptorPathFinder.java
@@ -22,18 +22,20 @@
class ProtoDescriptorPathFinder {
private final String descriptorFqn;
-
+
ProtoDescriptorPathFinder() {
this(separator);
}
-
+
@VisibleForTesting
ProtoDescriptorPathFinder(String fileSeparator) {
descriptorFqn = concat(fileSeparator, asList("", "google", "protobuf", "descriptor.proto"));
}
-
+
String findRootOf(String descriptorFilePath) {
- if (isEmpty(descriptorFilePath)) return null;
+ if (isEmpty(descriptorFilePath)) {
+ return null;
+ }
int indexOfDescriptorFqn = descriptorFilePath.indexOf(descriptorFqn);
if (indexOfDescriptorFqn == -1) {
String format = "Path '%s' does not contain '%s'";
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 7c7d5bb..91f6d67 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
@@ -16,14 +16,13 @@
import static org.eclipse.core.resources.IResource.DEPTH_INFINITE;
import java.io.*;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.*;
import org.eclipse.emf.common.util.URI;
import org.eclipse.xtext.builder.IXtextBuilderParticipant;
-import org.eclipse.xtext.resource.IResourceDescription;
+import org.eclipse.xtext.resource.*;
import org.eclipse.xtext.resource.IResourceDescription.Delta;
import com.google.eclipse.protobuf.ui.preferences.pages.compiler.*;
@@ -46,19 +45,29 @@
@Override public void build(IBuildContext context, IProgressMonitor monitor) throws CoreException {
IProject project = context.getBuiltProject();
CompilerPreferences preferences = compilerPreferencesFactory.preferences(project);
- if (!preferences.shouldCompileProtoFiles()) return;
+ if (!preferences.shouldCompileProtoFiles()) {
+ return;
+ }
List<Delta> deltas = context.getDeltas();
- if (deltas.isEmpty()) return;
+ if (deltas.isEmpty()) {
+ return;
+ }
OutputDirectories outputDirectories = findOrCreateOutputDirectories(project, preferences.codeGenerationSettings());
String descriptorPath = descriptorPath(preferences);
List<String> importRoots = importRoots(project);
for (Delta d : deltas) {
IFile source = protoFile(d.getNew(), project);
- if (source == null) continue;
- if (importRoots.isEmpty()) importRoots = singleImportRoot(source);
+ if (source == null) {
+ continue;
+ }
+ if (importRoots.isEmpty()) {
+ importRoots = singleImportRoot(source);
+ }
generateSingleProto(source, preferences.protocPath(), importRoots, descriptorPath, outputDirectories);
}
- if (preferences.shouldRefreshResources()) refresh(project, outputDirectories, preferences.refreshTarget(), monitor);
+ if (preferences.shouldRefreshResources()) {
+ refresh(project, outputDirectories, preferences.refreshTarget(), monitor);
+ }
}
private String descriptorPath(CompilerPreferences preferences) {
@@ -72,7 +81,9 @@
List<DirectoryPath> directoryPaths = preferences.importRoots();
for (DirectoryPath path : directoryPaths) {
String location = path.location(project);
- if (location != null) paths.add(location);
+ if (location != null) {
+ paths.add(location);
+ }
}
return unmodifiableList(paths);
}
@@ -85,14 +96,23 @@
}
private static String filePathIfIsProtoFile(IResourceDescription r) {
- if (r == null) return null;
+ if (r == null) {
+ return null;
+ }
URI uri = r.getURI();
- if (!uri.fileExtension().equals("proto")) return null; //$NON-NLS-1$
- if (uri.scheme() == null) return uri.toFileString();
+ if (!uri.fileExtension().equals("proto"))
+ {
+ return null;
+ }
+ if (uri.scheme() == null) {
+ return uri.toFileString();
+ }
StringBuilder b = new StringBuilder();
int segmentCount = uri.segmentCount();
for (int i = 1; i < segmentCount; i++)
- b.append("/").append(uri.segment(i)); //$NON-NLS-1$
+ {
+ b.append("/").append(uri.segment(i));
+ }
return b.length() == 0 ? null : b.toString();
}
@@ -128,7 +148,7 @@
ProtocMarkerFactory markerFactory = new ProtocMarkerFactory(source);
while ((line = bufferedReader.readLine()) != null) {
outputParser.parseAndAddMarkerIfNecessary(line, markerFactory);
- System.out.println("[protoc] " + line); //$NON-NLS-1$
+ System.out.println("[protoc] " + line);
}
} finally {
close(reader);
@@ -136,7 +156,9 @@
}
private static void close(Reader reader) {
- if (reader == null) return;
+ if (reader == null) {
+ return;
+ }
try {
reader.close();
} catch (IOException ignored) {}
@@ -148,7 +170,9 @@
refresh(project, monitor);
return;
}
- for (IFolder outputDirectory : outputDirectories.values()) refresh(outputDirectory, monitor);
+ for (IFolder outputDirectory : outputDirectories.values()) {
+ refresh(outputDirectory, monitor);
+ }
}
private static void refresh(IResource target, IProgressMonitor monitor) throws CoreException {
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtocCommandFactory.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtocCommandFactory.java
index f81bb1a..34211c1 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtocCommandFactory.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtocCommandFactory.java
@@ -12,8 +12,7 @@
import java.util.*;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.*;
import org.eclipse.xtext.util.Strings;
import com.google.eclipse.protobuf.ui.preferences.pages.compiler.SupportedLanguage;
@@ -26,8 +25,9 @@
private static final Map<SupportedLanguage, String> LANG_OUT_FLAG = new HashMap<SupportedLanguage, String>();
static {
- for (SupportedLanguage lang : SupportedLanguage.values())
+ for (SupportedLanguage lang : SupportedLanguage.values()) {
LANG_OUT_FLAG.put(lang, "--" + lang.code() + "_out=");
+ }
}
String protocCommand(IFile protoFile, String protocPath, List<String> importRoots, String descriptorPath,
@@ -42,7 +42,9 @@
}
for (SupportedLanguage language : SupportedLanguage.values()) {
IFolder outputDirectory = outputDirectories.outputDirectoryFor(language);
- if (outputDirectory == null) continue;
+ if (outputDirectory == null) {
+ continue;
+ }
command.append(langOutFlag(language)).append(outputDirectory.getLocation().toOSString()).append(space());
}
command.append(protoFile.getLocation().toOSString());
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtocMarkerFactory.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtocMarkerFactory.java
index 7470db9..4739f4b 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtocMarkerFactory.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtocMarkerFactory.java
@@ -35,7 +35,9 @@
void createErrorIfNecessary(String fileName, String message, int lineNumber) throws CoreException {
String location = file.getLocation().toOSString();
- if (!location.endsWith(fileName) || containsMarker(message, lineNumber)) return;
+ if (!location.endsWith(fileName) || containsMarker(message, lineNumber)) {
+ return;
+ }
IMarker marker = file.createMarker(PROTOC_CHECK);
marker.setAttribute(SEVERITY, SEVERITY_ERROR);
marker.setAttribute(MESSAGE, message);
@@ -45,8 +47,9 @@
private boolean containsMarker(String description, int lineNumber) throws CoreException {
for (IMarker marker : markers) {
String markerMessage = (String) marker.getAttribute(MESSAGE);
- if (markerMessage.equalsIgnoreCase(description) && marker.getAttribute(LINE_NUMBER).equals(lineNumber))
+ if (markerMessage.equalsIgnoreCase(description) && marker.getAttribute(LINE_NUMBER).equals(lineNumber)) {
return true;
+ }
}
return false;
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtocOutputParser.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtocOutputParser.java
index 2fae3f1..8b6c6b0 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtocOutputParser.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/builder/protoc/ProtocOutputParser.java
@@ -8,10 +8,10 @@
*/
package com.google.eclipse.protobuf.ui.builder.protoc;
-import com.google.inject.ImplementedBy;
-
import org.eclipse.core.runtime.CoreException;
+import com.google.inject.ImplementedBy;
+
/**
* @author alruiz@google.com (Alex Ruiz)
*/
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 9f69203..1c8271c 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
@@ -38,15 +38,23 @@
Pair<INode, Matcher> matchingCommentNode(EObject target, String...patternsToMatch) {
ICompositeNode node = getNode(target);
for (INode currentNode : node.getAsTreeIterable()) {
- if (!nodes.isHiddenLeafNode(currentNode)) continue;
- if (!nodes.belongsToComment(currentNode)) continue;
+ if (!nodes.isHiddenLeafNode(currentNode)) {
+ continue;
+ }
+ if (!nodes.belongsToComment(currentNode)) {
+ continue;
+ }
String rawComment = ((ILeafNode) currentNode).getText();
- if (isEmpty(rawComment)) continue;
+ if (isEmpty(rawComment)) {
+ continue;
+ }
String[] comment = rawComment.split(lineSeparator());
for (String line : comment) {
for (Pattern pattern : compile(patternsToMatch, target)) {
Matcher matcher = pattern.matcher(line);
- if (matcher.matches()) return pair(currentNode, matcher);
+ if (matcher.matches()) {
+ return pair(currentNode, matcher);
+ }
}
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/SmartInsertHandler.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/SmartInsertHandler.java
index 30dace2..2ba35b2 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/SmartInsertHandler.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/SmartInsertHandler.java
@@ -25,13 +25,17 @@
/** {@inheritDoc} */
@Override public final Object execute(ExecutionEvent event) {
XtextEditor activeEditor = getActiveXtextEditor();
- if (activeEditor != null) insertContent(activeEditor, styledTextFrom(activeEditor));
+ if (activeEditor != null) {
+ insertContent(activeEditor, styledTextFrom(activeEditor));
+ }
return null;
}
private StyledText styledTextFrom(XtextEditor editor) {
Object adapter = editor.getAdapter(Control.class);
- if (adapter instanceof StyledText) return (StyledText) adapter;
+ if (adapter instanceof StyledText) {
+ return (StyledText) adapter;
+ }
return null;
}
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 9dedf95..286bd9e 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/SmartSemicolonHandler.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/commands/SmartSemicolonHandler.java
@@ -31,7 +31,7 @@
import com.google.eclipse.protobuf.model.util.*;
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.eclipse.protobuf.ui.util.Literals;
import com.google.inject.Inject;
/**
@@ -78,7 +78,9 @@
}
private ContentToInsert newContent(final XtextEditor editor, final StyledText styledText, final String line) {
- if (line.endsWith(SEMICOLON)) return INSERT_SEMICOLON_AT_CURRENT_LOCATION;
+ if (line.endsWith(SEMICOLON)) {
+ return INSERT_SEMICOLON_AT_CURRENT_LOCATION;
+ }
final IXtextDocument document = editor.getDocument();
try {
return document.modify(new IUnitOfWork<ContentToInsert, XtextResource>() {
@@ -86,7 +88,9 @@
int offset = styledText.getCaretOffset();
ContentAssistContext[] context = contextFactory.create(editor.getInternalSourceViewer(), offset, resource);
for (ContentAssistContext c : context) {
- if (nodes.belongsToCommentOrString(c.getCurrentNode())) continue;
+ if (nodes.belongsToCommentOrString(c.getCurrentNode())) {
+ continue;
+ }
EObject model = modelFrom(c);
if (model instanceof FieldOption) {
FieldOption option = (FieldOption) model;
@@ -124,14 +128,16 @@
private EObject modelFrom(ContentAssistContext c) {
EObject current = c.getCurrentModel();
- if (isIndexed(current)) return current;
+ if (isIndexed(current)) {
+ return current;
+ }
return c.getPreviousModel();
}
private boolean isIndexed(EObject e) {
return e instanceof MessageField || e instanceof Literal;
}
-
+
private ContentToInsert newContent(Literal literal) {
INode indexNode = nodes.firstNodeForFeature(literal, LITERAL__INDEX);
ContentToInsert content = newContent(indexNode);
@@ -153,11 +159,15 @@
private void updateIndexInCommentOfParent(EObject o, long index, IXtextDocument document) {
EObject parent = o.eContainer();
- if (parent == null) return;
+ if (parent == null) {
+ return;
+ }
NumericTagPreferences preferences = preferencesFactory.preferences();
for (String pattern : preferences.patterns()) {
Pair<INode, Matcher> match = commentNodesFinder.matchingCommentNode(parent, pattern);
- if (match == null) return;
+ if (match == null) {
+ return;
+ }
String original = match.getSecond().group();
String replacement = NUMBERS_PATTERN.matcher(original).replaceFirst(String.valueOf(index + 1));
INode node = match.getFirst();
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 5345983..e88afea 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
@@ -10,26 +10,30 @@
import static java.util.Collections.*;
+import java.util.*;
+
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.resource.IEObjectDescription;
-import java.util.*;
-
/**
* @author alruiz@google.com (Alex Ruiz)
*/
class IEObjectDescriptionChooser {
Collection<IEObjectDescription> shortestQualifiedNamesIn(Collection<IEObjectDescription> descriptions) {
- if (descriptions.isEmpty()) return emptySet();
+ if (descriptions.isEmpty()) {
+ return emptySet();
+ }
Map<EObject, IEObjectDescription> shortestOnes = new HashMap<EObject, IEObjectDescription>();
for (IEObjectDescription d : descriptions) {
EObject e = d.getEObjectOrProxy();
IEObjectDescription stored = shortestOnes.get(e);
if (stored != null) {
QualifiedName currentName = d.getName();
- if (currentName.getSegmentCount() >= stored.getName().getSegmentCount()) continue;
+ if (currentName.getSegmentCount() >= stored.getName().getSegmentCount()) {
+ continue;
+ }
}
shortestOnes.put(e, d);
}
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 1a8d68f..a2ccd53 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
@@ -74,7 +74,9 @@
@Override public void completeComplexTypeLink_Target(EObject model, Assignment assignment,
ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
- if (!(model instanceof MessageField)) return;
+ if (!(model instanceof MessageField)) {
+ return;
+ }
Collection<IEObjectDescription> scope = scoping().allPossibleTypesFor((MessageField) model);
for (IEObjectDescription d : descriptionChooser.shortestQualifiedNamesIn(scope)) {
Image image = imageHelper.getImage(images.imageFor(d.getEObjectOrProxy()));
@@ -94,7 +96,7 @@
proposeAndAccept(d, image, context, acceptor);
}
}
-
+
@Override public void completeMessageLink_Target(EObject model, Assignment assignment, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
Collection<IEObjectDescription> scope = emptySet();
@@ -112,19 +114,25 @@
ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
ProtoDescriptor descriptor = descriptorProvider.primaryDescriptor();
Collection<MessageField> optionProperties = descriptor.availableOptionsFor(model);
- if (!optionProperties.isEmpty()) proposeOptions(optionProperties, context, acceptor);
+ if (!optionProperties.isEmpty()) {
+ proposeOptions(optionProperties, context, acceptor);
+ }
}
private void proposeOptions(Collection<MessageField> optionSources, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
- for (MessageField source : optionSources) proposeOption(source, context, acceptor);
+ for (MessageField source : optionSources) {
+ proposeOption(source, context, acceptor);
+ }
}
@Override public void completeNativeOption_Value(EObject model, Assignment assignment,
ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
NativeOption option = (NativeOption) model;
MessageField optionSource = (MessageField) options.rootSourceOf(option);
- if (optionSource == null) return;
+ if (optionSource == null) {
+ return;
+ }
ProtoDescriptor descriptor = descriptorProvider.primaryDescriptor();
Enum enumType = descriptor.enumTypeOf(optionSource);
if (enumType != null) {
@@ -142,14 +150,20 @@
@Override public void completeKeyword(Keyword keyword, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
- if (keyword == null) return;
+ if (keyword == null) {
+ return;
+ }
boolean proposalWasHandledAlready = completeKeyword(keyword.getValue(), context, acceptor);
- if (proposalWasHandledAlready) return;
+ if (proposalWasHandledAlready) {
+ return;
+ }
super.completeKeyword(keyword, context, acceptor);
}
private boolean completeKeyword(String keyword, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
- if (isLastWordFromCaretPositionEqualTo(keyword, context)) return true;
+ if (isLastWordFromCaretPositionEqualTo(keyword, context)) {
+ return true;
+ }
if (EQUAL.hasValue(keyword)) {
EObject grammarElement = context.getLastCompleteNode().getGrammarElement();
if (isKeyword(grammarElement, SYNTAX)) {
@@ -185,7 +199,9 @@
StyledText styledText = context.getViewer().getTextWidget();
int valueLength = word.length();
int start = styledText.getCaretOffset() - valueLength;
- if (start < 0) return false;
+ if (start < 0) {
+ return false;
+ }
String previousWord = styledText.getTextRange(start, valueLength);
return word.equals(previousWord);
}
@@ -215,23 +231,31 @@
private MessageField fieldFrom(ContentAssistContext context) {
EObject model = context.getCurrentModel();
- if (model instanceof MessageField) return (MessageField) model;
+ if (model instanceof MessageField) {
+ return (MessageField) model;
+ }
if (model instanceof Option) {
Option option = (Option) model;
IndexedElement source = options.rootSourceOf(option);
- if (source instanceof MessageField) return (MessageField) source;
+ if (source instanceof MessageField) {
+ return (MessageField) source;
+ }
}
if (model instanceof FieldOption) {
FieldOption option = (FieldOption) model;
IndexedElement source = fieldOptions.rootSourceOf(option);
- if (source instanceof MessageField) return (MessageField) source;
+ if (source instanceof MessageField) {
+ return (MessageField) source;
+ }
}
return null;
}
private boolean proposeOpeningBracket(ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
EObject model = context.getCurrentModel();
- if (model instanceof ComplexValue) return true;
+ if (model instanceof ComplexValue) {
+ return true;
+ }
if (model instanceof MessageField) {
MessageField field = (MessageField) model;
Modifier modifier = field.getModifier();
@@ -252,8 +276,12 @@
private <T> T extractElementFromContext(ContentAssistContext context, Class<T> type) {
EObject model = context.getCurrentModel();
// this is most likely a bug in Xtext:
- if (!type.isInstance(model)) model = context.getPreviousModel();
- if (!type.isInstance(model)) return null;
+ if (!type.isInstance(model)) {
+ model = context.getPreviousModel();
+ }
+ if (!type.isInstance(model)) {
+ return null;
+ }
return type.cast(model);
}
@@ -273,8 +301,12 @@
if (model instanceof DefaultValueFieldOption) {
field = (MessageField) model.eContainer();
}
- if (field == null) return;
- if (!messageFields.isOptional(field)) return;
+ if (field == null) {
+ return;
+ }
+ if (!messageFields.isOptional(field)) {
+ return;
+ }
Enum enumType = finder.enumTypeOf(field);
if (enumType != null) {
proposeAndAccept(enumType, context, acceptor);
@@ -297,9 +329,13 @@
int index = 1;
String name = typeName + index;
for (EObject o : model.eContainer().eContents()) {
- if (o == model || !(o instanceof MessageField)) continue;
+ if (o == model || !(o instanceof MessageField)) {
+ continue;
+ }
MessageField field = (MessageField) o;
- if (!name.equals(field.getName())) continue;
+ if (!name.equals(field.getName())) {
+ continue;
+ }
name = typeName + (++index);
}
proposeAndAccept(name, context, acceptor);
@@ -333,25 +369,34 @@
ProtoDescriptor descriptor = descriptorProvider.primaryDescriptor();
for (MessageField optionSource : descriptor.availableOptionsFor(field)) {
String optionName = optionSource.getName();
- if (optionNames.contains(optionName) || ("packed".equals(optionName) && !canBePacked(field))) continue;
+ if (optionNames.contains(optionName) || ("packed".equals(optionName) && !canBePacked(field))) {
+ continue;
+ }
proposeOption(optionSource, context, acceptor);
}
}
private List<String> existingFieldOptionNames(IndexedElement e) {
List<FieldOption> allFieldOptions = indexedElements.fieldOptionsOf(e);
- if (allFieldOptions.isEmpty()) return emptyList();
+ if (allFieldOptions.isEmpty()) {
+ return emptyList();
+ }
List<String> optionNames = new ArrayList<String>();
- for (FieldOption option : allFieldOptions)
+ for (FieldOption option : allFieldOptions) {
optionNames.add(fieldOptions.nameOf(option));
+ }
return optionNames;
}
private void proposeDefaultKeyword(IndexedElement e, List<String> existingOptionNames, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
- if (!(e instanceof MessageField)) return;
+ if (!(e instanceof MessageField)) {
+ return;
+ }
MessageField field = (MessageField) e;
- if (!messageFields.isOptional(field) || existingOptionNames.contains(DEFAULT.toString())) return;
+ if (!messageFields.isOptional(field) || existingOptionNames.contains(DEFAULT.toString())) {
+ return;
+ }
CompoundElement display = DEFAULT_EQUAL;
int cursorPosition = display.charCount();
if (messageFields.isString(field)) {
@@ -362,7 +407,9 @@
}
private boolean canBePacked(IndexedElement e) {
- if (!(e instanceof MessageField)) return false;
+ if (!(e instanceof MessageField)) {
+ return false;
+ }
MessageField field = (MessageField) e;
return messageFields.isPrimitive(field) && REPEATED.equals(field.getModifier());
}
@@ -372,7 +419,9 @@
String displayString = optionSource.getName();
String proposalText = displayString + space() + EQUAL + space();
Object value = defaultValueOf(optionSource);
- if (value != null) proposalText = proposalText + value;
+ if (value != null) {
+ proposalText = proposalText + value;
+ }
ICompletionProposal proposal = createCompletionProposal(proposalText, displayString, imageForOption(), context);
if (value == EMPTY_STRING && proposal instanceof ConfigurableCompletionProposal) {
// set cursor between the proposal's quotes
@@ -383,8 +432,12 @@
}
private Object defaultValueOf(MessageField field) {
- if (messageFields.isBool(field)) return TRUE;
- if (messageFields.isString(field)) return EMPTY_STRING;
+ if (messageFields.isBool(field)) {
+ return TRUE;
+ }
+ if (messageFields.isString(field)) {
+ return EMPTY_STRING;
+ }
return null;
}
@@ -397,14 +450,20 @@
if (model instanceof MessageField) {
field = (MessageField) model;
}
- if (field == null) return;
- if (!messageFields.isOptional(field)) return;
+ if (field == null) {
+ return;
+ }
+ if (!messageFields.isOptional(field)) {
+ return;
+ }
proposeFieldValue(field, context, acceptor);
}
@Override public void completeNativeFieldOption_Value(EObject model, Assignment assignment,
ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
- if (!(model instanceof NativeFieldOption)) return;
+ if (!(model instanceof NativeFieldOption)) {
+ return;
+ }
NativeFieldOption option = (NativeFieldOption) model;
ProtoDescriptor descriptor = descriptorProvider.primaryDescriptor();
MessageField field = (MessageField) fieldOptions.rootSourceOf(option);
@@ -436,8 +495,9 @@
private void proposeAndAccept(CommonKeyword[] keywords, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
- for (CommonKeyword keyword : keywords)
+ for (CommonKeyword keyword : keywords) {
proposeAndAccept(keyword.toString(), context, acceptor);
+ }
}
private void proposeEmptyString(ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
@@ -456,7 +516,9 @@
@Override public void completeCustomOption_Source(EObject model, Assignment assignment,
ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
- if (!(model instanceof CustomOption)) return;
+ if (!(model instanceof CustomOption)) {
+ return;
+ }
CustomOption option = (CustomOption) model;
Collection<IEObjectDescription> scope = scoping().allPossibleSourcesOf(option);
proposeAndAcceptOptions(scope, context, acceptor);
@@ -464,7 +526,9 @@
@Override public void completeCustomFieldOption_Source(EObject model, Assignment assignment,
ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
- if (!(model instanceof CustomFieldOption)) return;
+ if (!(model instanceof CustomFieldOption)) {
+ return;
+ }
CustomFieldOption option = (CustomFieldOption) model;
Collection<IEObjectDescription> scope = scoping().allPossibleSourcesOf(option);
proposeAndAcceptOptions(scope, context, acceptor);
@@ -488,7 +552,9 @@
@Override public void completeCustomOption_Fields(EObject model, Assignment assignment,
ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
- if (!(model instanceof CustomOption)) return;
+ if (!(model instanceof CustomOption)) {
+ return;
+ }
CustomOption option = (CustomOption) model;
proposeAndAccept(scoping().allPossibleNormalFieldsOf(option), context, acceptor);
proposeAndAccept(scoping().allPossibleExtensionFieldsOf(option), "(%s)", "(%s)", context, acceptor);
@@ -496,7 +562,9 @@
@Override public void completeCustomFieldOption_Fields(EObject model, Assignment assignment,
ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
- if (!(model instanceof CustomFieldOption)) return;
+ if (!(model instanceof CustomFieldOption)) {
+ return;
+ }
CustomFieldOption option = (CustomFieldOption) model;
proposeAndAccept(scoping().allPossibleNormalFieldsOf(option), context, acceptor);
proposeExtensionFields(scoping().allPossibleExtensionFieldsOf(option), context, acceptor);
@@ -533,10 +601,14 @@
@Override public void completeCustomOption_Value(EObject model, Assignment assignment, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
- if (!(model instanceof CustomOption)) return;
+ if (!(model instanceof CustomOption)) {
+ return;
+ }
CustomOption option = (CustomOption) model;
IndexedElement e = options.lastFieldSourceFrom(option);
- if (e == null) e = options.rootSourceOf(option);
+ if (e == null) {
+ e = options.rootSourceOf(option);
+ }
if (e instanceof MessageField) {
proposeFieldValue((MessageField) e, context, acceptor);
}
@@ -545,10 +617,14 @@
@Override public void completeCustomFieldOption_Value(EObject model, Assignment assignment,
ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
// TODO content assist returns "{"
- if (!(model instanceof CustomFieldOption)) return;
+ if (!(model instanceof CustomFieldOption)) {
+ return;
+ }
CustomFieldOption option = (CustomFieldOption) model;
IndexedElement e = fieldOptions.sourceOfLastFieldIn(option);
- if (e == null) e = fieldOptions.rootSourceOf(option);
+ if (e == null) {
+ e = fieldOptions.rootSourceOf(option);
+ }
if (e instanceof MessageField) {
proposeFieldValue((MessageField) e, context, acceptor);
}
@@ -556,8 +632,12 @@
private void proposeFieldValue(MessageField field, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
- if (field == null) return;
- if (proposePrimitiveValues(field, context, acceptor)) return;
+ if (field == null) {
+ return;
+ }
+ if (proposePrimitiveValues(field, context, acceptor)) {
+ return;
+ }
Enum enumType = finder.enumTypeOf(field);
if (enumType != null) {
proposeAndAccept(enumType, context, acceptor);
@@ -566,8 +646,9 @@
private void proposeAndAccept(Enum enumType, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
Image image = imageHelper.getImage(images.imageFor(Literal.class));
- for (Literal literal : getAllContentsOfType(enumType, Literal.class))
+ for (Literal literal : getAllContentsOfType(enumType, Literal.class)) {
proposeAndAccept(literal.getName(), image, context, acceptor);
+ }
}
@Override public void completeNormalFieldName_Target(EObject model, Assignment assignment,
@@ -580,7 +661,9 @@
@Override public void completeSimpleValueField_Value(EObject model, Assignment assignment,
ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
- if (!(model instanceof SimpleValueField)) return;
+ if (!(model instanceof SimpleValueField)) {
+ return;
+ }
SimpleValueField field = (SimpleValueField) model;
FieldName name = field.getName();
if (name != null) {
@@ -590,7 +673,9 @@
@Override public void completeSimpleValueField_Name(EObject model, Assignment assignment,
ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
- if (!(model instanceof ComplexValue)) return;
+ if (!(model instanceof ComplexValue)) {
+ return;
+ }
ComplexValue value = (ComplexValue) model;
proposeAndAccept(scoping().allPossibleNamesOfNormalFieldsOf(value), "%s:", null, context, acceptor);
proposeAndAccept(scoping().allPossibleNamesOfExtensionFieldsOf(value), "[%s]:", "[%s]", context, acceptor);
@@ -633,7 +718,9 @@
@Override public ICompletionProposal createCompletionProposal(String proposal, String displayString, Image image,
ContentAssistContext contentAssistContext) {
StyledString styled = null;
- if (displayString != null) styled = new StyledString(displayString);
+ if (displayString != null) {
+ styled = new StyledString(displayString);
+ }
int priority = getPriorityHelper().getDefaultPriority();
String prefix = contentAssistContext.getPrefix();
return createCompletionProposal(proposal, styled, image, priority, prefix, contentAssistContext);
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 07fefb2..ff49697 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
@@ -42,11 +42,17 @@
private String findComment(EObject o) {
String returnValue = null;
ICompositeNode node = getNode(o);
- if (node == null) return null;
+ if (node == null) {
+ return null;
+ }
// get the last multiple-line comment before a non hidden leaf node
for (INode currentNode : node.getAsTreeIterable()) {
- if (!nodes.isHiddenLeafNode(currentNode)) continue;
- if (!nodes.belongsToMultipleLineComment(currentNode)) continue;
+ if (!nodes.isHiddenLeafNode(currentNode)) {
+ continue;
+ }
+ if (!nodes.belongsToMultipleLineComment(currentNode)) {
+ continue;
+ }
String text = ((ILeafNode) currentNode).getText();
if (COMMENT.matcher(text).matches()) {
returnValue = cleanUp(text);
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 2fd0b0e..2ea544c 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
@@ -37,7 +37,9 @@
@Override public String getDocumentation(EObject o) {
for (IEObjectDocumentationProvider p: delegates) {
String documentation = p.getDocumentation(o);
- if (!(isEmpty(documentation))) return documentation;
+ if (!(isEmpty(documentation))) {
+ return documentation;
+ }
}
return "";
}
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 a816c71..94b939c 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
@@ -46,11 +46,17 @@
private String findComment(EObject o) {
EObject target = findRealTarget(o);
ICompositeNode node = getNode(target);
- if (node == null) return null;
+ if (node == null) {
+ return null;
+ }
StringBuilder commentBuilder = new StringBuilder();
for (INode currentNode : node.getAsTreeIterable()) {
- if (!nodes.isHiddenLeafNode(currentNode)) continue;
- if (!nodes.belongsToSingleLineComment(currentNode)) continue;
+ if (!nodes.isHiddenLeafNode(currentNode)) {
+ continue;
+ }
+ if (!nodes.belongsToSingleLineComment(currentNode)) {
+ continue;
+ }
String comment = ((ILeafNode) currentNode).getText();
commentBuilder.append(cleanUp(comment));
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/FileOpener.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/FileOpener.java
index c2653de..56eaa3c 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/FileOpener.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/FileOpener.java
@@ -8,8 +8,7 @@
*/
package com.google.eclipse.protobuf.ui.editor;
-import org.eclipse.core.filesystem.EFS;
-import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.filesystem.*;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.Path;
import org.eclipse.emf.common.util.URI;
@@ -18,8 +17,7 @@
import org.eclipse.ui.part.FileEditorInput;
import com.google.eclipse.protobuf.ui.util.Resources;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
+import com.google.inject.*;
/**
* Utility methods related to open file from different type of locations.
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/FileOutsideWorkspaceIconUpdater.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/FileOutsideWorkspaceIconUpdater.java
index d33862a..a529ac1 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/FileOutsideWorkspaceIconUpdater.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/FileOutsideWorkspaceIconUpdater.java
@@ -12,17 +12,14 @@
import static org.eclipse.xtext.ui.editor.Messages.XtextEditorErrorTickUpdater_JobName;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.swt.graphics.Image;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.*;
import org.eclipse.ui.progress.UIJob;
import org.eclipse.xtext.ui.PluginImageHelper;
import org.eclipse.xtext.ui.editor.IXtextEditorCallback.NullImpl;
-import org.eclipse.xtext.ui.editor.SchedulingRuleFactory;
-import org.eclipse.xtext.ui.editor.XtextEditor;
+import org.eclipse.xtext.ui.editor.*;
import com.google.inject.Inject;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/ProtobufUriEditorOpener.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/ProtobufUriEditorOpener.java
index c529cc8..db27f3e 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/ProtobufUriEditorOpener.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/ProtobufUriEditorOpener.java
@@ -13,8 +13,7 @@
import org.apache.log4j.Logger;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EReference;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.*;
import org.eclipse.xtext.ui.editor.LanguageSpecificURIEditorOpener;
import com.google.inject.Inject;
@@ -43,10 +42,12 @@
}
private IEditorPart editorFor(URI uri) throws PartInitException {
- if (uri.isFile())
+ if (uri.isFile()) {
return fileOpener.openProtoFileInFileSystem(uri);
- if (uri.isPlatformPlugin())
+ }
+ if (uri.isPlatformPlugin()) {
return fileOpener.openProtoFileInPlugin(uri);
+ }
return null;
}
}
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 fcfc111..638e17b 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,11 +8,12 @@
*/
package com.google.eclipse.protobuf.ui.editor;
+import static com.google.eclipse.protobuf.util.Objects.*;
+
import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IPersistableElement;
+import org.eclipse.ui.*;
/**
* @author alruiz@google.com (Alex Ruiz)
@@ -56,25 +57,25 @@
return fileUri;
}
- @Override public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result + ((fileUri == null) ? 0 : fileUri.hashCode());
- return result;
+ @Override public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
+ UriEditorInput other = (UriEditorInput) obj;
+ if (!areEqual(name, other.name)) {
+ return false;
+ }
+ return areEqual(fileUri, other.fileUri);
}
- @Override public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null) return false;
- if (getClass() != obj.getClass()) return false;
- UriEditorInput other = (UriEditorInput) obj;
- if (name == null) {
- if (other.name != null) return false;
- } else if (!name.equals(other.name)) return false;
- if (fileUri == null) {
- if (other.fileUri != null) return false;
- } else if (!fileUri.equals(other.fileUri)) return false;
- return true;
+ @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;
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/hyperlinking/ImportHyperlink.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/hyperlinking/ImportHyperlink.java
index 3022d5a..9fabec3 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/hyperlinking/ImportHyperlink.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/hyperlinking/ImportHyperlink.java
@@ -45,7 +45,9 @@
fileOpener.openProtoFileInPlugin(importUri);
return;
}
- if (importUri.isFile()) fileOpener.openProtoFileInFileSystem(importUri);
+ if (importUri.isFile()) {
+ fileOpener.openProtoFileInFileSystem(importUri);
+ }
} catch (PartInitException e) {
logger.error("Unable to open " + importUri.toString(), e);
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/hyperlinking/ProtobufHyperlinkDetector.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/hyperlinking/ProtobufHyperlinkDetector.java
index dfafa37..255023d 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/hyperlinking/ProtobufHyperlinkDetector.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/hyperlinking/ProtobufHyperlinkDetector.java
@@ -8,13 +8,9 @@
*/
package com.google.eclipse.protobuf.ui.editor.hyperlinking;
+import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.IMPORT__IMPORT_URI;
import static org.eclipse.emf.common.util.URI.createURI;
-import com.google.eclipse.protobuf.model.util.INodes;
-import com.google.eclipse.protobuf.protobuf.Import;
-import com.google.eclipse.protobuf.ui.editor.FileOpener;
-import com.google.inject.Inject;
-
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.text.*;
import org.eclipse.jface.text.hyperlink.*;
@@ -24,7 +20,11 @@
import org.eclipse.xtext.ui.editor.hyperlinking.DefaultHyperlinkDetector;
import org.eclipse.xtext.ui.editor.model.IXtextDocument;
import org.eclipse.xtext.util.concurrent.IUnitOfWork;
-import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.*;
+
+import com.google.eclipse.protobuf.model.util.INodes;
+import com.google.eclipse.protobuf.protobuf.Import;
+import com.google.eclipse.protobuf.ui.editor.FileOpener;
+import com.google.inject.Inject;
/**
@@ -45,7 +45,9 @@
final boolean canShowMultipleHyperlinks) {
IXtextDocument document = (IXtextDocument)textViewer.getDocument();
IHyperlink[] importHyperlinks = importHyperlinks(document, region);
- if (importHyperlinks != NO_HYPERLINKS) return importHyperlinks;
+ if (importHyperlinks != NO_HYPERLINKS) {
+ return importHyperlinks;
+ }
return document.readOnly(new IUnitOfWork<IHyperlink[], XtextResource>() {
@Override public IHyperlink[] exec(XtextResource resource) {
return getHelper().createHyperlinksByOffset(resource, region.getOffset(), canShowMultipleHyperlinks);
@@ -57,31 +59,41 @@
return document.readOnly(new IUnitOfWork<IHyperlink[], XtextResource>() {
@Override public IHyperlink[] exec(XtextResource resource) {
EObject resolved = eObjectAtOffsetHelper.resolveElementAt(resource, region.getOffset());
- if (!(resolved instanceof Import)) return NO_HYPERLINKS;
+ if (!(resolved instanceof Import)) {
+ return NO_HYPERLINKS;
+ }
Import anImport = (Import) resolved;
String importUri = rawUriIn(anImport);
- if (importUri == null) return NO_HYPERLINKS;
+ if (importUri == null) {
+ return NO_HYPERLINKS;
+ }
IRegion importUriRegion;
try {
importUriRegion = importUriRegion(document, region.getOffset(), importUri);
} catch (BadLocationException e) {
return NO_HYPERLINKS;
}
- if (importUriRegion == null) return NO_HYPERLINKS;
+ if (importUriRegion == null) {
+ return NO_HYPERLINKS;
+ }
IHyperlink hyperlink = new ImportHyperlink(createURI(anImport.getImportURI()), importUriRegion, fileOpener);
return new IHyperlink[] { hyperlink };
}
});
}
-
+
private String rawUriIn(Import anImport) {
INode node = nodes.firstNodeForFeature(anImport, IMPORT__IMPORT_URI);
- if (node == null) return null;
+ if (node == null) {
+ return null;
+ }
String text = node.getText();
- if (text == null || text.length() < 3) return null;
+ if (text == null || text.length() < 3) {
+ return null;
+ }
return text.substring(1, text.length() - 1); // remove quotes
}
-
+
private IRegion importUriRegion(IXtextDocument document, int offset, String importUri) throws BadLocationException {
int lineNumber = document.getLineOfOffset(offset);
int lineLength = document.getLineLength(lineNumber);
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 d8c1b1d..6915b11 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,8 +8,7 @@
*/
package com.google.eclipse.protobuf.ui.editor.model;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
import org.eclipse.ui.IEditorInput;
@@ -29,10 +28,14 @@
}
DocumentContentsFactory findFactory(Object element) {
- if (!(element instanceof IEditorInput)) return null;
+ if (!(element instanceof IEditorInput)) {
+ return null;
+ }
IEditorInput input = (IEditorInput) element;
for (DocumentContentsFactory factory : factories) {
- if (factory.supportsEditorInputType(input)) return factory;
+ if (factory.supportsEditorInputType(input)) {
+ return factory;
+ }
}
return null;
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/ProtobufDocumentProvider.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/ProtobufDocumentProvider.java
index f0d832d..5af5872 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/ProtobufDocumentProvider.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/ProtobufDocumentProvider.java
@@ -16,26 +16,17 @@
import static org.eclipse.core.filebuffers.LocationKind.*;
import static org.eclipse.text.undo.DocumentUndoManagerRegistry.getDocumentUndoManager;
-import org.eclipse.core.filebuffers.ITextFileBuffer;
-import org.eclipse.core.filebuffers.ITextFileBufferManager;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.Region;
+import org.eclipse.core.filebuffers.*;
+import org.eclipse.core.runtime.*;
+import org.eclipse.jface.text.*;
import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.text.edits.TextEdit;
import org.eclipse.text.undo.IDocumentUndoManager;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.xtext.ui.editor.model.XtextDocument;
-import org.eclipse.xtext.ui.editor.model.XtextDocumentProvider;
+import org.eclipse.ui.*;
+import org.eclipse.xtext.ui.editor.model.*;
-import com.google.eclipse.protobuf.ui.preferences.pages.editor.save.SaveActionsPreferences;
+import com.google.eclipse.protobuf.ui.preferences.pages.editor.save.*;
import com.google.eclipse.protobuf.ui.preferences.pages.editor.save.SaveActionsPreferences.RemoveTrailingSpace;
-import com.google.eclipse.protobuf.ui.preferences.pages.editor.save.SaveActionsPreferencesFactory;
import com.google.eclipse.protobuf.ui.util.editor.Editors;
import com.google.inject.Inject;
@@ -45,14 +36,16 @@
public class ProtobufDocumentProvider extends XtextDocumentProvider {
private static final IRegion[] NO_CHANGE = new IRegion[0];
-
+
@Inject private Editors editors;
@Inject private DocumentContentsFactoryRegistry documentContentsFactories;
- @Inject private SaveActionsPreferencesFactory preferencesFactory;
+ @Inject private SaveActionsPreferencesFactory preferencesFactory;
@Inject private SaveActions saveActions;
@Override protected ElementInfo createElementInfo(Object element) throws CoreException {
- if (documentContentsFactories.findFactory(element) != null) return createElementInfo((IEditorInput) element);
+ if (documentContentsFactories.findFactory(element) != null) {
+ return createElementInfo((IEditorInput) element);
+ }
return super.createElementInfo(element);
}
@@ -77,7 +70,9 @@
@Override protected IDocument createDocument(Object element) throws CoreException {
DocumentContentsFactory factory = documentContentsFactories.findFactory(element);
- if (factory != null) return createDocument(factory, element);
+ if (factory != null) {
+ return createDocument(factory, element);
+ }
return super.createDocument(element);
}
@@ -99,7 +94,9 @@
IFileEditorInput editorInput, IDocument document) throws CoreException {
IRegion[] changedRegions = changedRegions(monitor, editorInput, document);
TextEdit edit = saveActions.createSaveAction(document, changedRegions);
- if (edit == null) return;
+ if (edit == null) {
+ return;
+ }
try {
IDocumentUndoManager manager = getDocumentUndoManager(document);
manager.beginCompoundChange();
@@ -109,17 +106,19 @@
throw error(t);
}
}
-
+
private IRegion[] changedRegions(IProgressMonitor monitor, IFileEditorInput editorInput, IDocument document) throws CoreException {
SaveActionsPreferences preferences = preferencesFactory.preferences();
RemoveTrailingSpace removeTrailingSpace = preferences.removeTrailingSpace();
- if (removeTrailingSpace.equals(NONE)) return NO_CHANGE;
+ if (removeTrailingSpace.equals(NONE)) {
+ return NO_CHANGE;
+ }
if (removeTrailingSpace.equals(IN_EDITED_LINES)) {
return editors.calculateChangedLineRegions(textFileBuffer(monitor, editorInput), document, monitor);
}
return new IRegion[] { new Region(0, document.getLength()) };
}
-
+
private ITextFileBuffer textFileBuffer(IProgressMonitor monitor, IFileEditorInput editorInput) throws CoreException {
IPath location = editorInput.getFile().getFullPath();
ITextFileBufferManager textFileBufferManager = getTextFileBufferManager();
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/SaveActions.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/SaveActions.java
index 8258517..9e27081 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/SaveActions.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/SaveActions.java
@@ -1,10 +1,10 @@
/*
* Copyright (c) 2011 Google Inc.
- *
+ *
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
- *
+ *
* http://www.eclipse.org/legal/epl-v10.html
*/
package com.google.eclipse.protobuf.ui.editor.model;
@@ -14,13 +14,8 @@
import static org.eclipse.jface.text.TextUtilities.getPartition;
import org.apache.log4j.Logger;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITypedRegion;
-import org.eclipse.text.edits.DeleteEdit;
-import org.eclipse.text.edits.MultiTextEdit;
-import org.eclipse.text.edits.TextEdit;
+import org.eclipse.jface.text.*;
+import org.eclipse.text.edits.*;
import com.google.inject.Singleton;
@@ -31,7 +26,7 @@
class SaveActions {
private static Logger logger = Logger.getLogger(SaveActions.class);
-
+
TextEdit createSaveAction(IDocument document, IRegion[] changedRegions) {
TextEdit rootEdit = null;
try {
@@ -39,15 +34,23 @@
int lastLine = document.getLineOfOffset(region.getOffset() + region.getLength());
for (int line = firstLine(region, document); line <= lastLine; line++) {
IRegion lineRegion = document.getLineInformation(line);
- if (lineRegion.getLength() == 0) continue;
+ if (lineRegion.getLength() == 0) {
+ continue;
+ }
int lineStart = lineRegion.getOffset();
int lineEnd = lineStart + lineRegion.getLength();
int charPos = rightMostNonWhitespaceChar(document, lineStart, lineEnd);
- if (charPos >= lineEnd) continue;
+ if (charPos >= lineEnd) {
+ continue;
+ }
// check partition - don't remove whitespace inside strings
ITypedRegion partition = getPartition(document, DEFAULT_PARTITIONING, charPos, false);
- if ("__string".equals(partition.getType())) continue;
- if (rootEdit == null) rootEdit = new MultiTextEdit();
+ if ("__string".equals(partition.getType())) {
+ continue;
+ }
+ if (rootEdit == null) {
+ rootEdit = new MultiTextEdit();
+ }
rootEdit.addChild(new DeleteEdit(charPos, lineEnd - charPos));
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/UriDocumentContentsFactory.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/UriDocumentContentsFactory.java
index 2780f39..a34d84f 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/UriDocumentContentsFactory.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/model/UriDocumentContentsFactory.java
@@ -11,8 +11,7 @@
import static com.google.eclipse.protobuf.ui.exception.CoreExceptions.error;
import static com.google.eclipse.protobuf.util.Closeables.closeQuietly;
-import java.io.IOException;
-import java.io.InputStream;
+import java.io.*;
import java.net.URL;
import org.eclipse.core.runtime.CoreException;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/spelling/ProtobufReconcileStrategy.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/spelling/ProtobufReconcileStrategy.java
index 4b5cc25..670c4fe 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/spelling/ProtobufReconcileStrategy.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/spelling/ProtobufReconcileStrategy.java
@@ -29,7 +29,9 @@
@Override public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
super.reconcile(dirtyRegion, subRegion);
- if (spellingStrategy == null) return;
+ if (spellingStrategy == null) {
+ return;
+ }
spellingStrategy.reconcile(dirtyRegion, subRegion);
}
@@ -40,18 +42,24 @@
@Override public void setDocument(IDocument document) {
super.setDocument(document);
- if (spellingStrategy == null) return;
+ if (spellingStrategy == null) {
+ return;
+ }
spellingStrategy.setDocument(document);
initialReconcile();
}
private void initialReconcile() {
- if (spellingStrategy == null) return;
+ if (spellingStrategy == null) {
+ return;
+ }
spellingStrategy.initialReconcile();
}
void addSpellSupport(ISourceViewer viewer, SpellingService spellingService) {
- if (spellingStrategy != null) return;
+ if (spellingStrategy != null) {
+ return;
+ }
spellingStrategy = new ProtobufSpelling(viewer, spellingService, nodes);
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/spelling/ProtobufReconciler.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/spelling/ProtobufReconciler.java
index ba6496f..86f91f1 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/spelling/ProtobufReconciler.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/spelling/ProtobufReconciler.java
@@ -1,22 +1,22 @@
/*
* 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.editor.spelling;
import static org.eclipse.ui.editors.text.EditorsUI.getSpellingService;
-import com.google.inject.Inject;
-
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.xtext.ui.editor.reconciler.XtextReconciler;
+import com.google.inject.Inject;
+
/**
* @author alruiz@google.com (Alex Ruiz)
*/
@@ -29,7 +29,9 @@
}
@Override public void install(ITextViewer textViewer) {
- if (installed) return;
+ if (installed) {
+ return;
+ }
super.install(textViewer);
if (textViewer instanceof ISourceViewer) {
ISourceViewer viewer = (ISourceViewer) textViewer;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/spelling/ProtobufSpelling.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/spelling/ProtobufSpelling.java
index 5a14785..fc5b6aa 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/spelling/ProtobufSpelling.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/spelling/ProtobufSpelling.java
@@ -42,7 +42,9 @@
@Override public void reconcile(IRegion region) {
IAnnotationModel model = getAnnotationModel();
- if (model == null) return;
+ if (model == null) {
+ return;
+ }
super.reconcile(new Region(0, xtextDocument().getLength()));
removeUnwantedAnnotations(model);
}
@@ -59,17 +61,21 @@
return (XtextDocument) super.getDocument();
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("unchecked")
private void removeUnwantedAnnotations(INode rootNode, IAnnotationModel model) {
Iterator<Annotation> iterator = model.getAnnotationIterator();
while (iterator.hasNext()) {
Annotation annotation = iterator.next();
- if (shouldRemoveFromModel(annotation, model, rootNode)) model.removeAnnotation(annotation);
+ if (shouldRemoveFromModel(annotation, model, rootNode)) {
+ model.removeAnnotation(annotation);
+ }
}
}
private boolean shouldRemoveFromModel(Annotation annotation, IAnnotationModel model, INode rootNode) {
- if (!(annotation instanceof SpellingAnnotation)) return false;
+ if (!(annotation instanceof SpellingAnnotation)) {
+ return false;
+ }
SpellingAnnotation spellingAnnotation = (SpellingAnnotation) annotation;
Position position = model.getPosition(spellingAnnotation);
ILeafNode node = findLeafNodeAtOffset(rootNode, position.getOffset());
@@ -77,8 +83,12 @@
}
private boolean shouldSpellCheck(INode node) {
- if (node == null) return false;
- if (nodes.belongsToComment(node)) return true;
+ if (node == null) {
+ return false;
+ }
+ if (nodes.belongsToComment(node)) {
+ return true;
+ }
if (nodes.belongsToString(node)) {
EObject o = findActualSemanticObjectFor(node);
return !(o instanceof Import);
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/syntaxcoloring/HighlightingConfiguration.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/syntaxcoloring/HighlightingConfiguration.java
index 4429ac6..ccae5aa 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/syntaxcoloring/HighlightingConfiguration.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/syntaxcoloring/HighlightingConfiguration.java
@@ -1,10 +1,10 @@
/*
* Copyright (c) 2011 Google Inc.
- *
+ *
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
- *
+ *
* http://www.eclipse.org/legal/epl-v10.html
*/
package com.google.eclipse.protobuf.ui.editor.syntaxcoloring;
@@ -57,7 +57,7 @@
private TextStyle copyOfDefaultTextStyle() {
return defaultTextStyle().copy();
}
-
+
private TextStyle copyOfNumberTextStyle() {
return numberTextStyle().copy();
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/syntaxcoloring/Messages.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/syntaxcoloring/Messages.java
index f33316e..8ceacc4 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/syntaxcoloring/Messages.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/syntaxcoloring/Messages.java
@@ -1,10 +1,10 @@
/*
* Copyright (c) 2011 Google Inc.
- *
+ *
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
- *
+ *
* http://www.eclipse.org/legal/epl-v10.html
*/package com.google.eclipse.protobuf.ui.editor.syntaxcoloring;
@@ -34,7 +34,7 @@
public static String rpcReturnTypes;
public static String serviceDefinitions;
public static String strings;
-
+
static {
// initialize resource bundle
Class<Messages> type = Messages.class;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/syntaxcoloring/ProtobufSemanticHighlightingCalculator.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/syntaxcoloring/ProtobufSemanticHighlightingCalculator.java
index c9ecbdb..917bfb8 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/syntaxcoloring/ProtobufSemanticHighlightingCalculator.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/syntaxcoloring/ProtobufSemanticHighlightingCalculator.java
@@ -11,6 +11,7 @@
import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.*;
import static com.google.eclipse.protobuf.ui.editor.syntaxcoloring.HighlightingConfiguration.*;
+import static org.eclipse.xtext.ui.editor.syntaxcoloring.DefaultHighlightingConfiguration.*;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.*;
@@ -34,9 +35,13 @@
@Inject private Options options;
@Override public void provideHighlightingFor(XtextResource resource, IHighlightedPositionAcceptor acceptor) {
- if (resource == null) return;
+ if (resource == null) {
+ return;
+ }
EList<EObject> contents = resource.getContents();
- if (contents == null || contents.isEmpty()) return;
+ if (contents == null || contents.isEmpty()) {
+ return;
+ }
Protobuf protobuf = (Protobuf) contents.get(0);
highlight(protobuf, acceptor);
}
@@ -151,7 +156,9 @@
private void highlightPropertyType(MessageField field, IHighlightedPositionAcceptor acceptor) {
TypeLink link = field.getType();
- if (!(link instanceof ComplexTypeLink)) return;
+ if (!(link instanceof ComplexTypeLink)) {
+ return;
+ }
ComplexType type = ((ComplexTypeLink) link).getTarget();
if (type instanceof Message) {
highlightFirstFeature(field, MESSAGE_FIELD__TYPE, acceptor, MESSAGE_ID);
@@ -225,7 +232,9 @@
private void highlightFirstFeature(EObject semantic, EStructuralFeature feature,
IHighlightedPositionAcceptor acceptor, String highlightId) {
INode node = nodes.firstNodeForFeature(semantic, feature);
- if (node == null) return;
+ if (node == null) {
+ return;
+ }
acceptor.addPosition(node.getOffset(), node.getLength(), highlightId);
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/exception/CoreExceptions.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/exception/CoreExceptions.java
index 0cadeb5..111e795 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/exception/CoreExceptions.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/exception/CoreExceptions.java
@@ -11,8 +11,7 @@
import static com.google.eclipse.protobuf.ui.ProtobufUiModule.PLUGIN_ID;
import static org.eclipse.core.runtime.IStatus.ERROR;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.*;
/**
* Factory of <code>{@link CoreException}</code>s.
@@ -23,7 +22,9 @@
public static CoreException error(Throwable cause) {
String message = cause.getMessage();
- if (message == null) message = "";
+ if (message == null) {
+ message = "";
+ }
return new CoreException(new Status(ERROR, PLUGIN_ID, message, cause));
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/grammar/CompoundElement.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/grammar/CompoundElement.java
index d21b959..964be3f 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/grammar/CompoundElement.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/grammar/CompoundElement.java
@@ -47,7 +47,9 @@
for (int i = 0; i < count; i++) {
String s = objects[i].toString();
buffer.append(s);
- if (i < count - 1 && !s.endsWith(space())) buffer.append(space());
+ if (i < count - 1 && !s.endsWith(space())) {
+ buffer.append(space());
+ }
}
return buffer.toString();
}
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 bc3d548..3cb9de1 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
@@ -73,9 +73,13 @@
public String imageFor(Class<?> type) {
String image = IMAGES_BY_TYPE.get(type);
- if (image != null) return image;
+ if (image != null) {
+ return image;
+ }
Class<?>[] interfaces = type.getInterfaces();
- if (interfaces == null || interfaces.length != 1) return DEFAULT_IMAGE;
+ if (interfaces == null || interfaces.length != 1) {
+ return DEFAULT_IMAGE;
+ }
return imageFor(interfaces[0]);
}
@@ -83,15 +87,21 @@
String value = keyword.getValue();
Modifier m = Modifier.getByName(value);
String image = IMAGES_BY_MODIFIER.get(m);
- if (image != null) return image;
+ if (image != null) {
+ return image;
+ }
String imageName = value + GIF_EXTENSION;
- if (IMAGES_BY_TYPE.containsValue(imageName) || STANDALONE_IMAGES.contains(imageName)) return imageName;
+ if (IMAGES_BY_TYPE.containsValue(imageName) || STANDALONE_IMAGES.contains(imageName)) {
+ return imageName;
+ }
return DEFAULT_IMAGE;
}
private String imageFor(Modifier modifier) {
String image = IMAGES_BY_MODIFIER.get(modifier);
- if (image != null) return image;
+ if (image != null) {
+ return image;
+ }
return "field.gif";
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/labeling/Labels.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/labeling/Labels.java
index 516633f..4e0aacf 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/labeling/Labels.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/labeling/Labels.java
@@ -76,7 +76,9 @@
EList<Range> ranges = extensions.getRanges();
int rangeCount = ranges.size();
for (int i = 0; i < rangeCount; i++) {
- if (i > 0) builder.append(", ");
+ if (i > 0) {
+ builder.append(", ");
+ }
Range range = ranges.get(i);
builder.append(range.getFrom());
String to = range.getTo();
@@ -89,7 +91,9 @@
private Object labelFor(Import anImport) {
INode node = nodes.firstNodeForFeature(anImport, IMPORT__IMPORT_URI);
- if (node == null) return anImport.getImportURI();
+ if (node == null) {
+ return anImport.getImportURI();
+ }
return node.getText();
}
@@ -106,14 +110,19 @@
private String typeName(ExtensibleTypeLink link) {
ExtensibleType type = link.getTarget();
- if (type == null) return null;
+ if (type == null) {
+ return null;
+ }
return nameResolver.nameOf(type);
}
private Object labelFor(MessageField field) {
StyledString text = new StyledString(nameResolver.nameOf(field));
String typeName = messageFields.typeNameOf(field);
- if (typeName == null) typeName = "<unresolved reference>"; // TODO move to
+ if (typeName == null)
+ {
+ typeName = "<unresolved reference>"; // TODO move to
+ }
// properties
// file
String indexAndType = String.format(" [%d] : %s", field.getIndex(), typeName);
@@ -126,9 +135,13 @@
String name = options.nameForOption(e);
StringBuilder b = new StringBuilder();
boolean isCustomOption = option instanceof CustomOption || option instanceof CustomFieldOption;
- if (isCustomOption) b.append("(");
+ if (isCustomOption) {
+ b.append("(");
+ }
b.append(name);
- if (isCustomOption) b.append(")");
+ if (isCustomOption) {
+ b.append(")");
+ }
if (option instanceof CustomOption) {
appendFields(b, ((CustomOption) option).getFields());
}
@@ -162,7 +175,9 @@
private String messageName(MessageLink link) {
Message m = link.getTarget();
- if (m == null) return null;
+ if (m == null) {
+ return null;
+ }
return nameResolver.nameOf(m);
}
}
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 7e05c0e..9deb271 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
@@ -32,7 +32,9 @@
initialize();
for (ProtobufElement e : protobuf.getElements()) {
for (Class<?> type : GROUP_TYPES) {
- if (!type.isInstance(e)) continue;
+ if (!type.isInstance(e)) {
+ continue;
+ }
elements.get(type).add(e);
break;
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/outline/ProtobufOutlinePage.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/outline/ProtobufOutlinePage.java
index fe0d9b5..be7aec6 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/outline/ProtobufOutlinePage.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/outline/ProtobufOutlinePage.java
@@ -12,8 +12,7 @@
import static com.google.common.collect.Lists.newArrayList;
import static java.util.Collections.singletonList;
-import java.util.Collection;
-import java.util.List;
+import java.util.*;
import org.eclipse.xtext.ui.editor.outline.IOutlineNode;
import org.eclipse.xtext.ui.editor.outline.impl.*;
@@ -35,7 +34,9 @@
}
private void addChildrenToExpand(Collection<IOutlineNode> parents, List<IOutlineNode> nodes, int depth) {
- if (depth < 1) return;
+ if (depth < 1) {
+ return;
+ }
for (IOutlineNode parent : parents) {
Collection<IOutlineNode> children = childrenToExpand(parent);
nodes.addAll(children);
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 87fc2ca..e9122d3 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
@@ -49,10 +49,12 @@
boolean _isLeaf(Package aPackage) {
return true;
}
-
+
protected void _createChildren(DocumentRootNode parent, Protobuf protobuf) {
OutlineViewModel model = new OutlineViewModel(protobuf);
- for (EObject aPackage : model.packages()) createNode(parent, aPackage);
+ for (EObject aPackage : model.packages()) {
+ createNode(parent, aPackage);
+ }
addGroup(parent, protobuf, model.imports(), "imports", importDeclarations);
for (EObject e : model.remainingElements()) {
createNode(parent, e);
@@ -61,7 +63,9 @@
private void addGroup(DocumentRootNode parent, Protobuf protobuf, List<? extends EObject> group, String imageKey,
String text) {
- if (group.isEmpty()) return;
+ if (group.isEmpty()) {
+ return;
+ }
SimpleOutlineNode groupNode = new SimpleOutlineNode(parent, protobuf, labelProvider.getImage(imageKey), text, false);
for (EObject o : group) {
createNode(groupNode, o);
@@ -69,13 +73,18 @@
}
@Override protected void createNode(IOutlineNode parent, EObject modelElement) {
- if (isIgnored(modelElement)) return;
+ if (isIgnored(modelElement)) {
+ return;
+ }
super.createNode(parent, modelElement);
}
private boolean isIgnored(EObject modelElement) {
- for (Class<? extends EObject> ignoredType : IGNORED_ELEMENT_TYPES)
- if (ignoredType.isInstance(modelElement)) return true;
+ for (Class<? extends EObject> ignoredType : IGNORED_ELEMENT_TYPES) {
+ if (ignoredType.isInstance(modelElement)) {
+ return true;
+ }
+ }
return false;
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/outline/SimpleOutlineNode.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/outline/SimpleOutlineNode.java
index ae89fac..745ee8e 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/outline/SimpleOutlineNode.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/outline/SimpleOutlineNode.java
@@ -21,7 +21,7 @@
class SimpleOutlineNode extends AbstractOutlineNode {
private final URI ownerUri;
-
+
SimpleOutlineNode(IOutlineNode parent, EObject owner, Image image, Object text, boolean isLeaf) {
super(parent, image, text, isLeaf);
ownerUri = EcoreUtil.getURI(owner);
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/Buttons.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/Buttons.java
index 5e3a00f..dd80b83 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/Buttons.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/Buttons.java
@@ -29,6 +29,8 @@
}
public void add(SelectionListener l) {
- for (Button b : buttons) b.addSelectionListener(l);
+ for (Button b : buttons) {
+ b.addSelectionListener(l);
+ }
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/InputDialog.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/InputDialog.java
index 3d879e5..d7306cd 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/InputDialog.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/InputDialog.java
@@ -34,6 +34,8 @@
@Override protected void configureShell(Shell shell) {
super.configureShell(shell);
- if (title != null) shell.setText(title);
+ if (title != null) {
+ shell.setText(title);
+ }
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/PreferenceStoreAccess.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/PreferenceStoreAccess.java
index 6fce05e..1b7d06a 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/PreferenceStoreAccess.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/PreferenceStoreAccess.java
@@ -24,9 +24,9 @@
/**
* Workaround for bug in Xtext where a project's preference store is never used.
- *
+ *
* TODO verify if this bug is fixed in Xtext 2.0.1.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
@Singleton
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/binding/BindingToListItems.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/binding/BindingToListItems.java
index 2bf06d4..9deab97 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/binding/BindingToListItems.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/binding/BindingToListItems.java
@@ -54,7 +54,9 @@
private void apply(Collection<String> value) {
list.removeAll();
- for (String s : value) list.add(s);
+ for (String s : value) {
+ list.add(s);
+ }
}
/** {@inheritDoc} */
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/binding/PreferenceBinder.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/binding/PreferenceBinder.java
index b76e6af..523eb85 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/binding/PreferenceBinder.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/binding/PreferenceBinder.java
@@ -24,7 +24,9 @@
* @param bindings the bindings to add.
*/
public void addAll(Binding...bindings) {
- for (Binding binding : bindings) add(binding);
+ for (Binding binding : bindings) {
+ add(binding);
+ }
}
/**
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/Messages.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/Messages.java
index 59ae611..86d2e38 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/Messages.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/Messages.java
@@ -22,6 +22,6 @@
Class<Messages> targetType = Messages.class;
NLS.initializeMessages(targetType.getName(), targetType);
}
-
+
private Messages() {}
}
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 830506a..c8cbf10 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
@@ -49,7 +49,9 @@
@Override protected Control createContents(Composite parent) {
Composite contents = contentParent(parent);
doCreateContents(contents);
- if (isPropertyPage()) setupBindingOfBtnEnabledProjectSettings();
+ if (isPropertyPage()) {
+ setupBindingOfBtnEnabledProjectSettings();
+ }
setupBinding(preferenceBinder);
preferenceBinder.applyValues();
updateContents();
@@ -122,7 +124,9 @@
private void setupBindingOfBtnEnabledProjectSettings() {
BooleanPreference preference = enableProjectSettingsPreference(getPreferenceStore());
- if (preference == null) return;
+ if (preference == null) {
+ return;
+ }
preferenceBinder.add(bindSelectionOf(btnEnableProjectSettings).to(preference));
}
@@ -168,7 +172,9 @@
* @return the preference store.
*/
@Override protected final IPreferenceStore doGetPreferenceStore() {
- if (isPropertyPage()) return preferenceStoreAccess.getWritablePreferenceStore(currentProject());
+ if (isPropertyPage()) {
+ return preferenceStoreAccess.getWritablePreferenceStore(currentProject());
+ }
return preferenceStoreAccess.getWritablePreferenceStore();
}
@@ -182,15 +188,18 @@
}
private IProject currentProject() {
- if (project == null)
+ if (project == null) {
throw new IllegalStateException("Not a property page case, but current project was requested.");
+ }
return project;
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public final void applyData(Object data) {
- if (data instanceof Map) this.dataMap = (Map<String, Object>) data;
+ if (data instanceof Map) {
+ this.dataMap = (Map<String, Object>) data;
+ }
}
/**
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CodeGenerationEditor.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CodeGenerationEditor.java
index 5ac4f8d..086924f 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CodeGenerationEditor.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CodeGenerationEditor.java
@@ -57,12 +57,12 @@
tblclmnEnabled.setWidth(27);
tblclmnVwrEnabled.setLabelProvider(new ColumnLabelProvider() {
@Override public String getText(Object element) {
- return ""; //$NON-NLS-1$
+ return "";
}
@Override public Image getImage(Object element) {
boolean optionEnabled = ((CodeGenerationSetting)element).isEnabled();
- return imageHelper.getImage(optionEnabled ? "checked.gif" : "unchecked.gif"); //$NON-NLS-1$ //$NON-NLS-2$
+ return imageHelper.getImage(optionEnabled ? "checked.gif" : "unchecked.gif");
}
});
@@ -111,7 +111,9 @@
EditCodeGenerationDialog dialog = new EditCodeGenerationDialog(getShell(), option);
if (dialog.open() == OK) {
tblVwrCodeGenerationOptions.refresh();
- if (dataChangedListener != null) dataChangedListener.dataChanged();
+ if (dataChangedListener != null) {
+ dataChangedListener.dataChanged();
+ }
}
}
});
@@ -125,7 +127,9 @@
private void updateTable() {
tblVwrCodeGenerationOptions.setInput(settings);
- if (!settings.isEmpty()) tblCodeGenerationOptions.setSelection(0);
+ if (!settings.isEmpty()) {
+ tblCodeGenerationOptions.setSelection(0);
+ }
}
/** {@inheritDoc} */
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferencePage.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferencePage.java
index 930134f..88ea122 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferencePage.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferencePage.java
@@ -166,7 +166,9 @@
@Override public void widgetSelected(SelectionEvent e) {
FileDialog dialog = new FileDialog(getShell(), SWT.OPEN | SWT.SHEET);
String file = dialog.open();
- if (file != null) txtProtocFilePath.setText(file);
+ if (file != null) {
+ txtProtocFilePath.setText(file);
+ }
checkState();
}
});
@@ -175,7 +177,9 @@
FileDialog dialog = new FileDialog(getShell(), SWT.OPEN | SWT.SHEET);
dialog.setFilterExtensions(new String[] { "*.proto" });
String file = dialog.open();
- if (file != null) txtDescriptorFilePath.setText(file);
+ if (file != null) {
+ txtDescriptorFilePath.setText(file);
+ }
checkState();
}
});
@@ -225,7 +229,9 @@
private boolean isFileWithName(String filePath, String expectedFileName) {
File file = new File(filePath);
- if (!file.isFile()) return false;
+ if (!file.isFile()) {
+ return false;
+ }
String fileName = file.getName();
return expectedFileName.equals(fileName);
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferences.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferences.java
index 4f86403..ed01b7a 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferences.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferences.java
@@ -50,7 +50,7 @@
public String protocPath() {
return protocPath;
}
-
+
public String descriptorPath() {
return descriptorPath;
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferencesFactory.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferencesFactory.java
index 343560d..dbb8d67 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferencesFactory.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/CompilerPreferencesFactory.java
@@ -28,7 +28,9 @@
public CompilerPreferences preferences(IProject project) {
IPreferenceStore store = storeAccess.getWritablePreferenceStore(project);
boolean useProjectPreferences = enableProjectSettings(store).value();
- if (!useProjectPreferences) store = storeAccess.getWritablePreferenceStore();
+ if (!useProjectPreferences) {
+ store = storeAccess.getWritablePreferenceStore();
+ }
return new CompilerPreferences(new RawPreferences(store));
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/EditCodeGenerationDialog.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/EditCodeGenerationDialog.java
index 960ad2e..4dee583 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/EditCodeGenerationDialog.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/EditCodeGenerationDialog.java
@@ -113,7 +113,9 @@
IWorkspace workspace = ResourcesPlugin.getWorkspace();
for (String segment : segmentsOf(directoryName)) {
IStatus isValid = workspace.validateName(segment, FOLDER);
- if (isValid.getCode() == OK) continue;
+ if (isValid.getCode() == OK) {
+ continue;
+ }
return isValid.getMessage();
}
return null;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/RawPreferences.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/RawPreferences.java
index 356accb..81945d0 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/RawPreferences.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/compiler/RawPreferences.java
@@ -64,7 +64,7 @@
StringPreference protocPath() {
return protocPath;
}
-
+
StringPreference descriptorPath() {
return descriptorPath;
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/EditorPreferencePage.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/EditorPreferencePage.java
index f262274..3a40db5 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/EditorPreferencePage.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/EditorPreferencePage.java
@@ -1,10 +1,10 @@
/*
* Copyright (c) 2011 Google Inc.
- *
+ *
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
- *
+ *
* http://www.eclipse.org/legal/epl-v10.html
*/
package com.google.eclipse.protobuf.ui.preferences.pages.editor;
@@ -20,7 +20,7 @@
/**
* General editor preferences.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class EditorPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/Messages.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/Messages.java
index 20342ec..128473a 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/Messages.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/Messages.java
@@ -1,10 +1,10 @@
/*
* Copyright (c) 2011 Google Inc.
- *
+ *
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
- *
+ *
* http://www.eclipse.org/legal/epl-v10.html
*/
package com.google.eclipse.protobuf.ui.preferences.pages.editor;
@@ -15,7 +15,7 @@
* @author alruiz@google.com (Alex Ruiz)
*/
public class Messages extends NLS {
-
+
public static String header;
static {
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/AddOrEditPatternDialog.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/AddOrEditPatternDialog.java
index 6f5c77c..643ba56 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/AddOrEditPatternDialog.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/AddOrEditPatternDialog.java
@@ -154,7 +154,7 @@
}
private void clearTestErrorText() {
- txtTestError.setText(""); //$NON-NLS-1$
+ txtTestError.setText("");
}
/** {@inheritDoc} */
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferencePage.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferencePage.java
index 9e5319d..2a7e150 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferencePage.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferencePage.java
@@ -13,10 +13,6 @@
import static com.google.eclipse.protobuf.ui.preferences.pages.editor.numerictag.Messages.*;
import static org.eclipse.jface.window.Window.OK;
-import com.google.eclipse.protobuf.ui.preferences.*;
-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.jface.viewers.ListViewer;
import org.eclipse.swt.SWT;
@@ -24,6 +20,10 @@
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
+import com.google.eclipse.protobuf.ui.preferences.*;
+import com.google.eclipse.protobuf.ui.preferences.binding.PreferenceBinder;
+import com.google.eclipse.protobuf.ui.preferences.pages.PreferenceAndPropertyPage;
+
/**
* Preference page where users can specify the patterns to use to match comments where "the next id" is being tracked.
*
@@ -99,7 +99,9 @@
btnRemove.addSelectionListener(new SelectionAdapter() {
@Override public void widgetSelected(SelectionEvent e) {
int index = lstPaths.getSelectionIndex();
- if (index < 0) return;
+ if (index < 0) {
+ return;
+ }
lstPaths.remove(index);
enableButtonsDependingOnListSelection();
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferences.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferences.java
index cd13a7b..2113421 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferences.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferences.java
@@ -8,23 +8,23 @@
*/
package com.google.eclipse.protobuf.ui.preferences.pages.editor.numerictag;
-import org.eclipse.jface.preference.IPreferenceStore;
-
import java.util.List;
+import org.eclipse.jface.preference.IPreferenceStore;
+
/**
* "Numeric tag" preferences, retrieved from an <code>{@link IPreferenceStore}</code>.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class NumericTagPreferences {
private final List<String> patterns;
-
+
NumericTagPreferences(RawPreferences preferences) {
patterns = preferences.patterns().value();
}
-
+
public List<String> patterns() {
return patterns;
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferencesFactory.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferencesFactory.java
index 5c22c08..f7163a9 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferencesFactory.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/numerictag/NumericTagPreferencesFactory.java
@@ -8,11 +8,11 @@
*/
package com.google.eclipse.protobuf.ui.preferences.pages.editor.numerictag;
-import com.google.inject.Inject;
-
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.xtext.ui.editor.preferences.IPreferenceStoreAccess;
+import com.google.inject.Inject;
+
/**
* Factory of <code>{@link NumericTagPreferences}</code>.
*
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/save/RawPreferences.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/save/RawPreferences.java
index 0aad9be..ad731dc 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/save/RawPreferences.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/save/RawPreferences.java
@@ -1,18 +1,18 @@
/*
* Copyright (c) 2011 Google Inc.
- *
+ *
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse 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 com.google.eclipse.protobuf.ui.preferences.BooleanPreference;
-
import org.eclipse.jface.preference.IPreferenceStore;
+import com.google.eclipse.protobuf.ui.preferences.BooleanPreference;
+
/**
* @author alruiz@google.com (Alex Ruiz)
*/
@@ -31,7 +31,7 @@
BooleanPreference removeTrailingWhitespace() {
return removeTrailingWhitespace;
}
-
+
BooleanPreference inAllLines() {
return inAllLines;
}
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 73fd622..ef3bc24 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
@@ -14,8 +14,7 @@
import org.eclipse.jface.preference.*;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.ui.*;
@@ -50,17 +49,17 @@
btnRemoveTrailingwhitespace = new Button(contents, SWT.CHECK);
btnRemoveTrailingwhitespace.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, false, 1, 1));
btnRemoveTrailingwhitespace.setText(removeTrailingWhitespace);
-
+
Composite composite = new Composite(contents, SWT.NONE);
composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
composite.setLayout(new GridLayout(1, false));
-
+
btnInEditedLines = new Button(composite, SWT.RADIO);
btnInEditedLines.setText("In edited lines");
-
+
btnInAllLines = new Button(composite, SWT.RADIO);
btnInAllLines.setText("In all lines");
-
+
setUpBinding();
preferenceBinder.applyValues();
updateContents();
@@ -76,7 +75,7 @@
bindSelectionOf(btnInEditedLines).to(preferences.inEditedLines())
);
}
-
+
private void addEventListeners() {
btnRemoveTrailingwhitespace.addSelectionListener(new SelectionAdapter() {
@Override public void widgetSelected(SelectionEvent e) {
@@ -84,7 +83,7 @@
}
});
}
-
+
private void updateContents() {
boolean enabled = btnRemoveTrailingwhitespace.getSelection();
btnInEditedLines.setEnabled(enabled);
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/save/SaveActionsPreferences.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/save/SaveActionsPreferences.java
index 4964ad9..e82434b 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/save/SaveActionsPreferences.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/save/SaveActionsPreferences.java
@@ -12,26 +12,28 @@
/**
* "Save actions" preferences, retrieved from an <code>{@link IPreferenceStore}</code>.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class SaveActionsPreferences {
private final RemoveTrailingSpace removeTrailingSpace;
-
+
SaveActionsPreferences(RawPreferences preferences) {
removeTrailingSpace = RemoveTrailingSpace.valueFrom(preferences);
}
-
+
public RemoveTrailingSpace removeTrailingSpace() {
return removeTrailingSpace;
}
-
+
public static enum RemoveTrailingSpace {
NONE, IN_EDITED_LINES, IN_ALL_LINES;
-
+
static RemoveTrailingSpace valueFrom(RawPreferences preferences) {
- if (!preferences.removeTrailingWhitespace().value()) return NONE;
+ if (!preferences.removeTrailingWhitespace().value()) {
+ return NONE;
+ }
return preferences.inEditedLines().value() ? IN_EDITED_LINES : IN_ALL_LINES;
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/save/SaveActionsPreferencesFactory.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/save/SaveActionsPreferencesFactory.java
index e8edc4b..768c7c9 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/save/SaveActionsPreferencesFactory.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/editor/save/SaveActionsPreferencesFactory.java
@@ -8,11 +8,11 @@
*/
package com.google.eclipse.protobuf.ui.preferences.pages.editor.save;
-import com.google.inject.Inject;
-
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.xtext.ui.editor.preferences.IPreferenceStoreAccess;
+import com.google.inject.Inject;
+
/**
* Factory of <code>{@link SaveActionsPreferences}</code>.
*
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/GeneralPreferencesFactory.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/GeneralPreferencesFactory.java
index fb58e94..51a1f73 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/GeneralPreferencesFactory.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/general/GeneralPreferencesFactory.java
@@ -28,7 +28,9 @@
public GeneralPreferences preferences(IProject project) {
IPreferenceStore store = storeAccess.getWritablePreferenceStore(project);
boolean useProjectPreferences = enableProjectSettings(store).value();
- if (!useProjectPreferences) store = storeAccess.getWritablePreferenceStore();
+ if (!useProjectPreferences) {
+ store = storeAccess.getWritablePreferenceStore();
+ }
return new GeneralPreferences(new RawPreferences(store));
}
}
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 81c9400..9da8ec1 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
@@ -37,7 +37,9 @@
Matcher matcher = WORKSPACE_PATH_PATTERN.matcher(path);
if (matcher.matches()) {
String actualPath = matcher.group(1);
- if (project != null) actualPath = useProjectName(actualPath, project);
+ if (project != null) {
+ actualPath = useProjectName(actualPath, project);
+ }
return new DirectoryPath(actualPath, true);
}
return new DirectoryPath(path, false);
@@ -50,7 +52,9 @@
/** {@inheritDoc} */
@Override public String toString() {
- if (!isWorkspacePath) return value;
+ if (!isWorkspacePath) {
+ return value;
+ }
return "${workspace_loc:" + value + "}";
}
@@ -76,7 +80,9 @@
* @return the absolute path in the local file system, or {@code null} if no path can be determined.
*/
public String location(IProject project) {
- if (isWorkspacePath()) return locationOfWorkspaceDirectory(project);
+ if (isWorkspacePath()) {
+ return locationOfWorkspaceDirectory(project);
+ }
return locationOfFileSystemDirectory();
}
@@ -89,7 +95,9 @@
private String locationOfFileSystemDirectory() {
IFileSystem fileSystem = EFS.getLocalFileSystem();
IFileInfo fileInfo = fileSystem.getStore(new Path(value())).fetchInfo();
- if (!fileInfo.isDirectory()) return null;
+ if (!fileInfo.isDirectory()) {
+ return null;
+ }
return value();
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPathsEditor.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPathsEditor.java
index d2f3674..33becc9 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPathsEditor.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectoryPathsEditor.java
@@ -60,7 +60,7 @@
tblDirectoryPaths = tblVwrDirectoryPaths.getTable();
tblDirectoryPaths.setLinesVisible(true);
tblDirectoryPaths.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
-
+
TableViewerColumn tblclmnVwrPath = new TableViewerColumn(tblVwrDirectoryPaths, SWT.NONE);
TableColumn tblclmnPath = tblclmnVwrPath.getColumn();
tblclmnPath.setWidth(200);
@@ -119,7 +119,9 @@
btnRemove.addSelectionListener(new SelectionAdapter() {
@Override public void widgetSelected(SelectionEvent e) {
int index = tblDirectoryPaths.getSelectionIndex();
- if (index < 0) return;
+ if (index < 0) {
+ return;
+ }
importPaths.remove(index);
updateTable();
enableButtonsDependingOnTableSelection();
@@ -140,7 +142,9 @@
private void swap(boolean goUp) {
int index = tblDirectoryPaths.getSelectionIndex();
- if (index < 0) return;
+ if (index < 0) {
+ return;
+ }
int target = goUp ? index - 1 : index + 1;
int[] selection = tblDirectoryPaths.getSelectionIndices();
DirectoryPath path = importPaths.get(selection[0]);
@@ -187,8 +191,9 @@
private void updateTable() {
tblVwrDirectoryPaths.setInput(importPaths.toArray());
- if (tblDirectoryPaths.getItemCount() > 0 && tblDirectoryPaths.getSelectionCount() == 0)
+ if (tblDirectoryPaths.getItemCount() > 0 && tblDirectoryPaths.getSelectionCount() == 0) {
tblDirectoryPaths.setSelection(0);
+ }
}
public void setDataChangedListener(DataChangedListener listener) {
@@ -196,7 +201,9 @@
}
private void notifyDataHasChanged() {
- if (dataChangedListener != null) dataChangedListener.dataChanged();
+ if (dataChangedListener != null) {
+ dataChangedListener.dataChanged();
+ }
}
private static class RichLabelProvider extends LabelProvider implements ITableLabelProvider {
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectorySelectionDialogs.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectorySelectionDialogs.java
index c48e0cd..c54435b 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectorySelectionDialogs.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/DirectorySelectionDialogs.java
@@ -15,6 +15,8 @@
import static org.eclipse.jface.window.Window.OK;
import static org.eclipse.ui.views.navigator.ResourceComparator.NAME;
+import java.net.URI;
+
import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.*;
import org.eclipse.swt.SWT;
@@ -23,8 +25,6 @@
import org.eclipse.ui.model.*;
import org.eclipse.ui.views.navigator.ResourceComparator;
-import java.net.URI;
-
/**
* Launchers for dialogs where users can select a directory (either in a workspace or the file system.)
*
@@ -47,26 +47,33 @@
IResource container = null;
if (uri.isAbsolute()) {
IContainer containers[] = workspaceRoot.findContainersForLocationURI(uri);
- if (containers != null && containers.length > 0) container = containers[0];
+ if (containers != null && containers.length > 0) {
+ container = containers[0];
+ }
}
dialog.setInitialSelection(container);
dialog.setValidator(new ISelectionStatusValidator() {
@Override public IStatus validate(Object[] selection) {
- if (selection != null && selection.length > 0 && selection[0] instanceof IFile)
+ if (selection != null && selection.length > 0 && selection[0] instanceof IFile) {
return new Status(ERROR, PLUGIN_ID, errorElementIsNotDirectory);
+ }
return OK_STATUS;
}
});
dialog.setTitle(directorySelection);
dialog.setMessage(selectWorkspaceDirectory);
- if (dialog.open() != OK) return null;
+ if (dialog.open() != OK) {
+ return null;
+ }
IResource resource = (IResource) dialog.getFirstResult();
return (resource == null) ? null : resource.getFullPath();
}
static String showFileSystemDirectorySelectionDialog(Shell shell, String filterPath) {
DirectoryDialog dialog = new DirectoryDialog(shell, SWT.OPEN | SWT.APPLICATION_MODAL);
- if (filterPath != null && filterPath.trim().length() != 0) dialog.setFilterPath(filterPath);
+ if (filterPath != null && filterPath.trim().length() != 0) {
+ dialog.setFilterPath(filterPath);
+ }
dialog.setMessage(selectFileSystemDirectory);
return dialog.open();
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferencePage.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferencePage.java
index b72008a..4d95894 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferencePage.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferencePage.java
@@ -46,7 +46,7 @@
private static Logger logger = Logger.getLogger(PathsPreferencePage.class);
- private static final String COMMA_DELIMITER = ","; //$NON-NLS-1$
+ private static final String COMMA_DELIMITER = ",";
private static final String PREFERENCE_PAGE_ID = PathsPreferencePage.class.getName();
private Group grpResolutionOfImported;
@@ -136,7 +136,10 @@
private String directoryNames() {
List<DirectoryPath> paths = directoryPathsEditor.directoryPaths();
- if (paths.isEmpty()) return ""; //$NON-NLS-1$
+ if (paths.isEmpty())
+ {
+ return "";
+ }
List<String> pathsAsText = new ArrayList<String>();
for (DirectoryPath path : paths) {
pathsAsText.add(path.toString());
@@ -147,7 +150,9 @@
private void setDirectoryPaths(String directoryPaths) {
List<DirectoryPath> paths = new ArrayList<DirectoryPath>();
for (String path : split(directoryPaths, COMMA_DELIMITER)) {
- if (isEmpty(path)) continue;
+ if (isEmpty(path)) {
+ continue;
+ }
paths.add(DirectoryPath.parse(path));
}
directoryPathsEditor.directoryPaths(unmodifiableList(paths));
@@ -175,7 +180,9 @@
@Override protected void okPerformed() {
// TODO check threading
- if (!stateChanged) return;
+ if (!stateChanged) {
+ return;
+ }
stateChanged = false;
if (shouldRebuild()) {
rebuildProject();
@@ -192,13 +199,13 @@
}
private void rebuildProject() {
- Job job = new Job("Rebuilding project") { //$NON-NLS-1$
+ Job job = new Job("Rebuilding project") {
@Override protected IStatus run(IProgressMonitor monitor) {
try {
project().build(FULL_BUILD, monitor);
} catch (CoreException e) {
logger.error(e.getMessage(), e);
- return new Status(ERROR, PLUGIN_ID, ERROR, e.getMessage(), e); //$NON-NLS-1$
+ return new Status(ERROR, PLUGIN_ID, ERROR, e.getMessage(), e);
}
return OK_STATUS;
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferences.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferences.java
index bb87b1f..f50530b 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferences.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/PathsPreferences.java
@@ -27,7 +27,7 @@
private final List<DirectoryPath> importRoots;
private static final String CSV_PATTERN = "[\\s]*,[\\s]*";
-
+
PathsPreferences(RawPreferences preferences, IProject project) {
boolean filesInOneDirectoryOnly = preferences.filesInOneDirectoryOnly().value();
pathResolutionType = filesInOneDirectoryOnly ? SINGLE_DIRECTORY : MULTIPLE_DIRECTORIES;
@@ -35,7 +35,9 @@
}
private List<DirectoryPath> importRoots(RawPreferences preferences, IProject project) {
- if (pathResolutionType.equals(SINGLE_DIRECTORY)) return emptyList();
+ if (pathResolutionType.equals(SINGLE_DIRECTORY)) {
+ return emptyList();
+ }
List<DirectoryPath> roots = new ArrayList<DirectoryPath>();
for (String root : preferences.directoryPaths().value().split(CSV_PATTERN)) {
roots.add(DirectoryPath.parse(root, project));
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/ProjectVariable.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/ProjectVariable.java
index 840e4c4..10b4895 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/ProjectVariable.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/preferences/pages/paths/ProjectVariable.java
@@ -13,7 +13,7 @@
/**
* ${project} variable.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
class ProjectVariable {
@@ -23,17 +23,21 @@
static IPath useProjectVariable(IPath path, IProject project) {
return switchProjectSegments(path, project.getName(), VARIABLE_VALUE);
}
-
+
static String useProjectName(String path, IProject project) {
IPath newPath = switchProjectSegments(new Path(path), VARIABLE_VALUE, project.getName());
return newPath.toString();
}
-
+
private static IPath switchProjectSegments(IPath path, String currentSegment, String newSegment) {
- if (!currentSegment.equals(path.segment(0))) return path;
+ if (!currentSegment.equals(path.segment(0))) {
+ return path;
+ }
IPath newPath = new Path(newSegment);
newPath = newPath.append(path.removeFirstSegments(1));
- if (path.isAbsolute()) newPath = newPath.makeAbsolute();
+ if (path.isAbsolute()) {
+ newPath = newPath.makeAbsolute();
+ }
return newPath;
}
}
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 a5dc287..8c1d168 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
@@ -1,10 +1,10 @@
/*
* Copyright (c) 2011 Google Inc.
- *
+ *
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
- *
+ *
* http://www.eclipse.org/legal/epl-v10.html
*/
package com.google.eclipse.protobuf.ui.quickfix;
@@ -12,14 +12,14 @@
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
-import com.google.inject.Inject;
+import java.util.*;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext;
import org.eclipse.ui.texteditor.spelling.SpellingCorrectionProcessor;
import org.eclipse.xtext.ui.editor.quickfix.XtextQuickAssistProcessor;
-import java.util.*;
+import com.google.inject.Inject;
/**
* @author alruiz@google.com (Alex Ruiz)
@@ -34,14 +34,18 @@
proposals.addAll(asList(super.computeQuickAssistProposals(context)));
return proposals.toArray(new ICompletionProposal[proposals.size()]);
}
-
+
private List<ICompletionProposal> spellingFixes(IQuickAssistInvocationContext context) {
ICompletionProposal[] spellingFixes = spellingCorrectionProcessor.computeQuickAssistProposals(context);
- if (spellingFixes.length == 0) return emptyList();
- if (spellingFixes.length == 1 && isNoCompletionsProposal(spellingFixes[0])) return emptyList();
+ if (spellingFixes.length == 0) {
+ return emptyList();
+ }
+ if (spellingFixes.length == 1 && isNoCompletionsProposal(spellingFixes[0])) {
+ return emptyList();
+ }
return asList(spellingFixes);
}
-
+
private boolean isNoCompletionsProposal(ICompletionProposal p) {
return p.getClass().getSimpleName().equals("NoCompletionsProposal");
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/quickfix/ProtobufQuickfixProvider.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/quickfix/ProtobufQuickfixProvider.java
index bd694c6..c9f9d93 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/quickfix/ProtobufQuickfixProvider.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/quickfix/ProtobufQuickfixProvider.java
@@ -72,10 +72,14 @@
@Fix(MORE_THAN_ONE_PACKAGE_ERROR)
public void removeDuplicatePackage(Issue issue, IssueResolutionAcceptor acceptor) {
final Package aPackage = element(issue, Package.class);
- if (aPackage == null) return;
+ if (aPackage == null) {
+ return;
+ }
ISemanticModification modification = new ISemanticModification() {
@Override public void apply(EObject element, IModificationContext context) throws Exception {
- if (!(element instanceof Package)) return;
+ if (!(element instanceof Package)) {
+ return;
+ }
remove(aPackage);
}
};
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/resource/XtextResourceFactory.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/resource/XtextResourceFactory.java
index 584e464..702b2d0 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/resource/XtextResourceFactory.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/resource/XtextResourceFactory.java
@@ -25,8 +25,7 @@
import org.eclipse.xtext.util.StringInputStream;
import com.google.eclipse.protobuf.ui.util.Resources;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
+import com.google.inject.*;
/**
* Factory of <code>{@link XtextResource}</code>s.
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileResolverStrategies.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileResolverStrategies.java
index 6d606fd..458899d 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileResolverStrategies.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileResolverStrategies.java
@@ -10,13 +10,11 @@
import static com.google.eclipse.protobuf.ui.preferences.pages.paths.PathResolutionType.*;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
import com.google.eclipse.protobuf.ui.preferences.pages.paths.PathResolutionType;
import com.google.eclipse.protobuf.ui.util.Resources;
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
+import com.google.inject.*;
/**
* @author alruiz@google.com (Alex Ruiz)
@@ -24,7 +22,7 @@
@Singleton
class FileResolverStrategies {
- private final Map<PathResolutionType, FileResolverStrategy> strategies =
+ private final Map<PathResolutionType, FileResolverStrategy> strategies =
new HashMap<PathResolutionType, FileResolverStrategy>();
@Inject FileResolverStrategies(PathMapping mapping, Resources resources) {
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileUriResolver.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileUriResolver.java
index 95e2bf8..a8de8d1 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileUriResolver.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/FileUriResolver.java
@@ -14,10 +14,8 @@
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
-import com.google.eclipse.protobuf.scoping.IFileUriResolver;
-import com.google.eclipse.protobuf.scoping.ProtoDescriptorProvider;
-import com.google.eclipse.protobuf.ui.preferences.pages.paths.PathsPreferences;
-import com.google.eclipse.protobuf.ui.preferences.pages.paths.PathsPreferencesFactory;
+import com.google.eclipse.protobuf.scoping.*;
+import com.google.eclipse.protobuf.ui.preferences.pages.paths.*;
import com.google.eclipse.protobuf.ui.util.Resources;
import com.google.inject.Inject;
@@ -49,7 +47,9 @@
* We need to have the import URI as "platform:/resource/protobuf-test/folder/proto2.proto" for the editor to see it.
*/
@Override public String resolveUri(String importUri, Resource declaringResource) {
- if (hasScheme(importUri)) return importUri;
+ if (hasScheme(importUri)) {
+ return importUri;
+ }
String resolved = resolveUri(importUri, declaringResource.getURI());
return (resolved == null) ? importUri : resolved;
}
@@ -61,10 +61,16 @@
private String resolveUri(String importUri, URI resourceUri) {
URI location = descriptorProvider.descriptorLocation(importUri);
- if (location != null) return location.toString();
+ if (location != null) {
+ return location.toString();
+ }
IProject project = resources.project(resourceUri);
- if (project == null) project = resources.activeProject();
- if (project == null) throw new IllegalStateException("Unable to find current project");
+ if (project == null) {
+ project = resources.activeProject();
+ }
+ if (project == null) {
+ throw new IllegalStateException("Unable to find current project");
+ }
PathsPreferences preferences = preferencesFactory.preferences(project);
return resolver(preferences).resolveUri(importUri, resourceUri, preferences);
}
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 cfd354d..05bd6c8 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,15 +8,15 @@
*/
package com.google.eclipse.protobuf.ui.scoping;
-import com.google.eclipse.protobuf.ui.preferences.pages.paths.*;
-import com.google.eclipse.protobuf.ui.util.Resources;
+import java.util.List;
import org.eclipse.core.filesystem.*;
import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.runtime.*;
import org.eclipse.emf.common.util.URI;
-import java.util.List;
+import com.google.eclipse.protobuf.ui.preferences.pages.paths.*;
+import com.google.eclipse.protobuf.ui.util.Resources;
/**
* @author alruiz@google.com (Alex Ruiz)
@@ -36,19 +36,27 @@
List<DirectoryPath> importRoots = preferences.importRoots();
for (DirectoryPath root : importRoots) {
String resolved = resolveUri(importUri, root);
- if (resolved != null) return resolved;
+ if (resolved != null) {
+ return resolved;
+ }
}
for (DirectoryPath root : importRoots) {
- if (!root.isWorkspacePath()) continue;
+ if (!root.isWorkspacePath()) {
+ continue;
+ }
String resolved = resolveUriInFileSystem(importUri, mapping.folderLocation(root.value()));
- if (resolved != null) return resolved;
+ if (resolved != null) {
+ return resolved;
+ }
}
return null;
}
private String resolveUri(String importUri, DirectoryPath importRoot) {
String root = importRoot.value();
- if (importRoot.isWorkspacePath()) return resolveUriInWorkspace(importUri, root);
+ if (importRoot.isWorkspacePath()) {
+ return resolveUriInWorkspace(importUri, root);
+ }
return resolveUriInFileSystem(importUri, root);
}
@@ -62,7 +70,9 @@
IFileSystem fileSystem = EFS.getLocalFileSystem();
IPath path = new Path(importRoot + SEPARATOR + importUri);
IFileInfo fileInfo = fileSystem.getStore(path).fetchInfo();
- if (!fileInfo.exists()) return null;
+ if (!fileInfo.exists()) {
+ return null;
+ }
return URIUtil.toURI(path).toString();
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/PathMapping.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/PathMapping.java
index 0ea1e38..faa741a 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/PathMapping.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/scoping/PathMapping.java
@@ -20,7 +20,7 @@
class PathMapping {
private final SimpleCache<String, String> folderPathMapping = new SimpleCache<String, String>(new FolderPathMapper());
-
+
String folderLocation(String workspacePath) {
return folderPathMapping.get(workspacePath);
}
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 3cbec0a..d99f27c 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
@@ -35,10 +35,14 @@
private String resolveUri(URI importUri, URI declaringResourceUri) {
StringBuilder pathBuilder = new StringBuilder();
String[] segments = importUri.segments();
- if (segments.length == 0) return null;
+ if (segments.length == 0) {
+ return null;
+ }
String firstSegment = segments[0];
for (String segment : removeFirstAndLast(declaringResourceUri)) {
- if (segment.equals(firstSegment)) break;
+ if (segment.equals(firstSegment)) {
+ break;
+ }
pathBuilder.append(segment).append(SEPARATOR);
}
String resolved = createResolvedUri(pathBuilder.toString(), importUri);
@@ -53,15 +57,17 @@
.append(importUri.toString())
.toString();
}
-
+
private boolean fileExists(String uri) {
return resources.fileExists(createURI(uri));
}
-
+
// 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;
+ if (segments.isEmpty()) {
+ return segments;
+ }
segments.remove(0);
segments.remove(segments.size() - 1);
return segments;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Literals.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Literals.java
index eea1cac..68da120 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Literals.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Literals.java
@@ -29,14 +29,14 @@
* of the given literal's siblings, plus one. The minimum index value is zero.
* <p>
* For example, in the following message:
- *
+ *
* <pre>
* enum PhoneType {
* MOBILE = 0;
* HOME = 1;
* WORK =
* </pre>
- *
+ *
* The calculated index value for the literal {@code WORK} will be 2.
* </p>
* @param l the given literal.
@@ -46,7 +46,9 @@
long index = -1;
List<Literal> allLiterals = getAllContentsOfType(l.eContainer(), Literal.class);
for (Literal c : allLiterals) {
- if (c == l) continue;
+ if (c == l) {
+ continue;
+ }
index = max(index, c.getIndex());
}
return ++index;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Paths.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Paths.java
index 30ade64..4ea2ae9 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Paths.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Paths.java
@@ -24,7 +24,9 @@
* @throws NullPointerException if the given path is {@code null}.
*/
public static String[] segmentsOf(String path) {
- if (path == null) throw new NullPointerException("The given path should not be null");
+ if (path == null) {
+ throw new NullPointerException("The given path should not be null");
+ }
return path.split("\\Q" + separator + "\\E");
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Resources.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Resources.java
index 3abe890..cb8ccc2 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Resources.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/Resources.java
@@ -9,8 +9,7 @@
package com.google.eclipse.protobuf.ui.util;
import org.eclipse.core.resources.*;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.*;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.*;
@@ -23,12 +22,12 @@
*
* @author alruiz@google.com (Alex Ruiz)
*/
-@SuppressWarnings("deprecation")
+@SuppressWarnings("deprecation")
@Singleton
public class Resources {
private static final IViewReference[] NO_VIEW_REFERENCES = new IViewReference[0];
-
+
public static final String URI_SCHEME_FOR_FILES = "file";
/**
@@ -45,7 +44,9 @@
public IProject activeProject() {
for (IViewReference reference : viewReferencesInActivePage()) {
IViewPart part = reference.getView(false);
- if (!(part instanceof ResourceNavigator)) continue;
+ if (!(part instanceof ResourceNavigator)) {
+ continue;
+ }
ResourceNavigator navigator = (ResourceNavigator) part;
StructuredSelection selection = (StructuredSelection) navigator.getTreeViewer().getSelection();
IResource resource = (IResource) selection.getFirstElement();
@@ -56,18 +57,22 @@
private IViewReference[] viewReferencesInActivePage() {
IWorkbenchPage page = activeWorkbenchPage();
- if (page == null) return NO_VIEW_REFERENCES;
+ if (page == null) {
+ return NO_VIEW_REFERENCES;
+ }
IViewReference[] references = page.getViewReferences();
return (references == null) ? NO_VIEW_REFERENCES : references;
}
-
+
private IWorkbenchPage activeWorkbenchPage() {
IWorkbench workbench = PlatformUI.getWorkbench();
- if (workbench == null) return null;
+ if (workbench == null) {
+ return null;
+ }
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
return (window == null) ? null : window.getActivePage();
}
-
+
/**
* Indicates whether the given URI belongs to an existing file.
* @param fileUri the URI to check, as a {@code String}.
@@ -101,7 +106,9 @@
}
private IResource resourceFrom(IEditorPart editor) {
- if (editor == null) return null;
+ if (editor == null) {
+ return null;
+ }
Object adapter = editor.getEditorInput().getAdapter(IResource.class);
return (adapter == null) ? null : (IResource) adapter;
}
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 7fb06f8..47903dc 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
@@ -108,13 +108,17 @@
});
} finally {
IStatus status = errorStatus.get();
- if (!status.isOK()) throw new CoreException(status);
+ if (!status.isOK()) {
+ throw new CoreException(status);
+ }
}
return result.get();
}
private static IProgressMonitor getSubProgressMonitor(IProgressMonitor monitor, int ticks) {
- if (monitor != null) return new SubProgressMonitor(monitor, ticks, PREPEND_MAIN_LABEL_TO_SUBTASK);
+ if (monitor != null) {
+ return new SubProgressMonitor(monitor, ticks, PREPEND_MAIN_LABEL_TO_SUBTASK);
+ }
return new NullProgressMonitor();
}
}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/editor/LineComparator.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/editor/LineComparator.java
index 0e9310e..aad9211 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/editor/LineComparator.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/editor/LineComparator.java
@@ -1,26 +1,24 @@
/*
* 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.util.editor;
import org.apache.log4j.Logger;
import org.eclipse.compare.rangedifferencer.IRangeComparator;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.*;
/**
* Adapted from CDT's {@code org.eclipse.cdt.internal.ui.text.LineSeparator}.
- *
- * This implementation of <code>IRangeComparator</code> compares lines of a document. The lines are compared using a DJB
+ *
+ * This implementation of <code>IRangeComparator</code> compares lines of a document. The lines are compared using a DJB
* hash function.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
class LineComparator implements IRangeComparator {
@@ -28,7 +26,7 @@
private static final long UNKNOWN_HASH = Long.MIN_VALUE;
private static Logger logger = Logger.getLogger(LineComparator.class);
-
+
private final IDocument document;
private final long[] hashes;
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/editor/Messages.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/editor/Messages.java
index 0d62f2c..f17dac0 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/editor/Messages.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/util/editor/Messages.java
@@ -1,10 +1,10 @@
/*
* Copyright (c) 2011 Google Inc.
- *
+ *
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
- *
+ *
* http://www.eclipse.org/legal/epl-v10.html
*/
package com.google.eclipse.protobuf.ui.util.editor;
@@ -15,10 +15,10 @@
* @author alruiz@google.com (Alex Ruiz)
*/
public class Messages extends NLS {
-
+
public static String calculatingChangedRegions;
public static String errorCalculatingChangedRegions;
-
+
static {
Class<Messages> targetType = Messages.class;
NLS.initializeMessages(targetType.getName(), targetType);
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/validation/ValidateOnActivation.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/validation/ValidateOnActivation.java
index 322b8a7..6b5a4b8 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/validation/ValidateOnActivation.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/validation/ValidateOnActivation.java
@@ -32,7 +32,9 @@
@Override public void partActivated(IWorkbenchPartReference partRef) {
IEditorPart activeEditor = activeEditor(partRef);
IProject project = projectFrom(activeEditor);
- if (project == null || !shouldValidateEditor(project)) return;
+ if (project == null || !shouldValidateEditor(project)) {
+ return;
+ }
validate(activeEditor);
}
@@ -48,7 +50,9 @@
private boolean shouldValidateEditor(IProject project) {
GeneralPreferencesFactory factory = injector().getInstance(GeneralPreferencesFactory.class);
- if (factory == null) return false;
+ if (factory == null) {
+ return false;
+ }
GeneralPreferences preferences = factory.preferences(project);
return preferences.validateFilesOnActivation();
}
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 0ed6920..0e21e76 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
@@ -35,19 +35,27 @@
static void validate(IEditorPart editor) {
XtextEditor protoEditor = asProtoEditor(editor);
- if (protoEditor == null) return;
+ if (protoEditor == null) {
+ return;
+ }
validate(protoEditor);
}
private static XtextEditor asProtoEditor(IEditorPart editor) {
XtextEditor xtextEditor = asXtextEditor(editor);
- if (xtextEditor == null) return null;
- if (!languageName().equals(xtextEditor.getLanguageName())) return null;
+ if (xtextEditor == null) {
+ return null;
+ }
+ if (!languageName().equals(xtextEditor.getLanguageName())) {
+ return null;
+ }
return xtextEditor;
}
private static XtextEditor asXtextEditor(IEditorPart editor) {
- if (!isXtextEditorContainingWorkspaceFile(editor)) return null;
+ if (!isXtextEditorContainingWorkspaceFile(editor)) {
+ return null;
+ }
return (XtextEditor) editor;
}
@@ -57,11 +65,15 @@
private static void validate(XtextEditor editor) {
final IXtextDocument document = editor.getDocument();
- if (!(document instanceof XtextDocument)) return;
+ if (!(document instanceof XtextDocument)) {
+ return;
+ }
document.readOnly(new IUnitOfWork.Void<XtextResource>() {
@Override public void process(XtextResource resource) {
EObject root = rootOf(resource);
- if (root == null) return;
+ if (root == null) {
+ return;
+ }
resetImports(root);
resource.getLinker().linkModel(root, new ListBasedDiagnosticConsumer());
((XtextDocument) document).checkAndUpdateAnnotations();
@@ -70,26 +82,36 @@
}
private static EObject rootOf(XtextResource resource) {
- if (resource == null) return null;
+ if (resource == null) {
+ return null;
+ }
return resource.getParseResult().getRootASTElement();
}
private static void resetImports(EObject root) {
List<Import> imports = getAllContentsOfType(root, Import.class);
- for (Import anImport : imports) resetUri(anImport);
+ for (Import anImport : imports) {
+ resetUri(anImport);
+ }
}
private static void resetUri(Import anImport) {
String uri = uriAsEnteredInEditor(anImport);
- if (uri == null) return;
+ if (uri == null) {
+ return;
+ }
anImport.setImportURI(uri);
}
private static String uriAsEnteredInEditor(Import anImport) {
INode node = nodes().firstNodeForFeature(anImport, IMPORT__IMPORT_URI);
- if (node == null) return null;
+ if (node == null) {
+ return null;
+ }
String text = node.getText();
- if (text == null) return null;
+ if (text == null) {
+ return null;
+ }
STRINGValueConverter converter = injector().getInstance(STRINGValueConverter.class);
return converter.toValue(text, node);
}
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 9fc9f98..34d2d80 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
@@ -45,22 +45,30 @@
}
private void validateFileInEditor(IEditorReference editorRef, IProject project) {
- if (!PROTO_EDITOR_ID.equals(editorRef.getId())) return;
+ if (!PROTO_EDITOR_ID.equals(editorRef.getId())) {
+ return;
+ }
IEditorPart editor = editorRef.getEditor(true);
IProject fileProject = resources.project(editor);
- if (fileProject == null || !haveEqualUris(project, fileProject)) return;
+ if (fileProject == null || !haveEqualUris(project, fileProject)) {
+ return;
+ }
validate(editor);
}
private boolean haveEqualUris(IProject p1, IProject p2) {
- if (p1 == null || p2 == null) return false;
+ if (p1 == null || p2 == null) {
+ return false;
+ }
URI uri1 = p1.getLocationURI();
URI uri2 = p2.getLocationURI();
return areEqual(uri1, uri2);
}
private boolean areEqual(URI uri1, URI uri2) {
- if (uri1 == null) return false;
+ if (uri1 == null) {
+ return false;
+ }
return uri1.equals(uri2);
}
}
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 364cd70..b4a0508 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
@@ -11,6 +11,8 @@
import static java.lang.Double.*;
import static org.eclipse.xtext.util.Strings.isEmpty;
+import java.util.*;
+
import org.eclipse.xtext.conversion.ValueConverterException;
import org.eclipse.xtext.conversion.impl.AbstractLexerBasedConverter;
import org.eclipse.xtext.nodemodel.INode;
@@ -22,6 +24,14 @@
*/
public class DOUBLEValueConverter extends AbstractLexerBasedConverter<Double> {
+ private static final Map<String, Double> PREDEFINED_VALUES = new HashMap<String, Double>();
+
+ static {
+ PREDEFINED_VALUES.put("nan", NaN);
+ PREDEFINED_VALUES.put("inf", POSITIVE_INFINITY);
+ PREDEFINED_VALUES.put("-inf", NEGATIVE_INFINITY);
+ }
+
/**
* Creates an {@code float} from the given input, if the given input represents a floating-point number.
* @param string the given input.
@@ -31,10 +41,13 @@
* number.
*/
@Override public Double toValue(String string, INode node) throws ValueConverterException {
- if (isEmpty(string)) throw new ValueConverterException("Couldn't convert empty string to double.", node, null);
- if ("nan".equals(string)) return NaN;
- if ("inf".equals(string)) return POSITIVE_INFINITY;
- if ("-inf".equals(string)) return NEGATIVE_INFINITY;
+ if (isEmpty(string)) {
+ throw new ValueConverterException("Couldn't convert empty string to double.", node, null);
+ }
+ Double predefinedValue = PREDEFINED_VALUES.get(string);
+ if (predefinedValue != null) {
+ return predefinedValue;
+ }
try {
return Double.parseDouble(string);
} catch (NumberFormatException e) {
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/HEXValueConverter.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/HEXValueConverter.java
index 08d5813..91ae3db 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/HEXValueConverter.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/HEXValueConverter.java
@@ -34,8 +34,12 @@
* number.
*/
@Override public Long toValue(String string, INode node) throws ValueConverterException {
- if (isEmpty(string)) throw new ValueConverterException("Couldn't convert empty string to long.", node, null);
- if (!startsWithValidPrefix(string)) throw parsingError(string, node);
+ if (isEmpty(string)) {
+ throw new ValueConverterException("Couldn't convert empty string to long.", node, null);
+ }
+ if (!startsWithValidPrefix(string)) {
+ throw parsingError(string, node);
+ }
String withoutZeroX = removeZeroX(string);
try {
BigInteger value = new BigInteger(withoutZeroX, 16);
@@ -48,7 +52,9 @@
private boolean startsWithValidPrefix(String string) {
for (String prefix : VALID_PREFIXES) {
- if (string.startsWith(prefix)) return true;
+ if (string.startsWith(prefix)) {
+ return true;
+ }
}
return false;
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/LONGValueConverter.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/LONGValueConverter.java
index 67f05f5..ae399e5 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/LONGValueConverter.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/LONGValueConverter.java
@@ -1,24 +1,24 @@
/*
* 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.conversion;
import static org.eclipse.xtext.util.Strings.isEmpty;
+import java.math.BigInteger;
+
import org.eclipse.xtext.conversion.ValueConverterException;
import org.eclipse.xtext.conversion.impl.AbstractLexerBasedConverter;
import org.eclipse.xtext.nodemodel.INode;
-import java.math.BigInteger;
-
/**
* Converts numbers to {@code long}s.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class LONGValueConverter extends AbstractLexerBasedConverter<Long> {
@@ -31,15 +31,17 @@
* @throws ValueConverterException if the given input is {@code null}, empty or does not represent an integer number.
*/
@Override public Long toValue(String string, INode node) throws ValueConverterException {
- if (isEmpty(string)) throw new ValueConverterException("Couldn't convert empty string to long.", node, null);
+ if (isEmpty(string)) {
+ throw new ValueConverterException("Couldn't convert empty string to long.", node, null);
+ }
try {
return Long.parseLong(string, 10);
} catch (NumberFormatException e) {
- return parseAgain(string, node);
+ return parseUsingBigInteger(string, node);
}
}
- private Long parseAgain(String string, INode node) {
+ private Long parseUsingBigInteger(String string, INode node) {
// error could be overflow, parse again with BigInteger.
try {
BigInteger value = new BigInteger(string, 10);
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/ProtobufTerminalConverters.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/ProtobufTerminalConverters.java
index d613bdf..6fd3776 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/ProtobufTerminalConverters.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/conversion/ProtobufTerminalConverters.java
@@ -1,9 +1,9 @@
/*
* 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.conversion;
@@ -23,19 +23,23 @@
@Inject private LONGValueConverter longValueConverter;
@Inject private STRINGValueConverter stringValueConverter;
- @ValueConverter(rule = "DOUBLE") public IValueConverter<Double> DOUBLE() {
+ @ValueConverter(rule = "DOUBLE")
+ public IValueConverter<Double> DOUBLE() {
return doubleValueConverter;
}
- @ValueConverter(rule = "HEX") public IValueConverter<Long> HEX() {
+ @ValueConverter(rule = "HEX")
+ public IValueConverter<Long> HEX() {
return hexValueConverter;
}
- @ValueConverter(rule = "LONG") public IValueConverter<Long> LONG() {
+ @ValueConverter(rule = "LONG")
+ public IValueConverter<Long> LONG() {
return longValueConverter;
}
- @ValueConverter(rule = "STRING") @Override public IValueConverter<String> STRING() {
+ @ValueConverter(rule = "STRING")
+ @Override public IValueConverter<String> STRING() {
return stringValueConverter;
}
}
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 591efb7..ba1ae52 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
@@ -1,9 +1,9 @@
/*
* 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.conversion;
@@ -19,7 +19,7 @@
/**
* Converts multi-line strings to {@code String}s.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class STRINGValueConverter extends AbstractLexerBasedConverter<String> {
@@ -27,7 +27,9 @@
private static final Pattern LINE_BREAK = compile("\"[\t\r\n]+\"|'[\t\r\n]+'");
@Override protected String toEscapedString(String value) {
- if (value == null) return null;
+ if (value == null) {
+ return null;
+ }
return '"' + convertToJavaString(removeLineBreaksFrom(value), false) + '"';
}
@@ -39,7 +41,9 @@
* @throws ValueConverterException if the given input has illegal characters.
*/
@Override public String toValue(String string, INode node) throws ValueConverterException {
- if (string == null) return null;
+ if (string == null) {
+ return null;
+ }
try {
String clean = removeLineBreaksFrom(string).trim();
return convertToJavaString(clean.substring(1, clean.length() - 1), true);
@@ -49,7 +53,9 @@
}
private static String removeLineBreaksFrom(String s) {
- if (isEmpty(s)) return s;
+ if (isEmpty(s)) {
+ return s;
+ }
return LINE_BREAK.matcher(s).replaceAll("");
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/grammar/Keywords.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/grammar/Keywords.java
index 5220657..adf5763 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/grammar/Keywords.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/grammar/Keywords.java
@@ -1,24 +1,24 @@
/*
* 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.grammar;
import static org.eclipse.xtext.GrammarUtil.getAllKeywords;
-import com.google.inject.*;
+import java.util.Set;
import org.eclipse.xtext.IGrammarAccess;
-import java.util.Set;
+import com.google.inject.*;
/**
* Utility methods related to grammar keywords.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
@Singleton public class Keywords {
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/grammar/ValidSyntax.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/grammar/ValidSyntax.java
index f82e527..0b95ed9 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/grammar/ValidSyntax.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/grammar/ValidSyntax.java
@@ -1,9 +1,9 @@
/*
* 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.grammar;
@@ -13,10 +13,19 @@
*/
public final class ValidSyntax {
+ /**
+ * Returns the value to use to specify 'proto2' syntax.
+ * @return the {@code String} "proto2".
+ */
public static String proto2() {
return "proto2";
}
+ /**
+ * Indicates whether the given {@code String} is equal to the one returned by <code>{@link #proto2()}</code>.
+ * @param s the {@code String} to check.
+ * @return {@code true} if the given {@code String} is equal to "proto2," {@code false} otherwise.
+ */
public static boolean isProto2Syntax(String s) {
return proto2().equals(s);
}
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 0c9cd7f..e0af64b 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,6 +8,7 @@
*/
package com.google.eclipse.protobuf.linking;
+import static com.google.eclipse.protobuf.util.Objects.*;
import static java.util.Arrays.copyOf;
import static org.eclipse.xtext.util.Arrays.contains;
@@ -72,24 +73,24 @@
}
@Override public int hashCode() {
- final int prime = 31;
+ final int prime = HASH_CODE_PRIME;
int result = 1;
- result = prime * result + ((message == null) ? 0 : message.hashCode());
- result = prime * result + ((node == null) ? 0 : node.hashCode());
+ result = prime * result + hashCodeOf(message);
+ result = prime * result + hashCodeOf(node);
return result;
}
@Override public boolean equals(Object obj) {
- if (this == obj) return true;
- if (obj == null) return false;
- if (getClass() != obj.getClass()) return false;
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || getClass() != obj.getClass()) {
+ return false;
+ }
ProtobufDiagnostic other = (ProtobufDiagnostic) obj;
- if (message == null) {
- if (other.message != null) return false;
- } else if (!message.equals(other.message)) return false;
- if (node == null) {
- if (other.node != null) return false;
- } else if (!node.equals(other.node)) return false;
- return true;
+ if (!areEqual(message, other.message)) {
+ return false;
+ }
+ return areEqual(node, other.node);
}
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/linking/ProtobufResource.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/linking/ProtobufResource.java
index 047baf8..f84f975 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/linking/ProtobufResource.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/linking/ProtobufResource.java
@@ -1,9 +1,9 @@
/*
* 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.linking;
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/FieldOptions.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/FieldOptions.java
index 2567562..0676f91 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/FieldOptions.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/FieldOptions.java
@@ -72,7 +72,9 @@
*/
public IndexedElement sourceOf(CustomFieldOption option) {
IndexedElement e = sourceOfLastFieldIn(option);
- if (e == null) e = rootSourceOf(option);
+ if (e == null) {
+ e = rootSourceOf(option);
+ }
return e;
}
@@ -115,8 +117,11 @@
*/
public IndexedElement sourceOfLastFieldIn(CustomFieldOption option) {
List<OptionField> fields = option.getFields();
- if (fields.isEmpty()) return null;
- OptionField last = fields.get(fields.size() - 1);
+ int fieldCount = fields.size();
+ if (fieldCount == 0) {
+ return null;
+ }
+ OptionField last = fields.get(fieldCount - 1);
return optionFields.sourceOf(last);
}
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/INodes.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/INodes.java
index 525bead..66c8fde 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/INodes.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/INodes.java
@@ -34,7 +34,9 @@
*/
public INode firstNodeForFeature(EObject o, EStructuralFeature feature) {
List<INode> nodes = findNodesForFeature(o, feature);
- if (nodes.isEmpty()) return null;
+ if (nodes.isEmpty()) {
+ return null;
+ }
return nodes.get(0);
}
@@ -76,9 +78,13 @@
}
private static boolean belongsToComment(INode node, String commentRuleName) {
- if (!(node instanceof ILeafNode)) return false;
+ if (!(node instanceof ILeafNode)) {
+ return false;
+ }
EObject o = node.getGrammarElement();
- if (!(o instanceof TerminalRule)) return false;
+ if (!(o instanceof TerminalRule)) {
+ return false;
+ }
TerminalRule rule = (TerminalRule) o;
return commentRuleName.equals(rule.getName());
}
@@ -90,9 +96,13 @@
*/
public boolean belongsToString(INode node) {
EObject grammarElement = node.getGrammarElement();
- if (!(grammarElement instanceof RuleCall)) return false;
+ if (!(grammarElement instanceof RuleCall)) {
+ return false;
+ }
AbstractRule rule = ((RuleCall) grammarElement).getRule();
- if (!(rule instanceof TerminalRule)) return false;
+ if (!(rule instanceof TerminalRule)) {
+ return false;
+ }
TerminalRule terminalRule = (TerminalRule) rule;
return "STRING".equals(terminalRule.getName());
}
@@ -103,8 +113,10 @@
* @return {@code true} if the given node is a hidden leaf node; {@code false} otherwise.
*/
public boolean isHiddenLeafNode(INode node) {
- if (!(node instanceof ILeafNode)) return false;
- return ((ILeafNode) node).isHidden();
+ if (node instanceof ILeafNode) {
+ return ((ILeafNode) node).isHidden();
+ }
+ return false;
}
/**
@@ -113,7 +125,9 @@
* @return the text of the given node, with leading and trailing whitespace omitted.
*/
public String textOf(INode node) {
- if (node == null) return null;
+ if (node == null) {
+ return null;
+ }
String text = node.getText();
return (text == null) ? null : text.trim();
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Imports.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Imports.java
index 1341247..22b556f 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Imports.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Imports.java
@@ -31,7 +31,9 @@
* otherwise.
*/
public boolean hasUnresolvedDescriptorUri(Import anImport) {
- if (anImport == null) return false;
+ if (anImport == null) {
+ return false;
+ }
return descriptorProvider.descriptorLocation(anImport.getImportURI()) != null;
}
@@ -41,12 +43,18 @@
* @return {@code true} if the given import is pointing to descriptor.proto, {@code false} otherwise.
*/
public boolean isImportingDescriptor(Import anImport) {
- if (hasUnresolvedDescriptorUri(anImport)) return true;
- if (anImport == null) return false;
+ if (hasUnresolvedDescriptorUri(anImport)) {
+ return true;
+ }
+ if (anImport == null) {
+ return false;
+ }
String importUri = anImport.getImportURI();
for (URI locationUri : descriptorProvider.allDescriptorLocations()) {
String location = locationUri.toString();
- if (location.equals(importUri)) return true;
+ if (location.equals(importUri)) {
+ return true;
+ }
}
return false;
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/IndexedElements.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/IndexedElements.java
index d01d4cd..0f38084 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/IndexedElements.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/IndexedElements.java
@@ -51,8 +51,13 @@
* is {@code null}.
*/
public long indexOf(IndexedElement e) {
- if (e == null) return Long.MIN_VALUE;
- return (e instanceof Group) ? ((Group) e).getIndex() : ((MessageField) e).getIndex();
+ if (e instanceof Group) {
+ return ((Group) e).getIndex();
+ }
+ if (e instanceof MessageField) {
+ return ((MessageField) e).getIndex();
+ }
+ return Long.MIN_VALUE;
}
/**
@@ -62,8 +67,13 @@
* {@code IndexedElement} is {@code null}.
*/
public EStructuralFeature indexFeatureOf(IndexedElement e) {
- if (e == null) return null;
- return (e instanceof Group) ? GROUP__INDEX : MESSAGE_FIELD__INDEX;
+ if (e instanceof Group) {
+ return GROUP__INDEX;
+ }
+ if (e instanceof MessageField) {
+ return MESSAGE_FIELD__INDEX;
+ }
+ return null;
}
/**
@@ -73,8 +83,13 @@
* {@code null}.
*/
public List<FieldOption> fieldOptionsOf(IndexedElement e) {
- if (e == null) return emptyList();
- return (e instanceof Group) ? ((Group) e).getFieldOptions() : ((MessageField) e).getFieldOptions();
+ if (e instanceof Group) {
+ return ((Group) e).getFieldOptions();
+ }
+ if (e instanceof MessageField) {
+ return ((MessageField) e).getFieldOptions();
+ }
+ return emptyList();
}
/**
@@ -83,12 +98,12 @@
* @param newIndex the new index to set.
*/
public void setIndexTo(IndexedElement e, long newIndex) {
- if (e == null) return;
if (e instanceof Group) {
((Group) e).setIndex(newIndex);
- return;
}
- ((MessageField) e).setIndex(newIndex);
+ if (e instanceof MessageField) {
+ ((MessageField) e).setIndex(newIndex);
+ }
}
/**
@@ -112,7 +127,9 @@
public long calculateTagNumberOf(IndexedElement e) {
long index = 0;
for (EObject o : e.eContainer().eContents()) {
- if (o == e || !(o instanceof IndexedElement)) continue;
+ if (o == e || !(o instanceof IndexedElement)) {
+ continue;
+ }
index = max(index, indexOf((IndexedElement) o));
}
return ++index;
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/MessageFields.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/MessageFields.java
index cd85958..a9964e0 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/MessageFields.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/MessageFields.java
@@ -1,9 +1,9 @@
/*
* 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.model.util;
@@ -17,7 +17,7 @@
/**
* Utility methods related to <code>{@link MessageField}</code>s.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
@Singleton public class MessageFields {
@@ -40,7 +40,9 @@
*/
public boolean isPrimitive(MessageField field) {
TypeLink link = field.getType();
- if (!(link instanceof ScalarTypeLink)) return false;
+ if (!(link instanceof ScalarTypeLink)) {
+ return false;
+ }
String typeName = ((ScalarTypeLink) link).getTarget().getName();
return !STRING.hasValue(typeName) && !BYTES.hasValue(typeName);
}
@@ -105,7 +107,9 @@
if (link instanceof ScalarTypeLink) {
String typeName = ((ScalarTypeLink) link).getTarget().getName();
for (CommonKeyword scalarName : scalarNames) {
- if (scalarName.hasValue(typeName)) return true;
+ if (scalarName.hasValue(typeName)) {
+ return true;
+ }
}
}
return false;
@@ -118,7 +122,9 @@
*/
public String typeNameOf(MessageField field) {
TypeLink link = field.getType();
- if (link instanceof ScalarTypeLink) return ((ScalarTypeLink) link).getTarget().getName();
+ if (link instanceof ScalarTypeLink) {
+ return ((ScalarTypeLink) link).getTarget().getName();
+ }
if (link instanceof ComplexTypeLink) {
ComplexType type = ((ComplexTypeLink) link).getTarget();
return (type == null) ? null : type.getName();
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 bdc18cc..d9877d1 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
@@ -45,7 +45,9 @@
Set<TypeExtension> extensions = new HashSet<TypeExtension>();
for (TypeExtension extension : getAllContentsOfType(root, TypeExtension.class)) {
Message referred = messageFrom(extension);
- if (message.equals(referred)) extensions.add(extension);
+ if (message.equals(referred)) {
+ extensions.add(extension);
+ }
}
return extensions;
}
@@ -57,7 +59,9 @@
*/
public Message messageFrom(TypeExtension extension) {
ExtensibleTypeLink link = extension.getType();
- if (link == null) return null;
+ if (link == null) {
+ return null;
+ }
ExtensibleType type = link.getTarget();
return (type instanceof Message) ? (Message) type : null;
}
@@ -82,7 +86,9 @@
private <T extends ComplexType> T fieldType(MessageField field, Class<T> typeClazz) {
ComplexType type = typeOf(field);
- if (typeClazz.isInstance(type)) return typeClazz.cast(type);
+ if (typeClazz.isInstance(type)) {
+ return typeClazz.cast(type);
+ }
return null;
}
@@ -106,7 +112,9 @@
*/
public ScalarType scalarTypeOf(MessageField p) {
TypeLink link = (p).getType();
- if (link instanceof ScalarTypeLink) return ((ScalarTypeLink) link).getTarget();
+ if (link instanceof ScalarTypeLink) {
+ return ((ScalarTypeLink) link).getTarget();
+ }
return null;
}
@@ -185,7 +193,9 @@
TreeIterator<Object> contents = getAllContents(resource, true);
if (contents.hasNext()) {
Object next = contents.next();
- if (next instanceof Protobuf) return (Protobuf) next;
+ if (next instanceof Protobuf) {
+ return (Protobuf) next;
+ }
}
return null;
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/OptionFields.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/OptionFields.java
index 1f8ea5f..07fc6b8 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/OptionFields.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/OptionFields.java
@@ -1,9 +1,9 @@
/*
* 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.model.util;
@@ -13,7 +13,7 @@
/**
* Utility methods related to fields in <code>{@link Option}</code>s
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
@Singleton public class OptionFields {
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Options.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Options.java
index 725623c..c838c2b 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Options.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/Options.java
@@ -52,7 +52,9 @@
*/
public IndexedElement sourceOf(CustomOption option) {
IndexedElement e = lastFieldSourceFrom(option);
- if (e == null) e = rootSourceOf(option);
+ if (e == null) {
+ e = rootSourceOf(option);
+ }
return e;
}
@@ -86,7 +88,9 @@
*/
public IndexedElement lastFieldSourceFrom(CustomOption option) {
List<OptionField> fields = option.getFields();
- if (fields.isEmpty()) return null;
+ if (fields.isEmpty()) {
+ return null;
+ }
OptionField last = fields.get(fields.size() - 1);
return optionFields.sourceOf(last);
}
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 9dcfdc9..b05e9e9 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
@@ -1,9 +1,9 @@
/*
* 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.model.util;
@@ -20,7 +20,7 @@
/**
* Utility methods related to <code>{@link Package}</code>s.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class Packages {
@@ -35,11 +35,17 @@
* @return {@code true} if the given packages are related; {@code false} otherwise.
*/
public boolean areRelated(Package p1, Package p2) {
- if (p1 == null || p2 == null) return false;
+ if (p1 == null || p2 == null) {
+ return false;
+ }
QualifiedName name1 = nameOf(p1);
QualifiedName name2 = nameOf(p2);
- if (name1 == null || name2 == null) return false;
- if (name1.equals(name2)) return true;
+ if (name1 == null || name2 == null) {
+ return false;
+ }
+ if (name1.equals(name2)) {
+ return true;
+ }
return (isSubPackage(name1, name2));
}
@@ -48,8 +54,12 @@
int segment2Count = segments.size();
int counter = 0;
for (String segment1 : name1.getSegments()) {
- if (!segment1.equals(segments.get(counter++))) return false;
- if (counter == segment2Count) break;
+ if (!segment1.equals(segments.get(counter++))) {
+ return false;
+ }
+ if (counter == segment2Count) {
+ break;
+ }
}
return true;
}
@@ -58,7 +68,9 @@
QualifiedName current = name;
List<String> segments = segmentsOf(p);
int segmentCount = segments.size();
- if (segmentCount <= 1) return emptyList();
+ if (segmentCount <= 1) {
+ return emptyList();
+ }
List<QualifiedName> allNames = new ArrayList<QualifiedName>();
for (int i = segmentCount - 1; i > 0; i--) {
current = QualifiedName.create(segments.get(i)).append(current);
@@ -69,13 +81,17 @@
public List<String> segmentsOf(Package p) {
QualifiedName name = (p == null) ? null : nameOf(p);
- if (name == null) return emptyList();
+ if (name == null) {
+ return emptyList();
+ }
return name.getSegments();
}
private QualifiedName nameOf(Package p) {
String name = p.getName();
- if (isEmpty(name)) return null;
+ if (isEmpty(name)) {
+ return null;
+ }
return converter.toQualifiedName(name);
}
}
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 5e8fc1f..ee7fe40 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
@@ -1,22 +1,22 @@
/*
* 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.model.util;
-import com.google.inject.Singleton;
+import java.util.*;
import org.eclipse.xtext.naming.QualifiedName;
-import java.util.*;
+import com.google.inject.Singleton;
/**
* Utility methods related to <code>{@link QualifiedName}</code>s.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
@Singleton public class QualifiedNames {
@@ -30,7 +30,9 @@
}
public QualifiedName addLeadingDot(QualifiedName name) {
- if (name.getFirstSegment().equals("")) return name;
+ if (name.getFirstSegment().equals("")) {
+ return name;
+ }
List<String> segments = new ArrayList<String>();
segments.addAll(name.getSegments());
segments.add(0, "");
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/IProtobufQualifiedNameProvider.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/IProtobufQualifiedNameProvider.java
index 274b8b0..65f3c8f 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/IProtobufQualifiedNameProvider.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/IProtobufQualifiedNameProvider.java
@@ -1,19 +1,19 @@
/*
* 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.naming;
-import com.google.eclipse.protobuf.protobuf.Group;
-import com.google.inject.ImplementedBy;
-
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.naming.*;
+import com.google.eclipse.protobuf.protobuf.Group;
+import com.google.inject.ImplementedBy;
+
/**
* @author alruiz@google.com (Alex Ruiz)
*/
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 2e4bc9f..d1616e2 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
@@ -1,9 +1,9 @@
/*
* 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.naming;
@@ -13,34 +13,34 @@
import static org.eclipse.xtext.util.Strings.isEmpty;
import static org.eclipse.xtext.util.Tuples.pair;
-import com.google.eclipse.protobuf.model.util.*;
-import com.google.eclipse.protobuf.naming.Naming.NamingUsage;
-import com.google.inject.*;
+import java.util.*;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.naming.*;
import org.eclipse.xtext.util.*;
-import java.util.*;
+import com.google.eclipse.protobuf.model.util.*;
+import com.google.eclipse.protobuf.naming.Naming.NamingUsage;
+import com.google.inject.*;
/**
* Provides alternative qualified names for protobuf elements.
* <p>
* For example, given the following proto element:
- *
+ *
* <pre>
* package test.alternative.names;
- *
+ *
* message Person {
* optional string name = 1;
- *
+ *
* enum PhoneType {
* HOME = 0;
* WORK = 1;
* }
* }
* </pre>
- *
+ *
* The default qualified name for {@code PhoneType} is {@code alternative.names.Person.PhoneType}. The problem is that
* protoc also recognizes the following as qualified names:
* <ul>
@@ -53,7 +53,7 @@
* <p>
* This class provides the non-default qualified names recognized by protoc.
* </p>
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class LocalNamesProvider {
@@ -81,13 +81,17 @@
List<QualifiedName> allNames = new ArrayList<QualifiedName>();
EObject current = e;
String name = naming.nameOf(e, usage);
- if (isEmpty(name)) return emptyList();
+ if (isEmpty(name)) {
+ return emptyList();
+ }
QualifiedName qualifiedName = converter.toQualifiedName(name);
allNames.add(qualifiedName);
while (current.eContainer() != null) {
current = current.eContainer();
String containerName = nameResolver.nameOf(current);
- if (isEmpty(containerName)) continue;
+ if (isEmpty(containerName)) {
+ continue;
+ }
qualifiedName = converter.toQualifiedName(containerName).append(qualifiedName);
allNames.add(qualifiedName);
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/NameResolver.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/NameResolver.java
index 1ec1323..bfbf4e7 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/NameResolver.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/NameResolver.java
@@ -27,7 +27,9 @@
return CommonKeyword.DEFAULT.toString();
}
Object value = nameFeatureOf(o);
- if (value instanceof String) return (String) value;
+ if (value instanceof String) {
+ return (String) value;
+ }
return null;
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/Naming.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/Naming.java
index 826c2ad..69e7771 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/Naming.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/Naming.java
@@ -1,22 +1,22 @@
/*
* 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.naming;
+import org.eclipse.emf.ecore.EObject;
+
import com.google.eclipse.protobuf.model.util.Options;
import com.google.eclipse.protobuf.protobuf.*;
import com.google.inject.*;
-import org.eclipse.emf.ecore.EObject;
-
/**
* Utility methods related to naming.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
@Singleton public class Naming {
@@ -32,14 +32,18 @@
* @return the name of the given object.
*/
String nameOf(EObject e, NamingUsage usage) {
- if (NamingUsage.DEFAULT.equals(usage)) return nameResolver.nameOf(e);
- if (e instanceof IndexedElement) return options.nameForOption((IndexedElement) e);
+ if (NamingUsage.DEFAULT.equals(usage)) {
+ return nameResolver.nameOf(e);
+ }
+ if (e instanceof IndexedElement) {
+ return options.nameForOption((IndexedElement) e);
+ }
return nameResolver.nameOf(e);
}
/**
* Indicates if the name to obtain will be used by a type (default) or an option.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
static enum NamingUsage {
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/ProtobufQualifiedNameProvider.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/ProtobufQualifiedNameProvider.java
index 7bacc62..82501ac 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/ProtobufQualifiedNameProvider.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/ProtobufQualifiedNameProvider.java
@@ -1,9 +1,9 @@
/*
* 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.naming;
@@ -12,12 +12,12 @@
import static org.eclipse.xtext.util.Strings.isEmpty;
import static org.eclipse.xtext.util.Tuples.pair;
+import java.util.List;
+
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.naming.*;
import org.eclipse.xtext.util.*;
-import java.util.List;
-
import com.google.eclipse.protobuf.model.util.*;
import com.google.eclipse.protobuf.naming.Naming.NamingUsage;
import com.google.eclipse.protobuf.protobuf.Package;
@@ -25,7 +25,7 @@
/**
* Provides fully-qualified names for protobuf elements.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class ProtobufQualifiedNameProvider extends IQualifiedNameProvider.AbstractImpl implements
@@ -53,7 +53,9 @@
@Override public QualifiedName get() {
EObject current = e;
String name = naming.nameOf(e, usage);
- if (isEmpty(name)) return null;
+ if (isEmpty(name)) {
+ return null;
+ }
QualifiedName qualifiedName = converter.toQualifiedName(name);
while (current.eContainer() != null) {
current = current.eContainer();
@@ -66,13 +68,21 @@
}
private QualifiedName addPackage(EObject obj, QualifiedName qualifiedName) {
- if (qualifiedName == null || obj instanceof Package) return qualifiedName;
+ if (qualifiedName == null || obj instanceof Package) {
+ return qualifiedName;
+ }
Package p = finder.packageOf(obj);
- if (p == null) return qualifiedName;
+ if (p == null) {
+ return qualifiedName;
+ }
List<String> segments = packages.segmentsOf(p);
- if (segments.isEmpty()) return qualifiedName;
+ if (segments.isEmpty()) {
+ return qualifiedName;
+ }
QualifiedName packageQualifiedName = qualifiedNames.createFqn(segments);
- if (qualifiedName.startsWith(packageQualifiedName)) return qualifiedName;
+ if (qualifiedName.startsWith(packageQualifiedName)) {
+ return qualifiedName;
+ }
return packageQualifiedName.append(qualifiedName);
}
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/parser/NonProto2Protobuf.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/parser/NonProto2Protobuf.java
index 484d306..cba4895 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/parser/NonProto2Protobuf.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/parser/NonProto2Protobuf.java
@@ -1,9 +1,9 @@
/*
* 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.parser;
@@ -12,7 +12,7 @@
/**
* Represents a non-proto2 protocol buffer, which is ignored by the editor.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class NonProto2Protobuf extends ProtobufImpl {
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/parser/Proto2OnlyParser.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/parser/Proto2OnlyParser.java
index 400893e..a4b2d53 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/parser/Proto2OnlyParser.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/parser/Proto2OnlyParser.java
@@ -1,9 +1,9 @@
/*
* 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.parser;
@@ -18,7 +18,7 @@
/**
* Parser that only parses protocol buffers with "proto2" syntax, older syntax is ignored completely.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class Proto2OnlyParser extends ProtobufParser {
@@ -30,27 +30,37 @@
int initialLookAhead) {
IParseResult result = super.doParse(ruleName, in, builder, initialLookAhead);
// TODO ignore this check via preferences in open source version.
- if (isNonProto2(result)) { return new ParseResult(new NonProto2Protobuf(), result.getRootNode(), false); }
+ if (isNonProto2(result)) {
+ return new ParseResult(new NonProto2Protobuf(), result.getRootNode(), false);
+ }
return result;
}
private boolean isNonProto2(IParseResult result) {
- if (!result.hasSyntaxErrors()) return false;
+ if (!result.hasSyntaxErrors()) {
+ return false;
+ }
for (INode node : result.getSyntaxErrors()) {
- if (isNonProto2(node.getSyntaxErrorMessage())) return true;
+ if (isNonProto2(node.getSyntaxErrorMessage())) {
+ return true;
+ }
}
Protobuf root = (Protobuf) result.getRootASTElement();
- if (root != null) {
- if (root.getSyntax() == null) return true;
+ if (root != null && root.getSyntax() == null) {
+ return true;
}
return false;
}
private boolean isNonProto2(SyntaxErrorMessage syntaxErrorMessage) {
- if (syntaxErrorMessage == null) return false;
+ if (syntaxErrorMessage == null) {
+ return false;
+ }
String message = syntaxErrorMessage.getMessage();
for (String nonProto2Keyword : ERRORS_TO_LOOK_FOR) {
- if (message.contains(nonProto2Keyword)) return true;
+ if (message.contains(nonProto2Keyword)) {
+ return true;
+ }
}
return false;
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/resource/ResourceServiceProvider.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/resource/ResourceServiceProvider.java
index 7d2c5a8..c87cb60 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/resource/ResourceServiceProvider.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/resource/ResourceServiceProvider.java
@@ -31,7 +31,9 @@
return findService(((InternalEObject) e).eProxyURI(), serviceType);
}
Resource resource = e.eResource();
- if (resource == null) return null;
+ if (resource == null) {
+ return null;
+ }
return findService(resource.getURI(), serviceType);
}
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/AstWalker.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/AstWalker.java
index 698c656..b385be4 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/AstWalker.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/AstWalker.java
@@ -1,9 +1,9 @@
/*
* 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.scoping;
@@ -70,7 +70,9 @@
private Collection<IEObjectDescription> imported(Protobuf start, ScopeFinder scopeFinder, Object criteria) {
List<Import> allImports = modelFinder.importsIn(start);
- if (allImports.isEmpty()) return emptyList();
+ if (allImports.isEmpty()) {
+ return emptyList();
+ }
ResourceSet resourceSet = start.eResource().getResourceSet();
return imported(allImports, modelFinder.packageOf(start), resourceSet, scopeFinder, criteria);
}
@@ -84,9 +86,13 @@
continue;
}
Resource imported = resources.importedResource(anImport, resourceSet);
- if (imported == null) continue;
+ if (imported == null) {
+ continue;
+ }
Protobuf rootOfImported = modelFinder.rootOf(imported);
- if (!protobufs.isProto2(rootOfImported)) continue;
+ if (!protobufs.isProto2(rootOfImported)) {
+ continue;
+ }
if (rootOfImported != null) {
descriptions.addAll(publicImported(rootOfImported, scopeFinder, criteria));
if (arePackagesRelated(fromImporter, rootOfImported)) {
@@ -101,9 +107,13 @@
}
private Collection<IEObjectDescription> publicImported(Protobuf start, ScopeFinder scopeFinder, Object criteria) {
- if (!protobufs.isProto2(start)) return emptySet();
+ if (!protobufs.isProto2(start)) {
+ return emptySet();
+ }
List<Import> allImports = modelFinder.publicImportsIn(start);
- if (allImports.isEmpty()) return emptyList();
+ if (allImports.isEmpty()) {
+ return emptyList();
+ }
ResourceSet resourceSet = start.eResource().getResourceSet();
return imported(allImports, modelFinder.packageOf(start), resourceSet, scopeFinder, criteria);
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionFieldScopeFinder.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionFieldScopeFinder.java
index dbfc52a..ae9c04f 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionFieldScopeFinder.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionFieldScopeFinder.java
@@ -46,7 +46,9 @@
return options.rootSourceOf(option);
}
});
- if (e != null) return provider.fieldsInTypeOf(e);
+ if (e != null) {
+ return provider.fieldsInTypeOf(e);
+ }
return emptySet();
}
@@ -65,7 +67,9 @@
return fieldOptions.rootSourceOf(option);
}
});
- if (e != null) return provider.fieldsInTypeOf(e);
+ if (e != null) {
+ return provider.fieldsInTypeOf(e);
+ }
return emptySet();
}
@@ -81,7 +85,9 @@
isFirstField = false;
}
if (field == null) {
- if (previous == null) return provider.get();
+ if (previous == null) {
+ return provider.get();
+ }
return optionFields.sourceOf(previous);
}
return null;
@@ -94,20 +100,26 @@
Message fieldType = modelFinder.messageTypeOf((MessageField) e);
for (MessageElement element : fieldType.getElements()) {
IEObjectDescription d = describe(element);
- if (d != null) descriptions.add(d);
+ if (d != null) {
+ descriptions.add(d);
+ }
}
}
if (e instanceof Group) {
for (GroupElement element : ((Group) e).getElements()) {
IEObjectDescription d = describe(element);
- if (d != null) descriptions.add(d);
+ if (d != null) {
+ descriptions.add(d);
+ }
}
}
return descriptions;
}
private IEObjectDescription describe(EObject e) {
- if (!(e instanceof IndexedElement)) return null;
+ if (!(e instanceof IndexedElement)) {
+ return null;
+ }
String name = options.nameForOption((IndexedElement) e);
return create(name, e);
}
@@ -115,13 +127,19 @@
private class ExtensionFieldDescriptorProvider implements IEObjectDescriptionsProvider {
@Override public Collection<IEObjectDescription> fieldsInTypeOf(IndexedElement e) {
- if (!(e instanceof MessageField)) return emptyList();
+ if (!(e instanceof MessageField)) {
+ return emptyList();
+ }
Message fieldType = modelFinder.messageTypeOf((MessageField) e);
- if (fieldType == null) return emptyList();
+ if (fieldType == null) {
+ return emptyList();
+ }
Set<IEObjectDescription> descriptions = new HashSet<IEObjectDescription>();
for (TypeExtension extension : modelFinder.localExtensionsOf(fieldType)) {
for (MessageElement element : extension.getElements()) {
- if (!(element instanceof IndexedElement)) continue;
+ if (!(element instanceof IndexedElement)) {
+ continue;
+ }
IndexedElement current = (IndexedElement) element;
descriptions.addAll(qualifiedNameDescriptions.qualifiedNamesForOption(current));
String name = options.nameForOption(current);
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionScopeFinder.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionScopeFinder.java
index f27edd7..eabf76f 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionScopeFinder.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/CustomOptionScopeFinder.java
@@ -1,9 +1,9 @@
/*
* 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.scoping;
@@ -11,17 +11,17 @@
import static java.util.Collections.emptySet;
import static org.eclipse.xtext.resource.EObjectDescription.create;
+import java.util.*;
+
+import org.eclipse.xtext.naming.QualifiedName;
+import org.eclipse.xtext.resource.IEObjectDescription;
+
import com.google.eclipse.protobuf.model.util.ModelFinder;
import com.google.eclipse.protobuf.naming.LocalNamesProvider;
import com.google.eclipse.protobuf.protobuf.*;
import com.google.eclipse.protobuf.protobuf.Package;
import com.google.inject.Inject;
-import org.eclipse.xtext.naming.QualifiedName;
-import org.eclipse.xtext.resource.IEObjectDescription;
-
-import java.util.*;
-
/**
* @author alruiz@google.com (Alex Ruiz)
*/
@@ -34,7 +34,9 @@
@Override public Collection<IEObjectDescription> imported(Package fromImporter, Package fromImported, Object target,
Object criteria) {
OptionType optionType = optionTypeFrom(criteria);
- if (!isExtendingOptionMessage(target, optionType)) return emptySet();
+ if (!isExtendingOptionMessage(target, optionType)) {
+ return emptySet();
+ }
Set<IEObjectDescription> descriptions = new HashSet<IEObjectDescription>();
TypeExtension extension = (TypeExtension) target;
for (MessageElement e : extension.getElements()) {
@@ -49,7 +51,9 @@
@Override public Collection<IEObjectDescription> local(Object target, Object criteria, int level) {
OptionType optionType = optionTypeFrom(criteria);
- if (!isExtendingOptionMessage(target, optionType)) return emptySet();
+ if (!isExtendingOptionMessage(target, optionType)) {
+ return emptySet();
+ }
Set<IEObjectDescription> descriptions = new HashSet<IEObjectDescription>();
TypeExtension extension = (TypeExtension) target;
for (MessageElement e : extension.getElements()) {
@@ -64,14 +68,20 @@
}
private OptionType optionTypeFrom(Object criteria) {
- if (!(criteria instanceof OptionType)) throw new IllegalArgumentException("Search criteria should be OptionType");
+ if (!(criteria instanceof OptionType)) {
+ throw new IllegalArgumentException("Search criteria should be OptionType");
+ }
return (OptionType) criteria;
}
private boolean isExtendingOptionMessage(Object o, OptionType optionType) {
- if (!(o instanceof TypeExtension)) return false;
+ if (!(o instanceof TypeExtension)) {
+ return false;
+ }
Message message = modelFinder.messageFrom((TypeExtension) o);
- if (message == null) return false;
+ if (message == null) {
+ return false;
+ }
String name = message.getName();
return optionType.messageName().equals(name);
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ExtensionRegistryProvider.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ExtensionRegistryProvider.java
index f4bfdea..5357c24 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ExtensionRegistryProvider.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ExtensionRegistryProvider.java
@@ -1,20 +1,20 @@
/*
* 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.scoping;
-import com.google.inject.*;
-
import org.eclipse.core.runtime.*;
+import com.google.inject.*;
+
/**
* Provider of instances of <code>{@link IExtensionRegistry}</code>.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
@Singleton public class ExtensionRegistryProvider implements Provider<IExtensionRegistry> {
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/FieldNotationScopeFinder.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/FieldNotationScopeFinder.java
index 19a9c3a..ad59afc 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/FieldNotationScopeFinder.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/FieldNotationScopeFinder.java
@@ -1,9 +1,9 @@
/*
* 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.scoping;
@@ -32,13 +32,17 @@
Collection<IEObjectDescription> sourceOfNormalFieldNamesOf(ComplexValue value) {
MessageField source = sourceOf(value);
- if (source == null) return emptySet();
+ if (source == null) {
+ return emptySet();
+ }
return propertiesInTypeOf(source);
}
Collection<IEObjectDescription> sourceOfExtensionFieldNamesOf(ComplexValue value) {
MessageField source = sourceOf(value);
- if (source == null) return emptySet();
+ if (source == null) {
+ return emptySet();
+ }
return propertiesInExtendMessageOf(source);
}
@@ -56,7 +60,9 @@
if (container instanceof ComplexValueField) {
source = sourceOf((ComplexValueField) container);
}
- if (source instanceof MessageField) return (MessageField) source;
+ if (source instanceof MessageField) {
+ return (MessageField) source;
+ }
return null;
}
@@ -83,7 +89,9 @@
// check first in descriptor.proto
for (TypeExtension extension : modelFinder.extensionsOf(fieldType, modelFinder.rootOf(field))) {
for (MessageElement element : extension.getElements()) {
- if (!(element instanceof MessageField)) continue;
+ if (!(element instanceof MessageField)) {
+ continue;
+ }
descriptions.addAll(qualifiedNameDescriptions.qualifiedNames(element));
}
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/IFileUriResolver.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/IFileUriResolver.java
index afb2052..e2337cf 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/IFileUriResolver.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/IFileUriResolver.java
@@ -1,9 +1,9 @@
/*
* 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.scoping;
@@ -15,7 +15,7 @@
/**
* Resolves "import" URIs.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
@ImplementedBy(NullFileUriResolver.class) public interface IFileUriResolver {
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 ddeac6d..46f9693 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
@@ -1,9 +1,9 @@
/*
* 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.scoping;
@@ -12,12 +12,12 @@
import static org.eclipse.xtext.EcoreUtil2.getAllContentsOfType;
import static org.eclipse.xtext.resource.EObjectDescription.create;
-import com.google.eclipse.protobuf.protobuf.*;
-import com.google.eclipse.protobuf.protobuf.Enum;
+import java.util.*;
import org.eclipse.xtext.resource.IEObjectDescription;
-import java.util.*;
+import com.google.eclipse.protobuf.protobuf.*;
+import com.google.eclipse.protobuf.protobuf.Enum;
/**
* @author alruiz@google.com (Alex Ruiz)
@@ -25,7 +25,9 @@
class LiteralDescriptions {
Collection<IEObjectDescription> literalsOf(Enum anEnum) {
- if (anEnum == null) return emptyList();
+ if (anEnum == null) {
+ return emptyList();
+ }
List<IEObjectDescription> descriptions = new ArrayList<IEObjectDescription>();
for (Literal literal : getAllContentsOfType(anEnum, Literal.class)) {
String name = literal.getName();
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 0a499ea..7e00ff6 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
@@ -1,9 +1,9 @@
/*
* 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.scoping;
@@ -11,13 +11,13 @@
import static java.util.Collections.emptyList;
import static org.eclipse.xtext.resource.EObjectDescription.create;
-import com.google.eclipse.protobuf.protobuf.*;
-import com.google.inject.Inject;
+import java.util.*;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.resource.IEObjectDescription;
-import java.util.*;
+import com.google.eclipse.protobuf.protobuf.*;
+import com.google.inject.Inject;
/**
* @author alruiz@google.com (Alex Ruiz)
@@ -37,7 +37,9 @@
private Collection<IEObjectDescription> allSources(EObject option) {
ProtoDescriptor descriptor = descriptorProvider.primaryDescriptor();
Collection<MessageField> optionSources = descriptor.availableOptionsFor(option.eContainer());
- if (optionSources.isEmpty()) return emptyList();
+ if (optionSources.isEmpty()) {
+ return emptyList();
+ }
return describe(optionSources);
}
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 318d115..60b2ca3 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
@@ -1,9 +1,9 @@
/*
* 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.scoping;
@@ -11,15 +11,15 @@
import static java.util.Collections.emptySet;
import static org.eclipse.xtext.resource.EObjectDescription.create;
-import com.google.eclipse.protobuf.model.util.*;
-import com.google.eclipse.protobuf.protobuf.Package;
-import com.google.inject.Inject;
+import java.util.*;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.naming.*;
import org.eclipse.xtext.resource.IEObjectDescription;
-import java.util.*;
+import com.google.eclipse.protobuf.model.util.*;
+import com.google.eclipse.protobuf.protobuf.Package;
+import com.google.inject.Inject;
/**
* @author alruiz@google.com (Alex Ruiz)
@@ -32,7 +32,9 @@
// See issue 161
Collection<IEObjectDescription> intersection(Package fromImporter, Package fromImported, EObject e) {
- if (fromImporter == null || fromImported == null) return emptySet();
+ if (fromImporter == null || fromImported == null) {
+ return emptySet();
+ }
return intersection2(segmentNames(fromImporter), segmentNames(fromImported), e);
}
@@ -51,7 +53,10 @@
break;
}
}
- if (start == 0) return emptySet(); // no intersection found.
+ if (start == 0)
+ {
+ return emptySet(); // no intersection found.
+ }
Set<IEObjectDescription> descriptions = new HashSet<IEObjectDescription>();
QualifiedName fqn = nameProvider.getFullyQualifiedName(e);
List<String> segments = new ArrayList<String>(fqn.getSegments());
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 19c7b43..f18dbc6 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
@@ -1,9 +1,9 @@
/*
* 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.scoping;
@@ -34,7 +34,7 @@
/**
* Contains the elements from descriptor.proto (provided with protobuf's library.)
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class ProtoDescriptor {
@@ -93,17 +93,22 @@
}
private void addOptionTypes() {
- for (OptionType type : OptionType.values())
+ for (OptionType type : OptionType.values()) {
optionsByType.put(type, new LinkedHashMap<String, MessageField>());
+ }
}
private void initContents() {
allTypes.addAll(getAllContentsOfType(root, Message.class));
for (ComplexType t : allTypes) {
- if (!(t instanceof Message)) continue;
+ if (!(t instanceof Message)) {
+ continue;
+ }
Message m = (Message) t;
OptionType type = OPTION_DEFINITION_BY_NAME.get(m.getName());
- if (type == null) continue;
+ if (type == null) {
+ continue;
+ }
initOptions(m, type);
}
}
@@ -123,7 +128,9 @@
}
private void addOption(MessageField optionSource, OptionType type) {
- if (shouldIgnore(optionSource)) return;
+ if (shouldIgnore(optionSource)) {
+ return;
+ }
String name = optionSource.getName();
optionsByType.get(type).put(name, optionSource);
}
@@ -142,9 +149,13 @@
*/
public Collection<MessageField> availableOptionsFor(EObject o) {
EObject target = o;
- if (target instanceof NativeOption) target = target.eContainer();
+ if (target instanceof NativeOption) {
+ target = target.eContainer();
+ }
OptionType type = findOptionTypeForLevelOf(target);
- if (type == null) return emptyList();
+ if (type == null) {
+ return emptyList();
+ }
return optionsOfType(type);
}
@@ -160,9 +171,13 @@
* @return the enum type of the given field or {@code null} if the type of the given field is not enum.
*/
public Enum enumTypeOf(MessageField field) {
- if (field == null) return null;
+ if (field == null) {
+ return null;
+ }
INode node = nodes.firstNodeForFeature(field, MESSAGE_FIELD__TYPE);
- if (node == null) return null;
+ if (node == null) {
+ return null;
+ }
String typeName = node.getText();
return (isEmpty(typeName)) ? null : enumByName(typeName.trim());
}
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 897bb10..b3274a5 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
@@ -1,9 +1,9 @@
/*
* 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.scoping;
@@ -23,7 +23,7 @@
/**
* Provider of <code>{@link ProtoDescriptor}</code>s.
- *
+ *
* @author Alex Ruiz
*/
@Singleton public class ProtoDescriptorProvider {
@@ -48,11 +48,15 @@
public ProtoDescriptor descriptor(String importUri) {
ensureProtoDescriptorsAreCreated();
ProtoDescriptor protoDescriptor = descriptors.get(importUri);
- if (protoDescriptor != null) return protoDescriptor;
+ if (protoDescriptor != null) {
+ return protoDescriptor;
+ }
// URI could have been resolved
URI uri = URI.createURI(importUri);
for (Entry<String, URI> info : descriptorInfos.entrySet()) {
- if (info.getValue().equals(uri)) return descriptor(info.getKey());
+ if (info.getValue().equals(uri)) {
+ return descriptor(info.getKey());
+ }
}
return null;
}
@@ -102,32 +106,44 @@
private ProtoDescriptorInfo additionalDescriptorInfo() {
IConfigurationElement[] config = registry.getConfigurationElementsFor(EXTENSION_ID);
- if (config == null) return defaultDescriptorInfo();
+ if (config == null) {
+ return defaultDescriptorInfo();
+ }
for (IConfigurationElement e : config) {
ProtoDescriptorInfo info = descriptorInfo(e);
- if (info != null) return info;
+ if (info != null) {
+ return info;
+ }
}
return null;
}
private static ProtoDescriptorInfo descriptorInfo(IConfigurationElement e) {
String importUri = e.getAttribute("importUri");
- if (isEmpty(importUri)) return null;
+ if (isEmpty(importUri)) {
+ return null;
+ }
URI location = descriptorLocation(e);
- if (location == null) return null;
+ if (location == null) {
+ return null;
+ }
return new ProtoDescriptorInfo(importUri, location);
}
private static URI descriptorLocation(IConfigurationElement e) {
String path = e.getAttribute("path");
- if (isEmpty(path)) return null;
+ if (isEmpty(path)) {
+ return null;
+ }
StringBuilder uri = new StringBuilder();
uri.append("platform:/plugin/").append(e.getContributor().getName()).append("/").append(path);
return URI.createURI(uri.toString());
}
private void add(ProtoDescriptorInfo descriptorInfo) {
- if (descriptorInfo == null) return;
+ if (descriptorInfo == null) {
+ return;
+ }
primaryImportUri = descriptorInfo.importUri;
descriptorInfos.put(primaryImportUri, descriptorInfo.location);
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufImportUriResolver.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufImportUriResolver.java
index 320a2ed..0a4f851 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufImportUriResolver.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufImportUriResolver.java
@@ -1,9 +1,9 @@
/*
* 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.scoping;
@@ -22,7 +22,7 @@
* This {@link ImportUriResolver} adds "platform:/resource" to any URI if is not specified, so EMF can find the imported
* resource.
* </p>
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class ProtobufImportUriResolver extends ImportUriResolver {
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider.java
index 1883da8..58558d2 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufScopeProvider.java
@@ -1,9 +1,9 @@
/*
* 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.scoping;
@@ -25,9 +25,9 @@
/**
* Custom scoping description.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
- *
+ *
* @see <a href="http://www.eclipse.org/Xtext/documentation/latest/xtext.html#scoping">Xtext Scoping</a>
*/
public class ProtobufScopeProvider extends AbstractDeclarativeScopeProvider implements Scoping {
@@ -162,7 +162,9 @@
}
private Collection<IEObjectDescription> allPossibleSourcesOf(OptionField field) {
- if (field == null) return emptySet();
+ if (field == null) {
+ return emptySet();
+ }
EObject container = field.eContainer();
if (container instanceof CustomOption) {
CustomOption option = (CustomOption) container;
@@ -215,7 +217,9 @@
private Collection<IEObjectDescription> findSources(FieldName name) {
ComplexValue value = container(name);
- if (value == null) return emptySet();
+ if (value == null) {
+ return emptySet();
+ }
if (name instanceof NormalFieldName) { return allPossibleNamesOfNormalFieldsOf(value); }
return allPossibleNamesOfExtensionFieldsOf(value);
}
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 51f60b4..e9a14d7 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
@@ -1,24 +1,24 @@
/*
* 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.scoping;
import static org.eclipse.xtext.resource.EObjectDescription.create;
-import com.google.eclipse.protobuf.model.util.QualifiedNames;
-import com.google.eclipse.protobuf.naming.*;
-import com.google.inject.Inject;
+import java.util.*;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.resource.IEObjectDescription;
-import java.util.*;
+import com.google.eclipse.protobuf.model.util.QualifiedNames;
+import com.google.eclipse.protobuf.naming.IProtobufQualifiedNameProvider;
+import com.google.inject.Inject;
/**
* @author alruiz@google.com (Alex Ruiz)
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ScopeFinder.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ScopeFinder.java
index 488c53c..cc62372 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ScopeFinder.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ScopeFinder.java
@@ -1,19 +1,19 @@
/*
* 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.scoping;
-import com.google.eclipse.protobuf.protobuf.Import;
-import com.google.eclipse.protobuf.protobuf.Package;
+import java.util.Collection;
import org.eclipse.xtext.resource.IEObjectDescription;
-import java.util.Collection;
+import com.google.eclipse.protobuf.protobuf.*;
+import com.google.eclipse.protobuf.protobuf.Package;
/**
* @author alruiz@google.com (Alex Ruiz)
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/Scoping.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/Scoping.java
index 212fad2..9f526bf 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/Scoping.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/Scoping.java
@@ -1,18 +1,18 @@
/*
* 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.scoping;
-import com.google.eclipse.protobuf.protobuf.*;
+import java.util.Collection;
import org.eclipse.xtext.resource.IEObjectDescription;
-import java.util.Collection;
+import com.google.eclipse.protobuf.protobuf.*;
/**
* @author alruiz@google.com (Alex Ruiz)
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/TypeScopeFinder.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/TypeScopeFinder.java
index 7a8719b..a36eae3 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/TypeScopeFinder.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/TypeScopeFinder.java
@@ -1,9 +1,9 @@
/*
* 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.scoping;
@@ -11,16 +11,16 @@
import static java.util.Collections.emptySet;
import static org.eclipse.xtext.resource.EObjectDescription.create;
-import com.google.eclipse.protobuf.naming.LocalNamesProvider;
-import com.google.eclipse.protobuf.protobuf.*;
-import com.google.eclipse.protobuf.protobuf.Package;
-import com.google.inject.Inject;
+import java.util.*;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.resource.IEObjectDescription;
-import java.util.*;
+import com.google.eclipse.protobuf.naming.LocalNamesProvider;
+import com.google.eclipse.protobuf.protobuf.*;
+import com.google.eclipse.protobuf.protobuf.Package;
+import com.google.inject.Inject;
/**
* @author alruiz@google.com (Alex Ruiz)
@@ -34,7 +34,9 @@
@Override public Collection<IEObjectDescription> imported(Package fromImporter, Package fromImported, Object target,
Object criteria) {
- if (!isInstance(target, criteria)) return emptySet();
+ if (!isInstance(target, criteria)) {
+ return emptySet();
+ }
Set<IEObjectDescription> descriptions = new HashSet<IEObjectDescription>();
EObject e = (EObject) target;
descriptions.addAll(qualifiedNamesDescriptions.qualifiedNames(e));
@@ -46,14 +48,18 @@
Set<IEObjectDescription> descriptions = new HashSet<IEObjectDescription>();
ProtoDescriptor descriptor = descriptorProvider.descriptor(anImport.getImportURI());
for (ComplexType type : descriptor.allTypes()) {
- if (!isInstance(type, criteria)) continue;
+ if (!isInstance(type, criteria)) {
+ continue;
+ }
descriptions.addAll(qualifiedNamesDescriptions.qualifiedNames(type));
}
return descriptions;
}
@Override public Collection<IEObjectDescription> local(Object target, Object criteria, int level) {
- if (!isInstance(target, criteria)) return emptySet();
+ if (!isInstance(target, criteria)) {
+ return emptySet();
+ }
EObject e = (EObject) target;
Set<IEObjectDescription> descriptions = new HashSet<IEObjectDescription>();
List<QualifiedName> names = localNamesProvider.names(e);
@@ -71,7 +77,9 @@
}
private Class<?> targetTypeFrom(Object criteria) {
- if (criteria instanceof Class<?>) return (Class<?>) criteria;
+ if (criteria instanceof Class<?>) {
+ return (Class<?>) criteria;
+ }
throw new IllegalArgumentException("Search criteria should be Class<?>");
}
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Closeables.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Closeables.java
index a141bce..88a32ba 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Closeables.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Closeables.java
@@ -1,9 +1,9 @@
/*
* 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;
@@ -12,7 +12,7 @@
/**
* Utility methods related to <code>{@link Closeable}</code>s.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class Closeables {
@@ -23,7 +23,9 @@
* @return {@code false} if the given {@code Closeable} was {@code null}; {@code true} otherwise.
*/
public static boolean closeQuietly(Closeable c) {
- if (c == null) return false;
+ if (c == null) {
+ return false;
+ }
try {
c.close();
} catch (Throwable ignored) {}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/CommonWords.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/CommonWords.java
index 3405700..b74a539 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/CommonWords.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/CommonWords.java
@@ -1,9 +1,9 @@
/*
* 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;
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Encodings.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Encodings.java
index 6c2d8ac..f3cc3f8 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Encodings.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Encodings.java
@@ -1,16 +1,16 @@
/*
* 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;
/**
* Encodings used in this project.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public final class Encodings {
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
new file mode 100644
index 0000000..6b8b0b6
--- /dev/null
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Objects.java
@@ -0,0 +1,45 @@
+/*
+ * 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/util/Strings.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Strings.java
index 0c2c520..0dc138f 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Strings.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/Strings.java
@@ -1,16 +1,16 @@
/*
* 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 {@code String}.s
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public final class Strings {
@@ -21,7 +21,9 @@
* @return the given {@code String} in double quotes, or {@code null} if the given {@code String} is {@code null}.
*/
public static String quote(String s) {
- if (s == null) return s;
+ if (s == null) {
+ return s;
+ }
return "\"" + s + "\"";
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/SystemProperties.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/SystemProperties.java
index 91f7260..fa18ab6 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/SystemProperties.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/util/SystemProperties.java
@@ -1,16 +1,16 @@
/*
* 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;
/**
* System properties.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public final class SystemProperties {
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/DataTypeValidator.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/DataTypeValidator.java
index e0b764c..b40e264 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/DataTypeValidator.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/DataTypeValidator.java
@@ -1,9 +1,9 @@
/*
* 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.validation;
@@ -44,15 +44,25 @@
}
private void checkValueTypeMatchesFieldType(FieldOption option, MessageField field) {
- if (validateBool(option, field)) return;
- if (validateFloatingPointNumber(option, field)) return;
- if (validateInteger(option, field)) return;
- if (validateString(option, field)) return;
+ if (validateBool(option, field)) {
+ return;
+ }
+ if (validateFloatingPointNumber(option, field)) {
+ return;
+ }
+ if (validateInteger(option, field)) {
+ return;
+ }
+ if (validateString(option, field)) {
+ return;
+ }
validateEnumLiteral(option, field);
}
private boolean validateBool(FieldOption option, MessageField field) {
- if (!messageFields.isBool(field)) return false;
+ if (!messageFields.isBool(field)) {
+ return false;
+ }
Value value = option.getValue();
if (!(value instanceof BooleanLink)) {
error(expectedTrueOrFalse, option, FIELD_OPTION__VALUE, EXPECTED_BOOL_ERROR);
@@ -61,7 +71,9 @@
}
private boolean validateFloatingPointNumber(FieldOption option, MessageField field) {
- if (!messageFields.isFloatingPointNumber(field)) return false;
+ if (!messageFields.isFloatingPointNumber(field)) {
+ return false;
+ }
Value value = option.getValue();
if (!(value instanceof DoubleLink) && !isInteger(value)) {
error(expectedNumber, FIELD_OPTION__VALUE);
@@ -70,7 +82,9 @@
}
private boolean validateInteger(FieldOption option, MessageField field) {
- if (!messageFields.isInteger(field)) return false;
+ if (!messageFields.isInteger(field)) {
+ return false;
+ }
Value value = option.getValue();
if (!isInteger(value)) {
error(expectedInteger, FIELD_OPTION__VALUE);
@@ -102,7 +116,9 @@
}
private boolean validateString(FieldOption option, MessageField field) {
- if (!messageFields.isBytes(field) && !messageFields.isString(field)) return false;
+ if (!messageFields.isBytes(field) && !messageFields.isString(field)) {
+ return false;
+ }
Value value = option.getValue();
if (!(value instanceof StringLink)) {
error(expectedString, option, FIELD_OPTION__VALUE, EXPECTED_STRING_ERROR);
@@ -113,7 +129,9 @@
private boolean validateEnumLiteral(FieldOption option, MessageField field) {
Value value = option.getValue();
Enum anEnum = modelFinder.enumTypeOf(field);
- if (anEnum == null) return false;
+ if (anEnum == null) {
+ return false;
+ }
if (!(value instanceof LiteralLink)) {
error(expectedIdentifier, FIELD_OPTION__VALUE);
return true;
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 99c8006..3f03fb9 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
@@ -1,9 +1,9 @@
/*
* 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.validation;
@@ -25,7 +25,7 @@
/**
* Verifies that imports only refer to "proto2" files.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class ImportValidator extends AbstractDeclarativeValidator {
@@ -47,7 +47,9 @@
private void warnIfNonProto2ImportsFound(Resource resource) {
Protobuf root = finder.rootOf(resource);
- if (!protobufs.isProto2(root)) return;
+ if (!protobufs.isProto2(root)) {
+ return;
+ }
ResourceSet resourceSet = resource.getResourceSet();
boolean hasNonProto2 = false;
List<Pair<Import, Resource>> resourcesToCheck = new ArrayList<Pair<Import, Resource>>();
@@ -63,7 +65,9 @@
}
resourcesToCheck.add(pair(anImport, imported));
}
- if (hasNonProto2) return;
+ if (hasNonProto2) {
+ return;
+ }
for (Pair<Import, Resource> p : resourcesToCheck) {
if (hasNonProto2(p, checked, resourceSet)) {
warnNonProto2ImportFoundIn(p.getFirst());
@@ -74,16 +78,24 @@
private boolean hasNonProto2(Pair<Import, Resource> toCheck, Set<URI> checked, ResourceSet resourceSet) {
Protobuf root = finder.rootOf(toCheck.getSecond());
- if (!protobufs.isProto2(root)) return false;
+ if (!protobufs.isProto2(root)) {
+ return false;
+ }
List<Pair<Import, Resource>> resourcesToCheck = new ArrayList<Pair<Import, Resource>>();
for (Import anImport : finder.importsIn(root)) {
Resource imported = resources.importedResource(anImport, resourceSet);
- if (checked.contains(imported.getURI())) continue;
- if (!isProto2(imported)) return true;
+ if (checked.contains(imported.getURI())) {
+ continue;
+ }
+ if (!isProto2(imported)) {
+ return true;
+ }
resourcesToCheck.add(pair(toCheck.getFirst(), imported));
}
for (Pair<Import, Resource> p : resourcesToCheck) {
- if (hasNonProto2(p, checked, resourceSet)) return true;
+ if (hasNonProto2(p, checked, resourceSet)) {
+ return true;
+ }
}
return false;
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/Messages.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/Messages.java
index cbe6877..e9afea3 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/Messages.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/Messages.java
@@ -1,9 +1,9 @@
/*
* 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.validation;
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator.java
index ae65427..eeb76d8 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufJavaValidator.java
@@ -1,9 +1,9 @@
/*
* 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.validation;
@@ -47,12 +47,16 @@
}
@Check public void checkImportIsResolved(Import anImport) {
- if (retryUntilItIsResolved(anImport)) return;
+ if (retryUntilItIsResolved(anImport)) {
+ return;
+ }
error(format(importNotFound, anImport.getImportURI()), IMPORT__IMPORT_URI);
}
private boolean retryUntilItIsResolved(Import anImport) {
- if (isResolved(anImport)) return true;
+ if (isResolved(anImport)) {
+ return true;
+ }
uriResolver.apply(anImport);
return isResolved(anImport);
}
@@ -61,29 +65,42 @@
String importUri = anImport.getImportURI();
if (!isEmpty(importUri)) {
URI uri = URI.createURI(importUri);
- if (!isEmpty(uri.scheme())) return true;
+ if (!isEmpty(uri.scheme())) {
+ return true;
+ }
}
return false;
}
@Check public void checkSyntaxIsProto2(Syntax syntax) {
String name = syntax.getName();
- if (isProto2Syntax(name)) return;
+ if (isProto2Syntax(name)) {
+ return;
+ }
String msg = (name == null) ? expectedSyntaxIdentifier : format(unrecognizedSyntaxIdentifier, name);
error(msg, syntax, SYNTAX__NAME, SYNTAX_IS_NOT_PROTO2_ERROR);
}
@Check public void checkTagNumberIsUnique(IndexedElement e) {
- if (isNameNull(e)) return; // we already show an error if name is null, no need to go further.
+ if (isNameNull(e))
+ {
+ return; // we already show an error if name is null, no need to go further.
+ }
long index = indexedElements.indexOf(e);
EObject container = e.eContainer();
if (container instanceof Message) {
Message message = (Message) container;
for (MessageElement element : message.getElements()) {
- if (!(element instanceof IndexedElement)) continue;
+ if (!(element instanceof IndexedElement)) {
+ continue;
+ }
IndexedElement other = (IndexedElement) element;
- if (other == e) break;
- if (indexedElements.indexOf(other) != index) continue;
+ if (other == e) {
+ break;
+ }
+ if (indexedElements.indexOf(other) != index) {
+ continue;
+ }
QualifiedName messageName = qualifiedNameProvider.getFullyQualifiedName(message);
String msg = format(fieldNumberAlreadyUsed, index, messageName.toString(), indexedElements.nameOf(other));
invalidTagNumberError(msg, e);
@@ -93,9 +110,14 @@
}
@Check public void checkTagNumberIsGreaterThanZero(IndexedElement e) {
- if (isNameNull(e)) return; // we already show an error if name is null, no need to go further.
+ if (isNameNull(e))
+ {
+ return; // we already show an error if name is null, no need to go further.
+ }
long index = indexedElements.indexOf(e);
- if (index > 0) return;
+ if (index > 0) {
+ return;
+ }
String msg = (index == 0) ? fieldNumbersMustBePositive : expectedFieldNumber;
invalidTagNumberError(msg, e);
}
@@ -109,10 +131,14 @@
Protobuf root = (Protobuf) aPackage.eContainer();
for (ProtobufElement e : root.getElements()) {
if (e == aPackage) {
- if (firstFound) error(multiplePackages, aPackage, PACKAGE__NAME, MORE_THAN_ONE_PACKAGE_ERROR);
+ if (firstFound) {
+ error(multiplePackages, aPackage, PACKAGE__NAME, MORE_THAN_ONE_PACKAGE_ERROR);
+ }
return;
}
- if (e instanceof Package && !firstFound) firstFound = true;
+ if (e instanceof Package && !firstFound) {
+ firstFound = true;
+ }
}
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufResourceValidator.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufResourceValidator.java
index 2328725..7583cb0 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufResourceValidator.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufResourceValidator.java
@@ -1,9 +1,9 @@
/*
* 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.validation;
@@ -33,7 +33,7 @@
/**
* Adds support for converting scoping errors into warnings if non-proto2 files are imported.
- *
+ *
* @author alruiz@google.com (Alex Ruiz)
*/
public class ProtobufResourceValidator extends ResourceValidatorImpl {
@@ -43,18 +43,24 @@
@Override public List<Issue> validate(Resource resource, CheckMode mode, CancelIndicator indicator) {
CancelIndicator monitor = indicator == null ? CancelIndicator.NullImpl : indicator;
resolveProxies(resource, monitor);
- if (monitor.isCanceled()) return null;
+ if (monitor.isCanceled()) {
+ return null;
+ }
List<Issue> result = newArrayListWithExpectedSize(resource.getErrors().size() + resource.getWarnings().size());
try {
IAcceptor<Issue> acceptor = createAcceptor(result);
boolean hasNonProto2Import = false;
for (EObject element : resource.getContents()) {
try {
- if (monitor.isCanceled()) return null;
+ if (monitor.isCanceled()) {
+ return null;
+ }
Diagnostic diagnostic = getDiagnostician().validate(element, validationOptions(resource, mode, monitor));
if (!diagnostic.getChildren().isEmpty()) {
for (Diagnostic child : diagnostic.getChildren()) {
- if (importingNonProto2.equals(child.getMessage())) hasNonProto2Import = true;
+ if (importingNonProto2.equals(child.getMessage())) {
+ hasNonProto2Import = true;
+ }
issueFromEValidatorDiagnostic(child, acceptor);
}
} else {
@@ -66,13 +72,17 @@
}
if (mode.shouldCheck(FAST)) {
for (Resource.Diagnostic error : resource.getErrors()) {
- if (monitor.isCanceled()) return null;
+ if (monitor.isCanceled()) {
+ return null;
+ }
Severity severity = ERROR;
if (hasNonProto2Import && isUnresolveReferenceError(error)) {
severity = WARNING;
ProtobufDiagnostic d = (ProtobufDiagnostic) error;
if (!d.getMessage().endsWith(scopingError)) {
- if (!d.getMessage().endsWith(".")) d.appendToMessage(".");
+ if (!d.getMessage().endsWith(".")) {
+ d.appendToMessage(".");
+ }
d.appendToMessage(" ");
d.appendToMessage(scopingError);
}
@@ -80,7 +90,9 @@
issueFromXtextResourceDiagnostic(error, severity, acceptor);
}
for (Resource.Diagnostic warning : resource.getWarnings()) {
- if (monitor.isCanceled()) return null;
+ if (monitor.isCanceled()) {
+ return null;
+ }
issueFromXtextResourceDiagnostic(warning, WARNING, acceptor);
}
}
@@ -103,9 +115,13 @@
}
private boolean isUnresolveReferenceError(Resource.Diagnostic error) {
- if (!(error instanceof ProtobufDiagnostic)) return false;
+ if (!(error instanceof ProtobufDiagnostic)) {
+ return false;
+ }
ProtobufDiagnostic d = (ProtobufDiagnostic) error;
- if (!"org.eclipse.xtext.diagnostics.Diagnostic.Linking".equals(d.getCode())) return false;
+ if (!"org.eclipse.xtext.diagnostics.Diagnostic.Linking".equals(d.getCode())) {
+ return false;
+ }
return error.getMessage().startsWith("Couldn't resolve");
}
}
\ No newline at end of file
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufSyntaxErrorMessageProvider.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufSyntaxErrorMessageProvider.java
index 236aca8..34d2f36 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufSyntaxErrorMessageProvider.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufSyntaxErrorMessageProvider.java
@@ -27,13 +27,19 @@
@Override public SyntaxErrorMessage getSyntaxErrorMessage(IParserErrorContext context) {
String message = context.getDefaultMessage();
EObject currentContext = context.getCurrentContext();
- if (currentContext instanceof MessageField) message = mapToProtocMessage(message, (MessageField) currentContext);
- if (currentContext == null && message.contains("RULE_STRING")) return null;
+ if (currentContext instanceof MessageField) {
+ message = mapToProtocMessage(message, (MessageField) currentContext);
+ }
+ if (currentContext == null && message.contains("RULE_STRING")) {
+ return null;
+ }
return new SyntaxErrorMessage(message, SYNTAX_DIAGNOSTIC);
}
private String mapToProtocMessage(String message, MessageField field) {
- if (message.contains("RULE_ID") && field.getName() == null) return expectedFieldName;
+ if (message.contains("RULE_ID") && field.getName() == null) {
+ return expectedFieldName;
+ }
if (message.equals("mismatched input ';' expecting '='") && field.getIndex() == 0) {
return missingFieldNumber;
}