| 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 private EnclosingElement currentHolder; | 185 private EnclosingElement currentHolder; |
| 186 private EnclosingElement enclosingElement; | 186 private EnclosingElement enclosingElement; |
| 187 private MethodElement currentMethod; | 187 private MethodElement currentMethod; |
| 188 private boolean inInstanceVariableInitializer; | 188 private boolean inInstanceVariableInitializer; |
| 189 private boolean inInitializer; | 189 private boolean inInitializer; |
| 190 private MethodElement innermostFunction; | 190 private MethodElement innermostFunction; |
| 191 private ResolutionContext context; | 191 private ResolutionContext context; |
| 192 private Set<LabelElement> referencedLabels = Sets.newHashSet(); | 192 private Set<LabelElement> referencedLabels = Sets.newHashSet(); |
| 193 private Set<LabelElement> labelsInScopes = Sets.newHashSet(); | 193 private Set<LabelElement> labelsInScopes = Sets.newHashSet(); |
| 194 private Set<FieldElement> finalsNeedingInitializing = Sets.newHashSet(); | 194 private Set<FieldElement> finalsNeedingInitializing = Sets.newHashSet(); |
| 195 private Set<FieldElement> resolvedFields = Sets.newHashSet(); |
| 195 | 196 |
| 196 @VisibleForTesting | 197 @VisibleForTesting |
| 197 public ResolveElementsVisitor(ResolutionContext context, | 198 public ResolveElementsVisitor(ResolutionContext context, |
| 198 EnclosingElement currentHolder, | 199 EnclosingElement currentHolder, |
| 199 MethodElement currentMethod) { | 200 MethodElement currentMethod) { |
| 200 super(typeProvider); | 201 super(typeProvider); |
| 201 this.context = context; | 202 this.context = context; |
| 202 this.currentMethod = currentMethod; | 203 this.currentMethod = currentMethod; |
| 203 this.innermostFunction = currentMethod; | 204 this.innermostFunction = currentMethod; |
| 204 this.currentHolder = currentHolder; | 205 this.currentHolder = currentHolder; |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 728 } else if (isTopLevel) { | 729 } else if (isTopLevel) { |
| 729 onError(node, ResolverErrorCode.TOPLEVEL_FINAL_REQUIRES_VALUE); | 730 onError(node, ResolverErrorCode.TOPLEVEL_FINAL_REQUIRES_VALUE); |
| 730 } else { | 731 } else { |
| 731 // If a final instance field wasn't initialized at declaration, we mus
t check | 732 // If a final instance field wasn't initialized at declaration, we mus
t check |
| 732 // at construction time. | 733 // at construction time. |
| 733 this.finalsNeedingInitializing.add(node.getElement()); | 734 this.finalsNeedingInitializing.add(node.getElement()); |
| 734 } | 735 } |
| 735 } | 736 } |
| 736 | 737 |
| 737 // If field is an accessor, both getter and setter need to be visited (if
present). | 738 // If field is an accessor, both getter and setter need to be visited (if
present). |
| 739 // We check for duplicates because top-level fields are visited twice - fo
r each accessor. |
| 738 FieldNodeElement field = node.getElement(); | 740 FieldNodeElement field = node.getElement(); |
| 739 if (field.getGetter() != null) { | 741 if (!resolvedFields.contains(field)) { |
| 740 resolve(field.getGetter().getNode()); | 742 resolvedFields.add(field); |
| 741 } | 743 if (field.getGetter() != null) { |
| 742 if (field.getSetter() != null) { | 744 resolve(field.getGetter().getNode()); |
| 743 resolve(field.getSetter().getNode()); | 745 } |
| 746 if (field.getSetter() != null) { |
| 747 resolve(field.getSetter().getNode()); |
| 748 } |
| 744 } | 749 } |
| 745 return null; | 750 return null; |
| 746 } | 751 } |
| 747 | 752 |
| 748 @Override | 753 @Override |
| 749 public Element visitFieldDefinition(DartFieldDefinition node) { | 754 public Element visitFieldDefinition(DartFieldDefinition node) { |
| 750 node.getMetadata().accept(this); | 755 node.getMetadata().accept(this); |
| 751 visit(node.getFields()); | 756 visit(node.getFields()); |
| 752 return null; | 757 return null; |
| 753 } | 758 } |
| (...skipping 1550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2304 ClassElement currentClass = (ClassElement) constructor.getEnclosingEle
ment(); | 2309 ClassElement currentClass = (ClassElement) constructor.getEnclosingEle
ment(); |
| 2305 if (nextClass == currentClass) { | 2310 if (nextClass == currentClass) { |
| 2306 return (ConstructorNodeElement) nextConstructorElement; | 2311 return (ConstructorNodeElement) nextConstructorElement; |
| 2307 } | 2312 } |
| 2308 } | 2313 } |
| 2309 } | 2314 } |
| 2310 } | 2315 } |
| 2311 return null; | 2316 return null; |
| 2312 } | 2317 } |
| 2313 } | 2318 } |
| OLD | NEW |