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

Side by Side Diff: compiler/java/com/google/dart/compiler/resolver/TopLevelElementBuilder.java

Issue 10134035: Fix a bug that caused private names from an imported library to be included in the name scope of th… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/resolver/ResolverTestCase.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.Maps; 8 import com.google.common.collect.Maps;
9 import com.google.dart.compiler.DartCompilationError; 9 import com.google.dart.compiler.DartCompilationError;
10 import com.google.dart.compiler.DartCompilerContext; 10 import com.google.dart.compiler.DartCompilerContext;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 // Put the prefix in the scope. 69 // Put the prefix in the scope.
70 LibraryPrefixElement libraryPrefixElement = libraryPrefixElements.get(pr efix); 70 LibraryPrefixElement libraryPrefixElement = libraryPrefixElements.get(pr efix);
71 if (libraryPrefixElement == null) { 71 if (libraryPrefixElement == null) {
72 libraryPrefixElement = new LibraryPrefixElementImplementation(prefix, scope); 72 libraryPrefixElement = new LibraryPrefixElementImplementation(prefix, scope);
73 libraryPrefixElements.put(prefix, libraryPrefixElement); 73 libraryPrefixElements.put(prefix, libraryPrefixElement);
74 scope.declareElement(prefix, libraryPrefixElement); 74 scope.declareElement(prefix, libraryPrefixElement);
75 } 75 }
76 libraryPrefixElement.addLibrary(lib.getElement()); 76 libraryPrefixElement.addLibrary(lib.getElement());
77 // Fill library prefix scope. 77 // Fill library prefix scope.
78 for (DartUnit unit : lib.getUnits()) { 78 for (DartUnit unit : lib.getUnits()) {
79 fillInUnitScope(unit, listener, libraryPrefixElement.getScope()); 79 fillInUnitScope(unit, listener, libraryPrefixElement.getScope(), false );
80 } 80 }
81 } else { 81 } else {
82 // Put the elements of the library in the scope. 82 // Put the elements of the library in the scope.
83 for (DartUnit unit : lib.getUnits()) { 83 for (DartUnit unit : lib.getUnits()) {
84 fillInUnitScope(unit, listener, scope); 84 fillInUnitScope(unit, listener, scope, false);
85 } 85 }
86 } 86 }
87 } 87 }
88 88
89 for (DartUnit unit : library.getUnits()) { 89 for (DartUnit unit : library.getUnits()) {
90 fillInUnitScope(unit, listener, scope); 90 fillInUnitScope(unit, listener, scope, true);
91 } 91 }
92 } 92 }
93 93
94 @VisibleForTesting 94 @VisibleForTesting
95 void fillInUnitScope(DartUnit unit, DartCompilerListener listener, Scope scope ) { 95 void fillInUnitScope(DartUnit unit, DartCompilerListener listener, Scope scope , boolean includePrivate) {
96 for (DartNode node : unit.getTopLevelNodes()) { 96 for (DartNode node : unit.getTopLevelNodes()) {
97 if (node instanceof DartFieldDefinition) { 97 if (node instanceof DartFieldDefinition) {
98 for (DartField field : ((DartFieldDefinition) node).getFields()) { 98 for (DartField field : ((DartFieldDefinition) node).getFields()) {
99 declare(field.getElement(), listener, scope); 99 Element element = field.getElement();
100 if (includePrivate || !element.getName().startsWith("_")) {
scheglov 2012/04/24 18:32:11 May be use com.google.dart.compiler.ast.DartIdenti
Brian Wilkerson 2012/04/24 18:47:24 Done
101 declare(element, listener, scope);
scheglov 2012/04/24 18:32:11 indentation
Brian Wilkerson 2012/04/24 18:47:24 Done
102 }
100 } 103 }
101 } else { 104 } else {
102 declare((Element) node.getElement(), listener, scope); 105 Element element = node.getElement();
106 if (includePrivate || !element.getName().startsWith("_")) {
107 declare(element, listener, scope);
108 }
103 } 109 }
104 } 110 }
105 } 111 }
106 112
107 private void compilationError(DartCompilerListener listener, SourceInfo node, ErrorCode errorCode, 113 private void compilationError(DartCompilerListener listener, SourceInfo node, ErrorCode errorCode,
108 Object... args) { 114 Object... args) {
109 DartCompilationError error = new DartCompilationError(node, errorCode, args) ; 115 DartCompilationError error = new DartCompilationError(node, errorCode, args) ;
110 listener.onError(error); 116 listener.onError(error);
111 } 117 }
112 118
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 Modifiers modifiers = node.getModifiers(); 191 Modifiers modifiers = node.getModifiers();
186 if (modifiers.isFinal()) { 192 if (modifiers.isFinal()) {
187 // final toplevel fields are implicitly compile-time constants. 193 // final toplevel fields are implicitly compile-time constants.
188 modifiers = modifiers.makeConstant(); 194 modifiers = modifiers.makeConstant();
189 } 195 }
190 node.setElement(Elements.fieldFromNode(node, library, modifiers)); 196 node.setElement(Elements.fieldFromNode(node, library, modifiers));
191 return null; 197 return null;
192 } 198 }
193 } 199 }
194 } 200 }
OLDNEW
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/resolver/ResolverTestCase.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698