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

Side by Side Diff: pkg/analyzer/test/src/summary/summary_common.dart

Issue 1762193002: Resynthesize codeOffset/codeLength properties. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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 unified diff | Download patch
OLDNEW
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 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 numTypeParameters: 2); 1069 numTypeParameters: 2);
1070 } 1070 }
1071 1071
1072 test_class_alias_supertype() { 1072 test_class_alias_supertype() {
1073 UnlinkedClass cls = 1073 UnlinkedClass cls =
1074 serializeClassText('class C = D with E; class D {} class E {}'); 1074 serializeClassText('class C = D with E; class D {} class E {}');
1075 checkTypeRef(cls.supertype, null, null, 'D'); 1075 checkTypeRef(cls.supertype, null, null, 'D');
1076 expect(cls.hasNoSupertype, isFalse); 1076 expect(cls.hasNoSupertype, isFalse);
1077 } 1077 }
1078 1078
1079 test_class_codeRange() {
1080 UnlinkedClass cls = serializeClassText(' class C {}');
1081 expect(cls.hasCodeRange, true);
Paul Berry 2016/03/04 16:36:07 When would `hasCodeRange` be false? We need tests
scheglov 2016/03/04 17:15:19 In production - never. It tests - for every manual
1082 expect(cls.codeOffset, 1);
1083 expect(cls.codeLength, 10);
1084 }
1085
1079 test_class_concrete() { 1086 test_class_concrete() {
1080 UnlinkedClass cls = serializeClassText('class C {}'); 1087 UnlinkedClass cls = serializeClassText('class C {}');
1081 expect(cls.isAbstract, false); 1088 expect(cls.isAbstract, false);
1082 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); 1089 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1));
1083 expect(unlinkedUnits[0].publicNamespace.names[0].kind, 1090 expect(unlinkedUnits[0].publicNamespace.names[0].kind,
1084 ReferenceKind.classOrEnum); 1091 ReferenceKind.classOrEnum);
1085 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'C'); 1092 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'C');
1086 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0); 1093 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0);
1087 } 1094 }
1088 1095
(...skipping 2914 matching lines...) Expand 10 before | Expand all | Expand 10 after
4003 } 4010 }
4004 4011
4005 test_enum() { 4012 test_enum() {
4006 String text = 'enum E { v1 }'; 4013 String text = 'enum E { v1 }';
4007 UnlinkedEnum e = serializeEnumText(text); 4014 UnlinkedEnum e = serializeEnumText(text);
4008 expect(e.name, 'E'); 4015 expect(e.name, 'E');
4009 expect(e.nameOffset, text.indexOf('E')); 4016 expect(e.nameOffset, text.indexOf('E'));
4010 expect(e.values, hasLength(1)); 4017 expect(e.values, hasLength(1));
4011 expect(e.values[0].name, 'v1'); 4018 expect(e.values[0].name, 'v1');
4012 expect(e.values[0].nameOffset, text.indexOf('v1')); 4019 expect(e.values[0].nameOffset, text.indexOf('v1'));
4020 expect(e.hasCodeRange, true);
4021 expect(e.codeOffset, 0);
4022 expect(e.codeLength, 13);
4013 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); 4023 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1));
4014 expect(unlinkedUnits[0].publicNamespace.names[0].kind, 4024 expect(unlinkedUnits[0].publicNamespace.names[0].kind,
4015 ReferenceKind.classOrEnum); 4025 ReferenceKind.classOrEnum);
4016 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'E'); 4026 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'E');
4017 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0); 4027 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0);
4018 } 4028 }
4019 4029
4020 test_enum_documented() { 4030 test_enum_documented() {
4021 String text = ''' 4031 String text = '''
4022 // Extra comment so doc comment offset != 0 4032 // Extra comment so doc comment offset != 0
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
4403 } 4413 }
4404 4414
4405 test_executable_member_function() { 4415 test_executable_member_function() {
4406 UnlinkedExecutable executable = findExecutable('f', 4416 UnlinkedExecutable executable = findExecutable('f',
4407 executables: serializeClassText('class C { f() {} }').executables); 4417 executables: serializeClassText('class C { f() {} }').executables);
4408 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod); 4418 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod);
4409 expect(executable.returnType, isNull); 4419 expect(executable.returnType, isNull);
4410 expect(executable.isExternal, isFalse); 4420 expect(executable.isExternal, isFalse);
4411 expect(executable.visibleOffset, 0); 4421 expect(executable.visibleOffset, 0);
4412 expect(executable.visibleLength, 0); 4422 expect(executable.visibleLength, 0);
4423 expect(executable.hasCodeRange, true);
4424 expect(executable.codeOffset, 10);
4425 expect(executable.codeLength, 6);
4413 } 4426 }
4414 4427
4415 test_executable_member_function_explicit_return() { 4428 test_executable_member_function_explicit_return() {
4416 UnlinkedExecutable executable = findExecutable('f', 4429 UnlinkedExecutable executable = findExecutable('f',
4417 executables: 4430 executables:
4418 serializeClassText('class C { dynamic f() => null; }').executables); 4431 serializeClassText('class C { dynamic f() => null; }').executables);
4419 expect(executable.returnType, isNotNull); 4432 expect(executable.returnType, isNotNull);
4420 } 4433 }
4421 4434
4422 test_executable_member_function_external() { 4435 test_executable_member_function_external() {
4423 UnlinkedExecutable executable = findExecutable('f', 4436 UnlinkedExecutable executable = findExecutable('f',
4424 executables: 4437 executables:
4425 serializeClassText('class C { external f(); }').executables); 4438 serializeClassText('class C { external f(); }').executables);
4426 expect(executable.isExternal, isTrue); 4439 expect(executable.isExternal, isTrue);
4427 } 4440 }
4428 4441
4429 test_executable_member_getter() { 4442 test_executable_member_getter() {
4430 UnlinkedClass cls = serializeClassText('class C { int get f => 1; }'); 4443 UnlinkedClass cls = serializeClassText('class C { int get f => 1; }');
4431 UnlinkedExecutable executable = 4444 UnlinkedExecutable executable =
4432 findExecutable('f', executables: cls.executables, failIfAbsent: true); 4445 findExecutable('f', executables: cls.executables, failIfAbsent: true);
4433 expect(executable.kind, UnlinkedExecutableKind.getter); 4446 expect(executable.kind, UnlinkedExecutableKind.getter);
4434 expect(executable.returnType, isNotNull); 4447 expect(executable.returnType, isNotNull);
4435 expect(executable.isExternal, isFalse); 4448 expect(executable.isExternal, isFalse);
4449 expect(executable.hasCodeRange, true);
4450 expect(executable.codeOffset, 10);
4451 expect(executable.codeLength, 15);
4436 expect(findVariable('f', variables: cls.fields), isNull); 4452 expect(findVariable('f', variables: cls.fields), isNull);
4437 expect(findExecutable('f=', executables: cls.executables), isNull); 4453 expect(findExecutable('f=', executables: cls.executables), isNull);
4438 } 4454 }
4439 4455
4440 test_executable_member_getter_external() { 4456 test_executable_member_getter_external() {
4441 UnlinkedClass cls = serializeClassText('class C { external int get f; }'); 4457 UnlinkedClass cls = serializeClassText('class C { external int get f; }');
4442 UnlinkedExecutable executable = 4458 UnlinkedExecutable executable =
4443 findExecutable('f', executables: cls.executables, failIfAbsent: true); 4459 findExecutable('f', executables: cls.executables, failIfAbsent: true);
4444 expect(executable.isExternal, isTrue); 4460 expect(executable.isExternal, isTrue);
4445 } 4461 }
4446 4462
4447 test_executable_member_setter() { 4463 test_executable_member_setter() {
4448 UnlinkedClass cls = serializeClassText('class C { void set f(value) {} }'); 4464 UnlinkedClass cls = serializeClassText('class C { void set f(value) {} }');
4449 UnlinkedExecutable executable = 4465 UnlinkedExecutable executable =
4450 findExecutable('f=', executables: cls.executables, failIfAbsent: true); 4466 findExecutable('f=', executables: cls.executables, failIfAbsent: true);
4451 expect(executable.kind, UnlinkedExecutableKind.setter); 4467 expect(executable.kind, UnlinkedExecutableKind.setter);
4452 expect(executable.returnType, isNotNull); 4468 expect(executable.returnType, isNotNull);
4453 expect(executable.isExternal, isFalse); 4469 expect(executable.isExternal, isFalse);
4470 expect(executable.hasCodeRange, true);
4471 expect(executable.codeOffset, 10);
4472 expect(executable.codeLength, 20);
4454 expect(findVariable('f', variables: cls.fields), isNull); 4473 expect(findVariable('f', variables: cls.fields), isNull);
4455 expect(findExecutable('f', executables: cls.executables), isNull); 4474 expect(findExecutable('f', executables: cls.executables), isNull);
4456 } 4475 }
4457 4476
4458 test_executable_member_setter_external() { 4477 test_executable_member_setter_external() {
4459 UnlinkedClass cls = 4478 UnlinkedClass cls =
4460 serializeClassText('class C { external void set f(value); }'); 4479 serializeClassText('class C { external void set f(value); }');
4461 UnlinkedExecutable executable = 4480 UnlinkedExecutable executable =
4462 findExecutable('f=', executables: cls.executables, failIfAbsent: true); 4481 findExecutable('f=', executables: cls.executables, failIfAbsent: true);
4463 expect(executable.isExternal, isTrue); 4482 expect(executable.isExternal, isTrue);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
4565 expect(executable.typeParameters, isEmpty); 4584 expect(executable.typeParameters, isEmpty);
4566 } 4585 }
4567 4586
4568 test_executable_operator_less_equal() { 4587 test_executable_operator_less_equal() {
4569 UnlinkedExecutable executable = 4588 UnlinkedExecutable executable =
4570 serializeClassText('class C { bool operator<=(C other) => false; }') 4589 serializeClassText('class C { bool operator<=(C other) => false; }')
4571 .executables[0]; 4590 .executables[0];
4572 expect(executable.name, '<='); 4591 expect(executable.name, '<=');
4573 } 4592 }
4574 4593
4594 test_executable_param_codeRange() {
4595 UnlinkedExecutable executable = serializeExecutableText('f(int x) {}');
4596 UnlinkedParam parameter = executable.parameters[0];
4597 expect(parameter.hasCodeRange, true);
4598 expect(parameter.codeOffset, 2);
4599 expect(parameter.codeLength, 5);
4600 }
4601
4575 test_executable_param_function_typed() { 4602 test_executable_param_function_typed() {
4576 if (!checkAstDerivedData) { 4603 if (!checkAstDerivedData) {
4577 // TODO(paulberry): this test fails when building the summary from the 4604 // TODO(paulberry): this test fails when building the summary from the
4578 // element model because the elment model doesn't record whether a 4605 // element model because the elment model doesn't record whether a
4579 // function-typed parameter's return type is implicit. 4606 // function-typed parameter's return type is implicit.
4580 return; 4607 return;
4581 } 4608 }
4582 UnlinkedExecutable executable = serializeExecutableText('f(g()) {}'); 4609 UnlinkedExecutable executable = serializeExecutableText('f(g()) {}');
4583 expect(executable.parameters[0].isFunctionTyped, isTrue); 4610 expect(executable.parameters[0].isFunctionTyped, isTrue);
4584 expect(executable.parameters[0].type, isNull); 4611 expect(executable.parameters[0].type, isNull);
(...skipping 2202 matching lines...) Expand 10 before | Expand all | Expand 10 after
6787 allowTypeParameters: true, numTypeParameters: 2); 6814 allowTypeParameters: true, numTypeParameters: 2);
6788 expect(typeRef.typeArguments, hasLength(2)); 6815 expect(typeRef.typeArguments, hasLength(2));
6789 checkTypeRef(typeRef.typeArguments[0], 'dart:core', 'dart:core', 'int'); 6816 checkTypeRef(typeRef.typeArguments[0], 'dart:core', 'dart:core', 'int');
6790 checkTypeRef(typeRef.typeArguments[1], 'dart:core', 'dart:core', 'Object'); 6817 checkTypeRef(typeRef.typeArguments[1], 'dart:core', 'dart:core', 'Object');
6791 } 6818 }
6792 6819
6793 test_type_dynamic() { 6820 test_type_dynamic() {
6794 checkDynamicTypeRef(serializeTypeText('dynamic')); 6821 checkDynamicTypeRef(serializeTypeText('dynamic'));
6795 } 6822 }
6796 6823
6824 test_type_param_codeRange() {
6825 UnlinkedClass cls =
6826 serializeClassText('class A {} class C<T extends A> {}');
6827 var e = cls.typeParameters[0];
6828 expect(e.hasCodeRange, true);
6829 expect(e.codeOffset, 19);
6830 expect(e.codeLength, 11);
6831 }
6832
6797 test_type_param_not_shadowed_by_constructor() { 6833 test_type_param_not_shadowed_by_constructor() {
6798 UnlinkedClass cls = 6834 UnlinkedClass cls =
6799 serializeClassText('class C<D> { D x; C.D(); } class D {}'); 6835 serializeClassText('class C<D> { D x; C.D(); } class D {}');
6800 checkParamTypeRef(cls.fields[0].type, 1); 6836 checkParamTypeRef(cls.fields[0].type, 1);
6801 } 6837 }
6802 6838
6803 test_type_param_not_shadowed_by_field_in_extends() { 6839 test_type_param_not_shadowed_by_field_in_extends() {
6804 UnlinkedClass cls = 6840 UnlinkedClass cls =
6805 serializeClassText('class C<T> extends D<T> { T x; } class D<T> {}'); 6841 serializeClassText('class C<T> extends D<T> { T x; } class D<T> {}');
6806 checkParamTypeRef(cls.supertype.typeArguments[0], 1); 6842 checkParamTypeRef(cls.supertype.typeArguments[0], 1);
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
7045 // from them. 7081 // from them.
7046 checkTypeRef(typeRef, absUri('/a.dart'), 'a.dart', 'C', 7082 checkTypeRef(typeRef, absUri('/a.dart'), 'a.dart', 'C',
7047 expectedTargetUnit: 2); 7083 expectedTargetUnit: 2);
7048 } 7084 }
7049 7085
7050 test_type_unresolved() { 7086 test_type_unresolved() {
7051 EntityRef typeRef = serializeTypeText('Foo', allowErrors: true); 7087 EntityRef typeRef = serializeTypeText('Foo', allowErrors: true);
7052 checkUnresolvedTypeRef(typeRef, null, 'Foo'); 7088 checkUnresolvedTypeRef(typeRef, null, 'Foo');
7053 } 7089 }
7054 7090
7091 test_typedef_codeRange() {
7092 UnlinkedTypedef type = serializeTypedefText('typedef F();');
7093 expect(type.hasCodeRange, true);
7094 expect(type.codeOffset, 0);
7095 expect(type.codeLength, 12);
7096 }
7097
7055 test_typedef_documented() { 7098 test_typedef_documented() {
7056 String text = ''' 7099 String text = '''
7057 // Extra comment so doc comment offset != 0 7100 // Extra comment so doc comment offset != 0
7058 /** 7101 /**
7059 * Docs 7102 * Docs
7060 */ 7103 */
7061 typedef F();'''; 7104 typedef F();''';
7062 UnlinkedTypedef typedef = serializeTypedefText(text); 7105 UnlinkedTypedef typedef = serializeTypedefText(text);
7063 expect(typedef.documentationComment, isNotNull); 7106 expect(typedef.documentationComment, isNotNull);
7064 checkDocumentationComment(typedef.documentationComment, text); 7107 checkDocumentationComment(typedef.documentationComment, text);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
7129 expect(type.typeParameters, isEmpty); 7172 expect(type.typeParameters, isEmpty);
7130 } 7173 }
7131 7174
7132 test_typedef_type_param_order() { 7175 test_typedef_type_param_order() {
7133 UnlinkedTypedef type = serializeTypedefText('typedef F<T, U>();'); 7176 UnlinkedTypedef type = serializeTypedefText('typedef F<T, U>();');
7134 expect(type.typeParameters, hasLength(2)); 7177 expect(type.typeParameters, hasLength(2));
7135 expect(type.typeParameters[0].name, 'T'); 7178 expect(type.typeParameters[0].name, 'T');
7136 expect(type.typeParameters[1].name, 'U'); 7179 expect(type.typeParameters[1].name, 'U');
7137 } 7180 }
7138 7181
7182 test_unit_codeRange() {
7183 serializeLibraryText(' int a = 1; ');
7184 UnlinkedUnit unit = unlinkedUnits[0];
7185 expect(unit.hasCodeRange, true);
7186 expect(unit.codeOffset, 0);
7187 expect(unit.codeLength, 14);
7188 }
7189
7139 test_unresolved_reference_in_multiple_parts() { 7190 test_unresolved_reference_in_multiple_parts() {
7140 addNamedSource('/a.dart', 'part of foo; int x; Unresolved y;'); 7191 addNamedSource('/a.dart', 'part of foo; int x; Unresolved y;');
7141 serializeLibraryText('library foo; part "a.dart"; Unresolved z;', 7192 serializeLibraryText('library foo; part "a.dart"; Unresolved z;',
7142 allowErrors: true); 7193 allowErrors: true);
7143 // The unresolved types in the defining compilation unit and the part 7194 // The unresolved types in the defining compilation unit and the part
7144 // should both work correctly even though they use different reference 7195 // should both work correctly even though they use different reference
7145 // indices. 7196 // indices.
7146 checkUnresolvedTypeRef( 7197 checkUnresolvedTypeRef(
7147 unlinkedUnits[0].variables[0].type, null, 'Unresolved'); 7198 unlinkedUnits[0].variables[0].type, null, 'Unresolved');
7148 checkUnresolvedTypeRef( 7199 checkUnresolvedTypeRef(
(...skipping 21 matching lines...) Expand all
7170 expect(unlinkedUnits[0].publicNamespace.names[0].kind, 7221 expect(unlinkedUnits[0].publicNamespace.names[0].kind,
7171 ReferenceKind.topLevelPropertyAccessor); 7222 ReferenceKind.topLevelPropertyAccessor);
7172 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'i'); 7223 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'i');
7173 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0); 7224 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0);
7174 expect(unlinkedUnits[0].publicNamespace.names[1].kind, 7225 expect(unlinkedUnits[0].publicNamespace.names[1].kind,
7175 ReferenceKind.topLevelPropertyAccessor); 7226 ReferenceKind.topLevelPropertyAccessor);
7176 expect(unlinkedUnits[0].publicNamespace.names[1].name, 'i='); 7227 expect(unlinkedUnits[0].publicNamespace.names[1].name, 'i=');
7177 expect(unlinkedUnits[0].publicNamespace.names[1].numTypeParameters, 0); 7228 expect(unlinkedUnits[0].publicNamespace.names[1].numTypeParameters, 0);
7178 } 7229 }
7179 7230
7231 test_variable_codeRange() {
7232 serializeLibraryText(' int a = 1, b = 22;');
7233 List<UnlinkedVariable> variables = unlinkedUnits[0].variables;
7234 {
7235 UnlinkedVariable variable = variables[0];
7236 expect(variable.hasCodeRange, true);
7237 expect(variable.codeOffset, 1);
7238 expect(variable.codeLength, 18);
7239 }
7240 {
7241 UnlinkedVariable variable = variables[1];
7242 expect(variable.hasCodeRange, true);
7243 expect(variable.codeOffset, 1);
7244 expect(variable.codeLength, 18);
7245 }
7246 }
7247
7180 test_variable_const() { 7248 test_variable_const() {
7181 UnlinkedVariable variable = 7249 UnlinkedVariable variable =
7182 serializeVariableText('const int i = 0;', variableName: 'i'); 7250 serializeVariableText('const int i = 0;', variableName: 'i');
7183 expect(variable.isConst, isTrue); 7251 expect(variable.isConst, isTrue);
7184 } 7252 }
7185 7253
7186 test_variable_documented() { 7254 test_variable_documented() {
7187 String text = ''' 7255 String text = '''
7188 // Extra comment so doc comment offset != 0 7256 // Extra comment so doc comment offset != 0
7189 /** 7257 /**
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
7485 class _PrefixExpectation { 7553 class _PrefixExpectation {
7486 final ReferenceKind kind; 7554 final ReferenceKind kind;
7487 final String name; 7555 final String name;
7488 final String absoluteUri; 7556 final String absoluteUri;
7489 final String relativeUri; 7557 final String relativeUri;
7490 final int numTypeParameters; 7558 final int numTypeParameters;
7491 7559
7492 _PrefixExpectation(this.kind, this.name, 7560 _PrefixExpectation(this.kind, this.name,
7493 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); 7561 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0});
7494 } 7562 }
OLDNEW
« pkg/analyzer/lib/src/summary/idl.dart ('K') | « pkg/analyzer/test/src/summary/resynthesize_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698