Code cleanup.
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_belongsToCommentOrString_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_isCommentOrString_Test.java
similarity index 83%
rename from com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_belongsToCommentOrString_Test.java
rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_isCommentOrString_Test.java
index c33619c..1535bac 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_belongsToCommentOrString_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_isCommentOrString_Test.java
@@ -19,11 +19,11 @@
import com.google.eclipse.protobuf.junit.core.XtextRule;
/**
- * Test for <code>{@link INodes#belongsToCommentOrString(INode)}</code>
+ * Test for <code>{@link INodes#isCommentOrString(INode)}</code>
*
* @author alruiz@google.com (Alex Ruiz)
*/
-public class INodes_belongsToCommentOrString_Test {
+public class INodes_isCommentOrString_Test {
@Rule public XtextRule xtext = overrideRuntimeModuleWith(unitTestModule());
private INodes nodes;
@@ -38,7 +38,7 @@
// message Person {}
@Test public void should_return_true_if_node_belongs_to_single_line_comment() {
ILeafNode commentNode = xtext.find("// This is a test.");
- assertTrue(nodes.belongsToCommentOrString(commentNode));
+ assertTrue(nodes.isCommentOrString(commentNode));
}
// syntax = "proto2";
@@ -47,7 +47,7 @@
// message Person {}
@Test public void should_return_true_if_node_belongs_to_multiple_line_comment() {
ILeafNode commentNode = xtext.find("/* This is a test. */");
- assertTrue(nodes.belongsToCommentOrString(commentNode));
+ assertTrue(nodes.isCommentOrString(commentNode));
}
// syntax = "proto2";
@@ -57,7 +57,7 @@
// }
@Test public void should_return_true_if_node_belongs_to_string() {
ILeafNode node = xtext.find("'Alex'");
- assertTrue(nodes.belongsToCommentOrString(node));
+ assertTrue(nodes.isCommentOrString(node));
}
// syntax = "proto2";
@@ -65,6 +65,6 @@
// message Person {}
@Test public void should_return_false_if_node_does_not_belong_to_any_comment_or_string() {
ICompositeNode node = getNode(xtext.root());
- assertFalse(nodes.belongsToCommentOrString(node));
+ assertFalse(nodes.isCommentOrString(node));
}
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_belongsToComment_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_isComment_Test.java
similarity index 86%
rename from com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_belongsToComment_Test.java
rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_isComment_Test.java
index 8f091bf..78336c0 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_belongsToComment_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_isComment_Test.java
@@ -19,11 +19,11 @@
import com.google.eclipse.protobuf.junit.core.XtextRule;
/**
- * Test for <code>{@link INodes#belongsToComment(INode)}</code>
+ * Test for <code>{@link INodes#isComment(INode)}</code>
*
* @author alruiz@google.com (Alex Ruiz)
*/
-public class INodes_belongsToComment_Test {
+public class INodes_isComment_Test {
@Rule public XtextRule xtext = overrideRuntimeModuleWith(unitTestModule());
private INodes nodes;
@@ -38,7 +38,7 @@
// message Person {}
@Test public void should_return_true_if_node_belongs_to_single_line_comment() {
ILeafNode commentNode = xtext.find("// This is a test.");
- assertTrue(nodes.belongsToComment(commentNode));
+ assertTrue(nodes.isComment(commentNode));
}
// syntax = "proto2";
@@ -47,7 +47,7 @@
// message Person {}
@Test public void should_return_true_if_node_belongs_to_multiple_line_comment() {
ILeafNode commentNode = xtext.find("/* This is a test. */");
- assertTrue(nodes.belongsToComment(commentNode));
+ assertTrue(nodes.isComment(commentNode));
}
// syntax = "proto2";
@@ -55,6 +55,6 @@
// message Person {}
@Test public void should_return_false_if_node_does_not_belong_to_any_comment() {
ICompositeNode node = getNode(xtext.root());
- assertFalse(nodes.belongsToComment(node));
+ assertFalse(nodes.isComment(node));
}
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_belongsToMultipleLineComment_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_isMultipleLineComment_Test.java
similarity index 84%
rename from com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_belongsToMultipleLineComment_Test.java
rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_isMultipleLineComment_Test.java
index 3601fd0..b3112dd 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_belongsToMultipleLineComment_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_isMultipleLineComment_Test.java
@@ -19,11 +19,11 @@
import com.google.eclipse.protobuf.junit.core.XtextRule;
/**
- * Test for <code>{@link INodes#belongsToMultipleLineComment(INode)}</code>
+ * Test for <code>{@link INodes#isMultipleLineComment(INode)}</code>
*
* @author alruiz@google.com (Alex Ruiz)
*/
-public class INodes_belongsToMultipleLineComment_Test {
+public class INodes_isMultipleLineComment_Test {
@Rule public XtextRule xtext = overrideRuntimeModuleWith(unitTestModule());
private INodes nodes;
@@ -38,7 +38,7 @@
// message Person {}
@Test public void should_return_true_if_node_belongs_to_multiple_line_comment() {
ILeafNode commentNode = xtext.find("/* This is a test. */");
- assertTrue(nodes.belongsToMultipleLineComment(commentNode));
+ assertTrue(nodes.isMultipleLineComment(commentNode));
}
// syntax = "proto2";
@@ -46,6 +46,6 @@
// message Person {}
@Test public void should_return_false_if_node_does_not_belong_to_single_line_comment() {
ICompositeNode node = getNode(xtext.root());
- assertFalse(nodes.belongsToMultipleLineComment(node));
+ assertFalse(nodes.isMultipleLineComment(node));
}
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_belongsToSingleLineComment_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_isSingleLineComment_Test.java
similarity index 84%
rename from com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_belongsToSingleLineComment_Test.java
rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_isSingleLineComment_Test.java
index 630b218..22a25c7 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_belongsToSingleLineComment_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_isSingleLineComment_Test.java
@@ -19,11 +19,11 @@
import com.google.eclipse.protobuf.junit.core.XtextRule;
/**
- * Test for <code>{@link INodes#belongsToSingleLineComment(INode)}</code>
+ * Test for <code>{@link INodes#isSingleLineComment(INode)}</code>
*
* @author alruiz@google.com (Alex Ruiz)
*/
-public class INodes_belongsToSingleLineComment_Test {
+public class INodes_isSingleLineComment_Test {
@Rule public XtextRule xtext = overrideRuntimeModuleWith(unitTestModule());
private INodes nodes;
@@ -38,7 +38,7 @@
// message Person {}
@Test public void should_return_true_if_node_belongs_to_single_line_comment() {
ILeafNode commentNode = xtext.find("// This is a test.");
- assertTrue(nodes.belongsToSingleLineComment(commentNode));
+ assertTrue(nodes.isSingleLineComment(commentNode));
}
// syntax = "proto2";
@@ -46,6 +46,6 @@
// message Person {}
@Test public void should_return_false_if_node_does_not_belong_to_single_line_comment() {
ICompositeNode node = getNode(xtext.root());
- assertFalse(nodes.belongsToSingleLineComment(node));
+ assertFalse(nodes.isSingleLineComment(node));
}
}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_belongsToString_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_isString_Test.java
similarity index 87%
rename from com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_belongsToString_Test.java
rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_isString_Test.java
index 113c3ec..1adb2e2 100644
--- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_belongsToString_Test.java
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/INodes_isString_Test.java
@@ -19,11 +19,11 @@
import com.google.eclipse.protobuf.junit.core.XtextRule;
/**
- * Tests for <code>{@link INodes#belongsToString(INode)}</code>
+ * Tests for <code>{@link INodes#isString(INode)}</code>
*
* @author alruiz@google.com (Alex Ruiz)
*/
-public class INodes_belongsToString_Test {
+public class INodes_isString_Test {
@Rule public XtextRule xtext = overrideRuntimeModuleWith(unitTestModule());
private INodes nodes;
@@ -39,7 +39,7 @@
// }
@Test public void should_return_true_if_node_belongs_to_string() {
ILeafNode node = xtext.find("'Alex'");
- assertTrue(nodes.belongsToString(node));
+ assertTrue(nodes.isString(node));
}
// syntax = "proto2";
@@ -47,6 +47,6 @@
// message Person {}
@Test public void should_return_false_if_node_does_not_belong_to_string() {
ICompositeNode node = getNode(xtext.root());
- assertFalse(nodes.belongsToString(node));
+ assertFalse(nodes.isString(node));
}
}
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 9f80cbb..eda2424 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
@@ -40,7 +40,7 @@
if (!nodes.isHiddenLeafNode(currentNode)) {
continue;
}
- if (!nodes.belongsToComment(currentNode)) {
+ if (!nodes.isComment(currentNode)) {
continue;
}
String rawComment = ((ILeafNode) currentNode).getText();
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 548c46e..be09d33 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
@@ -88,7 +88,7 @@
int offset = styledText.getCaretOffset();
ContentAssistContext[] context = contextFactory.create(editor.getInternalSourceViewer(), offset, resource);
for (ContentAssistContext c : context) {
- if (nodes.belongsToCommentOrString(c.getCurrentNode())) {
+ if (nodes.isCommentOrString(c.getCurrentNode())) {
continue;
}
EObject model = modelFrom(c);
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 d03dd7e..9994bd5 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
@@ -48,7 +48,7 @@
if (!nodes.isHiddenLeafNode(currentNode)) {
continue;
}
- if (!nodes.belongsToMultipleLineComment(currentNode)) {
+ if (!nodes.isMultipleLineComment(currentNode)) {
continue;
}
String text = ((ILeafNode) currentNode).getText();
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 578453b..4e51b2e 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
@@ -52,7 +52,7 @@
if (!nodes.isHiddenLeafNode(currentNode)) {
continue;
}
- if (!nodes.belongsToSingleLineComment(currentNode)) {
+ if (!nodes.isSingleLineComment(currentNode)) {
continue;
}
String comment = ((ILeafNode) currentNode).getText();
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 286d51e..6d3eaa9 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
@@ -85,10 +85,10 @@
if (node == null) {
return false;
}
- if (nodes.belongsToComment(node)) {
+ if (nodes.isComment(node)) {
return true;
}
- if (nodes.belongsToString(node)) {
+ if (nodes.isString(node)) {
EObject o = findActualSemanticObjectFor(node);
return !(o instanceof Import);
}
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 45a8df4..061e0cc 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
@@ -45,8 +45,8 @@
* @return {@code true} if the given node belongs to a string, or a single- or multi-line comment; {@code false}
* otherwise.
*/
- public boolean belongsToCommentOrString(INode node) {
- return belongsToComment(node) || belongsToString(node);
+ public boolean isCommentOrString(INode node) {
+ return isComment(node) || isString(node);
}
/**
@@ -54,8 +54,8 @@
* @param node the node to check.
* @return {@code true} if the given node belongs to a single- or multiple-line comment; {@code false} otherwise.
*/
- public boolean belongsToComment(INode node) {
- return belongsToSingleLineComment(node) || belongsToMultipleLineComment(node);
+ public boolean isComment(INode node) {
+ return isSingleLineComment(node) || isMultipleLineComment(node);
}
/**
@@ -63,8 +63,8 @@
* @param node the node to check.
* @return {@code true} if the given node belongs to a single-line comment; {@code false} otherwise.
*/
- public boolean belongsToSingleLineComment(INode node) {
- return belongsToComment(node, "SL_COMMENT");
+ public boolean isSingleLineComment(INode node) {
+ return isComment(node, "SL_COMMENT");
}
/**
@@ -72,11 +72,11 @@
* @param node the node to check.
* @return {@code true} if the given node belongs to a multiple-line comment; {@code false} otherwise.
*/
- public boolean belongsToMultipleLineComment(INode node) {
- return belongsToComment(node, "ML_COMMENT");
+ public boolean isMultipleLineComment(INode node) {
+ return isComment(node, "ML_COMMENT");
}
- private static boolean belongsToComment(INode node, String commentRuleName) {
+ private static boolean isComment(INode node, String commentRuleName) {
if (!(node instanceof ILeafNode)) {
return false;
}
@@ -93,7 +93,7 @@
* @param node the node to check.
* @return {@code true} if the given node belongs to a string; {@code false} otherwise.
*/
- public boolean belongsToString(INode node) {
+ public boolean isString(INode node) {
EObject grammarElement = node.getGrammarElement();
if (!(grammarElement instanceof RuleCall)) {
return false;
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 deaef4c..516b167 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
@@ -39,7 +39,8 @@
if (anImport == null) {
return false;
}
- return descriptorProvider.descriptorLocation(anImport.getImportURI()) != null;
+ URI descriptorLocation = descriptorProvider.descriptorLocation(anImport.getImportURI());
+ return descriptorLocation != null;
}
/**
@@ -71,10 +72,7 @@
*/
public String uriAsEnteredByUser(Import anImport) {
INode node = nodes.firstNodeForFeature(anImport, IMPORT__IMPORT_URI);
- if (node == null) {
- return null;
- }
- String text = node.getText();
+ String text = (node == null) ? null : node.getText();
if (text == null) {
return null;
}
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 bfc191d..e744b0b 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
@@ -122,14 +122,14 @@
}
/**
- * Returns the name of the given <code>{@link IndexedElement}</code> used as a source of an option. If the given
- * element is a <code>{@link Group}</code>, this method will return its name in lower case.
- * @param e the given {@code IndexedElement}.
- * @return the name of the given <code>{@link IndexedElement}</code>.
+ * Returns the name of the given <code>{@link IndexedElement}</code> that is being used as a source of an option. If
+ * the given element is a <code>{@link Group}</code>, this method will return its name in lower case.
+ * @param optionSource the given {@code IndexedElement} that is being used as a source of an option.
+ * @return the name of the given {@code IndexedElement}.
*/
- public String nameForOption(IndexedElement e) {
- String name = nameResolver.nameOf(e);
- if (e instanceof Group && !isEmpty(name)) {
+ public String nameForOption(IndexedElement optionSource) {
+ String name = nameResolver.nameOf(optionSource);
+ if (optionSource instanceof Group && !isEmpty(name)) {
name = name.toLowerCase();
}
return name;
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 ab9db8c..aabd384 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
@@ -17,13 +17,13 @@
/**
* @author alruiz@google.com (Alex Ruiz)
*/
-@ImplementedBy(ProtobufQualifiedNameProvider.class) public interface IProtobufQualifiedNameProvider extends
- IQualifiedNameProvider {
+@ImplementedBy(ProtobufQualifiedNameProvider.class)
+public interface IProtobufQualifiedNameProvider extends IQualifiedNameProvider {
/**
- * Returns the qualified name of the given object, to be used in an option. If the given object is a
- * <code>{@link Group}</code>, this methods returns the name in lower case.
+ * Returns the qualified name of the given object, to be used as the name of an option. If the given object is a
+ * <code>{@link Group}</code>, this method returns the name in lower case.
* @param e the given object.
- * @return the qualified name of the given object, to be used in an option.
+ * @return the qualified name of the given object, to be used as the name of an option.
*/
QualifiedName getFullyQualifiedNameForOption(EObject e);
}
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 0ffc30d..0363fac 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
@@ -9,7 +9,6 @@
package com.google.eclipse.protobuf.naming;
import static com.google.common.collect.Lists.newArrayList;
-import static com.google.eclipse.protobuf.naming.Naming.NamingUsage.*;
import static java.util.Collections.*;
import static org.eclipse.xtext.util.Strings.isEmpty;
import static org.eclipse.xtext.util.Tuples.pair;
@@ -21,7 +20,6 @@
import org.eclipse.xtext.util.*;
import com.google.eclipse.protobuf.model.util.*;
-import com.google.eclipse.protobuf.naming.Naming.NamingUsage;
import com.google.inject.*;
/**
@@ -63,24 +61,24 @@
@Inject private ModelFinder finder;
@Inject private NameResolver nameResolver;
- @Inject private Naming naming;
+ @Inject private NamingStrategies namingStrategies;
@Inject private Packages packages;
public List<QualifiedName> names(EObject e) {
- return allNames(e, DEFAULT);
+ return allNames(e, namingStrategies.normal());
}
public List<QualifiedName> namesForOption(EObject e) {
- return allNames(e, OPTION);
+ return allNames(e, namingStrategies.option());
}
- private List<QualifiedName> allNames(final EObject e, final NamingUsage usage) {
+ private List<QualifiedName> allNames(final EObject e, final NamingStrategy naming) {
Pair<EObject, String> key = pair(e, "localFqns");
return cache.get(key, e.eResource(), new Provider<List<QualifiedName>>() {
@Override public List<QualifiedName> get() {
List<QualifiedName> allNames = newArrayList();
EObject current = e;
- String name = naming.nameOf(e, usage);
+ String name = naming.nameOf(e);
if (isEmpty(name)) {
return emptyList();
}
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
deleted file mode 100644
index 62b3229..0000000
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/Naming.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright (c) 2011 Google Inc.
- *
- * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
- * Public License v1.0 which accompanies this distribution, and is available at
- *
- * http://www.eclipse.org/legal/epl-v10.html
- */
-package com.google.eclipse.protobuf.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.*;
-
-/**
- * Utility methods related to naming.
- *
- * @author alruiz@google.com (Alex Ruiz)
- */
-@Singleton public class Naming {
- @Inject private NameResolver nameResolver;
- @Inject private Options options;
-
- /**
- * Returns the name of the given object. If the name will be used for an option and if the given object is a
- * <code>{@link Group}</code>, this method will return the name of the group in lower case.
- * @param e the given object.
- * @param usage indicates how the returned name will be used.
- * @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);
- }
- 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 {
- DEFAULT, OPTION;
- }
-}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/NamingStrategies.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/NamingStrategies.java
new file mode 100644
index 0000000..edc615a
--- /dev/null
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/NamingStrategies.java
@@ -0,0 +1,35 @@
+/*
+ * 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.model.util.Options;
+import com.google.inject.*;
+
+/**
+ * Utility methods related to naming.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+@Singleton public class NamingStrategies {
+ private final NamingStrategy normal;
+ private final NamingStrategy option;
+
+ @Inject public NamingStrategies(NameResolver nameResolver, Options options) {
+ normal = new NormalNamingStrategy(nameResolver);
+ option = new OptionNamingStrategy(nameResolver, options);
+ }
+
+ NamingStrategy normal() {
+ return normal;
+ }
+
+ NamingStrategy option() {
+ return option;
+ }
+}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/NamingStrategy.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/NamingStrategy.java
new file mode 100644
index 0000000..0a82786
--- /dev/null
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/NamingStrategy.java
@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2012 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;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+interface NamingStrategy {
+ String nameOf(EObject e);
+}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/NormalNamingStrategy.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/NormalNamingStrategy.java
new file mode 100644
index 0000000..e25a1ef
--- /dev/null
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/NormalNamingStrategy.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2012 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;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+class NormalNamingStrategy implements NamingStrategy {
+ private final NameResolver nameResolver;
+
+ public NormalNamingStrategy(NameResolver nameResolver) {
+ this.nameResolver = nameResolver;
+ }
+
+ @Override public String nameOf(EObject e) {
+ return nameResolver.nameOf(e);
+ }
+}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/OptionNamingStrategy.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/OptionNamingStrategy.java
new file mode 100644
index 0000000..0483fdd
--- /dev/null
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/OptionNamingStrategy.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2012 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.IndexedElement;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+class OptionNamingStrategy implements NamingStrategy {
+ private final NameResolver nameResolver;
+ private final Options options;
+
+ OptionNamingStrategy(NameResolver nameResolver, Options options) {
+ this.nameResolver = nameResolver;
+ this.options = options;
+ }
+
+
+ @Override public String nameOf(EObject e) {
+ if (e instanceof IndexedElement) {
+ return options.nameForOption((IndexedElement) e);
+ }
+ return nameResolver.nameOf(e);
+ }
+}
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 c6f458d..585ee20 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
@@ -8,7 +8,6 @@
*/
package com.google.eclipse.protobuf.naming;
-import static com.google.eclipse.protobuf.naming.Naming.NamingUsage.*;
import static org.eclipse.xtext.util.Strings.isEmpty;
import static org.eclipse.xtext.util.Tuples.pair;
@@ -19,7 +18,6 @@
import org.eclipse.xtext.util.*;
import com.google.eclipse.protobuf.model.util.*;
-import com.google.eclipse.protobuf.naming.Naming.NamingUsage;
import com.google.eclipse.protobuf.protobuf.Package;
import com.google.inject.*;
@@ -34,31 +32,31 @@
@Inject private final IResourceScopeCache cache = IResourceScopeCache.NullImpl.INSTANCE;
@Inject private ModelFinder finder;
- @Inject private Naming naming;
+ @Inject private NamingStrategies namingStrategies;
@Inject private Packages packages;
@Inject private QualifiedNames qualifiedNames;
@Override public QualifiedName getFullyQualifiedName(EObject e) {
- return getFullyQualifiedName(e, DEFAULT);
+ return getFullyQualifiedName(e, namingStrategies.normal());
}
@Override public QualifiedName getFullyQualifiedNameForOption(EObject e) {
- return getFullyQualifiedName(e, OPTION);
+ return getFullyQualifiedName(e, namingStrategies.option());
}
- private QualifiedName getFullyQualifiedName(final EObject e, final NamingUsage usage) {
+ private QualifiedName getFullyQualifiedName(final EObject e, final NamingStrategy naming) {
Pair<EObject, String> key = pair(e, "fqn");
return cache.get(key, e.eResource(), new Provider<QualifiedName>() {
@Override public QualifiedName get() {
EObject current = e;
- String name = naming.nameOf(e, usage);
+ String name = naming.nameOf(e);
if (isEmpty(name)) {
return null;
}
QualifiedName qualifiedName = converter.toQualifiedName(name);
while (current.eContainer() != null) {
current = current.eContainer();
- QualifiedName parentsQualifiedName = getFullyQualifiedName(current, usage);
+ QualifiedName parentsQualifiedName = getFullyQualifiedName(current, naming);
if (parentsQualifiedName != null) { return parentsQualifiedName.append(qualifiedName); }
}
return addPackage(e, qualifiedName);