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

Unified Diff: pkg/analysis_server/lib/src/services/correction/fix.dart

Issue 1080653003: Create a public API for contributing fixes and make fixes pluggable (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Missed clean-up Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/lib/src/services/correction/fix.dart
diff --git a/pkg/analysis_server/lib/src/services/correction/fix.dart b/pkg/analysis_server/lib/src/services/correction/fix.dart
index beb33674d6c511343b5bd94c854b226839a46e94..1387589be949832af433408fd33078966d7445f7 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix.dart
@@ -2,46 +2,43 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-library services.correction.fix;
+library analysis_server.src.services.correction.fix;
-import 'package:analysis_server/src/protocol.dart' show SourceChange;
-import 'package:analysis_server/src/services/correction/fix_internal.dart';
-import 'package:analyzer/src/generated/ast.dart';
+import 'package:analysis_server/edit/fix/fix_core.dart';
+import 'package:analysis_server/src/plugin/server_plugin.dart';
+import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/error.dart';
+import 'package:analyzer/src/generated/java_engine.dart';
/**
- * Computes [Fix]s for the given [AnalysisError].
- *
- * Returns the computed [Fix]s, not `null`.
+ * Compute and return the fixes available for the given [error]. The error was
+ * reported after it's source was analyzed in the given [context]. The [plugin]
+ * is used to get the list of fix contributors.
*/
-List<Fix> computeFixes(CompilationUnit unit, AnalysisError error) {
- var processor = new FixProcessor(unit, error);
- List<Fix> fixes = processor.compute();
- fixes.sort((Fix a, Fix b) {
- return a.kind.relevance - b.kind.relevance;
- });
- return fixes;
-}
-
-/**
- * A description of a single proposed fix for some problem.
- */
-class Fix {
- final FixKind kind;
- final SourceChange change;
-
- Fix(this.kind, this.change);
-
- @override
- String toString() {
- return '[kind=$kind, change=$change]';
+List<Fix> computeFixes(
+ ServerPlugin plugin, AnalysisContext context, AnalysisError error) {
+ List<Fix> fixes = <Fix>[];
+ List<FixContributor> contributors = plugin.fixContributors();
+ for (FixContributor contributor in contributors) {
+ try {
+ List<Fix> contributedFixes = contributor.computeFixes(context, error);
+ if (contributedFixes != null) {
+ fixes.addAll(contributedFixes);
+ }
+ } catch (exception, stackTrace) {
+ AnalysisEngine.instance.logger.logError(
+ 'Exception from fix contributor: ${contributor.runtimeType}',
+ new CaughtException(exception, stackTrace));
+ }
}
+ fixes.sort(Fix.SORT_BY_RELEVANCE);
+ return fixes;
}
/**
* An enumeration of possible quick fix kinds.
*/
-class FixKind {
+class DartFixKind {
static const ADD_ASYNC =
const FixKind('ADD_ASYNC', 50, "Add 'async' modifier");
static const ADD_FIELD_FORMAL_PARAMETERS = const FixKind(
@@ -99,8 +96,8 @@ class FixKind {
"Remove parentheses in getter invocation");
static const REMOVE_UNNECASSARY_CAST =
const FixKind('REMOVE_UNNECASSARY_CAST', 50, "Remove unnecessary cast");
- static const REMOVE_UNUSED_CATCH_CLAUSE = const FixKind(
- 'REMOVE_UNUSED_CATCH', 50, "Remove unused 'catch' clause");
+ static const REMOVE_UNUSED_CATCH_CLAUSE =
+ const FixKind('REMOVE_UNUSED_CATCH', 50, "Remove unused 'catch' clause");
static const REMOVE_UNUSED_CATCH_STACK = const FixKind(
'REMOVE_UNUSED_CATCH_STACK', 50, "Remove unused stack trace variable");
static const REMOVE_UNUSED_IMPORT =
@@ -122,13 +119,4 @@ class FixKind {
const FixKind('USE_EQ_EQ_NULL', 50, "Use == null instead of 'is Null'");
static const USE_NOT_EQ_NULL =
const FixKind('USE_NOT_EQ_NULL', 50, "Use != null instead of 'is! Null'");
-
- final name;
- final int relevance;
- final String message;
-
- const FixKind(this.name, this.relevance, this.message);
-
- @override
- String toString() => name;
}

Powered by Google App Engine
This is Rietveld 408576698