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 serialization.elements; | 5 library serialization.elements; |
6 | 6 |
7 import 'dart:convert'; | 7 import 'dart:convert'; |
8 | 8 |
9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 case ParameterKind.NAMED: | 895 case ParameterKind.NAMED: |
896 b.kind = UnlinkedParamKind.named; | 896 b.kind = UnlinkedParamKind.named; |
897 break; | 897 break; |
898 } | 898 } |
899 b.annotations = serializeAnnotations(parameter); | 899 b.annotations = serializeAnnotations(parameter); |
900 b.codeRange = serializeCodeRange(parameter); | 900 b.codeRange = serializeCodeRange(parameter); |
901 b.isInitializingFormal = parameter.isInitializingFormal; | 901 b.isInitializingFormal = parameter.isInitializingFormal; |
902 DartType type = parameter.type; | 902 DartType type = parameter.type; |
903 if (parameter.hasImplicitType) { | 903 if (parameter.hasImplicitType) { |
904 Element contextParent = context.enclosingElement; | 904 Element contextParent = context.enclosingElement; |
| 905 // Strong mode infers parameters in two cases: |
| 906 // - instance members (i.e. not constructors or static members), |
| 907 // - parameters with default values, except initializing formals |
| 908 // (the type comes from the field). |
905 if (!parameter.isInitializingFormal && | 909 if (!parameter.isInitializingFormal && |
906 contextParent is ExecutableElement && | 910 contextParent is ExecutableElement && |
907 !contextParent.isStatic && | 911 (!contextParent.isStatic && contextParent is! ConstructorElement || |
908 contextParent is! ConstructorElement) { | 912 parameter.parameterKind != ParameterKind.REQUIRED)) { |
909 b.inferredTypeSlot = storeInferredType(type, context); | 913 b.inferredTypeSlot = storeInferredType(type, context); |
910 } | 914 } |
911 } else { | 915 } else { |
912 if (type is FunctionType && type.element.isSynthetic) { | 916 if (type is FunctionType && type.element.isSynthetic) { |
913 b.isFunctionTyped = true; | 917 b.isFunctionTyped = true; |
914 b.type = serializeTypeRef(type.returnType, parameter); | 918 b.type = serializeTypeRef(type.returnType, parameter); |
915 b.parameters = type.parameters | 919 b.parameters = type.parameters |
916 .map((parameter) => serializeParam(parameter, context)) | 920 .map((parameter) => serializeParam(parameter, context)) |
917 .toList(); | 921 .toList(); |
918 } else { | 922 } else { |
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1675 exportNames.add(new LinkedExportNameBuilder( | 1679 exportNames.add(new LinkedExportNameBuilder( |
1676 name: name, | 1680 name: name, |
1677 dependency: serializeDependency(dependentLibrary), | 1681 dependency: serializeDependency(dependentLibrary), |
1678 unit: unit, | 1682 unit: unit, |
1679 kind: kind)); | 1683 kind: kind)); |
1680 } | 1684 } |
1681 pb.exportNames = exportNames; | 1685 pb.exportNames = exportNames; |
1682 return pb; | 1686 return pb; |
1683 } | 1687 } |
1684 } | 1688 } |
OLD | NEW |