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

Side by Side Diff: pkg/analyzer/lib/error/error.dart

Issue 2365553004: Convert subclasses of Enum (Closed)
Patch Set: 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
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.error.error; 5 library analyzer.error.error;
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/error/listener.dart'; 10 import 'package:analyzer/error/listener.dart';
(...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 _uniqueNameToCodeMap[errorCode.uniqueName] = errorCode; 885 _uniqueNameToCodeMap[errorCode.uniqueName] = errorCode;
886 } 886 }
887 } 887 }
888 return _uniqueNameToCodeMap[uniqueName]; 888 return _uniqueNameToCodeMap[uniqueName];
889 } 889 }
890 } 890 }
891 891
892 /** 892 /**
893 * The properties that can be associated with an [AnalysisError]. 893 * The properties that can be associated with an [AnalysisError].
894 */ 894 */
895 class ErrorProperty<V> extends Enum<ErrorProperty> { 895 class ErrorProperty<V> implements Comparable<ErrorProperty> {
896 /** 896 /**
897 * A property whose value is a list of [FieldElement]s that are final, but 897 * A property whose value is a list of [FieldElement]s that are final, but
898 * not initialized by a constructor. 898 * not initialized by a constructor.
899 */ 899 */
900 static const ErrorProperty<List<FieldElement>> NOT_INITIALIZED_FIELDS = 900 static const ErrorProperty<List<FieldElement>> NOT_INITIALIZED_FIELDS =
901 const ErrorProperty<List<FieldElement>>('NOT_INITIALIZED_FIELDS', 0); 901 const ErrorProperty<List<FieldElement>>('NOT_INITIALIZED_FIELDS', 0);
902 902
903 /** 903 /**
904 * A property whose value is the name of the library that is used by all 904 * A property whose value is the name of the library that is used by all
905 * of the "part of" directives, so should be used in the "library" directive. 905 * of the "part of" directives, so should be used in the "library" directive.
906 * Is `null` if there is no a single name used by all of the parts. 906 * Is `null` if there is no a single name used by all of the parts.
907 */ 907 */
908 static const ErrorProperty<String> PARTS_LIBRARY_NAME = 908 static const ErrorProperty<String> PARTS_LIBRARY_NAME =
909 const ErrorProperty<String>('PARTS_LIBRARY_NAME', 1); 909 const ErrorProperty<String>('PARTS_LIBRARY_NAME', 1);
910 910
911 /** 911 /**
912 * A property whose value is a list of [ExecutableElement] that should 912 * A property whose value is a list of [ExecutableElement] that should
913 * be but are not implemented by a concrete class. 913 * be but are not implemented by a concrete class.
914 */ 914 */
915 static const ErrorProperty<List<ExecutableElement>> UNIMPLEMENTED_METHODS = 915 static const ErrorProperty<List<ExecutableElement>> UNIMPLEMENTED_METHODS =
916 const ErrorProperty<List<ExecutableElement>>('UNIMPLEMENTED_METHODS', 2); 916 const ErrorProperty<List<ExecutableElement>>('UNIMPLEMENTED_METHODS', 2);
917 917
918 static const List<ErrorProperty> values = const [ 918 static const List<ErrorProperty> values = const [
919 NOT_INITIALIZED_FIELDS, 919 NOT_INITIALIZED_FIELDS,
920 PARTS_LIBRARY_NAME, 920 PARTS_LIBRARY_NAME,
921 UNIMPLEMENTED_METHODS 921 UNIMPLEMENTED_METHODS
922 ]; 922 ];
923 923
924 const ErrorProperty(String name, int ordinal) : super(name, ordinal); 924 /**
925 * The name of this property.
926 */
927 final String name;
928
929 /**
930 * The ordinal value of the property.
931 */
932 final int ordinal;
933
934 const ErrorProperty(this.name, this.ordinal);
935
936 @override
937 int get hashCode => ordinal;
938
939 @override
940 int compareTo(ErrorProperty other) => ordinal - other.ordinal;
941
942 @override
943 String toString() => name;
925 } 944 }
926 945
927 /** 946 /**
928 * The severity of an [ErrorCode]. 947 * The severity of an [ErrorCode].
929 */ 948 */
930 class ErrorSeverity extends Enum<ErrorSeverity> { 949 class ErrorSeverity implements Comparable<ErrorSeverity> {
931 /** 950 /**
932 * The severity representing a non-error. This is never used for any error 951 * The severity representing a non-error. This is never used for any error
933 * code, but is useful for clients. 952 * code, but is useful for clients.
934 */ 953 */
935 static const ErrorSeverity NONE = const ErrorSeverity('NONE', 0, " ", "none"); 954 static const ErrorSeverity NONE = const ErrorSeverity('NONE', 0, " ", "none");
936 955
937 /** 956 /**
938 * The severity representing an informational level analysis issue. 957 * The severity representing an informational level analysis issue.
939 */ 958 */
940 static const ErrorSeverity INFO = const ErrorSeverity('INFO', 1, "I", "info"); 959 static const ErrorSeverity INFO = const ErrorSeverity('INFO', 1, "I", "info");
941 960
942 /** 961 /**
943 * The severity representing a warning. Warnings can become errors if the `-We rror` command 962 * The severity representing a warning. Warnings can become errors if the `-We rror` command
944 * line flag is specified. 963 * line flag is specified.
945 */ 964 */
946 static const ErrorSeverity WARNING = 965 static const ErrorSeverity WARNING =
947 const ErrorSeverity('WARNING', 2, "W", "warning"); 966 const ErrorSeverity('WARNING', 2, "W", "warning");
948 967
949 /** 968 /**
950 * The severity representing an error. 969 * The severity representing an error.
951 */ 970 */
952 static const ErrorSeverity ERROR = 971 static const ErrorSeverity ERROR =
953 const ErrorSeverity('ERROR', 3, "E", "error"); 972 const ErrorSeverity('ERROR', 3, "E", "error");
954 973
955 static const List<ErrorSeverity> values = const [NONE, INFO, WARNING, ERROR]; 974 static const List<ErrorSeverity> values = const [NONE, INFO, WARNING, ERROR];
956 975
957 /** 976 /**
977 * The name of this error code.
978 */
979 final String name;
980
981 /**
982 * The ordinal value of the error code.
983 */
984 final int ordinal;
985
986 /**
958 * The name of the severity used when producing machine output. 987 * The name of the severity used when producing machine output.
959 */ 988 */
960 final String machineCode; 989 final String machineCode;
961 990
962 /** 991 /**
963 * The name of the severity used when producing readable output. 992 * The name of the severity used when producing readable output.
964 */ 993 */
965 final String displayName; 994 final String displayName;
966 995
967 /** 996 /**
968 * Initialize a newly created severity with the given names. 997 * Initialize a newly created severity with the given names.
969 *
970 * Parameters:
971 * 0: the name of the severity used when producing machine output
972 * 1: the name of the severity used when producing readable output
973 */ 998 */
974 const ErrorSeverity( 999 const ErrorSeverity(
975 String name, int ordinal, this.machineCode, this.displayName) 1000 this.name, this.ordinal, this.machineCode, this.displayName);
976 : super(name, ordinal); 1001
1002 @override
1003 int get hashCode => ordinal;
1004
1005 @override
1006 int compareTo(ErrorSeverity other) => ordinal - other.ordinal;
977 1007
978 /** 1008 /**
979 * Return the severity constant that represents the greatest severity. 1009 * Return the severity constant that represents the greatest severity.
980 */ 1010 */
981 ErrorSeverity max(ErrorSeverity severity) => 1011 ErrorSeverity max(ErrorSeverity severity) =>
982 this.ordinal >= severity.ordinal ? this : severity; 1012 this.ordinal >= severity.ordinal ? this : severity;
1013
1014 @override
1015 String toString() => name;
983 } 1016 }
984 1017
985 /** 1018 /**
986 * The type of an [ErrorCode]. 1019 * The type of an [ErrorCode].
987 */ 1020 */
988 class ErrorType extends Enum<ErrorType> { 1021 class ErrorType implements Comparable<ErrorType> {
989 /** 1022 /**
990 * Task (todo) comments in user code. 1023 * Task (todo) comments in user code.
991 */ 1024 */
992 static const ErrorType TODO = const ErrorType('TODO', 0, ErrorSeverity.INFO); 1025 static const ErrorType TODO = const ErrorType('TODO', 0, ErrorSeverity.INFO);
993 1026
994 /** 1027 /**
995 * Extra analysis run over the code to follow best practices, which are not in 1028 * Extra analysis run over the code to follow best practices, which are not in
996 * the Dart Language Specification. 1029 * the Dart Language Specification.
997 */ 1030 */
998 static const ErrorType HINT = const ErrorType('HINT', 1, ErrorSeverity.INFO); 1031 static const ErrorType HINT = const ErrorType('HINT', 1, ErrorSeverity.INFO);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 HINT, 1078 HINT,
1046 COMPILE_TIME_ERROR, 1079 COMPILE_TIME_ERROR,
1047 CHECKED_MODE_COMPILE_TIME_ERROR, 1080 CHECKED_MODE_COMPILE_TIME_ERROR,
1048 STATIC_WARNING, 1081 STATIC_WARNING,
1049 STATIC_TYPE_WARNING, 1082 STATIC_TYPE_WARNING,
1050 SYNTACTIC_ERROR, 1083 SYNTACTIC_ERROR,
1051 LINT 1084 LINT
1052 ]; 1085 ];
1053 1086
1054 /** 1087 /**
1088 * The name of this error type.
1089 */
1090 final String name;
1091
1092 /**
1093 * The ordinal value of the error type.
1094 */
1095 final int ordinal;
1096
1097 /**
1055 * The severity of this type of error. 1098 * The severity of this type of error.
1056 */ 1099 */
1057 final ErrorSeverity severity; 1100 final ErrorSeverity severity;
1058 1101
1059 /** 1102 /**
1060 * Initialize a newly created error type to have the given [name] and 1103 * Initialize a newly created error type to have the given [name] and
1061 * [severity]. 1104 * [severity].
1062 */ 1105 */
1063 const ErrorType(String name, int ordinal, this.severity) 1106 const ErrorType(this.name, this.ordinal, this.severity);
1064 : super(name, ordinal);
1065 1107
1066 String get displayName => name.toLowerCase().replaceAll('_', ' '); 1108 String get displayName => name.toLowerCase().replaceAll('_', ' ');
1109
1110 @override
1111 int get hashCode => ordinal;
1112
1113 @override
1114 int compareTo(ErrorType other) => ordinal - other.ordinal;
1115
1116 @override
1117 String toString() => name;
1067 } 1118 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/dart/element/element.dart ('k') | pkg/analyzer/lib/src/dart/element/element.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698