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

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

Issue 1390003002: Issue 24514. Set documentation range for LibraryElement. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/resolver_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) 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:collection'; 7 import 'dart:collection';
8 8
9 import 'ast.dart'; 9 import 'ast.dart';
10 import 'constant.dart'; 10 import 'constant.dart';
(...skipping 7070 matching lines...) Expand 10 before | Expand all | Expand 10 after
7081 * @throws AnalysisException if the analysis could not be performed 7081 * @throws AnalysisException if the analysis could not be performed
7082 */ 7082 */
7083 LibraryElementImpl buildLibrary(Library library) { 7083 LibraryElementImpl buildLibrary(Library library) {
7084 CompilationUnitBuilder builder = new CompilationUnitBuilder(); 7084 CompilationUnitBuilder builder = new CompilationUnitBuilder();
7085 Source librarySource = library.librarySource; 7085 Source librarySource = library.librarySource;
7086 CompilationUnit definingCompilationUnit = library.definingCompilationUnit; 7086 CompilationUnit definingCompilationUnit = library.definingCompilationUnit;
7087 CompilationUnitElementImpl definingCompilationUnitElement = builder 7087 CompilationUnitElementImpl definingCompilationUnitElement = builder
7088 .buildCompilationUnit( 7088 .buildCompilationUnit(
7089 librarySource, definingCompilationUnit, librarySource); 7089 librarySource, definingCompilationUnit, librarySource);
7090 NodeList<Directive> directives = definingCompilationUnit.directives; 7090 NodeList<Directive> directives = definingCompilationUnit.directives;
7091 LibraryDirective libraryDirective = null;
7091 LibraryIdentifier libraryNameNode = null; 7092 LibraryIdentifier libraryNameNode = null;
7092 bool hasPartDirective = false; 7093 bool hasPartDirective = false;
7093 FunctionElement entryPoint = 7094 FunctionElement entryPoint =
7094 _findEntryPoint(definingCompilationUnitElement); 7095 _findEntryPoint(definingCompilationUnitElement);
7095 List<Directive> directivesToResolve = new List<Directive>(); 7096 List<Directive> directivesToResolve = new List<Directive>();
7096 List<CompilationUnitElementImpl> sourcedCompilationUnits = 7097 List<CompilationUnitElementImpl> sourcedCompilationUnits =
7097 new List<CompilationUnitElementImpl>(); 7098 new List<CompilationUnitElementImpl>();
7098 for (Directive directive in directives) { 7099 for (Directive directive in directives) {
7099 // 7100 //
7100 // We do not build the elements representing the import and export 7101 // We do not build the elements representing the import and export
7101 // directives at this point. That is not done until we get to 7102 // directives at this point. That is not done until we get to
7102 // LibraryResolver.buildDirectiveModels() because we need the 7103 // LibraryResolver.buildDirectiveModels() because we need the
7103 // LibraryElements for the referenced libraries, which might not exist at 7104 // LibraryElements for the referenced libraries, which might not exist at
7104 // this point (due to the possibility of circular references). 7105 // this point (due to the possibility of circular references).
7105 // 7106 //
7106 if (directive is LibraryDirective) { 7107 if (directive is LibraryDirective) {
7107 if (libraryNameNode == null) { 7108 if (libraryNameNode == null) {
7109 libraryDirective = directive;
7108 libraryNameNode = directive.name; 7110 libraryNameNode = directive.name;
7109 directivesToResolve.add(directive); 7111 directivesToResolve.add(directive);
7110 } 7112 }
7111 } else if (directive is PartDirective) { 7113 } else if (directive is PartDirective) {
7112 PartDirective partDirective = directive; 7114 PartDirective partDirective = directive;
7113 StringLiteral partUri = partDirective.uri; 7115 StringLiteral partUri = partDirective.uri;
7114 Source partSource = partDirective.source; 7116 Source partSource = partDirective.source;
7115 if (_analysisContext.exists(partSource)) { 7117 if (_analysisContext.exists(partSource)) {
7116 hasPartDirective = true; 7118 hasPartDirective = true;
7117 CompilationUnit partUnit = library.getAST(partSource); 7119 CompilationUnit partUnit = library.getAST(partSource);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
7156 } 7158 }
7157 if (hasPartDirective && libraryNameNode == null) { 7159 if (hasPartDirective && libraryNameNode == null) {
7158 _errorListener.onError(new AnalysisError(librarySource, 0, 0, 7160 _errorListener.onError(new AnalysisError(librarySource, 0, 0,
7159 ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART)); 7161 ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART));
7160 } 7162 }
7161 // 7163 //
7162 // Create and populate the library element. 7164 // Create and populate the library element.
7163 // 7165 //
7164 LibraryElementImpl libraryElement = new LibraryElementImpl.forNode( 7166 LibraryElementImpl libraryElement = new LibraryElementImpl.forNode(
7165 _analysisContext.getContextFor(librarySource), libraryNameNode); 7167 _analysisContext.getContextFor(librarySource), libraryNameNode);
7168 _setDocRange(libraryElement, libraryDirective);
7166 libraryElement.definingCompilationUnit = definingCompilationUnitElement; 7169 libraryElement.definingCompilationUnit = definingCompilationUnitElement;
7167 if (entryPoint != null) { 7170 if (entryPoint != null) {
7168 libraryElement.entryPoint = entryPoint; 7171 libraryElement.entryPoint = entryPoint;
7169 } 7172 }
7170 int sourcedUnitCount = sourcedCompilationUnits.length; 7173 int sourcedUnitCount = sourcedCompilationUnits.length;
7171 libraryElement.parts = sourcedCompilationUnits; 7174 libraryElement.parts = sourcedCompilationUnits;
7172 for (Directive directive in directivesToResolve) { 7175 for (Directive directive in directivesToResolve) {
7173 directive.element = libraryElement; 7176 directive.element = libraryElement;
7174 } 7177 }
7175 library.libraryElement = libraryElement; 7178 library.libraryElement = libraryElement;
(...skipping 11 matching lines...) Expand all
7187 * @throws AnalysisException if the analysis could not be performed 7190 * @throws AnalysisException if the analysis could not be performed
7188 */ 7191 */
7189 void buildLibrary2(ResolvableLibrary library) { 7192 void buildLibrary2(ResolvableLibrary library) {
7190 CompilationUnitBuilder builder = new CompilationUnitBuilder(); 7193 CompilationUnitBuilder builder = new CompilationUnitBuilder();
7191 Source librarySource = library.librarySource; 7194 Source librarySource = library.librarySource;
7192 CompilationUnit definingCompilationUnit = library.definingCompilationUnit; 7195 CompilationUnit definingCompilationUnit = library.definingCompilationUnit;
7193 CompilationUnitElementImpl definingCompilationUnitElement = builder 7196 CompilationUnitElementImpl definingCompilationUnitElement = builder
7194 .buildCompilationUnit( 7197 .buildCompilationUnit(
7195 librarySource, definingCompilationUnit, librarySource); 7198 librarySource, definingCompilationUnit, librarySource);
7196 NodeList<Directive> directives = definingCompilationUnit.directives; 7199 NodeList<Directive> directives = definingCompilationUnit.directives;
7200 LibraryDirective libraryDirective = null;
7197 LibraryIdentifier libraryNameNode = null; 7201 LibraryIdentifier libraryNameNode = null;
7198 bool hasPartDirective = false; 7202 bool hasPartDirective = false;
7199 FunctionElement entryPoint = 7203 FunctionElement entryPoint =
7200 _findEntryPoint(definingCompilationUnitElement); 7204 _findEntryPoint(definingCompilationUnitElement);
7201 List<Directive> directivesToResolve = new List<Directive>(); 7205 List<Directive> directivesToResolve = new List<Directive>();
7202 List<CompilationUnitElementImpl> sourcedCompilationUnits = 7206 List<CompilationUnitElementImpl> sourcedCompilationUnits =
7203 new List<CompilationUnitElementImpl>(); 7207 new List<CompilationUnitElementImpl>();
7204 for (Directive directive in directives) { 7208 for (Directive directive in directives) {
7205 // 7209 //
7206 // We do not build the elements representing the import and export 7210 // We do not build the elements representing the import and export
7207 // directives at this point. That is not done until we get to 7211 // directives at this point. That is not done until we get to
7208 // LibraryResolver.buildDirectiveModels() because we need the 7212 // LibraryResolver.buildDirectiveModels() because we need the
7209 // LibraryElements for the referenced libraries, which might not exist at 7213 // LibraryElements for the referenced libraries, which might not exist at
7210 // this point (due to the possibility of circular references). 7214 // this point (due to the possibility of circular references).
7211 // 7215 //
7212 if (directive is LibraryDirective) { 7216 if (directive is LibraryDirective) {
7213 if (libraryNameNode == null) { 7217 if (libraryNameNode == null) {
7218 libraryDirective = directive;
7214 libraryNameNode = directive.name; 7219 libraryNameNode = directive.name;
7215 directivesToResolve.add(directive); 7220 directivesToResolve.add(directive);
7216 } 7221 }
7217 } else if (directive is PartDirective) { 7222 } else if (directive is PartDirective) {
7218 PartDirective partDirective = directive; 7223 PartDirective partDirective = directive;
7219 StringLiteral partUri = partDirective.uri; 7224 StringLiteral partUri = partDirective.uri;
7220 Source partSource = partDirective.source; 7225 Source partSource = partDirective.source;
7221 if (_analysisContext.exists(partSource)) { 7226 if (_analysisContext.exists(partSource)) {
7222 hasPartDirective = true; 7227 hasPartDirective = true;
7223 CompilationUnit partUnit = library.getAST(partSource); 7228 CompilationUnit partUnit = library.getAST(partSource);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
7264 } 7269 }
7265 if (hasPartDirective && libraryNameNode == null) { 7270 if (hasPartDirective && libraryNameNode == null) {
7266 _errorListener.onError(new AnalysisError(librarySource, 0, 0, 7271 _errorListener.onError(new AnalysisError(librarySource, 0, 0,
7267 ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART)); 7272 ResolverErrorCode.MISSING_LIBRARY_DIRECTIVE_WITH_PART));
7268 } 7273 }
7269 // 7274 //
7270 // Create and populate the library element. 7275 // Create and populate the library element.
7271 // 7276 //
7272 LibraryElementImpl libraryElement = new LibraryElementImpl.forNode( 7277 LibraryElementImpl libraryElement = new LibraryElementImpl.forNode(
7273 _analysisContext.getContextFor(librarySource), libraryNameNode); 7278 _analysisContext.getContextFor(librarySource), libraryNameNode);
7279 _setDocRange(libraryElement, libraryDirective);
7274 libraryElement.definingCompilationUnit = definingCompilationUnitElement; 7280 libraryElement.definingCompilationUnit = definingCompilationUnitElement;
7275 if (entryPoint != null) { 7281 if (entryPoint != null) {
7276 libraryElement.entryPoint = entryPoint; 7282 libraryElement.entryPoint = entryPoint;
7277 } 7283 }
7278 int sourcedUnitCount = sourcedCompilationUnits.length; 7284 int sourcedUnitCount = sourcedCompilationUnits.length;
7279 libraryElement.parts = sourcedCompilationUnits; 7285 libraryElement.parts = sourcedCompilationUnits;
7280 for (Directive directive in directivesToResolve) { 7286 for (Directive directive in directivesToResolve) {
7281 directive.element = libraryElement; 7287 directive.element = libraryElement;
7282 } 7288 }
7283 library.libraryElement = libraryElement; 7289 library.libraryElement = libraryElement;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
7367 for (PropertyAccessorElement setter in setters) { 7373 for (PropertyAccessorElement setter in setters) {
7368 PropertyAccessorElement getter = getters[setter.displayName]; 7374 PropertyAccessorElement getter = getters[setter.displayName];
7369 if (getter != null) { 7375 if (getter != null) {
7370 PropertyInducingElementImpl variable = 7376 PropertyInducingElementImpl variable =
7371 getter.variable as PropertyInducingElementImpl; 7377 getter.variable as PropertyInducingElementImpl;
7372 variable.setter = setter; 7378 variable.setter = setter;
7373 (setter as PropertyAccessorElementImpl).variable = variable; 7379 (setter as PropertyAccessorElementImpl).variable = variable;
7374 } 7380 }
7375 } 7381 }
7376 } 7382 }
7383
7384 /**
7385 * If the given [node] has a documentation comment, remember its range
7386 * into the given [element].
7387 */
7388 void _setDocRange(ElementImpl element, AnnotatedNode node) {
7389 Comment comment = node.documentationComment;
7390 if (comment != null && comment.isDocumentation) {
7391 element.setDocRange(comment.offset, comment.length);
7392 }
7393 }
7377 } 7394 }
7378 7395
7379 /** 7396 /**
7380 * Instances of the class `LibraryImportScope` represent the scope containing al l of the names 7397 * Instances of the class `LibraryImportScope` represent the scope containing al l of the names
7381 * available from imported libraries. 7398 * available from imported libraries.
7382 */ 7399 */
7383 class LibraryImportScope extends Scope { 7400 class LibraryImportScope extends Scope {
7384 /** 7401 /**
7385 * The element representing the library in which this scope is enclosed. 7402 * The element representing the library in which this scope is enclosed.
7386 */ 7403 */
(...skipping 8540 matching lines...) Expand 10 before | Expand all | Expand 10 after
15927 nonFields.add(node); 15944 nonFields.add(node);
15928 return null; 15945 return null;
15929 } 15946 }
15930 15947
15931 @override 15948 @override
15932 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); 15949 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this);
15933 15950
15934 @override 15951 @override
15935 Object visitWithClause(WithClause node) => null; 15952 Object visitWithClause(WithClause node) => null;
15936 } 15953 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698