OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 package com.google.dart.compiler.resolver; | 5 package com.google.dart.compiler.resolver; |
6 | 6 |
7 import com.google.common.annotations.VisibleForTesting; | 7 import com.google.common.annotations.VisibleForTesting; |
8 import com.google.common.collect.Lists; | 8 import com.google.common.collect.Lists; |
9 import com.google.common.collect.Sets; | 9 import com.google.common.collect.Sets; |
10 import com.google.dart.compiler.DartCompilationPhase; | 10 import com.google.dart.compiler.DartCompilationPhase; |
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 DartBlock body = functionNode.getBody(); | 647 DartBlock body = functionNode.getBody(); |
648 boolean isInterface = false; | 648 boolean isInterface = false; |
649 if (ElementKind.of(member.getEnclosingElement()).equals(ElementKind.CLASS) | 649 if (ElementKind.of(member.getEnclosingElement()).equals(ElementKind.CLASS) |
650 && ((ClassElement) member.getEnclosingElement()).isInterface()) { | 650 && ((ClassElement) member.getEnclosingElement()).isInterface()) { |
651 isInterface =true; | 651 isInterface =true; |
652 } | 652 } |
653 if (body == null | 653 if (body == null |
654 && !Elements.isNonFactoryConstructor(member) | 654 && !Elements.isNonFactoryConstructor(member) |
655 && !member.getModifiers().isAbstract() | 655 && !member.getModifiers().isAbstract() |
656 && !member.getModifiers().isExternal() | 656 && !member.getModifiers().isExternal() |
| 657 && node.getRedirectedTypeName() == null |
657 && !isInterface) { | 658 && !isInterface) { |
658 onError(functionNode, ResolverErrorCode.METHOD_MUST_HAVE_BODY); | 659 onError(functionNode, ResolverErrorCode.METHOD_MUST_HAVE_BODY); |
659 } | 660 } |
660 resolve(functionNode.getBody()); | 661 resolve(functionNode.getBody()); |
661 | 662 |
662 if (Elements.isNonFactoryConstructor(member) | 663 if (Elements.isNonFactoryConstructor(member) |
663 && !(body instanceof DartNativeBlock)) { | 664 && !(body instanceof DartNativeBlock)) { |
664 resolveInitializers(node, initializedFields); | 665 resolveInitializers(node, initializedFields); |
665 } | 666 } |
666 | 667 |
| 668 // resolve redirecting factory constructor |
| 669 { |
| 670 DartTypeNode rcTypeName = node.getRedirectedTypeName(); |
| 671 if (rcTypeName != null) { |
| 672 InterfaceType rcType = (InterfaceType) resolveType(rcTypeName, true, t
rue, |
| 673 TypeErrorCode.NO_SUCH_TYPE, ResolverErrorCode.WRONG_NUMBER_OF_TYPE
_ARGUMENTS); |
| 674 switch (TypeKind.of(rcType)) { |
| 675 case INTERFACE: |
| 676 Element element = recordType(rcTypeName, rcType); |
| 677 DartIdentifier rcName = node.getRedirectedConstructorName(); |
| 678 if (rcName != null) { |
| 679 element = ((ClassElement) element).lookupConstructor(rcName.getN
ame()); |
| 680 switch (ElementKind.of(element)) { |
| 681 case CONSTRUCTOR: |
| 682 recordElement(rcName, element); |
| 683 if (member.getModifiers().isConstant() && !element.getModifi
ers().isConstant()) { |
| 684 onError(rcName, |
| 685 ResolverErrorCode.REDIRECTION_CONSTRUCTOR_TARGET_MUST_
BE_CONST); |
| 686 } |
| 687 break; |
| 688 } |
| 689 } |
| 690 break; |
| 691 } |
| 692 } |
| 693 } |
| 694 |
667 context = previousContext; | 695 context = previousContext; |
668 innermostFunction = currentMethod = null; | 696 innermostFunction = currentMethod = null; |
669 enclosingElement = previousEnclosingElement; | 697 enclosingElement = previousEnclosingElement; |
670 return member; | 698 return member; |
671 } | 699 } |
672 | 700 |
673 @Override | 701 @Override |
674 public Element visitField(DartField node) { | 702 public Element visitField(DartField node) { |
675 DartExpression expression = node.getValue(); | 703 DartExpression expression = node.getValue(); |
676 Modifiers modifiers = node.getModifiers(); | 704 Modifiers modifiers = node.getModifiers(); |
(...skipping 1593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2270 ClassElement currentClass = (ClassElement) constructor.getEnclosingEle
ment(); | 2298 ClassElement currentClass = (ClassElement) constructor.getEnclosingEle
ment(); |
2271 if (nextClass == currentClass) { | 2299 if (nextClass == currentClass) { |
2272 return (ConstructorNodeElement) nextConstructorElement; | 2300 return (ConstructorNodeElement) nextConstructorElement; |
2273 } | 2301 } |
2274 } | 2302 } |
2275 } | 2303 } |
2276 } | 2304 } |
2277 return null; | 2305 return null; |
2278 } | 2306 } |
2279 } | 2307 } |
OLD | NEW |