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

Unified Diff: pkg/compiler/lib/src/native/enqueue.dart

Issue 971053003: Sets the native name of static native methods by using the @JSName with the @Native tag of the encl… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 | tests/compiler/dart2js_native/static_methods_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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?
« no previous file with comments | « no previous file | tests/compiler/dart2js_native/static_methods_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698