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

Side by Side Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 1125123006: Add a "librarySource" field to CompilationUnitElementImpl. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 engine.resolver; 5 library engine.resolver;
6 6
7 import "dart:math" as math; 7 import "dart:math" as math;
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/src/generated/utilities_collection.dart'; 10 import 'package:analyzer/src/generated/utilities_collection.dart';
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 } 773 }
774 774
775 /** 775 /**
776 * A `CompilationUnitBuilder` builds an element model for a single compilation 776 * A `CompilationUnitBuilder` builds an element model for a single compilation
777 * unit. 777 * unit.
778 */ 778 */
779 class CompilationUnitBuilder { 779 class CompilationUnitBuilder {
780 /** 780 /**
781 * Build the compilation unit element for the given [source] based on the 781 * Build the compilation unit element for the given [source] based on the
782 * compilation [unit] associated with the source. Throw an AnalysisException 782 * compilation [unit] associated with the source. Throw an AnalysisException
783 * if the element could not be built. 783 * if the element could not be built. [librarySource] is the source for the
784 * containing library.
784 */ 785 */
785 CompilationUnitElementImpl buildCompilationUnit( 786 CompilationUnitElementImpl buildCompilationUnit(
786 Source source, CompilationUnit unit) { 787 Source source, CompilationUnit unit, Source librarySource) {
787 return PerformanceStatistics.resolve.makeCurrentWhile(() { 788 return PerformanceStatistics.resolve.makeCurrentWhile(() {
788 if (unit == null) { 789 if (unit == null) {
789 return null; 790 return null;
790 } 791 }
791 ElementHolder holder = new ElementHolder(); 792 ElementHolder holder = new ElementHolder();
792 ElementBuilder builder = new ElementBuilder(holder); 793 ElementBuilder builder = new ElementBuilder(holder);
793 unit.accept(builder); 794 unit.accept(builder);
794 CompilationUnitElementImpl element = 795 CompilationUnitElementImpl element =
795 new CompilationUnitElementImpl(source.shortName); 796 new CompilationUnitElementImpl(source.shortName);
796 element.accessors = holder.accessors; 797 element.accessors = holder.accessors;
797 element.enums = holder.enums; 798 element.enums = holder.enums;
798 element.functions = holder.functions; 799 element.functions = holder.functions;
799 element.source = source; 800 element.source = source;
801 element.librarySource = librarySource;
800 element.typeAliases = holder.typeAliases; 802 element.typeAliases = holder.typeAliases;
801 element.types = holder.types; 803 element.types = holder.types;
802 element.topLevelVariables = holder.topLevelVariables; 804 element.topLevelVariables = holder.topLevelVariables;
803 unit.element = element; 805 unit.element = element;
804 holder.validate(); 806 holder.validate();
805 return element; 807 return element;
806 }); 808 });
807 } 809 }
808 } 810 }
809 811
(...skipping 6343 matching lines...) Expand 10 before | Expand all | Expand 10 after
7153 * Build the library element for the given library. 7155 * Build the library element for the given library.
7154 * 7156 *
7155 * @param library the library for which an element model is to be built 7157 * @param library the library for which an element model is to be built
7156 * @return the library element that was built 7158 * @return the library element that was built
7157 * @throws AnalysisException if the analysis could not be performed 7159 * @throws AnalysisException if the analysis could not be performed
7158 */ 7160 */
7159 LibraryElementImpl buildLibrary(Library library) { 7161 LibraryElementImpl buildLibrary(Library library) {
7160 CompilationUnitBuilder builder = new CompilationUnitBuilder(); 7162 CompilationUnitBuilder builder = new CompilationUnitBuilder();
7161 Source librarySource = library.librarySource; 7163 Source librarySource = library.librarySource;
7162 CompilationUnit definingCompilationUnit = library.definingCompilationUnit; 7164 CompilationUnit definingCompilationUnit = library.definingCompilationUnit;
7163 CompilationUnitElementImpl definingCompilationUnitElement = 7165 CompilationUnitElementImpl definingCompilationUnitElement = builder
7164 builder.buildCompilationUnit(librarySource, definingCompilationUnit); 7166 .buildCompilationUnit(
7167 librarySource, definingCompilationUnit, librarySource);
7165 NodeList<Directive> directives = definingCompilationUnit.directives; 7168 NodeList<Directive> directives = definingCompilationUnit.directives;
7166 LibraryIdentifier libraryNameNode = null; 7169 LibraryIdentifier libraryNameNode = null;
7167 bool hasPartDirective = false; 7170 bool hasPartDirective = false;
7168 FunctionElement entryPoint = 7171 FunctionElement entryPoint =
7169 _findEntryPoint(definingCompilationUnitElement); 7172 _findEntryPoint(definingCompilationUnitElement);
7170 List<Directive> directivesToResolve = new List<Directive>(); 7173 List<Directive> directivesToResolve = new List<Directive>();
7171 List<CompilationUnitElementImpl> sourcedCompilationUnits = 7174 List<CompilationUnitElementImpl> sourcedCompilationUnits =
7172 new List<CompilationUnitElementImpl>(); 7175 new List<CompilationUnitElementImpl>();
7173 for (Directive directive in directives) { 7176 for (Directive directive in directives) {
7174 // 7177 //
7175 // We do not build the elements representing the import and export 7178 // We do not build the elements representing the import and export
7176 // directives at this point. That is not done until we get to 7179 // directives at this point. That is not done until we get to
7177 // LibraryResolver.buildDirectiveModels() because we need the 7180 // LibraryResolver.buildDirectiveModels() because we need the
7178 // LibraryElements for the referenced libraries, which might not exist at 7181 // LibraryElements for the referenced libraries, which might not exist at
7179 // this point (due to the possibility of circular references). 7182 // this point (due to the possibility of circular references).
7180 // 7183 //
7181 if (directive is LibraryDirective) { 7184 if (directive is LibraryDirective) {
7182 if (libraryNameNode == null) { 7185 if (libraryNameNode == null) {
7183 libraryNameNode = directive.name; 7186 libraryNameNode = directive.name;
7184 directivesToResolve.add(directive); 7187 directivesToResolve.add(directive);
7185 } 7188 }
7186 } else if (directive is PartDirective) { 7189 } else if (directive is PartDirective) {
7187 PartDirective partDirective = directive; 7190 PartDirective partDirective = directive;
7188 StringLiteral partUri = partDirective.uri; 7191 StringLiteral partUri = partDirective.uri;
7189 Source partSource = partDirective.source; 7192 Source partSource = partDirective.source;
7190 if (_analysisContext.exists(partSource)) { 7193 if (_analysisContext.exists(partSource)) {
7191 hasPartDirective = true; 7194 hasPartDirective = true;
7192 CompilationUnit partUnit = library.getAST(partSource); 7195 CompilationUnit partUnit = library.getAST(partSource);
7193 CompilationUnitElementImpl part = 7196 CompilationUnitElementImpl part =
7194 builder.buildCompilationUnit(partSource, partUnit); 7197 builder.buildCompilationUnit(partSource, partUnit, librarySource);
7195 part.uriOffset = partUri.offset; 7198 part.uriOffset = partUri.offset;
7196 part.uriEnd = partUri.end; 7199 part.uriEnd = partUri.end;
7197 part.uri = partDirective.uriContent; 7200 part.uri = partDirective.uriContent;
7198 // 7201 //
7199 // Validate that the part contains a part-of directive with the same 7202 // Validate that the part contains a part-of directive with the same
7200 // name as the library. 7203 // name as the library.
7201 // 7204 //
7202 String partLibraryName = 7205 String partLibraryName =
7203 _getPartLibraryName(partSource, partUnit, directivesToResolve); 7206 _getPartLibraryName(partSource, partUnit, directivesToResolve);
7204 if (partLibraryName == null) { 7207 if (partLibraryName == null) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
7255 * Build the library element for the given library. The resulting element is 7258 * Build the library element for the given library. The resulting element is
7256 * stored in the [ResolvableLibrary] structure. 7259 * stored in the [ResolvableLibrary] structure.
7257 * 7260 *
7258 * @param library the library for which an element model is to be built 7261 * @param library the library for which an element model is to be built
7259 * @throws AnalysisException if the analysis could not be performed 7262 * @throws AnalysisException if the analysis could not be performed
7260 */ 7263 */
7261 void buildLibrary2(ResolvableLibrary library) { 7264 void buildLibrary2(ResolvableLibrary library) {
7262 CompilationUnitBuilder builder = new CompilationUnitBuilder(); 7265 CompilationUnitBuilder builder = new CompilationUnitBuilder();
7263 Source librarySource = library.librarySource; 7266 Source librarySource = library.librarySource;
7264 CompilationUnit definingCompilationUnit = library.definingCompilationUnit; 7267 CompilationUnit definingCompilationUnit = library.definingCompilationUnit;
7265 CompilationUnitElementImpl definingCompilationUnitElement = 7268 CompilationUnitElementImpl definingCompilationUnitElement = builder
7266 builder.buildCompilationUnit(librarySource, definingCompilationUnit); 7269 .buildCompilationUnit(
7270 librarySource, definingCompilationUnit, librarySource);
7267 NodeList<Directive> directives = definingCompilationUnit.directives; 7271 NodeList<Directive> directives = definingCompilationUnit.directives;
7268 LibraryIdentifier libraryNameNode = null; 7272 LibraryIdentifier libraryNameNode = null;
7269 bool hasPartDirective = false; 7273 bool hasPartDirective = false;
7270 FunctionElement entryPoint = 7274 FunctionElement entryPoint =
7271 _findEntryPoint(definingCompilationUnitElement); 7275 _findEntryPoint(definingCompilationUnitElement);
7272 List<Directive> directivesToResolve = new List<Directive>(); 7276 List<Directive> directivesToResolve = new List<Directive>();
7273 List<CompilationUnitElementImpl> sourcedCompilationUnits = 7277 List<CompilationUnitElementImpl> sourcedCompilationUnits =
7274 new List<CompilationUnitElementImpl>(); 7278 new List<CompilationUnitElementImpl>();
7275 for (Directive directive in directives) { 7279 for (Directive directive in directives) {
7276 // 7280 //
7277 // We do not build the elements representing the import and export 7281 // We do not build the elements representing the import and export
7278 // directives at this point. That is not done until we get to 7282 // directives at this point. That is not done until we get to
7279 // LibraryResolver.buildDirectiveModels() because we need the 7283 // LibraryResolver.buildDirectiveModels() because we need the
7280 // LibraryElements for the referenced libraries, which might not exist at 7284 // LibraryElements for the referenced libraries, which might not exist at
7281 // this point (due to the possibility of circular references). 7285 // this point (due to the possibility of circular references).
7282 // 7286 //
7283 if (directive is LibraryDirective) { 7287 if (directive is LibraryDirective) {
7284 if (libraryNameNode == null) { 7288 if (libraryNameNode == null) {
7285 libraryNameNode = directive.name; 7289 libraryNameNode = directive.name;
7286 directivesToResolve.add(directive); 7290 directivesToResolve.add(directive);
7287 } 7291 }
7288 } else if (directive is PartDirective) { 7292 } else if (directive is PartDirective) {
7289 PartDirective partDirective = directive; 7293 PartDirective partDirective = directive;
7290 StringLiteral partUri = partDirective.uri; 7294 StringLiteral partUri = partDirective.uri;
7291 Source partSource = partDirective.source; 7295 Source partSource = partDirective.source;
7292 if (_analysisContext.exists(partSource)) { 7296 if (_analysisContext.exists(partSource)) {
7293 hasPartDirective = true; 7297 hasPartDirective = true;
7294 CompilationUnit partUnit = library.getAST(partSource); 7298 CompilationUnit partUnit = library.getAST(partSource);
7295 if (partUnit != null) { 7299 if (partUnit != null) {
7296 CompilationUnitElementImpl part = 7300 CompilationUnitElementImpl part = builder.buildCompilationUnit(
7297 builder.buildCompilationUnit(partSource, partUnit); 7301 partSource, partUnit, librarySource);
7298 part.uriOffset = partUri.offset; 7302 part.uriOffset = partUri.offset;
7299 part.uriEnd = partUri.end; 7303 part.uriEnd = partUri.end;
7300 part.uri = partDirective.uriContent; 7304 part.uri = partDirective.uriContent;
7301 // 7305 //
7302 // Validate that the part contains a part-of directive with the same 7306 // Validate that the part contains a part-of directive with the same
7303 // name as the library. 7307 // name as the library.
7304 // 7308 //
7305 String partLibraryName = 7309 String partLibraryName =
7306 _getPartLibraryName(partSource, partUnit, directivesToResolve); 7310 _getPartLibraryName(partSource, partUnit, directivesToResolve);
7307 if (partLibraryName == null) { 7311 if (partLibraryName == null) {
(...skipping 8143 matching lines...) Expand 10 before | Expand all | Expand 10 after
15451 nonFields.add(node); 15455 nonFields.add(node);
15452 return null; 15456 return null;
15453 } 15457 }
15454 15458
15455 @override 15459 @override
15456 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); 15460 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this);
15457 15461
15458 @override 15462 @override
15459 Object visitWithClause(WithClause node) => null; 15463 Object visitWithClause(WithClause node) => null;
15460 } 15464 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/element.dart ('k') | pkg/analyzer/lib/src/generated/testing/element_factory.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698