| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library analyzer.src.task.dart; | 5 library analyzer.src.task.dart; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/src/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
| 10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
| (...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 BuildPublicNamespaceTask( | 882 BuildPublicNamespaceTask( |
| 883 InternalAnalysisContext context, AnalysisTarget target) | 883 InternalAnalysisContext context, AnalysisTarget target) |
| 884 : super(context, target); | 884 : super(context, target); |
| 885 | 885 |
| 886 @override | 886 @override |
| 887 TaskDescriptor get descriptor => DESCRIPTOR; | 887 TaskDescriptor get descriptor => DESCRIPTOR; |
| 888 | 888 |
| 889 @override | 889 @override |
| 890 void internalPerform() { | 890 void internalPerform() { |
| 891 LibraryElement library = getRequiredInput(BUILT_LIBRARY_ELEMENT_INPUT_NAME); | 891 LibraryElement library = getRequiredInput(BUILT_LIBRARY_ELEMENT_INPUT_NAME); |
| 892 | 892 Namespace namespace = new PublicNamespaceBuilder().build(library); |
| 893 NamespaceBuilder builder = new NamespaceBuilder(); | |
| 894 Namespace namespace = builder.createPublicNamespaceForLibrary(library); | |
| 895 | |
| 896 outputs[PUBLIC_NAMESPACE] = namespace; | 893 outputs[PUBLIC_NAMESPACE] = namespace; |
| 897 } | 894 } |
| 898 | 895 |
| 899 /** | 896 /** |
| 900 * Return a map from the names of the inputs of this kind of task to the task | 897 * Return a map from the names of the inputs of this kind of task to the task |
| 901 * input descriptors describing those inputs for a task with the | 898 * input descriptors describing those inputs for a task with the |
| 902 * given library [source]. | 899 * given library [source]. |
| 903 */ | 900 */ |
| 904 static Map<String, TaskInput> buildInputs(Source source) { | 901 static Map<String, TaskInput> buildInputs(Source source) { |
| 905 return <String, TaskInput>{ | 902 return <String, TaskInput>{ |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1162 errorListener.onError(new AnalysisError.con2(librarySource, | 1159 errorListener.onError(new AnalysisError.con2(librarySource, |
| 1163 uriLiteral.offset, uriLiteral.length, | 1160 uriLiteral.offset, uriLiteral.length, |
| 1164 CompileTimeErrorCode.INVALID_URI, [uriContent])); | 1161 CompileTimeErrorCode.INVALID_URI, [uriContent])); |
| 1165 return null; | 1162 return null; |
| 1166 } | 1163 } |
| 1167 throw new AnalysisException('Failed to handle validation code: $code'); | 1164 throw new AnalysisException('Failed to handle validation code: $code'); |
| 1168 } | 1165 } |
| 1169 } | 1166 } |
| 1170 | 1167 |
| 1171 /** | 1168 /** |
| 1169 * The helper for building the public [Namespace] of a [LibraryElement]. |
| 1170 */ |
| 1171 class PublicNamespaceBuilder { |
| 1172 final HashMap<String, Element> definedNames = new HashMap<String, Element>(); |
| 1173 |
| 1174 /** |
| 1175 * Build a public [Namespace] of the given [library]. |
| 1176 */ |
| 1177 Namespace build(LibraryElement library) { |
| 1178 definedNames.clear(); |
| 1179 _addPublicNames(library.definingCompilationUnit); |
| 1180 library.parts.forEach(_addPublicNames); |
| 1181 return new Namespace(definedNames); |
| 1182 } |
| 1183 |
| 1184 /** |
| 1185 * Add the given [element] if it has a publicly visible name. |
| 1186 */ |
| 1187 void _addIfPublic(Element element) { |
| 1188 String name = element.name; |
| 1189 if (name != null && !Scope.isPrivateName(name)) { |
| 1190 definedNames[name] = element; |
| 1191 } |
| 1192 } |
| 1193 |
| 1194 /** |
| 1195 * Add all of the public top-level names that are defined in the given |
| 1196 * [compilationUnit]. |
| 1197 */ |
| 1198 void _addPublicNames(CompilationUnitElement compilationUnit) { |
| 1199 compilationUnit.accessors.forEach(_addIfPublic); |
| 1200 compilationUnit.enums.forEach(_addIfPublic); |
| 1201 compilationUnit.functions.forEach(_addIfPublic); |
| 1202 compilationUnit.functionTypeAliases.forEach(_addIfPublic); |
| 1203 compilationUnit.types.forEach(_addIfPublic); |
| 1204 } |
| 1205 } |
| 1206 |
| 1207 /** |
| 1172 * A task that scans the content of a file, producing a set of Dart tokens. | 1208 * A task that scans the content of a file, producing a set of Dart tokens. |
| 1173 */ | 1209 */ |
| 1174 class ScanDartTask extends SourceBasedAnalysisTask { | 1210 class ScanDartTask extends SourceBasedAnalysisTask { |
| 1175 /** | 1211 /** |
| 1176 * The name of the input whose value is the content of the file. | 1212 * The name of the input whose value is the content of the file. |
| 1177 */ | 1213 */ |
| 1178 static const String CONTENT_INPUT_NAME = 'CONTENT_INPUT_NAME'; | 1214 static const String CONTENT_INPUT_NAME = 'CONTENT_INPUT_NAME'; |
| 1179 | 1215 |
| 1180 /** | 1216 /** |
| 1181 * The task descriptor describing this kind of task. | 1217 * The task descriptor describing this kind of task. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1221 } | 1257 } |
| 1222 | 1258 |
| 1223 /** | 1259 /** |
| 1224 * Create a [ScanDartTask] based on the given [target] in the given [context]. | 1260 * Create a [ScanDartTask] based on the given [target] in the given [context]. |
| 1225 */ | 1261 */ |
| 1226 static ScanDartTask createTask( | 1262 static ScanDartTask createTask( |
| 1227 AnalysisContext context, AnalysisTarget target) { | 1263 AnalysisContext context, AnalysisTarget target) { |
| 1228 return new ScanDartTask(context, target); | 1264 return new ScanDartTask(context, target); |
| 1229 } | 1265 } |
| 1230 } | 1266 } |
| OLD | NEW |