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

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

Issue 1145833004: fixes #173, ability to use native JS indexers (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: merged 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
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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 /// For example if we had the ClassDeclaration node for `FontElement`: 350 /// For example if we had the ClassDeclaration node for `FontElement`:
351 /// 351 ///
352 /// @JsName('HTMLFontElement') 352 /// @JsName('HTMLFontElement')
353 /// @deprecated 353 /// @deprecated
354 /// class FontElement { ... } 354 /// class FontElement { ... }
355 /// 355 ///
356 /// We could match `@deprecated` with a test function like: 356 /// We could match `@deprecated` with a test function like:
357 /// 357 ///
358 /// (v) => v.type.name == 'Deprecated' && v.type.element.library.isDartCore 358 /// (v) => v.type.name == 'Deprecated' && v.type.element.library.isDartCore
359 /// 359 ///
360 DartObjectImpl getAnnotationValue( 360 DartObjectImpl findAnnotation(
361 AnnotatedNode node, bool test(DartObjectImpl value)) { 361 Element element, bool test(DartObjectImpl value)) {
362 for (var metadata in node.metadata) { 362 for (var metadata in element.metadata) {
363 ElementAnnotationImpl element = metadata.elementAnnotation; 363 var evalResult = metadata.evaluationResult;
364 if (element == null) continue;
365
366 var evalResult = element.evaluationResult;
367 if (evalResult == null) continue; 364 if (evalResult == null) continue;
368 365
369 var value = evalResult.value; 366 var value = evalResult.value;
370 if (value != null && test(value)) return value; 367 if (value != null && test(value)) return value;
371 } 368 }
372 return null; 369 return null;
373 } 370 }
374 371
375 /// Given a constant [value], a [fieldName], and an [expectedType], returns the 372 /// Given a constant [value], a [fieldName], and an [expectedType], returns the
376 /// value of that field. 373 /// value of that field.
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 int lineEnd = endLoc.offset; 458 int lineEnd = endLoc.offset;
462 int unitEnd = unit.endToken.end; 459 int unitEnd = unit.endToken.end;
463 int lineNum = lineInfo.getLocation(lineEnd).lineNumber; 460 int lineNum = lineInfo.getLocation(lineEnd).lineNumber;
464 while (lineEnd < unitEnd && 461 while (lineEnd < unitEnd &&
465 lineInfo.getLocation(++lineEnd).lineNumber == lineNum); 462 lineInfo.getLocation(++lineEnd).lineNumber == lineNum);
466 463
467 var text = content.substring(start, end); 464 var text = content.substring(start, end);
468 var lineText = content.substring(lineStart, lineEnd); 465 var lineText = content.substring(lineStart, lineEnd);
469 return new SourceSpanWithContext(startLoc, endLoc, text, lineText); 466 return new SourceSpanWithContext(startLoc, endLoc, text, lineText);
470 } 467 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698