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

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

Issue 8786002: Check that interface constructors and default class constructors are compatible. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Check that types of constructors parameters are identical Created 9 years 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: 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 c9110ee7ea4685a83edc72d367ea78340a6f961d..906407103377a90da773e4eb67aeb09815ce2695 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.collect.Lists;
import com.google.dart.compiler.ast.DartClass;
import com.google.dart.compiler.ast.DartExpression;
import com.google.dart.compiler.ast.DartField;
@@ -271,4 +272,45 @@ public class Elements {
return getRawName(propertyAccess.getQualifier()) + "." + getRawName(propertyAccess.getName());
}
}
+
+ /**
+ * @return the number of required (not optional/named) parameters in given {@link MethodElement}.
+ */
+ public static int getNumberOfRequiredParameters(MethodElement method) {
+ int num = 0;
+ List<VariableElement> parameters = method.getParameters();
+ for (VariableElement parameter : parameters) {
+ if (!parameter.isNamed()) {
+ num++;
+ }
+ }
+ return num;
+ }
+
+ /**
+ * @return the names for named parameters in given {@link MethodElement}.
+ */
+ public static List<String> getNamedParameters(MethodElement method) {
+ List<String> names = Lists.newArrayList();
+ List<VariableElement> parameters = method.getParameters();
+ for (VariableElement parameter : parameters) {
+ if (parameter.isNamed()) {
+ names.add(parameter.getName());
+ }
+ }
+ return names;
+ }
+
+ /**
+ * @return the names for parameters types in given {@link MethodElement}.
+ */
+ public static List<String> getParameterTypeNames(MethodElement method) {
+ List<String> names = Lists.newArrayList();
+ List<VariableElement> parameters = method.getParameters();
+ for (VariableElement parameter : parameters) {
+ String typeName = parameter.getType().getElement().getName();
+ names.add(typeName);
+ }
+ return names;
+ }
}

Powered by Google App Engine
This is Rietveld 408576698