Fixed: [Issue 12] Make editor find type references to match behavior of protoc https://code.google.com/p/protobuf-dt/issues/detail?id=12 I think I got it right. Need more testing.
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/ProtobufRuntimeModule.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/ProtobufRuntimeModule.java index 929812b..c08fba0 100644 --- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/ProtobufRuntimeModule.java +++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/ProtobufRuntimeModule.java
@@ -8,11 +8,9 @@ */ package com.google.eclipse.protobuf; -import org.eclipse.xtext.naming.IQualifiedNameProvider; -import org.eclipse.xtext.scoping.IGlobalScopeProvider; -import org.eclipse.xtext.scoping.impl.*; +import org.eclipse.xtext.scoping.impl.ImportUriResolver; +import org.eclipse.xtext.scoping.impl.LoadOnDemandResourceDescriptions; -import com.google.eclipse.protobuf.naming.ProtobufQualifiedNameProvider; import com.google.eclipse.protobuf.scoping.ResourceDescriptions; import com.google.eclipse.protobuf.scoping.SimpleImportUriResolver; import com.google.inject.Binder; @@ -22,16 +20,6 @@ */ public class ProtobufRuntimeModule extends com.google.eclipse.protobuf.AbstractProtobufRuntimeModule { - /** {@inheritDoc} */ - @Override public Class<? extends IGlobalScopeProvider> bindIGlobalScopeProvider() { - return ImportUriGlobalScopeProvider.class; - } - - /** {@inheritDoc} */ - @Override public Class<? extends IQualifiedNameProvider> bindIQualifiedNameProvider() { - return ProtobufQualifiedNameProvider.class; - } - public void configureImportUriResolver(Binder binder) { binder.bind(ImportUriResolver.class).to(SimpleImportUriResolver.class); }
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 deleted file mode 100644 index a45f1bb..0000000 --- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/naming/ProtobufQualifiedNameProvider.java +++ /dev/null
@@ -1,56 +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 java.util.*; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.xtext.naming.*; - -import com.google.eclipse.protobuf.protobuf.Package; -import com.google.eclipse.protobuf.util.EObjectFinder; -import com.google.inject.Inject; - -/** - * Provides fully-qualified names for protobuf elements. - * - * @author alruiz@google.com (Alex Ruiz) - */ -public class ProtobufQualifiedNameProvider extends DefaultDeclarativeQualifiedNameProvider { - - @Inject private EObjectFinder finder; - - /** {@inheritDoc} */ - @Override public QualifiedName getFullyQualifiedName(EObject obj) { - QualifiedName qualifiedName = super.getFullyQualifiedName(obj); - if (qualifiedName == null || obj instanceof Package) return qualifiedName; - Package p = finder.findPackage(obj); - if (p == null) return qualifiedName; - List<String> newQualifiedNameSegments = new ArrayList<String>(); - List<String> qualifiedNameSegments = qualifiedName.getSegments(); - String packageName = p.getName(); - if (packageName != null) { - String[] packageNameSegments = packageName.split("\\."); - if (!qualifiedNameContainsPackageName(qualifiedNameSegments, packageNameSegments)) { - // add package to the new FQN - for (String packageSegment : packageNameSegments) newQualifiedNameSegments.add(packageSegment); - } - } - newQualifiedNameSegments.addAll(qualifiedNameSegments); - return QualifiedName.create(newQualifiedNameSegments.toArray(new String[newQualifiedNameSegments.size()])); - } - - private boolean qualifiedNameContainsPackageName(List<String> qualifiedNameSegments, String[] packageNameSegments) { - int packageNameSegmentCount = packageNameSegments.length; - if (qualifiedNameSegments.size() <= packageNameSegmentCount) return false; - for (int i = 0; i < packageNameSegmentCount; i++) - if (!qualifiedNameSegments.get(i).equals(packageNameSegments[i])) return false; - return true; - } -}