Add FunctionElement.isDartCoreIdentical
Change-Id: Ic1d2b17b4a6a41148f02b0f5e6b88dd9ef428bb6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/238303 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
committed by
Commit Bot
parent
ba68d0dfee
commit
0b12e3e936
@@ -1237,6 +1237,10 @@ abstract class FunctionElement implements ExecutableElement, LocalElement {
|
||||
/// invoke an undefined method on an object.
|
||||
static final String NO_SUCH_METHOD_METHOD_NAME = "noSuchMethod";
|
||||
|
||||
/// Return `true` if this function represents `identical` from the
|
||||
/// `dart:core` library.
|
||||
bool get isDartCoreIdentical;
|
||||
|
||||
/// Return `true` if the function is an entry point, i.e. a top-level function
|
||||
/// and has the name `main`.
|
||||
bool get isEntryPoint;
|
||||
|
||||
@@ -269,9 +269,9 @@ class _Collector {
|
||||
|
||||
void _methodInvocation(MethodInvocation node) {
|
||||
var arguments = node.argumentList.arguments;
|
||||
if (arguments.length == 2 && node.methodName.name == 'identical') {
|
||||
var library = node.methodName.staticElement?.library;
|
||||
if (library?.isDartCore == true) {
|
||||
if (arguments.length == 2) {
|
||||
var element = node.methodName.staticElement;
|
||||
if (element is FunctionElement && element.isDartCoreIdentical) {
|
||||
collect(arguments[0]);
|
||||
collect(arguments[1]);
|
||||
return;
|
||||
|
||||
@@ -3348,6 +3348,11 @@ class FunctionElementImpl extends ExecutableElementImpl
|
||||
return identifier;
|
||||
}
|
||||
|
||||
@override
|
||||
bool get isDartCoreIdentical {
|
||||
return isStatic && name == 'identical' && library.isDartCore;
|
||||
}
|
||||
|
||||
@override
|
||||
bool get isEntryPoint {
|
||||
return isStatic && displayName == FunctionElement.MAIN_FUNCTION_NAME;
|
||||
|
||||
@@ -418,6 +418,9 @@ class FunctionMember extends ExecutableMember implements FunctionElement {
|
||||
@override
|
||||
Element get enclosingElement => declaration.enclosingElement;
|
||||
|
||||
@override
|
||||
bool get isDartCoreIdentical => declaration.isDartCoreIdentical;
|
||||
|
||||
@override
|
||||
bool get isEntryPoint => declaration.isEntryPoint;
|
||||
|
||||
|
||||
@@ -461,8 +461,7 @@ class MethodInvocationInferrer
|
||||
bool _isIdentical(MethodInvocationImpl node) {
|
||||
var invokedMethod = node.methodName.staticElement;
|
||||
return invokedMethod is FunctionElement &&
|
||||
invokedMethod.name == 'identical' &&
|
||||
invokedMethod.library.isDartCore &&
|
||||
invokedMethod.isDartCoreIdentical &&
|
||||
node.argumentList.arguments.length == 2;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user