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

Side by Side Diff: pkg/analyzer/lib/src/dart/analysis/file_state.dart

Issue 2541793005: Return only public top-level declarations. (Closed)
Patch Set: after commit Created 4 years 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
« no previous file with comments | « no previous file | pkg/analyzer/test/src/dart/analysis/file_state_test.dart » ('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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 import 'dart:convert'; 5 import 'dart:convert';
6 import 'dart:typed_data'; 6 import 'dart:typed_data';
7 7
8 import 'package:analyzer/dart/ast/ast.dart'; 8 import 'package:analyzer/dart/ast/ast.dart';
9 import 'package:analyzer/dart/ast/token.dart'; 9 import 'package:analyzer/dart/ast/token.dart';
10 import 'package:analyzer/error/listener.dart'; 10 import 'package:analyzer/error/listener.dart';
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 * The list of files this library file references as parts. 167 * The list of files this library file references as parts.
168 */ 168 */
169 List<FileState> get partedFiles => _partedFiles; 169 List<FileState> get partedFiles => _partedFiles;
170 170
171 /** 171 /**
172 * The external names referenced by the file. 172 * The external names referenced by the file.
173 */ 173 */
174 Set<String> get referencedNames => _referencedNames; 174 Set<String> get referencedNames => _referencedNames;
175 175
176 /** 176 /**
177 * Return top-level declarations declared in the file. 177 * Return public top-level declarations declared in the file.
178 */ 178 */
179 List<TopLevelDeclaration> get topLevelDeclarations { 179 List<TopLevelDeclaration> get topLevelDeclarations {
180 if (_topLevelDeclarations == null) { 180 if (_topLevelDeclarations == null) {
181 _topLevelDeclarations = <TopLevelDeclaration>[]; 181 _topLevelDeclarations = <TopLevelDeclaration>[];
182
183 void addDeclaration(TopLevelDeclarationKind kind, String name) {
184 if (!name.startsWith('_')) {
185 _topLevelDeclarations.add(new TopLevelDeclaration(kind, name));
186 }
187 }
188
182 // Add types. 189 // Add types.
183 for (UnlinkedClass type in unlinked.classes) { 190 for (UnlinkedClass type in unlinked.classes) {
184 _topLevelDeclarations.add( 191 addDeclaration(TopLevelDeclarationKind.type, type.name);
185 new TopLevelDeclaration(TopLevelDeclarationKind.type, type.name));
186 } 192 }
187 for (UnlinkedEnum type in unlinked.enums) { 193 for (UnlinkedEnum type in unlinked.enums) {
188 _topLevelDeclarations.add( 194 addDeclaration(TopLevelDeclarationKind.type, type.name);
189 new TopLevelDeclaration(TopLevelDeclarationKind.type, type.name));
190 } 195 }
191 for (UnlinkedTypedef type in unlinked.typedefs) { 196 for (UnlinkedTypedef type in unlinked.typedefs) {
192 _topLevelDeclarations.add( 197 addDeclaration(TopLevelDeclarationKind.type, type.name);
193 new TopLevelDeclaration(TopLevelDeclarationKind.type, type.name));
194 } 198 }
195 // Add functions and variables. 199 // Add functions and variables.
196 Set<String> addedVariableNames = new Set<String>(); 200 Set<String> addedVariableNames = new Set<String>();
197 for (UnlinkedExecutable executable in unlinked.executables) { 201 for (UnlinkedExecutable executable in unlinked.executables) {
198 String name = executable.name; 202 String name = executable.name;
199 if (executable.kind == UnlinkedExecutableKind.functionOrMethod) { 203 if (executable.kind == UnlinkedExecutableKind.functionOrMethod) {
200 _topLevelDeclarations.add( 204 addDeclaration(TopLevelDeclarationKind.function, name);
201 new TopLevelDeclaration(TopLevelDeclarationKind.function, name));
202 } else if (executable.kind == UnlinkedExecutableKind.getter || 205 } else if (executable.kind == UnlinkedExecutableKind.getter ||
203 executable.kind == UnlinkedExecutableKind.setter) { 206 executable.kind == UnlinkedExecutableKind.setter) {
204 if (executable.kind == UnlinkedExecutableKind.setter) { 207 if (executable.kind == UnlinkedExecutableKind.setter) {
205 name = name.substring(0, name.length - 1); 208 name = name.substring(0, name.length - 1);
206 } 209 }
207 if (addedVariableNames.add(name)) { 210 if (addedVariableNames.add(name)) {
208 _topLevelDeclarations.add(new TopLevelDeclaration( 211 addDeclaration(TopLevelDeclarationKind.variable, name);
209 TopLevelDeclarationKind.variable, name));
210 } 212 }
211 } 213 }
212 } 214 }
213 for (UnlinkedVariable variable in unlinked.variables) { 215 for (UnlinkedVariable variable in unlinked.variables) {
214 String name = variable.name; 216 String name = variable.name;
215 if (addedVariableNames.add(name)) { 217 if (addedVariableNames.add(name)) {
216 _topLevelDeclarations.add( 218 addDeclaration(TopLevelDeclarationKind.variable, name);
217 new TopLevelDeclaration(TopLevelDeclarationKind.variable, name));
218 } 219 }
219 } 220 }
220 } 221 }
221 return _topLevelDeclarations; 222 return _topLevelDeclarations;
222 } 223 }
223 224
224 /** 225 /**
225 * Return the set of transitive files - the file itself and all of the 226 * Return the set of transitive files - the file itself and all of the
226 * directly or indirectly referenced files. 227 * directly or indirectly referenced files.
227 */ 228 */
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 .where((f) => f._transitiveFiles == null) 613 .where((f) => f._transitiveFiles == null)
613 .toSet(); 614 .toSet();
614 } 615 }
615 616
616 Set<FileState> get filesWithoutTransitiveSignature { 617 Set<FileState> get filesWithoutTransitiveSignature {
617 return state._uriToFile.values 618 return state._uriToFile.values
618 .where((f) => f._transitiveSignature == null) 619 .where((f) => f._transitiveSignature == null)
619 .toSet(); 620 .toSet();
620 } 621 }
621 } 622 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/dart/analysis/file_state_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698