Fixed broken import validation Change-Id: Iebbacf2bf6783f8b7baa5d0b5314a7c5d27a6e49
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 8fa6a93..c4e0f70 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
@@ -12,6 +12,7 @@ import static org.eclipse.xtext.util.Strings.isEmpty; import com.google.eclipse.protobuf.protobuf.Import; +import com.google.eclipse.protobuf.protobuf.StringLiteral; import com.google.eclipse.protobuf.resource.ResourceSets; import com.google.eclipse.protobuf.scoping.IImportResolver; import com.google.eclipse.protobuf.scoping.ProtoDescriptorProvider; @@ -22,6 +23,7 @@ import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.jdt.annotation.Nullable; /** * Utility methods related to imports. @@ -35,26 +37,28 @@ @Inject private IImportResolver importResolver; /** - * Indicates whether the URI of the given {@code Import} is equal to the path of the file "descriptor.proto." + * Indicates whether the URI of the given {@code Import} is equal to the path of the file + * "descriptor.proto." + * * @param anImport the {@code Import} to check. - * @return {@code true} if the URI of the given {@code Import} is equal to the path of the file "descriptor.proto," - * {@code false} - * otherwise. + * @return {@code true} if the URI of the given {@code Import} is equal to the path of the file + * "descriptor.proto," {@code false} otherwise. */ public boolean hasUnresolvedDescriptorUri(Import anImport) { if (anImport == null) { return false; } IProject project = EResources.getProjectOf(anImport.eResource()); - URI descriptorLocation = - descriptorProvider.descriptorLocation(project, getPath(anImport)); + URI descriptorLocation = descriptorProvider.descriptorLocation(project, getPath(anImport)); return descriptorLocation != null; } /** * Indicates whether the given {@code Import} is pointing to descriptor.proto. + * * @param anImport the given {@code Import} to check. - * @return {@code true} if the given {@code Import} is pointing to descriptor.proto, {@code false} otherwise. + * @return {@code true} if the given {@code Import} is pointing to descriptor.proto, {@code false} + * otherwise. */ public boolean isImportingDescriptor(Import anImport) { if (hasUnresolvedDescriptorUri(anImport)) { @@ -76,8 +80,10 @@ /** * Indicates whether the URI of the given {@code Import} can be resolved. + * * @param anImport the given {@code Import}. - * @return {@code true} if the URI of the given {@code Import} can be resolved, {@code false} otherwise. + * @return {@code true} if the URI of the given {@code Import} can be resolved, {@code false} + * otherwise. */ public boolean isResolved(Import anImport) { return resolvedUriOf(anImport) != null; @@ -85,9 +91,10 @@ /** * Returns the resource referred by the URI of the given {@code Import}. + * * @param anImport the given {@code Import}. - * @return the resource referred by the URI of the given {@code Import}, or {@code null} if the URI has not been - * resolved. + * @return the resource referred by the URI of the given {@code Import}, or {@code null} if the + * URI has not been resolved. */ public Resource importedResource(Import anImport) { URI resolvedUri = resolvedUriOf(anImport); @@ -100,8 +107,10 @@ /** * Returns the resolved URI of the given {@code Import}. + * * @param anImport the the given {@code Import}. - * @return the resolved URI of the given {@code Import}, or {@code null} if the URI was not successfully resolved. + * @return the resolved URI of the given {@code Import}, or {@code null} if the URI was not + * successfully resolved. */ public URI resolvedUriOf(Import anImport) { String resolvedUri = importResolver.resolve(anImport); @@ -117,9 +126,14 @@ } /** - * Returns the path that is being imported by the given {@link Import}. + * Returns the path that is being imported by the given {@link Import} as a {@code String} or null + * if the {@code anImport.getPath()} is null. */ - public String getPath(Import anImport) { - return stringLiterals.getCombinedString(anImport.getPath()); + public @Nullable String getPath(Import anImport) { + StringLiteral path = anImport.getPath(); + if (path != null) { + return stringLiterals.getCombinedString(path); + } + return null; } }
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufImportUriGlobalScopeProvider.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufImportUriGlobalScopeProvider.java index 0edb1a1..edc7eae 100644 --- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufImportUriGlobalScopeProvider.java +++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/scoping/ProtobufImportUriGlobalScopeProvider.java
@@ -81,9 +81,9 @@ private void resolveImport(LinkedHashSet<URI> importedUris, Import singleImport) { if (imports.isResolved(singleImport)) { - importedUris.add(imports.resolvedUriOf(singleImport)); Protobuf root = resources.rootOf(imports.importedResource(singleImport)); if (root != null) { + importedUris.add(imports.resolvedUriOf(singleImport)); addPublicImportedUris(root, importedUris); } } else if (imports.hasUnresolvedDescriptorUri(singleImport)) {
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ImportValidator.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ImportValidator.java index b418506..f03df7f 100644 --- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ImportValidator.java +++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ImportValidator.java
@@ -10,7 +10,7 @@ import static com.google.common.collect.Maps.newHashMap; import static com.google.common.collect.Sets.newHashSet; -import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.PACKAGE__IMPORTED_NAMESPACE; +import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.IMPORT__PATH; import static com.google.eclipse.protobuf.validation.Messages.importNotFound; import static com.google.eclipse.protobuf.validation.Messages.importingUnsupportedSyntax; import static java.lang.String.format; @@ -111,7 +111,7 @@ } private void warnUnsupportedImportFoundIn(Import anImport) { - warning(importingUnsupportedSyntax, anImport, PACKAGE__IMPORTED_NAMESPACE, INSIGNIFICANT_INDEX); + warning(importingUnsupportedSyntax, anImport, IMPORT__PATH, INSIGNIFICANT_INDEX); } /** @@ -125,7 +125,7 @@ if (imports.isResolved(anImport)) { return; } - error(format(importNotFound, imports.getPath(anImport)), PACKAGE__IMPORTED_NAMESPACE); + error(format(importNotFound, imports.getPath(anImport)), IMPORT__PATH); } private static enum HasKnownSyntax {