In progress: [ Issue 60 ] Imported types do not need to be fully-qualified https://code.google.com/p/protobuf-dt/issues/detail?id=60 Working on package name resolution. Code cleanup.
diff --git a/com.google.eclipse.protobuf.test/META-INF/MANIFEST.MF b/com.google.eclipse.protobuf.test/META-INF/MANIFEST.MF index d12e622..72b3f49 100644 --- a/com.google.eclipse.protobuf.test/META-INF/MANIFEST.MF +++ b/com.google.eclipse.protobuf.test/META-INF/MANIFEST.MF
@@ -13,5 +13,5 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.5 Export-Package: com.google.eclipse.protobuf.junit.core, com.google.eclipse.protobuf.junit.matchers, - com.google.eclipse.protobuf.junit.stubs, + com.google.eclipse.protobuf.junit.stubs.resources, com.google.eclipse.protobuf.junit.util
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/protobuf/PackageStub.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/protobuf/PackageStub.java new file mode 100644 index 0000000..12895f5 --- /dev/null +++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/protobuf/PackageStub.java
@@ -0,0 +1,138 @@ +/* + * 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.stubs.protobuf; + +import java.lang.reflect.InvocationTargetException; + +import org.eclipse.emf.common.notify.*; +import org.eclipse.emf.common.util.*; +import org.eclipse.emf.ecore.*; +import org.eclipse.emf.ecore.resource.Resource; + +import com.google.eclipse.protobuf.protobuf.Package; + +/** + * @author alruiz@google.com (Alex Ruiz) + */ +public class PackageStub implements Package { + + private String name; + + public PackageStub() {} + + public PackageStub(String name) { + this.name = name; + } + + /** {@inheritDoc} */ + public EClass eClass() { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + public Resource eResource() { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + public EObject eContainer() { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + public EStructuralFeature eContainingFeature() { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + public EReference eContainmentFeature() { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + public EList<EObject> eContents() { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + public TreeIterator<EObject> eAllContents() { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + public boolean eIsProxy() { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + public EList<EObject> eCrossReferences() { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + public Object eGet(EStructuralFeature feature) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + public Object eGet(EStructuralFeature feature, boolean resolve) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + public void eSet(EStructuralFeature feature, Object newValue) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + public boolean eIsSet(EStructuralFeature feature) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + public void eUnset(EStructuralFeature feature) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + public Object eInvoke(EOperation operation, EList<?> arguments) throws InvocationTargetException { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + public EList<Adapter> eAdapters() { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + public boolean eDeliver() { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + public void eSetDeliver(boolean deliver) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + public void eNotify(Notification notification) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + public String getName() { + return name; + } + + /** {@inheritDoc} */ + public void setName(String value) { + name = value; + } + +}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/FileStub.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/resources/FileStub.java similarity index 99% rename from com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/FileStub.java rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/resources/FileStub.java index d3b036d..524c744 100644 --- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/FileStub.java +++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/resources/FileStub.java
@@ -6,7 +6,7 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.junit.stubs; +package com.google.eclipse.protobuf.junit.stubs.resources; import static java.util.Collections.*;
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/MarkerStub.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/resources/MarkerStub.java similarity index 98% rename from com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/MarkerStub.java rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/resources/MarkerStub.java index 8386a8a..c34ef25 100644 --- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/MarkerStub.java +++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/resources/MarkerStub.java
@@ -6,7 +6,7 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.junit.stubs; +package com.google.eclipse.protobuf.junit.stubs.resources; import static java.util.Collections.unmodifiableMap;
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/ResourceStub.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/resources/ResourceStub.java similarity index 98% rename from com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/ResourceStub.java rename to com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/resources/ResourceStub.java index 3da6b23..45389bc 100644 --- a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/ResourceStub.java +++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/junit/stubs/resources/ResourceStub.java
@@ -6,7 +6,7 @@ * * http://www.eclipse.org/legal/epl-v10.html */ -package com.google.eclipse.protobuf.junit.stubs; +package com.google.eclipse.protobuf.junit.stubs.resources; import static org.eclipse.emf.common.util.URI.createURI;
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/PackageResolver_areRelated_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/PackageResolver_areRelated_Test.java new file mode 100644 index 0000000..23a7935 --- /dev/null +++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/scoping/PackageResolver_areRelated_Test.java
@@ -0,0 +1,44 @@ +/* + * 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.junit.*; + +import com.google.eclipse.protobuf.junit.stubs.protobuf.PackageStub; +import com.google.eclipse.protobuf.protobuf.Package; + +/** + * Tests for <code>{@link PackageResolver#areRelated(Package, Package)}</code>. + * + * @author alruiz@google.com (Alex Ruiz) + */ +public class PackageResolver_areRelated_Test { + + private static PackageResolver resolver; + + @BeforeClass public static void setUpOnce() { + resolver = new PackageResolver(); + } + + private Package p1; + private Package p2; + + @Before public void setUp() { + p1 = new PackageStub("may.the.force.be.with.you"); + p2 = new PackageStub(); + } + + @Test public void should_return_true_if_packages_are_equal() { + p2.setName(p1.getName()); + assertThat(resolver.areRelated(p1, p2), equalTo(true)); + } +}
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 d02e910..481d40d 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
@@ -8,7 +8,7 @@ */ package com.google.eclipse.protobuf.ui.builder; -import static com.google.eclipse.protobuf.junit.stubs.MarkerStub.error; +import static com.google.eclipse.protobuf.junit.stubs.resources.MarkerStub.error; import static org.eclipse.xtext.ui.MarkerTypes.FAST_VALIDATION; import static org.hamcrest.core.IsEqual.equalTo; import static org.junit.Assert.assertThat; @@ -19,8 +19,7 @@ import org.junit.Before; import org.junit.Test; -import com.google.eclipse.protobuf.junit.stubs.FileStub; -import com.google.eclipse.protobuf.junit.stubs.MarkerStub; +import com.google.eclipse.protobuf.junit.stubs.resources.*; /** * Tests for <code>{@link ProtocMarkerFactory#createErrorIfNecessary(String, int)}</code>.
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 043be93..e560ad3 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
@@ -1,16 +1,10 @@ /* - * Created on Jun 2, 2011 + * Copyright (c) 2011 Google Inc. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * 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.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * Copyright @2011 the original author or authors. + * http://www.eclipse.org/legal/epl-v10.html */ package com.google.eclipse.protobuf.ui.editor.syntaxcoloring;
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/DescriptorProvider.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/DescriptorProvider.java index edc0bb1..2ff1323 100644 --- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/DescriptorProvider.java +++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/DescriptorProvider.java
@@ -1,16 +1,10 @@ /* - * Created on May 30, 2011 + * Copyright (c) 2011 Google Inc. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * 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.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * Copyright @2011 the original author or authors. + * http://www.eclipse.org/legal/epl-v10.html */ package com.google.eclipse.protobuf.scoping;
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/LocalNamesProvider.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/LocalNamesProvider.java index b8713b5..5d4f98a 100644 --- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/LocalNamesProvider.java +++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/LocalNamesProvider.java
@@ -29,7 +29,7 @@ * <p> * For example, given the following proto element: * <pre> - * package alternative.names; + * package test.alternative.names; * * message Person { * optional string name = 1; @@ -45,6 +45,8 @@ * <ul> * <li>{@code PhoneType}</li> * <li>{@code Person.PhoneType}</li> + * <li>{@code names.Person.PhoneType}</li> + * <li>{@code test.names.Person.PhoneType}</li> * </ul> * </p> * <p>
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/PackageResolver.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/PackageResolver.java new file mode 100644 index 0000000..16b21b8 --- /dev/null +++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/PackageResolver.java
@@ -0,0 +1,40 @@ +/* + * 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.util.Strings.isEmpty; + +import org.eclipse.xtext.naming.*; + +import com.google.eclipse.protobuf.protobuf.Package; +import com.google.inject.*; + +/** + * @author alruiz@google.com (Alex Ruiz) + */ +@Singleton +class PackageResolver { + + @Inject private final IQualifiedNameConverter converter = new IQualifiedNameConverter.DefaultImpl(); + + boolean areRelated(Package p1, Package p2) { + 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; + return false; + } + + private QualifiedName nameOf(Package p) { + String name = p.getName(); + if (isEmpty(name)) return null; + return converter.toQualifiedName(name); + } +}
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 6d2ddd8..1f9b150 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
@@ -88,6 +88,7 @@ descriptions.add(create(names.get(i), element)); } descriptions.add(create(nameProvider.getFullyQualifiedName(element), 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)); }