Merge branch 'master' of https://code.google.com/p/protobuf-dt/
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 b161765..2959fc2 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,16 +10,20 @@
import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.IMPORT__IMPORT_URI;
import static com.google.eclipse.protobuf.validation.Messages.importingNonProto2;
+import static org.eclipse.xtext.util.Tuples.pair;
+
+import java.util.*;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.*;
+import org.eclipse.xtext.util.Pair;
+import org.eclipse.xtext.validation.*;
import com.google.eclipse.protobuf.model.util.*;
import com.google.eclipse.protobuf.parser.NonProto2;
import com.google.eclipse.protobuf.protobuf.*;
import com.google.inject.Inject;
-import org.eclipse.emf.ecore.resource.*;
-import org.eclipse.emf.ecore.resource.Resource.Diagnostic;
-import org.eclipse.xtext.validation.*;
-
/**
* @author alruiz@google.com (Alex Ruiz)
*/
@@ -39,21 +43,52 @@
Protobuf root = finder.rootOf(resource);
if (isNotProto2(root)) return;
ResourceSet resourceSet = resource.getResourceSet();
+ boolean hasNonProto2 = false;
+ List<Pair<Import, Resource>> resourcesToCheck = new ArrayList<Pair<Import, Resource>>();
+ Set<URI> checked = new HashSet<URI>();
+ checked.add(resource.getURI());
for (Import anImport : finder.importsIn(root)) {
Resource imported = resources.importedResource(anImport, resourceSet);
+ checked.add(imported.getURI());
if (isNotProto2(finder.rootOf(imported))) {
- acceptWarning(importingNonProto2, anImport, IMPORT__IMPORT_URI, INSIGNIFICANT_INDEX, null);
+ hasNonProto2 = true;
+ warnNonProto2ImportFoundIn(anImport);
continue;
}
- for (Diagnostic d : imported.getWarnings()) {
- if (importingNonProto2.equals(d.getMessage())) {
- acceptWarning(importingNonProto2, anImport, IMPORT__IMPORT_URI, INSIGNIFICANT_INDEX, null);
- }
+ resourcesToCheck.add(pair(anImport, imported));
+ }
+ if (hasNonProto2) return;
+ for (Pair<Import, Resource> p : resourcesToCheck) {
+ if (hasNonProto2(p, checked, resourceSet)) {
+ warnNonProto2ImportFoundIn(p.getFirst());
+ break;
}
}
}
-
+
+ private boolean hasNonProto2(Pair<Import, Resource> toCheck, Set<URI> checked, ResourceSet resourceSet) {
+ Protobuf root = finder.rootOf(toCheck.getSecond());
+ if (isNotProto2(root)) return false;
+ List<Pair<Import, Resource>> resourcesToCheck = new ArrayList<Pair<Import, Resource>>();
+ for (Import anImport : finder.importsIn(root)) {
+ Resource imported = resources.importedResource(anImport, resourceSet);
+ if (checked.contains(imported.getURI())) continue;
+ if (isNotProto2(finder.rootOf(imported))) {
+ return true;
+ }
+ resourcesToCheck.add(pair(toCheck.getFirst(), imported));
+ }
+ for (Pair<Import, Resource> p : resourcesToCheck) {
+ if (hasNonProto2(p, checked, resourceSet)) return true;
+ }
+ return false;
+ }
+
private boolean isNotProto2(Protobuf root) {
return root instanceof NonProto2;
}
+
+ private void warnNonProto2ImportFoundIn(Import anImport) {
+ acceptWarning(importingNonProto2, anImport, IMPORT__IMPORT_URI, INSIGNIFICANT_INDEX, null);
+ }
}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/Messages.properties b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/Messages.properties
index 7f8eb32..adfad66 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/Messages.properties
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/Messages.properties
@@ -5,7 +5,7 @@
expectedTrueOrFalse = Expected "true" or "false".
fieldNumberAlreadyUsed = Field number %d has already been used in \"%s\" by field \"%s\".
fieldNumbersMustBePositive = Field numbers must be positive integers.
-importingNonProto2 = Importing non-proto2 file. This may result in errors related to unresolved references.
+importingNonProto2 = Importing non-proto2 file (directly or indirectly.) This may cause errors related to unresolved references.
importNotFound = Import \"%s\" was not found.
missingFieldNumber = Missing field number.
multiplePackages = Multiple package definitions.
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufResourceValidator.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufResourceValidator.java
index e16ee7c..b83e052 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufResourceValidator.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/ProtobufResourceValidator.java
@@ -18,7 +18,7 @@
import static org.eclipse.xtext.validation.CheckType.FAST;
import static org.eclipse.xtext.validation.impl.ConcreteSyntaxEValidator.DISABLE_CONCRETE_SYNTAX_EVALIDATOR;
-import com.google.eclipse.protobuf.linking.ProtobufLinkingDiagnostic;
+import java.util.*;
import org.apache.log4j.Logger;
import org.eclipse.emf.common.util.Diagnostic;
@@ -29,7 +29,7 @@
import org.eclipse.xtext.util.*;
import org.eclipse.xtext.validation.*;
-import java.util.*;
+import com.google.eclipse.protobuf.linking.ProtobufLinkingDiagnostic;
/**
* Adds support for converting scoping errors into warnings if non-proto2 files are imported.
@@ -39,7 +39,7 @@
public class ProtobufResourceValidator extends ResourceValidatorImpl {
private static final Logger log = Logger.getLogger(ProtobufResourceValidator.class);
-
+
@Override public List<Issue> validate(Resource resource, CheckMode mode, CancelIndicator indicator) {
CancelIndicator monitor = indicator == null ? CancelIndicator.NullImpl : indicator;
resolveProxies(resource, monitor);
@@ -71,9 +71,11 @@
if (hasNonProto2Import && isUnresolveReferenceError(error)) {
severity = WARNING;
ProtobufLinkingDiagnostic d = (ProtobufLinkingDiagnostic) error;
- if (!d.getMessage().endsWith(".")) d.appendToMessage(".");
- d.appendToMessage(" ");
- d.appendToMessage(scopingError);
+ if (!d.getMessage().endsWith(scopingError)) {
+ if (!d.getMessage().endsWith(".")) d.appendToMessage(".");
+ d.appendToMessage(" ");
+ d.appendToMessage(scopingError);
+ }
}
issueFromXtextResourceDiagnostic(error, severity, acceptor);
}