Chromium Code Reviews| Index: pkg/compiler/lib/src/native/enqueue.dart |
| diff --git a/pkg/compiler/lib/src/native/enqueue.dart b/pkg/compiler/lib/src/native/enqueue.dart |
| index 131ba1844094e411b864e67fefe6ed604501ee8c..92d55860686ede2a59940e7089057a40b4a4b82a 100644 |
| --- a/pkg/compiler/lib/src/native/enqueue.dart |
| +++ b/pkg/compiler/lib/src/native/enqueue.dart |
| @@ -399,7 +399,11 @@ abstract class NativeEnqueuerBase implements NativeEnqueuer { |
| handleMethodAnnotations(Element method) { |
| if (isNativeMethod(method)) { |
| - setNativeName(method); |
| + if (method.isStatic) { |
| + setStaticNativeMethodName(method); |
|
sra1
2015/03/03 02:00:02
better name: setNativeNameForStaticMethod
Harry Terkelsen
2015/03/03 03:02:16
Done.
|
| + } else { |
| + setNativeName(method); |
| + } |
| } |
| } |
| @@ -411,6 +415,36 @@ abstract class NativeEnqueuerBase implements NativeEnqueuer { |
| element.setNative(name); |
| } |
| + /// Sets the native name of the static native method [element], using the |
| + /// following rules: |
| + /// 1. If [element] has a @JSName annotation that is an identifier, qualify |
| + /// that identifier to the @Native name of the enclosing class |
| + /// 2. If [element] has a @JSName annotation that is not an identifier, |
| + /// use the declared @JSName as the expression |
| + /// 3. If [element] does not have a @JSName annotation, qualify the name of |
| + /// the method with the @Native name of the enclosing class. |
| + void setStaticNativeMethodName(Element element) { |
| + String name = findJsNameFromAnnotation(element); |
| + if (name == null) name = element.name; |
| + if (isIdentifier(name)) { |
| + String nativeName = unquote(element.enclosingClass.nativeTagInfo); |
|
sra1
2015/03/03 02:00:02
There is code somewhere that parses the tag info.
Harry Terkelsen
2015/03/03 03:02:16
Done.
|
| + element.setNative('$nativeName.$name'); |
| + } else { |
| + element.setNative(name); |
| + } |
| + } |
| + |
| + bool isIdentifier(String s) => |
| + new RegExp(r'^[a-zA-Z_$][a-zA-Z0-9_$]*$').hasMatch(s); |
|
sra1
2015/03/03 02:00:02
Put regexp in a static class variable so it is not
Harry Terkelsen
2015/03/03 03:02:16
Done.
|
| + |
| + String unquote(String s) { |
| + if (s.length < 2) return s; |
| + if (s[0] == '"' && s[s.length - 1] == '"') { |
| + return s.substring(1, s.length - 1); |
| + } |
| + return s; |
| + } |
| + |
| bool isNativeMethod(FunctionElementX element) { |
| if (!element.library.canUseNative) return false; |
| // Native method? |