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

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

Issue 2096103002: Analyzer support for `@factory` methods (linter#253). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Allow decls w/o a return type. Created 4 years, 5 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) 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 2444 matching lines...) Expand 10 before | Expand all | Expand 10 after
2455 */ 2455 */
2456 static String _DEPRECATED_CLASS_NAME = "Deprecated"; 2456 static String _DEPRECATED_CLASS_NAME = "Deprecated";
2457 2457
2458 /** 2458 /**
2459 * The name of the top-level variable used to mark an element as being 2459 * The name of the top-level variable used to mark an element as being
2460 * deprecated. 2460 * deprecated.
2461 */ 2461 */
2462 static String _DEPRECATED_VARIABLE_NAME = "deprecated"; 2462 static String _DEPRECATED_VARIABLE_NAME = "deprecated";
2463 2463
2464 /** 2464 /**
2465 * The name of the top-level variable used to mark a method as being a
2466 * factory.
2467 */
2468 static String _FACTORY_VARIABLE_NAME = "factory";
2469
2470 /**
2465 * The name of the class used to JS annotate an element. 2471 * The name of the class used to JS annotate an element.
2466 */ 2472 */
2467 static String _JS_CLASS_NAME = "JS"; 2473 static String _JS_CLASS_NAME = "JS";
2468 2474
2469 /** 2475 /**
2470 * The name of `js` library, used to define JS annotations. 2476 * The name of `js` library, used to define JS annotations.
2471 */ 2477 */
2472 static String _JS_LIB_NAME = "js"; 2478 static String _JS_LIB_NAME = "js";
2473 2479
2474 /** 2480 /**
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2553 if (element is ConstructorElement) { 2559 if (element is ConstructorElement) {
2554 return element.enclosingElement.name == _DEPRECATED_CLASS_NAME; 2560 return element.enclosingElement.name == _DEPRECATED_CLASS_NAME;
2555 } else if (element is PropertyAccessorElement) { 2561 } else if (element is PropertyAccessorElement) {
2556 return element.name == _DEPRECATED_VARIABLE_NAME; 2562 return element.name == _DEPRECATED_VARIABLE_NAME;
2557 } 2563 }
2558 } 2564 }
2559 return false; 2565 return false;
2560 } 2566 }
2561 2567
2562 @override 2568 @override
2569 bool get isFactory =>
2570 element is PropertyAccessorElement &&
2571 element.name == _FACTORY_VARIABLE_NAME &&
2572 element.library?.name == _META_LIB_NAME;
2573
2574 @override
2563 bool get isJS => 2575 bool get isJS =>
2564 element is ConstructorElement && 2576 element is ConstructorElement &&
2565 element.enclosingElement.name == _JS_CLASS_NAME && 2577 element.enclosingElement.name == _JS_CLASS_NAME &&
2566 element.library?.name == _JS_LIB_NAME; 2578 element.library?.name == _JS_LIB_NAME;
2567 2579
2568 @override 2580 @override
2569 bool get isMustCallSuper => 2581 bool get isMustCallSuper =>
2570 element is PropertyAccessorElement && 2582 element is PropertyAccessorElement &&
2571 element.name == _MUST_CALL_SUPER_VARIABLE_NAME && 2583 element.name == _MUST_CALL_SUPER_VARIABLE_NAME &&
2572 element.library?.name == _META_LIB_NAME; 2584 element.library?.name == _META_LIB_NAME;
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
2796 bool get isDeprecated { 2808 bool get isDeprecated {
2797 for (ElementAnnotation annotation in metadata) { 2809 for (ElementAnnotation annotation in metadata) {
2798 if (annotation.isDeprecated) { 2810 if (annotation.isDeprecated) {
2799 return true; 2811 return true;
2800 } 2812 }
2801 } 2813 }
2802 return false; 2814 return false;
2803 } 2815 }
2804 2816
2805 @override 2817 @override
2818 bool get isFactory {
2819 for (ElementAnnotation annotation in metadata) {
2820 if (annotation.isFactory) {
2821 return true;
2822 }
2823 }
2824 return false;
2825 }
2826
2827 @override
2806 bool get isJS { 2828 bool get isJS {
2807 for (ElementAnnotation annotation in metadata) { 2829 for (ElementAnnotation annotation in metadata) {
2808 if (annotation.isJS) { 2830 if (annotation.isJS) {
2809 return true; 2831 return true;
2810 } 2832 }
2811 } 2833 }
2812 return false; 2834 return false;
2813 } 2835 }
2814 2836
2815 @override 2837 @override
(...skipping 3659 matching lines...) Expand 10 before | Expand all | Expand 10 after
6475 @override 6497 @override
6476 String get documentationComment => null; 6498 String get documentationComment => null;
6477 6499
6478 @override 6500 @override
6479 Element get enclosingElement => null; 6501 Element get enclosingElement => null;
6480 6502
6481 @override 6503 @override
6482 bool get isDeprecated => false; 6504 bool get isDeprecated => false;
6483 6505
6484 @override 6506 @override
6507 bool get isFactory => false;
6508
6509 @override
6485 bool get isJS => false; 6510 bool get isJS => false;
6486 6511
6487 @override 6512 @override
6488 bool get isOverride => false; 6513 bool get isOverride => false;
6489 6514
6490 @override 6515 @override
6491 bool get isPrivate { 6516 bool get isPrivate {
6492 String name = displayName; 6517 String name = displayName;
6493 if (name == null) { 6518 if (name == null) {
6494 return false; 6519 return false;
(...skipping 1947 matching lines...) Expand 10 before | Expand all | Expand 10 after
8442 8467
8443 @override 8468 @override
8444 void visitElement(Element element) { 8469 void visitElement(Element element) {
8445 int offset = element.nameOffset; 8470 int offset = element.nameOffset;
8446 if (offset != -1) { 8471 if (offset != -1) {
8447 map[offset] = element; 8472 map[offset] = element;
8448 } 8473 }
8449 super.visitElement(element); 8474 super.visitElement(element);
8450 } 8475 }
8451 } 8476 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/dart/element/element.dart ('k') | pkg/analyzer/lib/src/dart/element/handle.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698