Working on fixing scopes.
diff --git a/com.google.eclipse.protobuf.junit/src/com/google/eclipse/protobuf/junit/stubs/MarkerStub.java b/com.google.eclipse.protobuf.junit/src/com/google/eclipse/protobuf/junit/stubs/MarkerStub.java
index 4312479..ee384e6 100644
--- a/com.google.eclipse.protobuf.junit/src/com/google/eclipse/protobuf/junit/stubs/MarkerStub.java
+++ b/com.google.eclipse.protobuf.junit/src/com/google/eclipse/protobuf/junit/stubs/MarkerStub.java
@@ -150,4 +150,30 @@
public int lineNumber() throws CoreException {
return getAttribute(LINE_NUMBER, -1);
}
+
+ @Override public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (obj == null) return false;
+ if (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;
+ }
+
+ @Override public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((attributes == null) ? 0 : attributes.hashCode());
+ result = prime * result + ((type == null) ? 0 : type.hashCode());
+ return result;
+ }
+
+ @Override public String toString() {
+ return "MarkerStub [attributes=" + attributes + "]";
+ }
}
diff --git a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/builder/ProtocMarkerFactory_createErrorIfNecessary_Test.java b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/builder/ProtocMarkerFactory_createErrorIfNecessary_Test.java
index c88b35c..d02e910 100644
--- a/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/builder/ProtocMarkerFactory_createErrorIfNecessary_Test.java
+++ b/com.google.eclipse.protobuf.ui.test/src/com/google/eclipse/protobuf/ui/builder/ProtocMarkerFactory_createErrorIfNecessary_Test.java
@@ -9,7 +9,6 @@
package com.google.eclipse.protobuf.ui.builder;
import static com.google.eclipse.protobuf.junit.stubs.MarkerStub.error;
-import static org.eclipse.core.resources.IMarker.SEVERITY_ERROR;
import static org.eclipse.xtext.ui.MarkerTypes.FAST_VALIDATION;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.junit.Assert.assertThat;
@@ -39,11 +38,9 @@
@Before public void setUp() throws CoreException {
file = new FileStub();
file.createMarker(PROTOC);
- assertThat(file.markerCount(PROTOC), equalTo(1));
fastValidationMarker = error(FAST_VALIDATION, "Expected field name.", 68);
file.addMarker(fastValidationMarker);
markerFactory = new ProtocMarkerFactory(file);
- assertThat(file.markerCount(PROTOC), equalTo(0));
}
@Test public void should_create_marker_if_a_similar_one_does_not_exist() throws CoreException {
@@ -52,10 +49,7 @@
markerFactory.createErrorIfNecessary(message, lineNumber);
List<MarkerStub> markers = file.markers(PROTOC);
assertThat(markers.size(), equalTo(1));
- MarkerStub marker = markers.get(0);
- assertThat(marker.severity(), equalTo(SEVERITY_ERROR));
- assertThat(marker.message(), equalTo(message));
- assertThat(marker.lineNumber(), equalTo(lineNumber));
+ assertThat(markers.get(0), equalTo(error(PROTOC, message, lineNumber)));
}
@Test public void should_not_create_marker_if_a_similar_one_exists() throws CoreException {
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 4af752b..0275d65 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
@@ -10,7 +10,6 @@
import static org.eclipse.emf.common.util.URI.createURI;
import static org.eclipse.emf.ecore.util.EcoreUtil.getAllContents;
-import static org.eclipse.xtext.EcoreUtil2.getAllContentsOfType;
import static org.eclipse.xtext.resource.EObjectDescription.create;
import java.util.ArrayList;
@@ -23,21 +22,14 @@
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.xtext.naming.IQualifiedNameProvider;
+import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.resource.IEObjectDescription;
import org.eclipse.xtext.scoping.IScope;
-import org.eclipse.xtext.scoping.impl.AbstractDeclarativeScopeProvider;
-import org.eclipse.xtext.scoping.impl.ImportUriResolver;
-import org.eclipse.xtext.scoping.impl.SimpleScope;
+import org.eclipse.xtext.scoping.impl.*;
+import com.google.eclipse.protobuf.protobuf.*;
import com.google.eclipse.protobuf.protobuf.Enum;
-import com.google.eclipse.protobuf.protobuf.Import;
-import com.google.eclipse.protobuf.protobuf.Literal;
-import com.google.eclipse.protobuf.protobuf.LiteralRef;
-import com.google.eclipse.protobuf.protobuf.Option;
-import com.google.eclipse.protobuf.protobuf.Property;
-import com.google.eclipse.protobuf.protobuf.Protobuf;
-import com.google.eclipse.protobuf.protobuf.Type;
-import com.google.eclipse.protobuf.protobuf.TypeReference;
+import com.google.eclipse.protobuf.protobuf.Package;
import com.google.eclipse.protobuf.util.ProtobufElementFinder;
import com.google.inject.Inject;
@@ -61,14 +53,38 @@
IScope scope_TypeReference_type(TypeReference typeRef, EReference reference) {
Protobuf root = finder.rootOf(typeRef);
List<IEObjectDescription> descriptions = new ArrayList<IEObjectDescription>();
- for (Type type : getAllContentsOfType(root, Type.class)) {
- descriptions.add(describeUsingQualifiedName(type));
- descriptions.add(create(type.getName(), type));
- }
+ Message message = (Message) typeRef.eContainer().eContainer();
+ addAllTypeDescriptionsInsideRoot(message, descriptions);
descriptions.addAll(importedTypes(root));
return createScope(descriptions);
}
+ private void addAllTypeDescriptionsInsideRoot(Message root, List<IEObjectDescription> descriptions) {
+ TreeIterator<EObject> allContents = root.eAllContents();
+ while (allContents.hasNext()) {
+ EObject element = allContents.next();
+ if (!(element instanceof Type)) continue;
+ Type type = (Type) element;
+ descriptions.addAll(describeUsingQualifiedNames(type));
+ descriptions.add(create(type.getName(), type));
+ }
+ }
+
+ private List<IEObjectDescription> describeUsingQualifiedNames(Type type) {
+ List<IEObjectDescription> descriptions = new ArrayList<IEObjectDescription>();
+ QualifiedName fqn = nameProvider.getFullyQualifiedName(type);
+ descriptions.add(create(fqn, type));
+ QualifiedName fqnWithoutPackage = removePackage(fqn, type);
+ if (fqnWithoutPackage != null) descriptions.add(create(fqnWithoutPackage, type));
+ return descriptions;
+ }
+
+ private QualifiedName removePackage(QualifiedName fqn, Type type) {
+ Package aPackage = finder.packageOf(type);
+ if (aPackage == null) return null;
+ return null;
+ }
+
private List<IEObjectDescription> importedTypes(Protobuf root) {
ResourceSet resourceSet = root.eResource().getResourceSet();
List<IEObjectDescription> descriptions = new ArrayList<IEObjectDescription>();
@@ -86,15 +102,12 @@
while (contents.hasNext()) {
Object next = contents.next();
if (!(next instanceof Type)) continue;
- descriptions.add(describeUsingQualifiedName((Type) next));
+ Type type = (Type) next;
+ descriptions.add(create(nameProvider.getFullyQualifiedName(type), type));
}
return descriptions;
}
- private IEObjectDescription describeUsingQualifiedName(Type type) {
- return create(nameProvider.getFullyQualifiedName(type), type);
- }
-
@SuppressWarnings("unused")
IScope scope_LiteralRef_literal(LiteralRef literalRef, EReference reference) {
EObject container = literalRef.eContainer();