| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.test.generated.non_error_resolver_test; | 5 library analyzer.test.generated.non_error_resolver_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/element/element.dart'; | 7 import 'package:analyzer/dart/element/element.dart'; |
| 8 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
| 9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
| 10 import 'package:analyzer/src/generated/error.dart'; | 10 import 'package:analyzer/src/generated/error.dart'; |
| (...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 abstract class A { | 919 abstract class A { |
| 920 /// [p] | 920 /// [p] |
| 921 A(int p) {} | 921 A(int p) {} |
| 922 }'''; | 922 }'''; |
| 923 Source source = addSource(code); | 923 Source source = addSource(code); |
| 924 computeLibrarySourceErrors(source); | 924 computeLibrarySourceErrors(source); |
| 925 assertNoErrors(source); | 925 assertNoErrors(source); |
| 926 verify([source]); | 926 verify([source]); |
| 927 CompilationUnit unit = _getResolvedLibraryUnit(source); | 927 CompilationUnit unit = _getResolvedLibraryUnit(source); |
| 928 { | 928 { |
| 929 SimpleIdentifier ref = EngineTestCase.findNode( | 929 SimpleIdentifier ref = |
| 930 unit, code, "p]", (node) => node is SimpleIdentifier); | 930 EngineTestCase.findSimpleIdentifier(unit, code, "p]"); |
| 931 EngineTestCase.assertInstanceOf((obj) => obj is ParameterElement, | 931 expect(ref.staticElement, new isInstanceOf<ParameterElement>()); |
| 932 ParameterElement, ref.staticElement); | |
| 933 } | 932 } |
| 934 } | 933 } |
| 935 | 934 |
| 936 void test_commentReference_beforeEnum() { | 935 void test_commentReference_beforeEnum() { |
| 937 String code = r''' | 936 String code = r''' |
| 938 /// This is the [Samurai] kind. | 937 /// This is the [Samurai] kind. |
| 939 enum Samurai { | 938 enum Samurai { |
| 940 /// Use [int]. | 939 /// Use [int]. |
| 941 WITH_SWORD, | 940 WITH_SWORD, |
| 942 /// Like [WITH_SWORD], but only without one. | 941 /// Like [WITH_SWORD], but only without one. |
| 943 WITHOUT_SWORD | 942 WITHOUT_SWORD |
| 944 }'''; | 943 }'''; |
| 945 Source source = addSource(code); | 944 Source source = addSource(code); |
| 946 computeLibrarySourceErrors(source); | 945 computeLibrarySourceErrors(source); |
| 947 assertNoErrors(source); | 946 assertNoErrors(source); |
| 948 verify([source]); | 947 verify([source]); |
| 949 CompilationUnit unit = _getResolvedLibraryUnit(source); | 948 CompilationUnit unit = _getResolvedLibraryUnit(source); |
| 950 { | 949 { |
| 951 SimpleIdentifier ref = EngineTestCase.findNode( | 950 SimpleIdentifier ref = |
| 952 unit, code, "Samurai]", (node) => node is SimpleIdentifier); | 951 EngineTestCase.findSimpleIdentifier(unit, code, 'Samurai]'); |
| 953 ClassElement refElement = ref.staticElement; | 952 ClassElement refElement = ref.staticElement; |
| 954 expect(refElement, isNotNull); | 953 expect(refElement, isNotNull); |
| 955 expect(refElement.name, 'Samurai'); | 954 expect(refElement.name, 'Samurai'); |
| 956 } | 955 } |
| 957 { | 956 { |
| 958 SimpleIdentifier ref = EngineTestCase.findNode( | 957 SimpleIdentifier ref = |
| 959 unit, code, "int]", (node) => node is SimpleIdentifier); | 958 EngineTestCase.findSimpleIdentifier(unit, code, 'int]'); |
| 960 ClassElement refElement = ref.staticElement; | 959 ClassElement refElement = ref.staticElement; |
| 961 expect(refElement, isNotNull); | 960 expect(refElement, isNotNull); |
| 962 expect(refElement.name, 'int'); | 961 expect(refElement.name, 'int'); |
| 963 } | 962 } |
| 964 { | 963 { |
| 965 SimpleIdentifier ref = EngineTestCase.findNode( | 964 SimpleIdentifier ref = |
| 966 unit, code, "WITH_SWORD]", (node) => node is SimpleIdentifier); | 965 EngineTestCase.findSimpleIdentifier(unit, code, 'WITH_SWORD]'); |
| 967 PropertyAccessorElement refElement = ref.staticElement; | 966 PropertyAccessorElement refElement = ref.staticElement; |
| 968 expect(refElement, isNotNull); | 967 expect(refElement, isNotNull); |
| 969 expect(refElement.name, 'WITH_SWORD'); | 968 expect(refElement.name, 'WITH_SWORD'); |
| 970 } | 969 } |
| 971 } | 970 } |
| 972 | 971 |
| 973 void test_commentReference_beforeFunction_blockBody() { | 972 void test_commentReference_beforeFunction_blockBody() { |
| 974 String code = r''' | 973 String code = r''' |
| 975 /// [p] | 974 /// [p] |
| 976 foo(int p) { | 975 foo(int p) { |
| 977 }'''; | 976 }'''; |
| 978 Source source = addSource(code); | 977 Source source = addSource(code); |
| 979 computeLibrarySourceErrors(source); | 978 computeLibrarySourceErrors(source); |
| 980 assertNoErrors(source); | 979 assertNoErrors(source); |
| 981 verify([source]); | 980 verify([source]); |
| 982 CompilationUnit unit = _getResolvedLibraryUnit(source); | 981 CompilationUnit unit = _getResolvedLibraryUnit(source); |
| 983 SimpleIdentifier ref = EngineTestCase.findNode( | 982 SimpleIdentifier ref = |
| 984 unit, code, "p]", (node) => node is SimpleIdentifier); | 983 EngineTestCase.findSimpleIdentifier(unit, code, 'p]'); |
| 985 EngineTestCase.assertInstanceOf( | 984 expect(ref.staticElement, new isInstanceOf<ParameterElement>()); |
| 986 (obj) => obj is ParameterElement, ParameterElement, ref.staticElement); | |
| 987 } | 985 } |
| 988 | 986 |
| 989 void test_commentReference_beforeFunction_expressionBody() { | 987 void test_commentReference_beforeFunction_expressionBody() { |
| 990 String code = r''' | 988 String code = r''' |
| 991 /// [p] | 989 /// [p] |
| 992 foo(int p) => null;'''; | 990 foo(int p) => null;'''; |
| 993 Source source = addSource(code); | 991 Source source = addSource(code); |
| 994 computeLibrarySourceErrors(source); | 992 computeLibrarySourceErrors(source); |
| 995 assertNoErrors(source); | 993 assertNoErrors(source); |
| 996 verify([source]); | 994 verify([source]); |
| 997 CompilationUnit unit = _getResolvedLibraryUnit(source); | 995 CompilationUnit unit = _getResolvedLibraryUnit(source); |
| 998 SimpleIdentifier ref = EngineTestCase.findNode( | 996 SimpleIdentifier ref = |
| 999 unit, code, "p]", (node) => node is SimpleIdentifier); | 997 EngineTestCase.findSimpleIdentifier(unit, code, 'p]'); |
| 1000 EngineTestCase.assertInstanceOf( | 998 expect(ref.staticElement, new isInstanceOf<ParameterElement>()); |
| 1001 (obj) => obj is ParameterElement, ParameterElement, ref.staticElement); | |
| 1002 } | 999 } |
| 1003 | 1000 |
| 1004 void test_commentReference_beforeFunctionTypeAlias() { | 1001 void test_commentReference_beforeFunctionTypeAlias() { |
| 1005 String code = r''' | 1002 String code = r''' |
| 1006 /// [p] | 1003 /// [p] |
| 1007 typedef Foo(int p); | 1004 typedef Foo(int p); |
| 1008 '''; | 1005 '''; |
| 1009 Source source = addSource(code); | 1006 Source source = addSource(code); |
| 1010 computeLibrarySourceErrors(source); | 1007 computeLibrarySourceErrors(source); |
| 1011 assertNoErrors(source); | 1008 assertNoErrors(source); |
| 1012 verify([source]); | 1009 verify([source]); |
| 1013 CompilationUnit unit = _getResolvedLibraryUnit(source); | 1010 CompilationUnit unit = _getResolvedLibraryUnit(source); |
| 1014 SimpleIdentifier ref = EngineTestCase.findNode( | 1011 SimpleIdentifier ref = |
| 1015 unit, code, "p]", (node) => node is SimpleIdentifier); | 1012 EngineTestCase.findSimpleIdentifier(unit, code, 'p]'); |
| 1016 EngineTestCase.assertInstanceOf( | 1013 expect(ref.staticElement, new isInstanceOf<ParameterElement>()); |
| 1017 (obj) => obj is ParameterElement, ParameterElement, ref.staticElement); | |
| 1018 } | 1014 } |
| 1019 | 1015 |
| 1020 void test_commentReference_beforeGetter() { | 1016 void test_commentReference_beforeGetter() { |
| 1021 String code = r''' | 1017 String code = r''' |
| 1022 abstract class A { | 1018 abstract class A { |
| 1023 /// [int] | 1019 /// [int] |
| 1024 get g => null; | 1020 get g => null; |
| 1025 }'''; | 1021 }'''; |
| 1026 Source source = addSource(code); | 1022 Source source = addSource(code); |
| 1027 computeLibrarySourceErrors(source); | 1023 computeLibrarySourceErrors(source); |
| 1028 assertNoErrors(source); | 1024 assertNoErrors(source); |
| 1029 verify([source]); | 1025 verify([source]); |
| 1030 CompilationUnit unit = _getResolvedLibraryUnit(source); | 1026 CompilationUnit unit = _getResolvedLibraryUnit(source); |
| 1031 { | 1027 { |
| 1032 SimpleIdentifier ref = EngineTestCase.findNode( | 1028 SimpleIdentifier ref = |
| 1033 unit, code, "int]", (node) => node is SimpleIdentifier); | 1029 EngineTestCase.findSimpleIdentifier(unit, code, 'int]'); |
| 1034 expect(ref.staticElement, isNotNull); | 1030 expect(ref.staticElement, isNotNull); |
| 1035 } | 1031 } |
| 1036 } | 1032 } |
| 1037 | 1033 |
| 1038 void test_commentReference_beforeMethod() { | 1034 void test_commentReference_beforeMethod() { |
| 1039 String code = r''' | 1035 String code = r''' |
| 1040 abstract class A { | 1036 abstract class A { |
| 1041 /// [p1] | 1037 /// [p1] |
| 1042 ma(int p1) {} | 1038 ma(int p1) {} |
| 1043 /// [p2] | 1039 /// [p2] |
| 1044 mb(int p2); | 1040 mb(int p2); |
| 1041 /// [p3] and [p4] |
| 1042 mc(int p3, p4()); |
| 1043 /// [p5] |
| 1044 md(int p5, {int p6}); |
| 1045 }'''; | 1045 }'''; |
| 1046 Source source = addSource(code); | 1046 Source source = addSource(code); |
| 1047 computeLibrarySourceErrors(source); | 1047 computeLibrarySourceErrors(source); |
| 1048 assertNoErrors(source); | 1048 assertNoErrors(source); |
| 1049 verify([source]); | 1049 verify([source]); |
| 1050 CompilationUnit unit = _getResolvedLibraryUnit(source); | 1050 CompilationUnit unit = _getResolvedLibraryUnit(source); |
| 1051 { | 1051 assertIsParameter(String search) { |
| 1052 SimpleIdentifier ref = EngineTestCase.findNode( | 1052 SimpleIdentifier ref = |
| 1053 unit, code, "p1]", (node) => node is SimpleIdentifier); | 1053 EngineTestCase.findSimpleIdentifier(unit, code, search); |
| 1054 EngineTestCase.assertInstanceOf((obj) => obj is ParameterElement, | 1054 expect(ref.staticElement, new isInstanceOf<ParameterElement>()); |
| 1055 ParameterElement, ref.staticElement); | |
| 1056 } | 1055 } |
| 1057 { | 1056 assertIsParameter('p1'); |
| 1058 SimpleIdentifier ref = EngineTestCase.findNode( | 1057 assertIsParameter('p2'); |
| 1059 unit, code, "p2]", (node) => node is SimpleIdentifier); | 1058 assertIsParameter('p3'); |
| 1060 EngineTestCase.assertInstanceOf((obj) => obj is ParameterElement, | 1059 assertIsParameter('p4'); |
| 1061 ParameterElement, ref.staticElement); | 1060 assertIsParameter('p5'); |
| 1062 } | 1061 assertIsParameter('p6'); |
| 1063 } | 1062 } |
| 1064 | 1063 |
| 1065 void test_commentReference_class() { | 1064 void test_commentReference_class() { |
| 1066 String code = r''' | 1065 String code = r''' |
| 1067 /// [foo] | 1066 /// [foo] |
| 1068 class A { | 1067 class A { |
| 1069 foo() {} | 1068 foo() {} |
| 1070 }'''; | 1069 }'''; |
| 1071 Source source = addSource(code); | 1070 Source source = addSource(code); |
| 1072 computeLibrarySourceErrors(source); | 1071 computeLibrarySourceErrors(source); |
| 1073 assertNoErrors(source); | 1072 assertNoErrors(source); |
| 1074 verify([source]); | 1073 verify([source]); |
| 1075 CompilationUnit unit = _getResolvedLibraryUnit(source); | 1074 CompilationUnit unit = _getResolvedLibraryUnit(source); |
| 1076 SimpleIdentifier ref = EngineTestCase.findNode( | 1075 SimpleIdentifier ref = |
| 1077 unit, code, "foo]", (node) => node is SimpleIdentifier); | 1076 EngineTestCase.findSimpleIdentifier(unit, code, 'foo]'); |
| 1078 EngineTestCase.assertInstanceOf( | 1077 expect(ref.staticElement, new isInstanceOf<MethodElement>()); |
| 1079 (obj) => obj is MethodElement, MethodElement, ref.staticElement); | |
| 1080 } | 1078 } |
| 1081 | 1079 |
| 1082 void test_commentReference_setter() { | 1080 void test_commentReference_setter() { |
| 1083 String code = r''' | 1081 String code = r''' |
| 1084 class A { | 1082 class A { |
| 1085 /// [x] in A | 1083 /// [x] in A |
| 1086 mA() {} | 1084 mA() {} |
| 1087 set x(value) {} | 1085 set x(value) {} |
| 1088 } | 1086 } |
| 1089 class B extends A { | 1087 class B extends A { |
| 1090 /// [x] in B | 1088 /// [x] in B |
| 1091 mB() {} | 1089 mB() {} |
| 1092 } | 1090 } |
| 1093 '''; | 1091 '''; |
| 1094 Source source = addSource(code); | 1092 Source source = addSource(code); |
| 1095 computeLibrarySourceErrors(source); | 1093 computeLibrarySourceErrors(source); |
| 1096 assertNoErrors(source); | 1094 assertNoErrors(source); |
| 1097 verify([source]); | 1095 verify([source]); |
| 1098 CompilationUnit unit = _getResolvedLibraryUnit(source); | 1096 CompilationUnit unit = _getResolvedLibraryUnit(source); |
| 1099 { | 1097 { |
| 1100 SimpleIdentifier ref = EngineTestCase.findNode( | 1098 SimpleIdentifier ref = |
| 1101 unit, code, "x] in A", (node) => node is SimpleIdentifier); | 1099 EngineTestCase.findSimpleIdentifier(unit, code, "x] in A"); |
| 1102 EngineTestCase.assertInstanceOf((obj) => obj is PropertyAccessorElement, | 1100 expect(ref.staticElement, new isInstanceOf<PropertyAccessorElement>()); |
| 1103 PropertyAccessorElement, ref.staticElement); | |
| 1104 } | 1101 } |
| 1105 { | 1102 { |
| 1106 SimpleIdentifier ref = EngineTestCase.findNode( | 1103 SimpleIdentifier ref = |
| 1107 unit, code, "x] in B", (node) => node is SimpleIdentifier); | 1104 EngineTestCase.findSimpleIdentifier(unit, code, 'x] in B'); |
| 1108 EngineTestCase.assertInstanceOf((obj) => obj is PropertyAccessorElement, | 1105 expect(ref.staticElement, new isInstanceOf<PropertyAccessorElement>()); |
| 1109 PropertyAccessorElement, ref.staticElement); | |
| 1110 } | 1106 } |
| 1111 } | 1107 } |
| 1112 | 1108 |
| 1113 void test_concreteClassWithAbstractMember() { | 1109 void test_concreteClassWithAbstractMember() { |
| 1114 Source source = addSource(r''' | 1110 Source source = addSource(r''' |
| 1115 abstract class A { | 1111 abstract class A { |
| 1116 m(); | 1112 m(); |
| 1117 }'''); | 1113 }'''); |
| 1118 computeLibrarySourceErrors(source); | 1114 computeLibrarySourceErrors(source); |
| 1119 assertNoErrors(source); | 1115 assertNoErrors(source); |
| (...skipping 4844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5964 reset(); | 5960 reset(); |
| 5965 } | 5961 } |
| 5966 | 5962 |
| 5967 void _check_wrongNumberOfParametersForOperator1(String name) { | 5963 void _check_wrongNumberOfParametersForOperator1(String name) { |
| 5968 _check_wrongNumberOfParametersForOperator(name, "a"); | 5964 _check_wrongNumberOfParametersForOperator(name, "a"); |
| 5969 } | 5965 } |
| 5970 | 5966 |
| 5971 CompilationUnit _getResolvedLibraryUnit(Source source) => | 5967 CompilationUnit _getResolvedLibraryUnit(Source source) => |
| 5972 analysisContext.getResolvedCompilationUnit2(source, source); | 5968 analysisContext.getResolvedCompilationUnit2(source, source); |
| 5973 } | 5969 } |
| OLD | NEW |