[vm/kernel/aot] Fix recognition of native methods after annotations are constant evaluated

This change fixes findNativeName() in package:kernel/transformations/treeshaker
to handle constant evaluated Dart annotations. This function is used from
TFA and kernel tree shaker.

This change is a prerequisite for enabling constant evaluation of annotations.

Change-Id: I40f91cce6b34f0e262db7ae6f0fd98303acbf133
Reviewed-on: https://dart-review.googlesource.com/57401
Reviewed-by: Samir Jindel <sjindel@google.com>
Commit-Queue: Samir Jindel <sjindel@google.com>
This commit is contained in:
Alexander Markov 2018-05-30 19:29:20 +00:00 committed by commit-bot@chromium.org
parent 753d95453c
commit fb4f887eff

View file

@ -1265,6 +1265,16 @@ String findNativeName(Member procedure) {
assert(annotation.arguments.positional.length == 1);
return (annotation.arguments.positional[0] as StringLiteral).value;
}
} else if (annotation is ConstantExpression) {
final constant = annotation.constant;
if (constant is InstanceConstant) {
final Class klass = constant.klass;
if (klass.name == 'ExternalName' &&
klass.enclosingLibrary.importUri.toString() == 'dart:_internal') {
assert(constant.fieldValues.length == 1);
return (constant.fieldValues.values.single as StringConstant).value;
}
}
}
}
}