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

Side by Side Diff: pkg/analyzer/lib/src/dart/element/element.dart

Issue 2033293003: Compute ConstructorElement.returnType/type dynamically. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 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) 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.src.dart.element.element; 5 library analyzer.src.dart.element.element;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:math' show min; 8 import 'dart:math' show min;
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 } 1078 }
1079 1079
1080 // Now create an implicit constructor for every constructor found above, 1080 // Now create an implicit constructor for every constructor found above,
1081 // substituting type parameters as appropriate. 1081 // substituting type parameters as appropriate.
1082 return constructorsToForward 1082 return constructorsToForward
1083 .map((ConstructorElement superclassConstructor) { 1083 .map((ConstructorElement superclassConstructor) {
1084 ConstructorElementImpl implicitConstructor = 1084 ConstructorElementImpl implicitConstructor =
1085 new ConstructorElementImpl(superclassConstructor.name, -1); 1085 new ConstructorElementImpl(superclassConstructor.name, -1);
1086 implicitConstructor.synthetic = true; 1086 implicitConstructor.synthetic = true;
1087 implicitConstructor.redirectedConstructor = superclassConstructor; 1087 implicitConstructor.redirectedConstructor = superclassConstructor;
1088 implicitConstructor.returnType = type;
1089 List<ParameterElement> superParameters = superclassConstructor.parameters; 1088 List<ParameterElement> superParameters = superclassConstructor.parameters;
1090 int count = superParameters.length; 1089 int count = superParameters.length;
1091 if (count > 0) { 1090 if (count > 0) {
1092 List<ParameterElement> implicitParameters = 1091 List<ParameterElement> implicitParameters =
1093 new List<ParameterElement>(count); 1092 new List<ParameterElement>(count);
1094 for (int i = 0; i < count; i++) { 1093 for (int i = 0; i < count; i++) {
1095 ParameterElement superParameter = superParameters[i]; 1094 ParameterElement superParameter = superParameters[i];
1096 ParameterElementImpl implicitParameter = 1095 ParameterElementImpl implicitParameter =
1097 new ParameterElementImpl(superParameter.name, -1); 1096 new ParameterElementImpl(superParameter.name, -1);
1098 implicitParameter.const3 = superParameter.isConst; 1097 implicitParameter.const3 = superParameter.isConst;
1099 implicitParameter.final2 = superParameter.isFinal; 1098 implicitParameter.final2 = superParameter.isFinal;
1100 implicitParameter.parameterKind = superParameter.parameterKind; 1099 implicitParameter.parameterKind = superParameter.parameterKind;
1101 implicitParameter.synthetic = true; 1100 implicitParameter.synthetic = true;
1102 implicitParameter.type = 1101 implicitParameter.type =
1103 superParameter.type.substitute2(argumentTypes, parameterTypes); 1102 superParameter.type.substitute2(argumentTypes, parameterTypes);
1104 implicitParameters[i] = implicitParameter; 1103 implicitParameters[i] = implicitParameter;
1105 } 1104 }
1106 implicitConstructor.parameters = implicitParameters; 1105 implicitConstructor.parameters = implicitParameters;
1107 } 1106 }
1108 implicitConstructor.enclosingElement = this; 1107 implicitConstructor.enclosingElement = this;
1109 implicitConstructor.type = new FunctionTypeImpl(implicitConstructor);
1110 return implicitConstructor; 1108 return implicitConstructor;
1111 }).toList(growable: false); 1109 }).toList(growable: false);
1112 } 1110 }
1113 1111
1114 bool _safeIsOrInheritsProxy( 1112 bool _safeIsOrInheritsProxy(
1115 ClassElement classElt, HashSet<ClassElement> visitedClassElts) { 1113 ClassElement classElt, HashSet<ClassElement> visitedClassElts) {
1116 if (visitedClassElts.contains(classElt)) { 1114 if (visitedClassElts.contains(classElt)) {
1117 return false; 1115 return false;
1118 } 1116 }
1119 visitedClassElts.add(classElt); 1117 visitedClassElts.add(classElt);
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after
1875 } 1873 }
1876 1874
1877 void set redirectedConstructor(ConstructorElement redirectedConstructor) { 1875 void set redirectedConstructor(ConstructorElement redirectedConstructor) {
1878 assert(serializedExecutable == null); 1876 assert(serializedExecutable == null);
1879 _redirectedConstructor = redirectedConstructor; 1877 _redirectedConstructor = redirectedConstructor;
1880 } 1878 }
1881 1879
1882 @override 1880 @override
1883 DartType get returnType => enclosingElement.type; 1881 DartType get returnType => enclosingElement.type;
1884 1882
1883 void set returnType(DartType returnType) {
1884 assert(false);
1885 }
1886
1887 @override
1888 FunctionType get type {
1889 return _type ??= new FunctionTypeImpl(this);
1890 }
1891
1892 void set type(FunctionType type) {
1893 assert(false);
1894 }
1895
1885 @override 1896 @override
1886 accept(ElementVisitor visitor) => visitor.visitConstructorElement(this); 1897 accept(ElementVisitor visitor) => visitor.visitConstructorElement(this);
1887 1898
1888 @override 1899 @override
1889 void appendTo(StringBuffer buffer) { 1900 void appendTo(StringBuffer buffer) {
1890 if (enclosingElement == null) { 1901 if (enclosingElement == null) {
1891 String message; 1902 String message;
1892 String name = displayName; 1903 String name = displayName;
1893 if (name != null && !name.isEmpty) { 1904 if (name != null && !name.isEmpty) {
1894 message = 1905 message =
(...skipping 6152 matching lines...) Expand 10 before | Expand all | Expand 10 after
8047 8058
8048 @override 8059 @override
8049 void visitElement(Element element) { 8060 void visitElement(Element element) {
8050 int offset = element.nameOffset; 8061 int offset = element.nameOffset;
8051 if (offset != -1) { 8062 if (offset != -1) {
8052 map[offset] = element; 8063 map[offset] = element;
8053 } 8064 }
8054 super.visitElement(element); 8065 super.visitElement(element);
8055 } 8066 }
8056 } 8067 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698