| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.src.summary.summary_common; | 5 library analyzer.test.src.summary.summary_common; |
| 6 | 6 |
| 7 import 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/dart/ast/ast.dart'; | 8 import 'package:analyzer/dart/ast/ast.dart'; |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/src/dart/scanner/reader.dart'; | 10 import 'package:analyzer/src/dart/scanner/reader.dart'; |
| (...skipping 7788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7799 (EntityRef r) => checkTypeRef(r, null, null, 'named', | 7799 (EntityRef r) => checkTypeRef(r, null, null, 'named', |
| 7800 expectedKind: ReferenceKind.constructor, | 7800 expectedKind: ReferenceKind.constructor, |
| 7801 prefixExpectations: [ | 7801 prefixExpectations: [ |
| 7802 new _PrefixExpectation(ReferenceKind.classOrEnum, 'A', | 7802 new _PrefixExpectation(ReferenceKind.classOrEnum, 'A', |
| 7803 absoluteUri: absUri('/foo.dart'), relativeUri: 'foo.dart'), | 7803 absoluteUri: absUri('/foo.dart'), relativeUri: 'foo.dart'), |
| 7804 new _PrefixExpectation(ReferenceKind.prefix, 'foo') | 7804 new _PrefixExpectation(ReferenceKind.prefix, 'foo') |
| 7805 ]) | 7805 ]) |
| 7806 ]); | 7806 ]); |
| 7807 } | 7807 } |
| 7808 | 7808 |
| 7809 test_metadata_constructor_call_named_prefixed_unresolved_class() { |
| 7810 addNamedSource('/foo.dart', ''); |
| 7811 UnlinkedClass cls = serializeClassText( |
| 7812 'import "foo.dart" as foo; @foo.A.named() class C {}', |
| 7813 allowErrors: true); |
| 7814 expect(cls.annotations, hasLength(1)); |
| 7815 _assertUnlinkedConst(cls.annotations[0], operators: [ |
| 7816 UnlinkedConstOperation.invokeConstructor, |
| 7817 ], ints: [ |
| 7818 0, |
| 7819 0 |
| 7820 ], referenceValidators: [ |
| 7821 (EntityRef r) => checkTypeRef(r, null, null, 'named', |
| 7822 expectedKind: ReferenceKind.unresolved, |
| 7823 prefixExpectations: [ |
| 7824 new _PrefixExpectation(ReferenceKind.unresolved, 'A'), |
| 7825 new _PrefixExpectation(ReferenceKind.prefix, 'foo') |
| 7826 ], |
| 7827 checkAstDerivedDataOverride: true) |
| 7828 ]); |
| 7829 } |
| 7830 |
| 7831 test_metadata_constructor_call_named_prefixed_unresolved_constructor() { |
| 7832 addNamedSource('/foo.dart', 'class A {}'); |
| 7833 UnlinkedClass cls = serializeClassText( |
| 7834 'import "foo.dart" as foo; @foo.A.named() class C {}', |
| 7835 allowErrors: true); |
| 7836 expect(cls.annotations, hasLength(1)); |
| 7837 _assertUnlinkedConst(cls.annotations[0], operators: [ |
| 7838 UnlinkedConstOperation.invokeConstructor, |
| 7839 ], ints: [ |
| 7840 0, |
| 7841 0 |
| 7842 ], referenceValidators: [ |
| 7843 (EntityRef r) => checkTypeRef(r, null, null, 'named', |
| 7844 expectedKind: ReferenceKind.unresolved, |
| 7845 prefixExpectations: [ |
| 7846 new _PrefixExpectation(ReferenceKind.classOrEnum, 'A', |
| 7847 absoluteUri: absUri('/foo.dart'), relativeUri: 'foo.dart'), |
| 7848 new _PrefixExpectation(ReferenceKind.prefix, 'foo') |
| 7849 ], |
| 7850 checkAstDerivedDataOverride: true) |
| 7851 ]); |
| 7852 } |
| 7853 |
| 7854 test_metadata_constructor_call_named_unresolved_class() { |
| 7855 UnlinkedClass cls = |
| 7856 serializeClassText('@A.named() class C {}', allowErrors: true); |
| 7857 expect(cls.annotations, hasLength(1)); |
| 7858 _assertUnlinkedConst(cls.annotations[0], operators: [ |
| 7859 UnlinkedConstOperation.invokeConstructor, |
| 7860 ], ints: [ |
| 7861 0, |
| 7862 0 |
| 7863 ], referenceValidators: [ |
| 7864 (EntityRef r) => checkTypeRef(r, null, null, 'named', |
| 7865 expectedKind: ReferenceKind.unresolved, |
| 7866 prefixExpectations: [ |
| 7867 new _PrefixExpectation(ReferenceKind.unresolved, 'A') |
| 7868 ], |
| 7869 checkAstDerivedDataOverride: true) |
| 7870 ]); |
| 7871 } |
| 7872 |
| 7873 test_metadata_constructor_call_named_unresolved_constructor() { |
| 7874 UnlinkedClass cls = serializeClassText('class A {} @A.named() class C {}', |
| 7875 allowErrors: true); |
| 7876 expect(cls.annotations, hasLength(1)); |
| 7877 _assertUnlinkedConst(cls.annotations[0], operators: [ |
| 7878 UnlinkedConstOperation.invokeConstructor, |
| 7879 ], ints: [ |
| 7880 0, |
| 7881 0 |
| 7882 ], referenceValidators: [ |
| 7883 (EntityRef r) => checkTypeRef(r, null, null, 'named', |
| 7884 expectedKind: ReferenceKind.unresolved, |
| 7885 prefixExpectations: [ |
| 7886 new _PrefixExpectation(ReferenceKind.classOrEnum, 'A') |
| 7887 ], |
| 7888 checkAstDerivedDataOverride: true) |
| 7889 ]); |
| 7890 } |
| 7891 |
| 7809 test_metadata_constructor_call_unnamed() { | 7892 test_metadata_constructor_call_unnamed() { |
| 7810 UnlinkedClass cls = | 7893 UnlinkedClass cls = |
| 7811 serializeClassText('class A { const A(); } @A() class C {}'); | 7894 serializeClassText('class A { const A(); } @A() class C {}'); |
| 7812 expect(cls.annotations, hasLength(1)); | 7895 expect(cls.annotations, hasLength(1)); |
| 7813 _assertUnlinkedConst(cls.annotations[0], operators: [ | 7896 _assertUnlinkedConst(cls.annotations[0], operators: [ |
| 7814 UnlinkedConstOperation.invokeConstructor, | 7897 UnlinkedConstOperation.invokeConstructor, |
| 7815 ], ints: [ | 7898 ], ints: [ |
| 7816 0, | 7899 0, |
| 7817 0 | 7900 0 |
| 7818 ], referenceValidators: [ | 7901 ], referenceValidators: [ |
| (...skipping 11 matching lines...) Expand all Loading... |
| 7830 UnlinkedConstOperation.invokeConstructor, | 7913 UnlinkedConstOperation.invokeConstructor, |
| 7831 ], ints: [ | 7914 ], ints: [ |
| 7832 0, | 7915 0, |
| 7833 0 | 7916 0 |
| 7834 ], referenceValidators: [ | 7917 ], referenceValidators: [ |
| 7835 (EntityRef r) => checkTypeRef(r, absUri('/foo.dart'), 'foo.dart', 'A', | 7918 (EntityRef r) => checkTypeRef(r, absUri('/foo.dart'), 'foo.dart', 'A', |
| 7836 expectedKind: ReferenceKind.classOrEnum, expectedPrefix: 'foo') | 7919 expectedKind: ReferenceKind.classOrEnum, expectedPrefix: 'foo') |
| 7837 ]); | 7920 ]); |
| 7838 } | 7921 } |
| 7839 | 7922 |
| 7923 test_metadata_constructor_call_unnamed_prefixed_unresolved() { |
| 7924 addNamedSource('/foo.dart', ''); |
| 7925 UnlinkedClass cls = serializeClassText( |
| 7926 'import "foo.dart" as foo; @foo.A() class C {}', |
| 7927 allowErrors: true); |
| 7928 expect(cls.annotations, hasLength(1)); |
| 7929 _assertUnlinkedConst(cls.annotations[0], operators: [ |
| 7930 UnlinkedConstOperation.invokeConstructor, |
| 7931 ], ints: [ |
| 7932 0, |
| 7933 0 |
| 7934 ], referenceValidators: [ |
| 7935 (EntityRef r) => checkTypeRef(r, null, null, 'A', |
| 7936 expectedKind: ReferenceKind.unresolved, |
| 7937 expectedPrefix: 'foo', |
| 7938 checkAstDerivedDataOverride: true) |
| 7939 ]); |
| 7940 } |
| 7941 |
| 7942 test_metadata_constructor_call_unnamed_unresolved() { |
| 7943 UnlinkedClass cls = |
| 7944 serializeClassText('@A() class C {}', allowErrors: true); |
| 7945 expect(cls.annotations, hasLength(1)); |
| 7946 _assertUnlinkedConst(cls.annotations[0], operators: [ |
| 7947 UnlinkedConstOperation.invokeConstructor, |
| 7948 ], ints: [ |
| 7949 0, |
| 7950 0 |
| 7951 ], referenceValidators: [ |
| 7952 (EntityRef r) => checkTypeRef(r, null, null, 'A', |
| 7953 expectedKind: ReferenceKind.unresolved, |
| 7954 checkAstDerivedDataOverride: true) |
| 7955 ]); |
| 7956 } |
| 7957 |
| 7840 test_metadata_constructor_call_with_args() { | 7958 test_metadata_constructor_call_with_args() { |
| 7841 UnlinkedClass cls = | 7959 UnlinkedClass cls = |
| 7842 serializeClassText('class A { const A(x); } @A(null) class C {}'); | 7960 serializeClassText('class A { const A(x); } @A(null) class C {}'); |
| 7843 expect(cls.annotations, hasLength(1)); | 7961 expect(cls.annotations, hasLength(1)); |
| 7844 _assertUnlinkedConst(cls.annotations[0], operators: [ | 7962 _assertUnlinkedConst(cls.annotations[0], operators: [ |
| 7845 UnlinkedConstOperation.pushNull, | 7963 UnlinkedConstOperation.pushNull, |
| 7846 UnlinkedConstOperation.invokeConstructor, | 7964 UnlinkedConstOperation.invokeConstructor, |
| 7847 ], ints: [ | 7965 ], ints: [ |
| 7848 0, | 7966 0, |
| 7849 1 | 7967 1 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7998 expect(cls.annotations, hasLength(1)); | 8116 expect(cls.annotations, hasLength(1)); |
| 7999 _assertUnlinkedConst(cls.annotations[0], operators: [ | 8117 _assertUnlinkedConst(cls.annotations[0], operators: [ |
| 8000 UnlinkedConstOperation.pushReference | 8118 UnlinkedConstOperation.pushReference |
| 8001 ], referenceValidators: [ | 8119 ], referenceValidators: [ |
| 8002 (EntityRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'b', | 8120 (EntityRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'b', |
| 8003 expectedKind: ReferenceKind.topLevelPropertyAccessor, | 8121 expectedKind: ReferenceKind.topLevelPropertyAccessor, |
| 8004 expectedPrefix: 'a') | 8122 expectedPrefix: 'a') |
| 8005 ]); | 8123 ]); |
| 8006 } | 8124 } |
| 8007 | 8125 |
| 8126 test_metadata_prefixed_variable_unresolved() { |
| 8127 addNamedSource('/a.dart', ''); |
| 8128 UnlinkedClass cls = serializeClassText( |
| 8129 'import "a.dart" as a; @a.b class C {}', |
| 8130 allowErrors: true); |
| 8131 expect(cls.annotations, hasLength(1)); |
| 8132 _assertUnlinkedConst(cls.annotations[0], operators: [ |
| 8133 UnlinkedConstOperation.pushReference |
| 8134 ], referenceValidators: [ |
| 8135 (EntityRef r) => checkTypeRef(r, null, null, 'b', |
| 8136 expectedKind: ReferenceKind.unresolved, |
| 8137 expectedPrefix: 'a', |
| 8138 checkAstDerivedDataOverride: true) |
| 8139 ]); |
| 8140 } |
| 8141 |
| 8008 test_metadata_simpleFormalParameter() { | 8142 test_metadata_simpleFormalParameter() { |
| 8009 checkAnnotationA(serializeExecutableText('const a = null; f(@a x) {}') | 8143 checkAnnotationA(serializeExecutableText('const a = null; f(@a x) {}') |
| 8010 .parameters[0] | 8144 .parameters[0] |
| 8011 .annotations); | 8145 .annotations); |
| 8012 } | 8146 } |
| 8013 | 8147 |
| 8014 test_metadata_simpleFormalParameter_withDefault() { | 8148 test_metadata_simpleFormalParameter_withDefault() { |
| 8015 checkAnnotationA( | 8149 checkAnnotationA( |
| 8016 serializeExecutableText('const a = null; f([@a x = null]) {}') | 8150 serializeExecutableText('const a = null; f([@a x = null]) {}') |
| 8017 .parameters[0] | 8151 .parameters[0] |
| (...skipping 24 matching lines...) Expand all Loading... |
| 8042 .typeParameters[0] | 8176 .typeParameters[0] |
| 8043 .annotations); | 8177 .annotations); |
| 8044 } | 8178 } |
| 8045 | 8179 |
| 8046 test_metadata_typeParameter_ofTypedef() { | 8180 test_metadata_typeParameter_ofTypedef() { |
| 8047 checkAnnotationA(serializeTypedefText('const a = null; typedef F<@a T>();') | 8181 checkAnnotationA(serializeTypedefText('const a = null; typedef F<@a T>();') |
| 8048 .typeParameters[0] | 8182 .typeParameters[0] |
| 8049 .annotations); | 8183 .annotations); |
| 8050 } | 8184 } |
| 8051 | 8185 |
| 8186 test_metadata_variable_unresolved() { |
| 8187 UnlinkedClass cls = serializeClassText('@a class C {}', allowErrors: true); |
| 8188 expect(cls.annotations, hasLength(1)); |
| 8189 _assertUnlinkedConst(cls.annotations[0], operators: [ |
| 8190 UnlinkedConstOperation.pushReference |
| 8191 ], referenceValidators: [ |
| 8192 (EntityRef r) => checkTypeRef(r, null, null, 'a', |
| 8193 expectedKind: ReferenceKind.unresolved, |
| 8194 checkAstDerivedDataOverride: true) |
| 8195 ]); |
| 8196 } |
| 8197 |
| 8052 test_method_documented() { | 8198 test_method_documented() { |
| 8053 String text = ''' | 8199 String text = ''' |
| 8054 class C { | 8200 class C { |
| 8055 /** | 8201 /** |
| 8056 * Docs | 8202 * Docs |
| 8057 */ | 8203 */ |
| 8058 f() {} | 8204 f() {} |
| 8059 }'''; | 8205 }'''; |
| 8060 UnlinkedExecutable executable = serializeClassText(text).executables[0]; | 8206 UnlinkedExecutable executable = serializeClassText(text).executables[0]; |
| 8061 expect(executable.documentationComment, isNotNull); | 8207 expect(executable.documentationComment, isNotNull); |
| (...skipping 1316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9378 class _PrefixExpectation { | 9524 class _PrefixExpectation { |
| 9379 final ReferenceKind kind; | 9525 final ReferenceKind kind; |
| 9380 final String name; | 9526 final String name; |
| 9381 final String absoluteUri; | 9527 final String absoluteUri; |
| 9382 final String relativeUri; | 9528 final String relativeUri; |
| 9383 final int numTypeParameters; | 9529 final int numTypeParameters; |
| 9384 | 9530 |
| 9385 _PrefixExpectation(this.kind, this.name, | 9531 _PrefixExpectation(this.kind, this.name, |
| 9386 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); | 9532 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); |
| 9387 } | 9533 } |
| OLD | NEW |