Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Unified Diff: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java

Issue 15741017: Issue 8365. Report error when user library imports an internal SDK library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java
diff --git a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java
index c08dc81b49e1b89bc7c773b1e34ccab8347302f2..786cf4415d58dd0736bb4e94d8e04380bfe69722 100644
--- a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java
+++ b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/verifier/ErrorVerifier.java
@@ -114,6 +114,10 @@ import com.google.dart.engine.scanner.Keyword;
import com.google.dart.engine.scanner.KeywordToken;
import com.google.dart.engine.scanner.Token;
import com.google.dart.engine.scanner.TokenType;
+import com.google.dart.engine.sdk.DartSdk;
+import com.google.dart.engine.sdk.SdkLibrary;
+import com.google.dart.engine.source.Source;
+import com.google.dart.engine.source.UriKind;
import com.google.dart.engine.type.FunctionType;
import com.google.dart.engine.type.InterfaceType;
import com.google.dart.engine.type.Type;
@@ -137,6 +141,13 @@ import java.util.Stack;
*/
public class ErrorVerifier extends RecursiveASTVisitor<Void> {
/**
+ * Information about accessors in classes.
+ */
+ private static class ClassAccessorInformation {
+ public HashMap<String, MethodDeclaration> classGettersAndSetters = null;
+ }
+
+ /**
* This enum holds one of four states of a field initialization state through a constructor
* signature, not initialized, initialized in the field declaration, initialized in the field
* formal, and finally, initialized in the initializers list.
@@ -520,6 +531,7 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
@Override
public Void visitImportDirective(ImportDirective node) {
checkForImportDuplicateLibraryName(node);
+ checkForImportInternalLibrary(node);
return super.visitImportDirective(node);
}
@@ -2220,6 +2232,53 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
}
/**
+ * Check that if the visiting library is not system, then any passed library should not be SDK
+ * internal library.
+ *
+ * @param node the import directive to evaluate
+ * @return {@code true} if and only if an error code is generated on the passed node
+ * @see CompileTimeErrorCode#IMPORT_INTERNAL_LIBRARY
+ */
+ private boolean checkForImportInternalLibrary(ImportDirective node) {
+ if (isInSystemLibrary) {
+ return false;
+ }
+ // prepare import element
+ Element element = node.getElement();
+ if (!(element instanceof ImportElement)) {
+ return false;
+ }
+ ImportElement importElement = (ImportElement) element;
+ // prepare imported library
+ LibraryElement importedLibrary = importElement.getImportedLibrary();
+ if (importedLibrary == null) {
+ return false;
+ }
+ // prepare imported library source
+ Source importSource = importedLibrary.getSource();
+ if (importSource == null) {
+ return false;
+ }
+ // should be dart: URI
+ if (importSource.getUriKind() != UriKind.DART_URI) {
+ return false;
+ }
+ // should be private
+ DartSdk sdk = currentLibrary.getContext().getSourceFactory().getDartSdk();
+ String uri = importElement.getUri();
+ SdkLibrary sdkLibrary = sdk.getSdkLibrary(uri);
+ if (sdkLibrary == null) {
+ return false;
+ }
+ if (!sdkLibrary.isInternal()) {
+ return false;
+ }
+ // report problem
+ errorReporter.reportError(CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, node, node.getUri());
+ return true;
+ }
+
+ /**
* This verifies that the passed switch statement case expressions all have the same type.
*
* @param node the switch statement to evaluate
@@ -3364,10 +3423,3 @@ public class ErrorVerifier extends RecursiveASTVisitor<Void> {
return false;
}
}
-
-/**
- * Information about accessors in classes.
- */
-final class ClassAccessorInformation {
- public HashMap<String, MethodDeclaration> classGettersAndSetters = null;
-}

Powered by Google App Engine
This is Rietveld 408576698