Fixed: [ Issue 69 ] Fully-qualified names can start with a period.
https://code.google.com/p/protobuf-dt/issues/detail?id=69
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/QualifiedNames_addLeadingDot_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/QualifiedNames_addLeadingDot_Test.java
new file mode 100644
index 0000000..ff1cea0
--- /dev/null
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/QualifiedNames_addLeadingDot_Test.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.scoping;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
+
+import org.eclipse.xtext.naming.QualifiedName;
+import org.junit.Test;
+
+/**
+ * Tests for <code>{@link QualifiedNames#addLeadingDot(QualifiedName)}</code>.
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class QualifiedNames_addLeadingDot_Test {
+
+ @Test public void should_add_leading_dot() {
+ QualifiedName name = QualifiedName.create("jedis", "Luke");
+ QualifiedName withLeadingDot = QualifiedNames.addLeadingDot(name);
+ assertThat(withLeadingDot.toString(), equalTo(".jedis.Luke"));
+ }
+
+ @Test public void should_not_add_leading_dot_if_qualified_name_already_has_it() {
+ QualifiedName name = QualifiedName.create("", "jedis", "Luke");
+ QualifiedName withLeadingDot = QualifiedNames.addLeadingDot(name);
+ assertThat(withLeadingDot.toString(), equalTo(".jedis.Luke"));
+ }
+}
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 5a11f2a..68441f6 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
@@ -55,7 +55,6 @@
@Inject private Literals literals;
@Inject private Properties properties;
- /** {@inheritDoc} */
@Override public void completeProtobuf_Syntax(EObject model, Assignment assignment, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
}
@@ -340,11 +339,6 @@
return imageHelper.getImage(images.defaultImage());
}
- @Override public void complete_FieldOption(EObject model, RuleCall ruleCall, ContentAssistContext context,
- ICompletionProposalAcceptor acceptor) {
- System.out.println("complete_FieldOption");
- }
-
@Override public void completeFieldOption_Name(EObject model, Assignment assignment, ContentAssistContext context,
ICompletionProposalAcceptor acceptor) {
Field field = extractFieldFrom(context);
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext
index 1f00280..61a0f2c 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/Protobuf.xtext
@@ -31,7 +31,7 @@
'import' importURI=STRING ';';
QualifiedName:
- Name ('.' Name)*;
+ '.'? Name ('.' Name)*;
Option:
'option' name=Name '=' value=ValueRef ';';
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 562a552..7feb1fb 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
@@ -8,6 +8,7 @@
*/
package com.google.eclipse.protobuf.scoping;
+import static com.google.eclipse.protobuf.scoping.QualifiedNames.addLeadingDot;
import static java.util.Collections.emptyList;
import static org.eclipse.emf.common.util.URI.createURI;
import static org.eclipse.emf.ecore.util.EcoreUtil.getAllContents;
@@ -91,7 +92,7 @@
for (int i = level; i < nameCount; i++) {
descriptions.add(create(names.get(i), element));
}
- descriptions.add(create(nameProvider.getFullyQualifiedName(element), element));
+ descriptions.addAll(fullyQualifiedNamesOf(element));
// TODO investigate if groups can have messages, and if so, add those messages to the scope.
if (element instanceof Message) {
descriptions.addAll(children(element, targetType, level + 1));
@@ -136,7 +137,7 @@
}
return null;
}
-
+
private boolean arePackagesRelated(Package aPackage, EObject root) {
Package p = finder.packageOf(root);
return packageResolver.areRelated(aPackage, p);
@@ -149,7 +150,7 @@
Object next = contents.next();
if (!targetType.isInstance(next)) continue;
T type = targetType.cast(next);
- descriptions.add(create(nameProvider.getFullyQualifiedName(type), type));
+ descriptions.addAll(fullyQualifiedNamesOf(type));
for (QualifiedName name : importedNamesProvider.namesOf(type)) {
descriptions.add(create(name, type));
}
@@ -157,6 +158,14 @@
return descriptions;
}
+ private Collection<IEObjectDescription> fullyQualifiedNamesOf(EObject obj) {
+ List<IEObjectDescription> descriptions = new ArrayList<IEObjectDescription>();
+ QualifiedName fqn = nameProvider.getFullyQualifiedName(obj);
+ descriptions.add(create(fqn, obj));
+ descriptions.add(create(addLeadingDot(fqn), obj));
+ return descriptions;
+ }
+
@SuppressWarnings("unused")
IScope scope_LiteralRef_literal(LiteralRef literalRef, EReference reference) {
EObject container = literalRef.eContainer();
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/QualifiedNames.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/QualifiedNames.java
index 047a80a..23c73cb 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/QualifiedNames.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/QualifiedNames.java
@@ -11,27 +11,34 @@
import static java.util.Collections.*;
import static org.eclipse.xtext.util.Strings.isEmpty;
-import com.google.eclipse.protobuf.protobuf.Package;
+import java.util.*;
import org.eclipse.xtext.naming.*;
-import java.util.*;
+import com.google.eclipse.protobuf.protobuf.Package;
/**
* @author alruiz@google.com (Alex Ruiz)
*/
final class QualifiedNames {
- static List<QualifiedName> addPackageNameSegments(QualifiedName qualifiedName, Package p,
- IQualifiedNameConverter converter) {
- QualifiedName name = qualifiedName;
+ static QualifiedName addLeadingDot(QualifiedName name) {
+ if (name.getFirstSegment().equals("")) return name;
+ List<String> segments = new ArrayList<String>();
+ segments.addAll(name.getSegments());
+ segments.add(0, "");
+ return QualifiedName.create(segments.toArray(new String[segments.size()]));
+ }
+
+ static List<QualifiedName> addPackageNameSegments(QualifiedName name, Package p, IQualifiedNameConverter converter) {
+ QualifiedName current = name;
List<String> segments = fqnSegments(p, converter);
int segmentCount = segments.size();
if (segmentCount <= 1) return emptyList();
List<QualifiedName> allNames = new ArrayList<QualifiedName>();
for (int i = segmentCount - 1; i > 0; i--) {
- name = QualifiedName.create(segments.get(i)).append(name);
- allNames.add(name);
+ current = QualifiedName.create(segments.get(i)).append(current);
+ allNames.add(current);
}
return unmodifiableList(allNames);
}
@@ -42,6 +49,6 @@
if (isEmpty(packageName)) return emptyList();
return converter.toQualifiedName(packageName).getSegments();
}
-
+
private QualifiedNames() {}
}