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

Side by Side Diff: pkg/analyzer/lib/src/dart/element/element.dart

Issue 2353433002: Use configurations and declared variables to select import/export URIs during prelinking. (Closed)
Patch Set: Cache selected URI. Created 4 years, 3 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/lib/src/summary/link.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 analyzer.src.dart.element.element; 5 library analyzer.src.dart.element.element;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:math' show min; 8 import 'dart:math' show min;
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 3985 matching lines...) Expand 10 before | Expand all | Expand 10 after
3996 */ 3996 */
3997 LibraryElement _exportedLibrary; 3997 LibraryElement _exportedLibrary;
3998 3998
3999 /** 3999 /**
4000 * The combinators that were specified as part of the export directive in the 4000 * The combinators that were specified as part of the export directive in the
4001 * order in which they were specified. 4001 * order in which they were specified.
4002 */ 4002 */
4003 List<NamespaceCombinator> _combinators; 4003 List<NamespaceCombinator> _combinators;
4004 4004
4005 /** 4005 /**
4006 * The URI that was selected based on the [context] declared variables.
4007 */
4008 String _selectedUri;
4009
4010 /**
4006 * Initialize a newly created export element at the given [offset]. 4011 * Initialize a newly created export element at the given [offset].
4007 */ 4012 */
4008 ExportElementImpl(int offset) 4013 ExportElementImpl(int offset)
4009 : _unlinkedExportPublic = null, 4014 : _unlinkedExportPublic = null,
4010 _unlinkedExportNonPublic = null, 4015 _unlinkedExportNonPublic = null,
4011 super(null, offset); 4016 super(null, offset);
4012 4017
4013 /** 4018 /**
4014 * Initialize using the given serialized information. 4019 * Initialize using the given serialized information.
4015 */ 4020 */
(...skipping 12 matching lines...) Expand all
4028 4033
4029 void set combinators(List<NamespaceCombinator> combinators) { 4034 void set combinators(List<NamespaceCombinator> combinators) {
4030 assert(_unlinkedExportPublic == null); 4035 assert(_unlinkedExportPublic == null);
4031 _combinators = combinators; 4036 _combinators = combinators;
4032 } 4037 }
4033 4038
4034 @override 4039 @override
4035 LibraryElement get exportedLibrary { 4040 LibraryElement get exportedLibrary {
4036 if (_unlinkedExportNonPublic != null && _exportedLibrary == null) { 4041 if (_unlinkedExportNonPublic != null && _exportedLibrary == null) {
4037 LibraryElementImpl library = enclosingElement as LibraryElementImpl; 4042 LibraryElementImpl library = enclosingElement as LibraryElementImpl;
4038 _exportedLibrary = library.resynthesizerContext 4043 _exportedLibrary = library.resynthesizerContext.buildExportedLibrary(uri);
4039 .buildExportedLibrary(_unlinkedExportPublic.uri);
4040 } 4044 }
4041 return _exportedLibrary; 4045 return _exportedLibrary;
4042 } 4046 }
4043 4047
4044 void set exportedLibrary(LibraryElement exportedLibrary) { 4048 void set exportedLibrary(LibraryElement exportedLibrary) {
4045 assert(_unlinkedExportNonPublic == null); 4049 assert(_unlinkedExportNonPublic == null);
4046 _exportedLibrary = exportedLibrary; 4050 _exportedLibrary = exportedLibrary;
4047 } 4051 }
4048 4052
4049 @override 4053 @override
(...skipping 21 matching lines...) Expand all
4071 int get nameOffset { 4075 int get nameOffset {
4072 if (_unlinkedExportNonPublic != null) { 4076 if (_unlinkedExportNonPublic != null) {
4073 return _unlinkedExportNonPublic.offset; 4077 return _unlinkedExportNonPublic.offset;
4074 } 4078 }
4075 return super.nameOffset; 4079 return super.nameOffset;
4076 } 4080 }
4077 4081
4078 @override 4082 @override
4079 String get uri { 4083 String get uri {
4080 if (_unlinkedExportPublic != null) { 4084 if (_unlinkedExportPublic != null) {
4081 return _unlinkedExportPublic.uri; 4085 return _selectedUri ??= _selectUri(
4086 _unlinkedExportPublic.uri, _unlinkedExportPublic.configurations);
4082 } 4087 }
4083 return super.uri; 4088 return super.uri;
4084 } 4089 }
4085 4090
4086 @override 4091 @override
4087 void set uri(String uri) { 4092 void set uri(String uri) {
4088 assert(_unlinkedExportPublic == null); 4093 assert(_unlinkedExportPublic == null);
4089 super.uri = uri; 4094 super.uri = uri;
4090 } 4095 }
4091 4096
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
4860 */ 4865 */
4861 List<NamespaceCombinator> _combinators; 4866 List<NamespaceCombinator> _combinators;
4862 4867
4863 /** 4868 /**
4864 * The prefix that was specified as part of the import directive, or `null` if 4869 * The prefix that was specified as part of the import directive, or `null` if
4865 * there was no prefix specified. 4870 * there was no prefix specified.
4866 */ 4871 */
4867 PrefixElement _prefix; 4872 PrefixElement _prefix;
4868 4873
4869 /** 4874 /**
4875 * The URI that was selected based on the [context] declared variables.
4876 */
4877 String _selectedUri;
4878
4879 /**
4870 * Initialize a newly created import element at the given [offset]. 4880 * Initialize a newly created import element at the given [offset].
4871 * The offset may be `-1` if the import is synthetic. 4881 * The offset may be `-1` if the import is synthetic.
4872 */ 4882 */
4873 ImportElementImpl(int offset) 4883 ImportElementImpl(int offset)
4874 : _unlinkedImport = null, 4884 : _unlinkedImport = null,
4875 _linkedDependency = null, 4885 _linkedDependency = null,
4876 super(null, offset); 4886 super(null, offset);
4877 4887
4878 /** 4888 /**
4879 * Initialize using the given serialized information. 4889 * Initialize using the given serialized information.
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
4999 assert(_unlinkedImport == null); 5009 assert(_unlinkedImport == null);
5000 _prefixOffset = prefixOffset; 5010 _prefixOffset = prefixOffset;
5001 } 5011 }
5002 5012
5003 @override 5013 @override
5004 String get uri { 5014 String get uri {
5005 if (_unlinkedImport != null) { 5015 if (_unlinkedImport != null) {
5006 if (_unlinkedImport.isImplicit) { 5016 if (_unlinkedImport.isImplicit) {
5007 return null; 5017 return null;
5008 } 5018 }
5009 return _unlinkedImport.uri; 5019 return _selectedUri ??=
5020 _selectUri(_unlinkedImport.uri, _unlinkedImport.configurations);
5010 } 5021 }
5011 return super.uri; 5022 return super.uri;
5012 } 5023 }
5013 5024
5014 @override 5025 @override
5015 void set uri(String uri) { 5026 void set uri(String uri) {
5016 assert(_unlinkedImport == null); 5027 assert(_unlinkedImport == null);
5017 super.uri = uri; 5028 super.uri = uri;
5018 } 5029 }
5019 5030
(...skipping 3175 matching lines...) Expand 10 before | Expand all | Expand 10 after
8195 * Return the offset of the URI in the file, or `-1` if this node is synthetic . 8206 * Return the offset of the URI in the file, or `-1` if this node is synthetic .
8196 */ 8207 */
8197 int get uriOffset => _uriOffset; 8208 int get uriOffset => _uriOffset;
8198 8209
8199 /** 8210 /**
8200 * Set the offset of the URI in the file to the given [offset]. 8211 * Set the offset of the URI in the file to the given [offset].
8201 */ 8212 */
8202 void set uriOffset(int offset) { 8213 void set uriOffset(int offset) {
8203 _uriOffset = offset; 8214 _uriOffset = offset;
8204 } 8215 }
8216
8217 String _selectUri(
8218 String defaultUri, List<UnlinkedConfiguration> configurations) {
8219 for (UnlinkedConfiguration configuration in configurations) {
8220 if (context.declaredVariables.get(configuration.name) ==
8221 configuration.value) {
8222 return configuration.uri;
8223 }
8224 }
8225 return defaultUri;
8226 }
8205 } 8227 }
8206 8228
8207 /** 8229 /**
8208 * A concrete implementation of a [VariableElement]. 8230 * A concrete implementation of a [VariableElement].
8209 */ 8231 */
8210 abstract class VariableElementImpl extends ElementImpl 8232 abstract class VariableElementImpl extends ElementImpl
8211 implements VariableElement { 8233 implements VariableElement {
8212 /** 8234 /**
8213 * The declared type of this variable. 8235 * The declared type of this variable.
8214 */ 8236 */
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
8364 8386
8365 @override 8387 @override
8366 void visitElement(Element element) { 8388 void visitElement(Element element) {
8367 int offset = element.nameOffset; 8389 int offset = element.nameOffset;
8368 if (offset != -1) { 8390 if (offset != -1) {
8369 map[offset] = element; 8391 map[offset] = element;
8370 } 8392 }
8371 super.visitElement(element); 8393 super.visitElement(element);
8372 } 8394 }
8373 } 8395 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/summary/link.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698