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

Side by Side Diff: pkg/analysis_server/lib/src/services/correction/assist.dart

Issue 969113002: Reformat (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 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 | Annotate | Revision Log
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 services.correction.assist; 5 library services.correction.assist;
6 6
7 import 'package:analysis_server/src/protocol.dart'; 7 import 'package:analysis_server/src/protocol.dart';
8 import 'package:analysis_server/src/services/correction/assist_internal.dart'; 8 import 'package:analysis_server/src/services/correction/assist_internal.dart';
9 import 'package:analyzer/src/generated/ast.dart'; 9 import 'package:analyzer/src/generated/ast.dart';
10 import 'package:analyzer/src/generated/source.dart'; 10 import 'package:analyzer/src/generated/source.dart';
11 11
12
13 /** 12 /**
14 * Computes [Assist]s at the given location. 13 * Computes [Assist]s at the given location.
15 * 14 *
16 * Returns the computed [Assist]s, not `null`. 15 * Returns the computed [Assist]s, not `null`.
17 */ 16 */
18 List<Assist> computeAssists(CompilationUnit unit, int offset, int length) { 17 List<Assist> computeAssists(CompilationUnit unit, int offset, int length) {
19 Source source = unit.element.source; 18 Source source = unit.element.source;
20 String file = source.fullName; 19 String file = source.fullName;
21 AssistProcessor processor = 20 AssistProcessor processor =
22 new AssistProcessor(source, file, unit, offset, length); 21 new AssistProcessor(source, file, unit, offset, length);
23 return processor.compute(); 22 return processor.compute();
24 } 23 }
25 24
26
27 /** 25 /**
28 * A description of a single proposed assist. 26 * A description of a single proposed assist.
29 */ 27 */
30 class Assist { 28 class Assist {
31 final AssistKind kind; 29 final AssistKind kind;
32 final SourceChange change; 30 final SourceChange change;
33 31
34 Assist(this.kind, this.change); 32 Assist(this.kind, this.change);
35 33
36 @override 34 @override
37 String toString() { 35 String toString() {
38 return 'Assist(kind=$kind, change=$change)'; 36 return 'Assist(kind=$kind, change=$change)';
39 } 37 }
40 } 38 }
41 39
42
43 /** 40 /**
44 * An enumeration of possible quick assist kinds. 41 * An enumeration of possible quick assist kinds.
45 */ 42 */
46 class AssistKind { 43 class AssistKind {
47 static const ADD_PART_DIRECTIVE = 44 static const ADD_PART_DIRECTIVE =
48 const AssistKind('ADD_PART_DIRECTIVE', 30, "Add 'part' directive"); 45 const AssistKind('ADD_PART_DIRECTIVE', 30, "Add 'part' directive");
49 static const ADD_TYPE_ANNOTATION = 46 static const ADD_TYPE_ANNOTATION =
50 const AssistKind('ADD_TYPE_ANNOTATION', 30, "Add type annotation"); 47 const AssistKind('ADD_TYPE_ANNOTATION', 30, "Add type annotation");
51 static const ASSIGN_TO_LOCAL_VARIABLE = const AssistKind( 48 static const ASSIGN_TO_LOCAL_VARIABLE = const AssistKind(
52 'ASSIGN_TO_LOCAL_VARIABLE', 49 'ASSIGN_TO_LOCAL_VARIABLE', 30, "Assign value to new local variable");
53 30, 50 static const CONVERT_INTO_BLOCK_BODY = const AssistKind(
54 "Assign value to new local variable"); 51 'CONVERT_INTO_BLOCK_BODY', 30, "Convert into block body");
55 static const CONVERT_INTO_BLOCK_BODY =
56 const AssistKind('CONVERT_INTO_BLOCK_BODY', 30, "Convert into block body") ;
57 static const CONVERT_INTO_EXPRESSION_BODY = const AssistKind( 52 static const CONVERT_INTO_EXPRESSION_BODY = const AssistKind(
58 'CONVERT_INTO_EXPRESSION_BODY', 53 'CONVERT_INTO_EXPRESSION_BODY', 30, "Convert into expression body");
59 30,
60 "Convert into expression body");
61 static const CONVERT_INTO_IS_NOT = 54 static const CONVERT_INTO_IS_NOT =
62 const AssistKind('CONVERT_INTO_IS_NOT', 30, "Convert into is!"); 55 const AssistKind('CONVERT_INTO_IS_NOT', 30, "Convert into is!");
63 static const CONVERT_INTO_IS_NOT_EMPTY = 56 static const CONVERT_INTO_IS_NOT_EMPTY = const AssistKind(
64 const AssistKind('CONVERT_INTO_IS_NOT_EMPTY', 30, "Convert into 'isNotEmpt y'"); 57 'CONVERT_INTO_IS_NOT_EMPTY', 30, "Convert into 'isNotEmpty'");
65 static const EXCHANGE_OPERANDS = 58 static const EXCHANGE_OPERANDS =
66 const AssistKind('EXCHANGE_OPERANDS', 30, "Exchange operands"); 59 const AssistKind('EXCHANGE_OPERANDS', 30, "Exchange operands");
67 static const EXTRACT_CLASS = 60 static const EXTRACT_CLASS =
68 const AssistKind('EXTRACT_CLASS', 30, "Extract class into file '{0}'"); 61 const AssistKind('EXTRACT_CLASS', 30, "Extract class into file '{0}'");
69 static const IMPORT_ADD_SHOW = 62 static const IMPORT_ADD_SHOW =
70 const AssistKind('IMPORT_ADD_SHOW', 30, "Add explicit 'show' combinator"); 63 const AssistKind('IMPORT_ADD_SHOW', 30, "Add explicit 'show' combinator");
71 static const INTRODUCE_LOCAL_CAST_TYPE = const AssistKind( 64 static const INTRODUCE_LOCAL_CAST_TYPE = const AssistKind(
72 'INTRODUCE_LOCAL_CAST_TYPE', 65 'INTRODUCE_LOCAL_CAST_TYPE', 30, "Introduce new local with tested type");
73 30,
74 "Introduce new local with tested type");
75 static const INVERT_IF_STATEMENT = 66 static const INVERT_IF_STATEMENT =
76 const AssistKind('INVERT_IF_STATEMENT', 30, "Invert 'if' statement"); 67 const AssistKind('INVERT_IF_STATEMENT', 30, "Invert 'if' statement");
77 static const JOIN_IF_WITH_INNER = const AssistKind( 68 static const JOIN_IF_WITH_INNER = const AssistKind('JOIN_IF_WITH_INNER', 30,
78 'JOIN_IF_WITH_INNER',
79 30,
80 "Join 'if' statement with inner 'if' statement"); 69 "Join 'if' statement with inner 'if' statement");
81 static const JOIN_IF_WITH_OUTER = const AssistKind( 70 static const JOIN_IF_WITH_OUTER = const AssistKind('JOIN_IF_WITH_OUTER', 30,
82 'JOIN_IF_WITH_OUTER',
83 30,
84 "Join 'if' statement with outer 'if' statement"); 71 "Join 'if' statement with outer 'if' statement");
85 static const JOIN_VARIABLE_DECLARATION = 72 static const JOIN_VARIABLE_DECLARATION = const AssistKind(
86 const AssistKind('JOIN_VARIABLE_DECLARATION', 30, "Join variable declarati on"); 73 'JOIN_VARIABLE_DECLARATION', 30, "Join variable declaration");
87 static const REMOVE_TYPE_ANNOTATION = 74 static const REMOVE_TYPE_ANNOTATION =
88 const AssistKind('REMOVE_TYPE_ANNOTATION', 29, "Remove type annotation"); 75 const AssistKind('REMOVE_TYPE_ANNOTATION', 29, "Remove type annotation");
89 static const REPLACE_CONDITIONAL_WITH_IF_ELSE = const AssistKind( 76 static const REPLACE_CONDITIONAL_WITH_IF_ELSE = const AssistKind(
90 'REPLACE_CONDITIONAL_WITH_IF_ELSE', 77 'REPLACE_CONDITIONAL_WITH_IF_ELSE', 30,
91 30,
92 "Replace conditional with 'if-else'"); 78 "Replace conditional with 'if-else'");
93 static const REPLACE_IF_ELSE_WITH_CONDITIONAL = const AssistKind( 79 static const REPLACE_IF_ELSE_WITH_CONDITIONAL = const AssistKind(
94 'REPLACE_IF_ELSE_WITH_CONDITIONAL', 80 'REPLACE_IF_ELSE_WITH_CONDITIONAL', 30,
95 30,
96 "Replace 'if-else' with conditional ('c ? x : y')"); 81 "Replace 'if-else' with conditional ('c ? x : y')");
97 static const SPLIT_AND_CONDITION = 82 static const SPLIT_AND_CONDITION =
98 const AssistKind('SPLIT_AND_CONDITION', 30, "Split && condition"); 83 const AssistKind('SPLIT_AND_CONDITION', 30, "Split && condition");
99 static const SPLIT_VARIABLE_DECLARATION = const AssistKind( 84 static const SPLIT_VARIABLE_DECLARATION = const AssistKind(
100 'SPLIT_VARIABLE_DECLARATION', 85 'SPLIT_VARIABLE_DECLARATION', 30, "Split variable declaration");
101 30,
102 "Split variable declaration");
103 static const SURROUND_WITH_BLOCK = 86 static const SURROUND_WITH_BLOCK =
104 const AssistKind('SURROUND_WITH_BLOCK', 30, "Surround with block"); 87 const AssistKind('SURROUND_WITH_BLOCK', 30, "Surround with block");
105 static const SURROUND_WITH_DO_WHILE = 88 static const SURROUND_WITH_DO_WHILE = const AssistKind(
106 const AssistKind('SURROUND_WITH_DO_WHILE', 30, "Surround with 'do-while'") ; 89 'SURROUND_WITH_DO_WHILE', 30, "Surround with 'do-while'");
107 static const SURROUND_WITH_FOR = 90 static const SURROUND_WITH_FOR =
108 const AssistKind('SURROUND_WITH_FOR', 30, "Surround with 'for'"); 91 const AssistKind('SURROUND_WITH_FOR', 30, "Surround with 'for'");
109 static const SURROUND_WITH_FOR_IN = 92 static const SURROUND_WITH_FOR_IN =
110 const AssistKind('SURROUND_WITH_FOR_IN', 30, "Surround with 'for-in'"); 93 const AssistKind('SURROUND_WITH_FOR_IN', 30, "Surround with 'for-in'");
111 static const SURROUND_WITH_IF = 94 static const SURROUND_WITH_IF =
112 const AssistKind('SURROUND_WITH_IF', 30, "Surround with 'if'"); 95 const AssistKind('SURROUND_WITH_IF', 30, "Surround with 'if'");
113 static const SURROUND_WITH_TRY_CATCH = 96 static const SURROUND_WITH_TRY_CATCH = const AssistKind(
114 const AssistKind('SURROUND_WITH_TRY_CATCH', 30, "Surround with 'try-catch' "); 97 'SURROUND_WITH_TRY_CATCH', 30, "Surround with 'try-catch'");
115 static const SURROUND_WITH_TRY_FINALLY = const AssistKind( 98 static const SURROUND_WITH_TRY_FINALLY = const AssistKind(
116 'SURROUND_WITH_TRY_FINALLY', 99 'SURROUND_WITH_TRY_FINALLY', 30, "Surround with 'try-finally'");
117 30,
118 "Surround with 'try-finally'");
119 static const SURROUND_WITH_WHILE = 100 static const SURROUND_WITH_WHILE =
120 const AssistKind('SURROUND_WITH_WHILE', 30, "Surround with 'while'"); 101 const AssistKind('SURROUND_WITH_WHILE', 30, "Surround with 'while'");
121 102
122 final name; 103 final name;
123 final int relevance; 104 final int relevance;
124 final String message; 105 final String message;
125 106
126 const AssistKind(this.name, this.relevance, this.message); 107 const AssistKind(this.name, this.relevance, this.message);
127 108
128 @override 109 @override
129 String toString() => name; 110 String toString() => name;
130 } 111 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698