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

Side by Side Diff: pkg/analyzer_plugin/lib/plugin/fix_mixin.dart

Issue 3008433002: Unify lots of copied code in one utility method (Closed)
Patch Set: Created 3 years, 4 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) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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 import 'dart:async'; 5 import 'dart:async';
6 6
7 import 'package:analyzer/dart/analysis/results.dart'; 7 import 'package:analyzer/dart/analysis/results.dart';
8 import 'package:analyzer/error/error.dart'; 8 import 'package:analyzer/error/error.dart';
9 import 'package:analyzer/src/dart/analysis/driver.dart'; 9 import 'package:analyzer/src/dart/analysis/driver.dart';
10 import 'package:analyzer/src/generated/source.dart'; 10 import 'package:analyzer/src/generated/source.dart';
(...skipping 11 matching lines...) Expand all
22 * 22 *
23 * Clients may not extend or implement this class, but are allowed to use it as 23 * Clients may not extend or implement this class, but are allowed to use it as
24 * a mix-in when creating a subclass of [ServerPlugin] that also uses 24 * a mix-in when creating a subclass of [ServerPlugin] that also uses
25 * [FixesMixin] as a mix-in. 25 * [FixesMixin] as a mix-in.
26 */ 26 */
27 abstract class DartFixesMixin implements FixesMixin { 27 abstract class DartFixesMixin implements FixesMixin {
28 @override 28 @override
29 Future<FixesRequest> getFixesRequest(EditGetFixesParams parameters) async { 29 Future<FixesRequest> getFixesRequest(EditGetFixesParams parameters) async {
30 String path = parameters.file; 30 String path = parameters.file;
31 int offset = parameters.offset; 31 int offset = parameters.offset;
32 AnalysisDriver driver = driverForPath(path); 32 ResolveResult result = await getResolveResult(path);
33 if (driver == null) {
34 // Return an error from the request.
35 throw new RequestFailure(
36 RequestErrorFactory.pluginError('Failed to analyze $path', null));
37 }
38 ResolveResult result = await driver.getResult(path);
39 return new DartFixesRequestImpl( 33 return new DartFixesRequestImpl(
40 resourceProvider, offset, _getErrors(offset, result), result); 34 resourceProvider, offset, _getErrors(offset, result), result);
41 } 35 }
42 36
43 List<AnalysisError> _getErrors(int offset, ResolveResult result) { 37 List<AnalysisError> _getErrors(int offset, ResolveResult result) {
44 LineInfo lineInfo = result.lineInfo; 38 LineInfo lineInfo = result.lineInfo;
45 int offsetLine = lineInfo.getLocation(offset).lineNumber; 39 int offsetLine = lineInfo.getLocation(offset).lineNumber;
46 return result.errors.where((AnalysisError error) { 40 return result.errors.where((AnalysisError error) {
47 int errorLine = lineInfo.getLocation(error.offset).lineNumber; 41 int errorLine = lineInfo.getLocation(error.offset).lineNumber;
48 return errorLine == offsetLine; 42 return errorLine == offsetLine;
(...skipping 11 matching lines...) Expand all
60 abstract class FixesMixin implements ServerPlugin { 54 abstract class FixesMixin implements ServerPlugin {
61 /** 55 /**
62 * Return a list containing the fix contributors that should be used to create 56 * Return a list containing the fix contributors that should be used to create
63 * fixes for the file with the given [path]. 57 * fixes for the file with the given [path].
64 */ 58 */
65 List<FixContributor> getFixContributors(String path); 59 List<FixContributor> getFixContributors(String path);
66 60
67 /** 61 /**
68 * Return the fixes request that should be passes to the contributors 62 * Return the fixes request that should be passes to the contributors
69 * returned from [getFixContributors]. 63 * returned from [getFixContributors].
64 *
65 * Throw a [RequestFailure] if the request could not be created.
70 */ 66 */
71 Future<FixesRequest> getFixesRequest(EditGetFixesParams parameters); 67 Future<FixesRequest> getFixesRequest(EditGetFixesParams parameters);
72 68
73 @override 69 @override
74 Future<EditGetFixesResult> handleEditGetFixes( 70 Future<EditGetFixesResult> handleEditGetFixes(
75 EditGetFixesParams parameters) async { 71 EditGetFixesParams parameters) async {
76 String path = parameters.file; 72 String path = parameters.file;
77 FixesRequest request = await getFixesRequest(parameters); 73 FixesRequest request = await getFixesRequest(parameters);
78 FixGenerator generator = new FixGenerator(getFixContributors(path)); 74 FixGenerator generator = new FixGenerator(getFixContributors(path));
79 GeneratorResult result = await generator.generateFixesResponse(request); 75 GeneratorResult result = await generator.generateFixesResponse(request);
80 result.sendNotifications(channel); 76 result.sendNotifications(channel);
81 return result.result; 77 return result.result;
82 } 78 }
83 } 79 }
OLDNEW
« no previous file with comments | « pkg/analyzer_plugin/lib/plugin/completion_mixin.dart ('k') | pkg/analyzer_plugin/lib/plugin/kythe_mixin.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698