Report UNRESOLVED_INSTANCE_MEMBER_REFERENCE for dynamicVar.member references.

R=brianwilkerson@google.com
BUG=

Review URL: https://codereview.chromium.org//1345943006 .
This commit is contained in:
Konstantin Shcheglov 2015-09-17 10:37:04 -07:00
parent 1a6daab9d1
commit 75600fc162
2 changed files with 94 additions and 0 deletions

View file

@ -96,6 +96,9 @@ class DartUnitHighlightsComputer2 {
if (_addIdentifierRegion_typeParameter(node)) {
return;
}
if (_addIdentifierRegion_unresolvedInstanceMemberReference(node)) {
return;
}
_addRegion_node(node, HighlightRegionType.IDENTIFIER_DEFAULT);
}
@ -352,6 +355,38 @@ class DartUnitHighlightsComputer2 {
return _addRegion_node(node, HighlightRegionType.TYPE_PARAMETER);
}
bool _addIdentifierRegion_unresolvedInstanceMemberReference(
SimpleIdentifier node) {
// unresolved
Element element = node.bestElement;
if (element != null) {
return false;
}
// invoke / get / set
bool decorate = false;
AstNode parent = node.parent;
if (parent is MethodInvocation) {
Expression target = parent.realTarget;
if (parent.methodName == node &&
target != null &&
_isDynamicExpression(target)) {
decorate = true;
}
} else if (node.inGetterContext() || node.inSetterContext()) {
if (parent is PrefixedIdentifier) {
decorate = parent.identifier == node;
} else if (parent is PropertyAccess) {
decorate = parent.propertyName == node;
}
}
if (decorate) {
_addRegion_node(
node, HighlightRegionType.UNRESOLVED_INSTANCE_MEMBER_REFERENCE);
return true;
}
return false;
}
void _addRegion(int offset, int length, HighlightRegionType type) {
_regions.add(new HighlightRegion(type, offset, length));
}
@ -384,6 +419,13 @@ class DartUnitHighlightsComputer2 {
int end = b.end;
_addRegion(offset, end - offset, type);
}
static bool _isDynamicExpression(Expression e) {
if (e is SimpleIdentifier && e.staticElement is PrefixElement) {
return false;
}
return e.bestType.isDynamic;
}
}
/**

View file

@ -1094,6 +1094,58 @@ class A<T> {
});
}
test_UNRESOLVED_INSTANCE_MEMBER_REFERENCE_dynamicVarTarget() {
addTestFile('''
main(p) {
p.aaa;
p.aaa++;
p.aaa += 0;
++p.aaa; // ++
p.aaa = 0;
p.bbb(0);
''.length.ccc().ddd();
}
''');
return prepareHighlights().then((_) {
HighlightRegionType type =
HighlightRegionType.UNRESOLVED_INSTANCE_MEMBER_REFERENCE;
assertHasRegion(type, 'aaa');
assertHasRegion(type, 'aaa++');
assertHasRegion(type, 'aaa += 0');
assertHasRegion(type, 'aaa; // ++');
assertHasRegion(type, 'aaa =');
assertHasRegion(type, 'bbb(');
assertHasRegion(type, 'ddd()');
});
}
test_UNRESOLVED_INSTANCE_MEMBER_REFERENCE_nonDynamicTarget() {
addTestFile('''
import 'dart:math' as math;
main(String str) {
new Object().aaa();
math.bbb();
str.ccc();
}
class A {
m() {
unresolved(1);
this.unresolved(2);
super.unresolved(3);
}
}
''');
return prepareHighlights().then((_) {
HighlightRegionType type = HighlightRegionType.IDENTIFIER_DEFAULT;
assertHasRegion(type, 'aaa()');
assertHasRegion(type, 'bbb()');
assertHasRegion(type, 'ccc()');
assertHasRegion(type, 'unresolved(1)');
assertHasRegion(type, 'unresolved(2)');
assertHasRegion(type, 'unresolved(3)');
});
}
void _addLibraryForTestPart() {
addFile(
'$testFolder/my_lib.dart',