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

Side by Side Diff: lib/src/utils.dart

Issue 1165823002: fixes #200, library prefixes for unknown imports (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 6 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 | no next file » | 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) 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 /// Holds a couple utility functions used at various places in the system. 5 /// Holds a couple utility functions used at various places in the system.
6 library dev_compiler.src.utils; 6 library dev_compiler.src.utils;
7 7
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:path/path.dart' as path; 10 import 'package:path/path.dart' as path;
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } catch (e) { 200 } catch (e) {
201 // TODO(sigmund): remove this try-catch block (see issue #48). 201 // TODO(sigmund): remove this try-catch block (see issue #48).
202 } 202 }
203 if (baseMethod == null || baseMethod.isStatic) return null; 203 if (baseMethod == null || baseMethod.isStatic) return null;
204 return baseMethod.type; 204 return baseMethod.type;
205 } 205 }
206 ; 206 ;
207 return f; 207 return f;
208 } 208 }
209 209
210 bool isDynamicTarget(Expression node) => 210 bool isDynamicTarget(Expression node) {
211 node != null && !isLibraryPrefix(node) && node.staticType.isDynamic; 211 if (node == null) return false;
212 var type = node.staticType;
213
214 // This is an unknown identifier, like an import that doesn't resolve.
215 if (type == null) return true;
216
217 return type.isDynamic && !isLibraryPrefix(node);
218 }
212 219
213 bool isLibraryPrefix(Expression node) => 220 bool isLibraryPrefix(Expression node) =>
214 node is SimpleIdentifier && node.staticElement is PrefixElement; 221 node is SimpleIdentifier && node.staticElement is PrefixElement;
215 222
216 /// Returns an ANSII color escape sequence corresponding to [levelName]. Colors 223 /// Returns an ANSII color escape sequence corresponding to [levelName]. Colors
217 /// are defined for: severe, error, warning, or info. Returns null if the level 224 /// are defined for: severe, error, warning, or info. Returns null if the level
218 /// name is not recognized. 225 /// name is not recognized.
219 String colorOf(String levelName) { 226 String colorOf(String levelName) {
220 levelName = levelName.toLowerCase(); 227 levelName = levelName.toLowerCase();
221 if (levelName == 'shout' || levelName == 'severe' || levelName == 'error') { 228 if (levelName == 'shout' || levelName == 'severe' || levelName == 'error') {
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 int lineEnd = endLoc.offset; 460 int lineEnd = endLoc.offset;
454 int unitEnd = unit.endToken.end; 461 int unitEnd = unit.endToken.end;
455 int lineNum = lineInfo.getLocation(lineEnd).lineNumber; 462 int lineNum = lineInfo.getLocation(lineEnd).lineNumber;
456 while (lineEnd < unitEnd && 463 while (lineEnd < unitEnd &&
457 lineInfo.getLocation(++lineEnd).lineNumber == lineNum); 464 lineInfo.getLocation(++lineEnd).lineNumber == lineNum);
458 465
459 var text = content.substring(start, end); 466 var text = content.substring(start, end);
460 var lineText = content.substring(lineStart, lineEnd); 467 var lineText = content.substring(lineStart, lineEnd);
461 return new SourceSpanWithContext(startLoc, endLoc, text, lineText); 468 return new SourceSpanWithContext(startLoc, endLoc, text, lineText);
462 } 469 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698