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

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

Issue 2706123002: Remove AnalysisErrorWithProperties and ErrorProperty. (Closed)
Patch Set: Created 3 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
« no previous file with comments | « no previous file | pkg/analyzer/lib/error/listener.dart » ('j') | 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) 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/error/listener.dart'; 9 import 'package:analyzer/error/listener.dart';
10 import 'package:analyzer/src/dart/scanner/scanner.dart' show ScannerErrorCode; 10 import 'package:analyzer/src/dart/scanner/scanner.dart' show ScannerErrorCode;
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 } 799 }
800 if (source != other.source) { 800 if (source != other.source) {
801 return false; 801 return false;
802 } 802 }
803 // OK 803 // OK
804 return true; 804 return true;
805 } 805 }
806 return false; 806 return false;
807 } 807 }
808 808
809 /**
810 * Return the value of the given [property], or `null` if the given property
811 * is not defined for this error.
812 */
813 Object/*=V*/ getProperty/*<V>*/(ErrorProperty/*<V>*/ property) => null;
814
815 @override 809 @override
816 String toString() { 810 String toString() {
817 StringBuffer buffer = new StringBuffer(); 811 StringBuffer buffer = new StringBuffer();
818 buffer.write((source != null) ? source.fullName : "<unknown source>"); 812 buffer.write((source != null) ? source.fullName : "<unknown source>");
819 buffer.write("("); 813 buffer.write("(");
820 buffer.write(offset); 814 buffer.write(offset);
821 buffer.write(".."); 815 buffer.write("..");
822 buffer.write(offset + length - 1); 816 buffer.write(offset + length - 1);
823 buffer.write("): "); 817 buffer.write("): ");
824 //buffer.write("(" + lineNumber + ":" + columnNumber + "): "); 818 //buffer.write("(" + lineNumber + ":" + columnNumber + "): ");
825 buffer.write(_message); 819 buffer.write(_message);
826 return buffer.toString(); 820 return buffer.toString();
827 } 821 }
828 822
829 /** 823 /**
830 * Merge all of the errors in the lists in the given list of [errorLists] into 824 * Merge all of the errors in the lists in the given list of [errorLists] into
831 * a single list of errors. 825 * a single list of errors.
832 */ 826 */
833 static List<AnalysisError> mergeLists(List<List<AnalysisError>> errorLists) { 827 static List<AnalysisError> mergeLists(List<List<AnalysisError>> errorLists) {
834 Set<AnalysisError> errors = new HashSet<AnalysisError>(); 828 Set<AnalysisError> errors = new HashSet<AnalysisError>();
835 for (List<AnalysisError> errorList in errorLists) { 829 for (List<AnalysisError> errorList in errorLists) {
836 errors.addAll(errorList); 830 errors.addAll(errorList);
837 } 831 }
838 return errors.toList(); 832 return errors.toList();
839 } 833 }
840 } 834 }
841
842 /**
843 * An [AnalysisError] that can have arbitrary properties associated with it.
844 */
845 class AnalysisErrorWithProperties extends AnalysisError {
846 /**
847 * The properties associated with this error.
848 */
849 HashMap<ErrorProperty, Object> _propertyMap =
850 new HashMap<ErrorProperty, Object>();
851
852 /**
853 * Initialize a newly created analysis error. The error is associated with the
854 * given [source] and is located at the given [offset] with the given
855 * [length]. The error will have the given [errorCode] and the list of
856 * [arguments] will be used to complete the message.
857 */
858 AnalysisErrorWithProperties(
859 Source source, int offset, int length, ErrorCode errorCode,
860 [List<Object> arguments])
861 : super(source, offset, length, errorCode, arguments);
862
863 @override
864 Object/*=V*/ getProperty/*<V>*/(ErrorProperty/*<V>*/ property) =>
865 _propertyMap[property] as Object/*=V*/;
866
867 /**
868 * Set the value of the given [property] to the given [value]. Using a value
869 * of `null` will effectively remove the property from this error.
870 */
871 void setProperty/*<V>*/(ErrorProperty/*<V>*/ property, Object/*=V*/ value) {
872 _propertyMap[property] = value;
873 }
874 }
875
876 /**
877 * The properties that can be associated with an [AnalysisError].
878 */
879 class ErrorProperty<V> implements Comparable<ErrorProperty> {
880 /**
881 * A property whose value is the name of the library that is used by all
882 * of the "part of" directives, so should be used in the "library" directive.
883 * Is `null` if there is no a single name used by all of the parts.
884 */
885 static const ErrorProperty<String> PARTS_LIBRARY_NAME =
886 const ErrorProperty<String>('PARTS_LIBRARY_NAME', 1);
887
888 static const List<ErrorProperty> values = const [
889 PARTS_LIBRARY_NAME,
890 ];
891
892 /**
893 * The name of this property.
894 */
895 final String name;
896
897 /**
898 * The ordinal value of the property.
899 */
900 final int ordinal;
901
902 const ErrorProperty(this.name, this.ordinal);
903
904 @override
905 int get hashCode => ordinal;
906
907 @override
908 int compareTo(ErrorProperty other) => ordinal - other.ordinal;
909
910 @override
911 String toString() => name;
912 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/error/listener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698