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

Side by Side Diff: pkg/analyzer/lib/src/summary/resynthesize.dart

Issue 1647553002: Add the ability to resynthesize class members from summaries. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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
OLDNEW
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 summary_resynthesizer; 5 library summary_resynthesizer;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/dart/element/type.dart'; 10 import 'package:analyzer/dart/element/type.dart';
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 Element getElement(ElementLocation location) { 89 Element getElement(ElementLocation location) {
90 List<String> components = location.components; 90 List<String> components = location.components;
91 String libraryUri = components[0]; 91 String libraryUri = components[0];
92 // Ask the parent resynthesizer. 92 // Ask the parent resynthesizer.
93 if (parent != null && parent._hasLibrarySummary(libraryUri)) { 93 if (parent != null && parent._hasLibrarySummary(libraryUri)) {
94 return parent.getElement(location); 94 return parent.getElement(location);
95 } 95 }
96 // Resynthesize locally. 96 // Resynthesize locally.
97 if (components.length == 1) { 97 if (components.length == 1) {
98 return getLibraryElement(libraryUri); 98 return getLibraryElement(libraryUri);
99 } else if (components.length == 3) { 99 } else if (components.length == 3 || components.length == 4) {
100 Map<String, Map<String, Element>> libraryMap = 100 Map<String, Map<String, Element>> libraryMap =
101 _resynthesizedElements[libraryUri]; 101 _resynthesizedElements[libraryUri];
102 if (libraryMap == null) { 102 if (libraryMap == null) {
103 getLibraryElement(libraryUri); 103 getLibraryElement(libraryUri);
104 libraryMap = _resynthesizedElements[libraryUri]; 104 libraryMap = _resynthesizedElements[libraryUri];
105 assert(libraryMap != null); 105 assert(libraryMap != null);
106 } 106 }
107 Map<String, Element> compilationUnitElements = libraryMap[components[1]]; 107 Map<String, Element> compilationUnitElements = libraryMap[components[1]];
108 Element element;
108 if (compilationUnitElements != null) { 109 if (compilationUnitElements != null) {
109 Element element = compilationUnitElements[components[2]]; 110 element = compilationUnitElements[components[2]];
110 if (element != null) { 111 }
111 return element; 112 if (element != null && components.length == 4) {
113 String name = components[3];
114 Element parentElement = element;
115 if (parentElement is ClassElement) {
116 if (name.endsWith('?')) {
117 element =
118 parentElement.getGetter(name.substring(0, name.length - 1));
119 } else if (name.endsWith('=')) {
120 element =
121 parentElement.getSetter(name.substring(0, name.length - 1));
122 } else if (name.isEmpty) {
123 element = parentElement.unnamedConstructor;
124 } else {
125 element = parentElement.getField(name) ??
126 parentElement.getMethod(name) ??
127 parentElement.getNamedConstructor(name);
128 }
129 } else {
130 // The only elements that are currently retrieved using 4-component
131 // locations are class members.
132 throw new StateError(
133 '4-element locations not supported for ${element.runtimeType}');
112 } 134 }
113 } 135 }
114 throw new Exception('Element not found in summary: $location'); 136 if (element == null) {
137 throw new Exception('Element not found in summary: $location');
138 }
139 return element;
115 } else { 140 } else {
116 throw new UnimplementedError(location.toString()); 141 throw new UnimplementedError(location.toString());
117 } 142 }
118 } 143 }
119 144
120 /** 145 /**
121 * Get the [LibraryElement] for the given [uri], resynthesizing it if it 146 * Get the [LibraryElement] for the given [uri], resynthesizing it if it
122 * hasn't been resynthesized already. 147 * hasn't been resynthesized already.
123 */ 148 */
124 LibraryElement getLibraryElement(String uri) { 149 LibraryElement getLibraryElement(String uri) {
(...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after
1217 for (PropertyAccessorElementImpl accessor in unit.accessors) { 1242 for (PropertyAccessorElementImpl accessor in unit.accessors) {
1218 elementMap[accessor.identifier] = accessor; 1243 elementMap[accessor.identifier] = accessor;
1219 } 1244 }
1220 resummarizedElements[absoluteUri] = elementMap; 1245 resummarizedElements[absoluteUri] = elementMap;
1221 unitHolder = null; 1246 unitHolder = null;
1222 linkedUnit = null; 1247 linkedUnit = null;
1223 unlinkedUnit = null; 1248 unlinkedUnit = null;
1224 linkedTypeMap = null; 1249 linkedTypeMap = null;
1225 } 1250 }
1226 } 1251 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698