| 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 protocol2; | 5 library protocol2; |
| 6 | 6 |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/computer/element.dart' show | 9 import 'package:analysis_server/src/computer/element.dart' show |
| 10 elementFromEngine; | 10 elementFromEngine; |
| 11 import 'package:analysis_server/src/services/correction/fix.dart' show Fix; |
| 11 import 'package:analysis_server/src/search/search_result.dart' show | 12 import 'package:analysis_server/src/search/search_result.dart' show |
| 12 searchResultFromMatch; | 13 searchResultFromMatch; |
| 13 import 'package:analysis_server/src/services/json.dart'; | 14 import 'package:analysis_server/src/services/json.dart'; |
| 14 import 'package:analysis_server/src/services/search/search_engine.dart' as | 15 import 'package:analysis_server/src/services/search/search_engine.dart' as |
| 15 engine; | 16 engine; |
| 16 import 'package:analyzer/src/generated/ast.dart' as engine; | 17 import 'package:analyzer/src/generated/ast.dart' as engine; |
| 17 import 'package:analyzer/src/generated/element.dart' as engine; | 18 import 'package:analyzer/src/generated/element.dart' as engine; |
| 18 import 'package:analyzer/src/generated/engine.dart' as engine; | 19 import 'package:analyzer/src/generated/engine.dart' as engine; |
| 19 import 'package:analyzer/src/generated/error.dart' as engine; | 20 import 'package:analyzer/src/generated/error.dart' as engine; |
| 20 import 'package:analyzer/src/generated/source.dart' as engine; | 21 import 'package:analyzer/src/generated/source.dart' as engine; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 void _addEditForSource(SourceFileEdit sourceFileEdit, SourceEdit sourceEdit) { | 56 void _addEditForSource(SourceFileEdit sourceFileEdit, SourceEdit sourceEdit) { |
| 56 List<SourceEdit> edits = sourceFileEdit.edits; | 57 List<SourceEdit> edits = sourceFileEdit.edits; |
| 57 int index = 0; | 58 int index = 0; |
| 58 while (index < edits.length && edits[index].offset > sourceEdit.offset) { | 59 while (index < edits.length && edits[index].offset > sourceEdit.offset) { |
| 59 index++; | 60 index++; |
| 60 } | 61 } |
| 61 edits.insert(index, sourceEdit); | 62 edits.insert(index, sourceEdit); |
| 62 } | 63 } |
| 63 | 64 |
| 64 /** | 65 /** |
| 66 * Adds [edit] to the [FileEdit] for the given [file]. |
| 67 */ |
| 68 void _addEditToSourceChange(SourceChange change, String file, SourceEdit edit) { |
| 69 SourceFileEdit fileEdit = change.getFileEdit(file); |
| 70 if (fileEdit == null) { |
| 71 fileEdit = new SourceFileEdit(file); |
| 72 change.addFileEdit(fileEdit); |
| 73 } |
| 74 fileEdit.add(edit); |
| 75 } |
| 76 |
| 77 /** |
| 78 * Returns the [FileEdit] for the given [file], maybe `null`. |
| 79 */ |
| 80 SourceFileEdit _getChangeFileEdit(SourceChange change, String file) { |
| 81 for (SourceFileEdit fileEdit in change.edits) { |
| 82 if (fileEdit.file == file) { |
| 83 return fileEdit; |
| 84 } |
| 85 } |
| 86 return null; |
| 87 } |
| 88 |
| 89 /** |
| 65 * Create an AnalysisError based on error information from the analyzer | 90 * Create an AnalysisError based on error information from the analyzer |
| 66 * engine. Access via AnalysisError.fromEngine(). | 91 * engine. Access via AnalysisError.fromEngine(). |
| 67 */ | 92 */ |
| 68 AnalysisError _analysisErrorFromEngine(engine.LineInfo lineInfo, | 93 AnalysisError _analysisErrorFromEngine(engine.LineInfo lineInfo, |
| 69 engine.AnalysisError error) { | 94 engine.AnalysisError error) { |
| 70 engine.ErrorCode errorCode = error.errorCode; | 95 engine.ErrorCode errorCode = error.errorCode; |
| 71 // prepare location | 96 // prepare location |
| 72 Location location; | 97 Location location; |
| 73 { | 98 { |
| 74 String file = error.source.fullName; | 99 String file = error.source.fullName; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 92 String correction = error.correction; | 117 String correction = error.correction; |
| 93 return new AnalysisError( | 118 return new AnalysisError( |
| 94 severity, | 119 severity, |
| 95 type, | 120 type, |
| 96 location, | 121 location, |
| 97 message, | 122 message, |
| 98 correction: correction); | 123 correction: correction); |
| 99 } | 124 } |
| 100 | 125 |
| 101 /** | 126 /** |
| 127 * Returns a list of AnalysisErrors correponding to the given list of Engine |
| 128 * errors. Access via AnalysisError.listFromEngine(). |
| 129 */ |
| 130 List<AnalysisError> _analysisErrorListFromEngine(engine.LineInfo lineInfo, |
| 131 List<engine.AnalysisError> errors) { |
| 132 return errors.map((engine.AnalysisError error) { |
| 133 return new AnalysisError.fromEngine(lineInfo, error); |
| 134 }).toList(); |
| 135 } |
| 136 |
| 137 /** |
| 102 * Get the result of applying the edit to the given [code]. Access via | 138 * Get the result of applying the edit to the given [code]. Access via |
| 103 * SourceEdit.apply(). | 139 * SourceEdit.apply(). |
| 104 */ | 140 */ |
| 105 String _applyEdit(String code, SourceEdit edit) { | 141 String _applyEdit(String code, SourceEdit edit) { |
| 106 return code.substring(0, edit.offset) + | 142 return code.substring(0, edit.offset) + |
| 107 edit.replacement + | 143 edit.replacement + |
| 108 code.substring(edit.end); | 144 code.substring(edit.end); |
| 109 } | 145 } |
| 110 | 146 |
| 111 /** | 147 /** |
| 112 * Get the result of applying a set of [edits] to the given [code]. Edits | 148 * Get the result of applying a set of [edits] to the given [code]. Edits |
| 113 * are applied in the order they appear in [edits]. Access via | 149 * are applied in the order they appear in [edits]. Access via |
| 114 * SourceEdit.applySequence(). | 150 * SourceEdit.applySequence(). |
| 115 */ | 151 */ |
| 116 String _applySequence(String code, Iterable<SourceEdit> edits) { | 152 String _applySequence(String code, Iterable<SourceEdit> edits) { |
| 117 edits.forEach((SourceEdit edit) { | 153 edits.forEach((SourceEdit edit) { |
| 118 code = edit.apply(code); | 154 code = edit.apply(code); |
| 119 }); | 155 }); |
| 120 return code; | 156 return code; |
| 121 } | 157 } |
| 122 | 158 |
| 123 /** | 159 /** |
| 160 * Map an element kind from the analyzer engine to a [CompletionSuggestionKind]. |
| 161 */ |
| 162 CompletionSuggestionKind _completionSuggestionKindFromElementKind(engine.Element
Kind kind) { |
| 163 // ElementKind.ANGULAR_FORMATTER, |
| 164 // ElementKind.ANGULAR_COMPONENT, |
| 165 // ElementKind.ANGULAR_CONTROLLER, |
| 166 // ElementKind.ANGULAR_DIRECTIVE, |
| 167 // ElementKind.ANGULAR_PROPERTY, |
| 168 // ElementKind.ANGULAR_SCOPE_PROPERTY, |
| 169 // ElementKind.ANGULAR_SELECTOR, |
| 170 // ElementKind.ANGULAR_VIEW, |
| 171 if (kind == engine.ElementKind.CLASS) return CompletionSuggestionKind.CLASS; |
| 172 // ElementKind.COMPILATION_UNIT, |
| 173 if (kind == engine.ElementKind.CONSTRUCTOR) return CompletionSuggestionKind.CO
NSTRUCTOR; |
| 174 // ElementKind.DYNAMIC, |
| 175 // ElementKind.EMBEDDED_HTML_SCRIPT, |
| 176 // ElementKind.ERROR, |
| 177 // ElementKind.EXPORT, |
| 178 // ElementKind.EXTERNAL_HTML_SCRIPT, |
| 179 if (kind == engine.ElementKind.FIELD) return CompletionSuggestionKind.FIELD; |
| 180 if (kind == engine.ElementKind.FUNCTION) return CompletionSuggestionKind.FUNCT
ION; |
| 181 if (kind == engine.ElementKind.FUNCTION_TYPE_ALIAS) return CompletionSuggestio
nKind.FUNCTION_TYPE_ALIAS; |
| 182 if (kind == engine.ElementKind.GETTER) return CompletionSuggestionKind.GETTER; |
| 183 // ElementKind.HTML, |
| 184 if (kind == engine.ElementKind.IMPORT) return CompletionSuggestionKind.IMPORT; |
| 185 // ElementKind.LABEL, |
| 186 // ElementKind.LIBRARY, |
| 187 if (kind == engine.ElementKind.LOCAL_VARIABLE) return CompletionSuggestionKind
.LOCAL_VARIABLE; |
| 188 if (kind == engine.ElementKind.METHOD) return CompletionSuggestionKind.METHOD; |
| 189 // ElementKind.NAME, |
| 190 if (kind == engine.ElementKind.PARAMETER) return CompletionSuggestionKind.PARA
METER; |
| 191 // ElementKind.POLYMER_ATTRIBUTE, |
| 192 // ElementKind.POLYMER_TAG_DART, |
| 193 // ElementKind.POLYMER_TAG_HTML, |
| 194 // ElementKind.PREFIX, |
| 195 if (kind == engine.ElementKind.SETTER) return CompletionSuggestionKind.SETTER; |
| 196 if (kind == engine.ElementKind.TOP_LEVEL_VARIABLE) return CompletionSuggestion
Kind.TOP_LEVEL_VARIABLE; |
| 197 // ElementKind.TYPE_PARAMETER, |
| 198 // ElementKind.UNIVERSE |
| 199 throw new ArgumentError('Unknown CompletionSuggestionKind for: $kind'); |
| 200 } |
| 201 |
| 202 /** |
| 124 * Create an ElementKind based on a value from the analyzer engine. Access | 203 * Create an ElementKind based on a value from the analyzer engine. Access |
| 125 * this function via new ElementKind.fromEngine(). | 204 * this function via new ElementKind.fromEngine(). |
| 126 */ | 205 */ |
| 127 ElementKind _elementKindFromEngine(engine.ElementKind kind) { | 206 ElementKind _elementKindFromEngine(engine.ElementKind kind) { |
| 128 if (kind == engine.ElementKind.CLASS) { | 207 if (kind == engine.ElementKind.CLASS) { |
| 129 return ElementKind.CLASS; | 208 return ElementKind.CLASS; |
| 130 } | 209 } |
| 131 if (kind == engine.ElementKind.COMPILATION_UNIT) { | 210 if (kind == engine.ElementKind.COMPILATION_UNIT) { |
| 132 return ElementKind.COMPILATION_UNIT; | 211 return ElementKind.COMPILATION_UNIT; |
| 133 } | 212 } |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); | 619 hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); |
| 541 hash = hash ^ (hash >> 11); | 620 hash = hash ^ (hash >> 11); |
| 542 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); | 621 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); |
| 543 } | 622 } |
| 544 | 623 |
| 545 static int hash2(a, b) => finish(combine(combine(0, a), b)); | 624 static int hash2(a, b) => finish(combine(combine(0, a), b)); |
| 546 | 625 |
| 547 static int hash4(a, b, c, d) => | 626 static int hash4(a, b, c, d) => |
| 548 finish(combine(combine(combine(combine(0, a), b), c), d)); | 627 finish(combine(combine(combine(combine(0, a), b), c), d)); |
| 549 } | 628 } |
| OLD | NEW |