OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 /** A formal parameter to a [Method]. */ | 5 /** A formal parameter to a [Method]. */ |
6 class Parameter { | 6 class Parameter { |
7 FormalNode definition; | 7 FormalNode definition; |
8 | 8 |
9 String name; | 9 String name; |
10 Type type; | 10 Type type; |
(...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 Value target, Arguments args, argsString) { | 998 Value target, Arguments args, argsString) { |
999 declaringType.markUsed(); | 999 declaringType.markUsed(); |
1000 | 1000 |
1001 if (!target.isType) { | 1001 if (!target.isType) { |
1002 // initializer call to another constructor | 1002 // initializer call to another constructor |
1003 var code = (constructorName != '') | 1003 var code = (constructorName != '') |
1004 ? '${declaringType.jsname}.${constructorName}\$ctor.call($argsString)' | 1004 ? '${declaringType.jsname}.${constructorName}\$ctor.call($argsString)' |
1005 : '${declaringType.jsname}.call($argsString)'; | 1005 : '${declaringType.jsname}.call($argsString)'; |
1006 return new Value(target.type, code, node.span); | 1006 return new Value(target.type, code, node.span); |
1007 } else { | 1007 } else { |
| 1008 if (declaringType.isAbstract) { |
| 1009 // Warn at the constructor location |
| 1010 world.warning('Cannot instantiate abstract class ${declaringType.name}', |
| 1011 node.span); |
| 1012 |
| 1013 // Now make a message explaining why the type is abstract. |
| 1014 |
| 1015 // Get abstract members grouped by type |
| 1016 var members = groupBy(declaringType.inheritedMembers.getValues().filter( |
| 1017 (m) => m.isAbstract), (m) => m.declaringType); |
| 1018 |
| 1019 var msg = new StringBuffer('Type ${declaringType.name} is abstract ' |
| 1020 + 'because it does not implement the following members'); |
| 1021 |
| 1022 var types = members.getKeys(); |
| 1023 types.sort((x, y) => x.name.compareTo(y.name)); |
| 1024 for (var type in types) { |
| 1025 if (type != types[0]) msg.add(';'); |
| 1026 msg.add(' from type ${type.name}: '); |
| 1027 msg.add(Strings.join(map(members[type], (m) => m.name), ', ')); |
| 1028 } |
| 1029 |
| 1030 // Warn at the type's location |
| 1031 world.warning(msg.toString(), declaringType.span); |
| 1032 } |
| 1033 |
1008 var code = (constructorName != '') | 1034 var code = (constructorName != '') |
1009 ? 'new ${declaringType.jsname}.${constructorName}\$ctor($argsString)' | 1035 ? 'new ${declaringType.jsname}.${constructorName}\$ctor($argsString)' |
1010 : 'new ${declaringType.jsname}($argsString)'; | 1036 : 'new ${declaringType.jsname}($argsString)'; |
1011 // TODO(jmesserly): using the "node" here feels really hacky | 1037 // TODO(jmesserly): using the "node" here feels really hacky |
1012 if (isConst && node is NewExpression && node.dynamic.isConst) { | 1038 if (isConst && node is NewExpression && node.dynamic.isConst) { |
1013 return _invokeConstConstructor(node, code, target, args); | 1039 return _invokeConstConstructor(node, code, target, args); |
1014 } else { | 1040 } else { |
1015 return new Value(target.type, code, node.span); | 1041 return new Value(target.type, code, node.span); |
1016 } | 1042 } |
1017 } | 1043 } |
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1694 } | 1720 } |
1695 | 1721 |
1696 void forEach(void f(Member member)) { | 1722 void forEach(void f(Member member)) { |
1697 factories.forEach((_, Map constructors) { | 1723 factories.forEach((_, Map constructors) { |
1698 constructors.forEach((_, Member member) { | 1724 constructors.forEach((_, Member member) { |
1699 f(member); | 1725 f(member); |
1700 }); | 1726 }); |
1701 }); | 1727 }); |
1702 } | 1728 } |
1703 } | 1729 } |
OLD | NEW |