OLD | NEW |
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 analysis_server.src.services.correction.fix_internal; | 5 library analysis_server.src.services.correction.fix_internal; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 import 'dart:core' hide Resource; | 9 import 'dart:core' hide Resource; |
10 | 10 |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 errorCode == StaticTypeWarningCode.UNDEFINED_METHOD) { | 336 errorCode == StaticTypeWarningCode.UNDEFINED_METHOD) { |
337 _addFix_importLibrary_withFunction(); | 337 _addFix_importLibrary_withFunction(); |
338 _addFix_undefinedMethod_useSimilar(); | 338 _addFix_undefinedMethod_useSimilar(); |
339 _addFix_undefinedMethod_create(); | 339 _addFix_undefinedMethod_create(); |
340 _addFix_undefinedFunction_create(); | 340 _addFix_undefinedFunction_create(); |
341 } | 341 } |
342 if (errorCode == StaticTypeWarningCode.UNDEFINED_SETTER) { | 342 if (errorCode == StaticTypeWarningCode.UNDEFINED_SETTER) { |
343 _addFix_undefinedClassAccessor_useSimilar(); | 343 _addFix_undefinedClassAccessor_useSimilar(); |
344 _addFix_createField(); | 344 _addFix_createField(); |
345 } | 345 } |
| 346 // lints |
| 347 if (errorCode is LintCode) { |
| 348 if (errorCode.name == LintNames.annotate_overrides) { |
| 349 _addLintFixAddOverrideAnnotation(); |
| 350 } |
| 351 } |
346 // done | 352 // done |
347 return fixes; | 353 return fixes; |
348 } | 354 } |
349 | 355 |
350 /** | 356 /** |
351 * Adds a new [SourceEdit] to [change]. | 357 * Adds a new [SourceEdit] to [change]. |
352 */ | 358 */ |
353 void _addEdit(Element target, SourceEdit edit) { | 359 void _addEdit(Element target, SourceEdit edit) { |
354 if (target == null) { | 360 if (target == null) { |
355 target = unitElement; | 361 target = unitElement; |
(...skipping 1839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2195 int delta = sb.length; | 2201 int delta = sb.length; |
2196 offset += delta; | 2202 offset += delta; |
2197 } | 2203 } |
2198 // prepare group | 2204 // prepare group |
2199 LinkedEditGroup group = _getLinkedPosition(groupId); | 2205 LinkedEditGroup group = _getLinkedPosition(groupId); |
2200 // add position | 2206 // add position |
2201 Position position = new Position(file, offset); | 2207 Position position = new Position(file, offset); |
2202 group.addPosition(position, range.length); | 2208 group.addPosition(position, range.length); |
2203 } | 2209 } |
2204 | 2210 |
| 2211 void _addLintFixAddOverrideAnnotation() { |
| 2212 ClassMember member = node.getAncestor((n) => n is ClassMember); |
| 2213 if (member == null) { |
| 2214 return; |
| 2215 } |
| 2216 exitPosition = new Position(file, member.offset - 1); |
| 2217 String indent = utils.getIndent(1); |
| 2218 _addReplaceEdit(rf.rangeStartLength(member, 0), '@override$eol$indent'); |
| 2219 _addFix(DartFixKind.LINT_ADD_OVERRIDE, []); |
| 2220 } |
| 2221 |
2205 /** | 2222 /** |
2206 * Prepares proposal for creating function corresponding to the given | 2223 * Prepares proposal for creating function corresponding to the given |
2207 * [FunctionType]. | 2224 * [FunctionType]. |
2208 */ | 2225 */ |
2209 void _addProposal_createFunction( | 2226 void _addProposal_createFunction( |
2210 FunctionType functionType, | 2227 FunctionType functionType, |
2211 String name, | 2228 String name, |
2212 Source targetSource, | 2229 Source targetSource, |
2213 int insertOffset, | 2230 int insertOffset, |
2214 bool isStatic, | 2231 bool isStatic, |
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2877 if (parent is TypeName) { | 2894 if (parent is TypeName) { |
2878 return true; | 2895 return true; |
2879 } | 2896 } |
2880 return _isNameOfType(node.name); | 2897 return _isNameOfType(node.name); |
2881 } | 2898 } |
2882 return false; | 2899 return false; |
2883 } | 2900 } |
2884 } | 2901 } |
2885 | 2902 |
2886 /** | 2903 /** |
| 2904 * An enumeration of lint names. |
| 2905 */ |
| 2906 class LintNames { |
| 2907 static const String annotate_overrides = 'annotate_overrides'; |
| 2908 } |
| 2909 |
| 2910 /** |
2887 * Helper for finding [Element] with name closest to the given. | 2911 * Helper for finding [Element] with name closest to the given. |
2888 */ | 2912 */ |
2889 class _ClosestElementFinder { | 2913 class _ClosestElementFinder { |
2890 final String _targetName; | 2914 final String _targetName; |
2891 final ElementPredicate _predicate; | 2915 final ElementPredicate _predicate; |
2892 | 2916 |
2893 Element _element = null; | 2917 Element _element = null; |
2894 int _distance; | 2918 int _distance; |
2895 | 2919 |
2896 _ClosestElementFinder(this._targetName, this._predicate, this._distance); | 2920 _ClosestElementFinder(this._targetName, this._predicate, this._distance); |
(...skipping 29 matching lines...) Expand all Loading... |
2926 /** | 2950 /** |
2927 * Describes the location for a newly created [FieldDeclaration]. | 2951 * Describes the location for a newly created [FieldDeclaration]. |
2928 */ | 2952 */ |
2929 class _FieldLocation { | 2953 class _FieldLocation { |
2930 final String prefix; | 2954 final String prefix; |
2931 final int offset; | 2955 final int offset; |
2932 final String suffix; | 2956 final String suffix; |
2933 | 2957 |
2934 _FieldLocation(this.prefix, this.offset, this.suffix); | 2958 _FieldLocation(this.prefix, this.offset, this.suffix); |
2935 } | 2959 } |
OLD | NEW |