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

Unified Diff: pkg/analysis_server/test/analysis/notification_highlights_test.dart

Issue 1227143003: Update Analysis Server highlight API and implementation. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Split DYNAMIC_VARIABLE, add UNRESOLVED_INSTANCE_MEMBER_REFERENCE. Created 5 years, 5 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
Index: pkg/analysis_server/test/analysis/notification_highlights_test.dart
diff --git a/pkg/analysis_server/test/analysis/notification_highlights_test.dart b/pkg/analysis_server/test/analysis/notification_highlights_test.dart
index 5e08e7bcce9048ad7bc35aa13af77562d61112d2..665408b7f3af7eb18fc68612234ff627646564c0 100644
--- a/pkg/analysis_server/test/analysis/notification_highlights_test.dart
+++ b/pkg/analysis_server/test/analysis/notification_highlights_test.dart
@@ -569,103 +569,73 @@ part of lib;
});
}
- test_DYNAMIC_TYPE() {
+ test_DYNAMIC_LOCAL_VARIABLE() {
addTestFile('''
f() {}
main(p) {
- print(p);
- var v1 = f();
- int v2;
- var v3 = v2;
+ var v = f();
+ v;
}
''');
return prepareHighlights().then((_) {
- assertHasRegion(HighlightRegionType.DYNAMIC_TYPE, 'p)');
- assertHasRegion(HighlightRegionType.DYNAMIC_TYPE, 'v1 =');
- assertNoRegion(HighlightRegionType.DYNAMIC_TYPE, 'v2;');
- assertNoRegion(HighlightRegionType.DYNAMIC_TYPE, 'v3 =');
- });
- }
-
- test_ENUM() {
- addTestFile('''
-enum MyEnum {A, B, C}
-MyEnum value;
-''');
- return prepareHighlights().then((_) {
- assertHasRegion(HighlightRegionType.ENUM, 'MyEnum {');
- assertHasRegion(HighlightRegionType.ENUM, 'MyEnum value;');
+ assertHasRegion(
+ HighlightRegionType.DYNAMIC_LOCAL_VARIABLE_DECLARATION, 'v = f()');
+ assertHasRegion(
+ HighlightRegionType.DYNAMIC_LOCAL_VARIABLE_REFERENCE, 'v;');
});
}
- test_ENUM_CONSTANT() {
+ test_DYNAMIC_PARAMETER() {
addTestFile('''
-enum MyEnum {AAA, BBB}
-main() {
- print(MyEnum.AAA);
- print(MyEnum.BBB);
+main(p) {
+ print(p);
}
''');
return prepareHighlights().then((_) {
- assertHasRegion(HighlightRegionType.ENUM_CONSTANT, 'AAA, ');
- assertHasRegion(HighlightRegionType.ENUM_CONSTANT, 'BBB}');
- assertHasRegion(HighlightRegionType.ENUM_CONSTANT, 'AAA);');
- assertHasRegion(HighlightRegionType.ENUM_CONSTANT, 'BBB);');
+ assertHasRegion(HighlightRegionType.DYNAMIC_PARAMETER_DECLARATION, 'p)');
+ assertHasRegion(HighlightRegionType.DYNAMIC_PARAMETER_REFERENCE, 'p);');
});
}
- test_FIELD() {
+ test_DYNAMIC_VARIABLE_field() {
addTestFile('''
class A {
- int aaa = 1;
- int bbb = 2;
- A([this.bbb = 3]);
-}
-main(A a) {
- a.aaa = 4;
- a.bbb = 5;
+ var f;
+ m() {
+ f = 1;
+ }
}
''');
return prepareHighlights().then((_) {
- assertHasRegion(HighlightRegionType.FIELD, 'aaa = 1');
- assertHasRegion(HighlightRegionType.FIELD, 'bbb = 2');
- assertHasRegion(HighlightRegionType.FIELD, 'bbb = 3');
- assertHasRegion(HighlightRegionType.FIELD, 'aaa = 4');
- assertHasRegion(HighlightRegionType.FIELD, 'bbb = 5');
+ assertHasRegion(HighlightRegionType.INSTANCE_FIELD_DECLARATION, 'f;');
+ assertHasRegion(HighlightRegionType.INSTANCE_FIELD_REFERENCE, 'f = 1');
});
}
- test_FIELD_STATIC() {
+ test_ENUM() {
addTestFile('''
-class A {
- static aaa = 1;
- static get bbb => null;
- static set ccc(x) {}
-}
-main() {
- A.aaa = 2;
- A.bbb;
- A.ccc = 3;
-}
+enum MyEnum {A, B, C}
+MyEnum value;
''');
return prepareHighlights().then((_) {
- assertHasRegion(HighlightRegionType.FIELD_STATIC, 'aaa = 1');
- assertHasRegion(HighlightRegionType.FIELD_STATIC, 'aaa = 2');
- assertHasRegion(HighlightRegionType.FIELD_STATIC, 'bbb;');
- assertHasRegion(HighlightRegionType.FIELD_STATIC, 'ccc = 3');
+ assertHasRegion(HighlightRegionType.ENUM, 'MyEnum {');
+ assertHasRegion(HighlightRegionType.ENUM, 'MyEnum value;');
});
}
- test_FUNCTION() {
+ test_ENUM_CONSTANT() {
addTestFile('''
-fff(p) {}
+enum MyEnum {AAA, BBB}
main() {
- fff(42);
+ print(MyEnum.AAA);
+ print(MyEnum.BBB);
}
''');
return prepareHighlights().then((_) {
- assertHasRegion(HighlightRegionType.FUNCTION_DECLARATION, 'fff(p) {}');
- assertHasRegion(HighlightRegionType.FUNCTION, 'fff(42)');
+ assertHasRegion(HighlightRegionType.ENUM_CONSTANT, 'AAA, ');
+ assertHasRegion(HighlightRegionType.ENUM_CONSTANT, 'BBB}');
+ assertHasRegion(HighlightRegionType.ENUM_CONSTANT, 'AAA);');
+ assertHasRegion(HighlightRegionType.ENUM_CONSTANT, 'BBB);');
});
}
@@ -681,22 +651,29 @@ main(FFF fff) {
});
}
- test_GETTER_DECLARATION() {
+ test_GETTER() {
addTestFile('''
get aaa => null;
class A {
get bbb => null;
+ static get ccc => null;
}
main(A a) {
aaa;
a.bbb;
+ A.ccc;
}
''');
return prepareHighlights().then((_) {
- assertHasRegion(HighlightRegionType.GETTER_DECLARATION, 'aaa => null');
- assertHasRegion(HighlightRegionType.GETTER_DECLARATION, 'bbb => null');
- assertHasRegion(HighlightRegionType.TOP_LEVEL_VARIABLE, 'aaa;');
- assertHasRegion(HighlightRegionType.FIELD, 'bbb;');
+ assertHasRegion(
+ HighlightRegionType.TOP_LEVEL_GETTER_DECLARATION, 'aaa => null');
+ assertHasRegion(
+ HighlightRegionType.INSTANCE_GETTER_DECLARATION, 'bbb => null');
+ assertHasRegion(
+ HighlightRegionType.STATIC_GETTER_DECLARATION, 'ccc => null');
+ assertHasRegion(HighlightRegionType.TOP_LEVEL_VARIABLE_REFERENCE, 'aaa;');
+ assertHasRegion(HighlightRegionType.INSTANCE_FIELD_REFERENCE, 'bbb;');
+ assertHasRegion(HighlightRegionType.STATIC_FIELD_REFERENCE, 'ccc;');
});
}
@@ -728,6 +705,29 @@ main() {
});
}
+ test_INSTANCE_FIELD() {
+ addTestFile('''
+class A {
+ int aaa = 1;
+ int bbb = 2;
+ A([this.bbb = 3]);
+}
+main(A a) {
+ a.aaa = 4;
+ a.bbb = 5;
+}
+''');
+ return prepareHighlights().then((_) {
+ assertHasRegion(
+ HighlightRegionType.INSTANCE_FIELD_DECLARATION, 'aaa = 1');
+ assertHasRegion(
+ HighlightRegionType.INSTANCE_FIELD_DECLARATION, 'bbb = 2');
+ assertHasRegion(HighlightRegionType.INSTANCE_FIELD_REFERENCE, 'bbb = 3');
+ assertHasRegion(HighlightRegionType.INSTANCE_FIELD_REFERENCE, 'aaa = 4');
+ assertHasRegion(HighlightRegionType.INSTANCE_FIELD_REFERENCE, 'bbb = 5');
+ });
+ }
+
test_KEYWORD() {
addTestFile('''
main() {
@@ -862,6 +862,22 @@ myLabel:
});
}
+ test_LOCAL_FUNCTION() {
+ addTestFile('''
+main() {
+ fff() {}
+ fff();
+ fff;
+}
+''');
+ return prepareHighlights().then((_) {
+ assertHasRegion(
+ HighlightRegionType.LOCAL_FUNCTION_DECLARATION, 'fff() {}');
+ assertHasRegion(HighlightRegionType.LOCAL_FUNCTION_REFERENCE, 'fff();');
+ assertHasRegion(HighlightRegionType.LOCAL_FUNCTION_REFERENCE, 'fff;');
+ });
+ }
+
test_LOCAL_VARIABLE() {
addTestFile('''
main() {
@@ -873,8 +889,8 @@ main() {
return prepareHighlights().then((_) {
assertHasRegion(
HighlightRegionType.LOCAL_VARIABLE_DECLARATION, 'vvv = 0');
- assertHasRegion(HighlightRegionType.LOCAL_VARIABLE, 'vvv;');
- assertHasRegion(HighlightRegionType.LOCAL_VARIABLE, 'vvv = 1;');
+ assertHasRegion(HighlightRegionType.LOCAL_VARIABLE_REFERENCE, 'vvv;');
+ assertHasRegion(HighlightRegionType.LOCAL_VARIABLE_REFERENCE, 'vvv = 1;');
});
}
@@ -892,13 +908,14 @@ main(A a) {
}
''');
return prepareHighlights().then((_) {
- assertHasRegion(HighlightRegionType.METHOD_DECLARATION, 'aaa() {}');
assertHasRegion(
- HighlightRegionType.METHOD_DECLARATION_STATIC, 'bbb() {}');
- assertHasRegion(HighlightRegionType.METHOD, 'aaa();');
- assertHasRegion(HighlightRegionType.METHOD, 'aaa;');
- assertHasRegion(HighlightRegionType.METHOD_STATIC, 'bbb();');
- assertHasRegion(HighlightRegionType.METHOD_STATIC, 'bbb;');
+ HighlightRegionType.INSTANCE_METHOD_DECLARATION, 'aaa() {}');
+ assertHasRegion(
+ HighlightRegionType.STATIC_METHOD_DECLARATION, 'bbb() {}');
+ assertHasRegion(HighlightRegionType.INSTANCE_METHOD_REFERENCE, 'aaa();');
+ assertHasRegion(HighlightRegionType.INSTANCE_METHOD_REFERENCE, 'aaa;');
+ assertHasRegion(HighlightRegionType.STATIC_METHOD_REFERENCE, 'bbb();');
+ assertHasRegion(HighlightRegionType.STATIC_METHOD_REFERENCE, 'bbb;');
});
}
@@ -911,7 +928,8 @@ main(p) {
}
''');
return prepareHighlights().then((_) {
- assertHasRegion(HighlightRegionType.METHOD, 'add(null)');
+ assertHasRegion(
+ HighlightRegionType.INSTANCE_METHOD_REFERENCE, 'add(null)');
});
}
@@ -923,9 +941,9 @@ main(int p) {
}
''');
return prepareHighlights().then((_) {
- assertHasRegion(HighlightRegionType.PARAMETER, 'p) {');
- assertHasRegion(HighlightRegionType.PARAMETER, 'p;');
- assertHasRegion(HighlightRegionType.PARAMETER, 'p = 42');
+ assertHasRegion(HighlightRegionType.PARAMETER_DECLARATION, 'p) {');
+ assertHasRegion(HighlightRegionType.PARAMETER_REFERENCE, 'p;');
+ assertHasRegion(HighlightRegionType.PARAMETER_REFERENCE, 'p = 42');
});
}
@@ -934,17 +952,60 @@ main(int p) {
set aaa(x) {}
class A {
set bbb(x) {}
+ static set ccc(x) {}
}
main(A a) {
aaa = 1;
a.bbb = 2;
+ A.ccc = 3;
+}
+''');
+ return prepareHighlights().then((_) {
+ assertHasRegion(
+ HighlightRegionType.TOP_LEVEL_SETTER_DECLARATION, 'aaa(x)');
+ assertHasRegion(
+ HighlightRegionType.INSTANCE_SETTER_DECLARATION, 'bbb(x)');
+ assertHasRegion(HighlightRegionType.STATIC_SETTER_DECLARATION, 'ccc(x)');
+ assertHasRegion(
+ HighlightRegionType.TOP_LEVEL_VARIABLE_REFERENCE, 'aaa = 1');
+ assertHasRegion(HighlightRegionType.INSTANCE_FIELD_REFERENCE, 'bbb = 2');
+ assertHasRegion(HighlightRegionType.STATIC_FIELD_REFERENCE, 'ccc = 3');
+ });
+ }
+
+ test_STATIC_FIELD() {
+ addTestFile('''
+class A {
+ static aaa = 1;
+ static get bbb => null;
+ static set ccc(x) {}
+}
+main() {
+ A.aaa = 2;
+ A.bbb;
+ A.ccc = 3;
}
''');
return prepareHighlights().then((_) {
- assertHasRegion(HighlightRegionType.SETTER_DECLARATION, 'aaa(x)');
- assertHasRegion(HighlightRegionType.SETTER_DECLARATION, 'bbb(x)');
- assertHasRegion(HighlightRegionType.TOP_LEVEL_VARIABLE, 'aaa = 1');
- assertHasRegion(HighlightRegionType.FIELD, 'bbb = 2');
+ assertHasRegion(HighlightRegionType.STATIC_FIELD_DECLARATION, 'aaa = 1');
+ assertHasRegion(HighlightRegionType.STATIC_FIELD_REFERENCE, 'aaa = 2');
+ assertHasRegion(HighlightRegionType.STATIC_FIELD_REFERENCE, 'bbb;');
+ assertHasRegion(HighlightRegionType.STATIC_FIELD_REFERENCE, 'ccc = 3');
+ });
+ }
+
+ test_TOP_LEVEL_FUNCTION() {
+ addTestFile('''
+fff(p) {}
+main() {
+ fff(42);
+}
+''');
+ return prepareHighlights().then((_) {
+ assertHasRegion(
+ HighlightRegionType.TOP_LEVEL_FUNCTION_DECLARATION, 'fff(p) {}');
+ assertHasRegion(
+ HighlightRegionType.TOP_LEVEL_FUNCTION_REFERENCE, 'fff(42)');
});
}
@@ -958,11 +1019,14 @@ main() {
}
''');
return prepareHighlights().then((_) {
- assertHasRegion(HighlightRegionType.TOP_LEVEL_VARIABLE, 'VVV = 0');
assertHasRegion(
- HighlightRegionType.TOP_LEVEL_VARIABLE, 'VVV // annotation');
- assertHasRegion(HighlightRegionType.TOP_LEVEL_VARIABLE, 'VVV);');
- assertHasRegion(HighlightRegionType.TOP_LEVEL_VARIABLE, 'VVV = 1');
+ HighlightRegionType.TOP_LEVEL_VARIABLE_DECLARATION, 'VVV = 0');
+ assertHasRegion(HighlightRegionType.TOP_LEVEL_VARIABLE_REFERENCE,
+ 'VVV // annotation');
+ assertHasRegion(
+ HighlightRegionType.TOP_LEVEL_VARIABLE_REFERENCE, 'VVV);');
+ assertHasRegion(
+ HighlightRegionType.TOP_LEVEL_VARIABLE_REFERENCE, 'VVV = 1');
});
}

Powered by Google App Engine
This is Rietveld 408576698