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

Unified Diff: compiler/java/com/google/dart/compiler/resolver/Elements.java

Issue 9124006: Blacklist types from core library, issue 969 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use Set for checking type names. Created 8 years, 11 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
« no previous file with comments | « no previous file | compiler/java/com/google/dart/compiler/resolver/ResolutionContext.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiler/java/com/google/dart/compiler/resolver/Elements.java
diff --git a/compiler/java/com/google/dart/compiler/resolver/Elements.java b/compiler/java/com/google/dart/compiler/resolver/Elements.java
index a8bce5b737be5d41c7fd4f47c66396b93a891634..5d7ced4c0ad0c0345be0feeee88aa79f4010d794 100644
--- a/compiler/java/com/google/dart/compiler/resolver/Elements.java
+++ b/compiler/java/com/google/dart/compiler/resolver/Elements.java
@@ -5,6 +5,7 @@
package com.google.dart.compiler.resolver;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Objects;
import com.google.common.collect.Lists;
import com.google.dart.compiler.Source;
import com.google.dart.compiler.ast.DartClass;
@@ -24,6 +25,7 @@ import com.google.dart.compiler.ast.DartParameter;
import com.google.dart.compiler.ast.DartParameterizedTypeNode;
import com.google.dart.compiler.ast.DartPropertyAccess;
import com.google.dart.compiler.ast.DartSuperExpression;
+import com.google.dart.compiler.ast.DartTypeNode;
import com.google.dart.compiler.ast.DartTypeParameter;
import com.google.dart.compiler.ast.DartUnit;
import com.google.dart.compiler.ast.DartVariable;
@@ -39,6 +41,7 @@ import java.io.File;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.List;
+import java.util.Set;
/**
* Utility and factory methods for elements.
@@ -494,4 +497,43 @@ static FieldElementImplementation fieldFromNode(DartField node,
}
return null;
}
+
+ /**
+ * @return <code>true</code> if the given {@link DartTypeNode} is type with one of the given
+ * names.
+ */
+ public static boolean isTypeNode(DartTypeNode typeNode, Set<String> names) {
+ if (typeNode != null) {
+ DartNode identifier = typeNode.getIdentifier();
+ String typeName = getIdentifierName(identifier);
+ return names.contains(typeName);
+ }
+ return false;
+ }
+
+ /**
+ * @return <code>true</code> if the given {@link DartTypeNode} is type with given name.
+ */
+ public static boolean isTypeNode(DartTypeNode typeNode, String name) {
+ return typeNode != null && isIdentifierName(typeNode.getIdentifier(), name);
+ }
+
+ /**
+ * @return <code>true</code> if the given {@link DartNode} is type identifier with given name.
+ */
+ public static boolean isIdentifierName(DartNode identifier, String name) {
+ String identifierName = getIdentifierName(identifier);
+ return Objects.equal(identifierName, name);
+ }
+
+ /**
+ * @return the name of given {@link DartNode} if it is {@link DartIdentifier}, or
+ * <code>null</code> otherwise.
+ */
+ private static String getIdentifierName(DartNode identifier) {
+ if (identifier != null && identifier instanceof DartIdentifier) {
+ return ((DartIdentifier) identifier).getTargetName();
+ }
+ return null;
+ }
}
« no previous file with comments | « no previous file | compiler/java/com/google/dart/compiler/resolver/ResolutionContext.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698