| 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 test.services.refactoring; | 5 library test.services.refactoring; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 9 import 'package:analysis_server/plugin/protocol/protocol.dart' |
| 10 show |
| 11 RefactoringProblem, |
| 12 RefactoringProblemSeverity, |
| 13 SourceChange, |
| 14 SourceEdit, |
| 15 SourceFileEdit; |
| 10 import 'package:analysis_server/src/services/correction/status.dart'; | 16 import 'package:analysis_server/src/services/correction/status.dart'; |
| 11 import 'package:analysis_server/src/services/index/index.dart'; | 17 import 'package:analysis_server/src/services/index/index.dart'; |
| 12 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 18 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| 13 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; | 19 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; |
| 14 import 'package:analyzer/dart/ast/ast.dart'; | 20 import 'package:analyzer/dart/ast/ast.dart'; |
| 21 import 'package:analyzer/dart/element/element.dart' show Element; |
| 15 import 'package:analyzer/file_system/file_system.dart'; | 22 import 'package:analyzer/file_system/file_system.dart'; |
| 16 import 'package:analyzer/src/generated/source.dart'; | 23 import 'package:analyzer/src/generated/source.dart'; |
| 17 import 'package:test/test.dart'; | 24 import 'package:test/test.dart'; |
| 18 | 25 |
| 19 import '../../abstract_single_unit.dart'; | 26 import '../../abstract_single_unit.dart'; |
| 20 | 27 |
| 21 int findIdentifierLength(String search) { | 28 int findIdentifierLength(String search) { |
| 22 int length = 0; | 29 int length = 0; |
| 23 while (length < search.length) { | 30 while (length < search.length) { |
| 24 int c = search.codeUnitAt(length); | 31 int c = search.codeUnitAt(length); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 */ | 145 */ |
| 139 void assertTestChangeResult(String expectedCode) { | 146 void assertTestChangeResult(String expectedCode) { |
| 140 // prepare FileEdit | 147 // prepare FileEdit |
| 141 SourceFileEdit fileEdit = refactoringChange.getFileEdit(testFile); | 148 SourceFileEdit fileEdit = refactoringChange.getFileEdit(testFile); |
| 142 expect(fileEdit, isNotNull); | 149 expect(fileEdit, isNotNull); |
| 143 // validate resulting code | 150 // validate resulting code |
| 144 String actualCode = SourceEdit.applySequence(testCode, fileEdit.edits); | 151 String actualCode = SourceEdit.applySequence(testCode, fileEdit.edits); |
| 145 expect(actualCode, expectedCode); | 152 expect(actualCode, expectedCode); |
| 146 } | 153 } |
| 147 | 154 |
| 155 /** |
| 156 * Completes with a fully resolved unit that contains the [element]. |
| 157 */ |
| 158 Future<CompilationUnit> getResolvedUnitWithElement(Element element) async { |
| 159 return element.context |
| 160 .resolveCompilationUnit(element.source, element.library); |
| 161 } |
| 162 |
| 148 void indexTestUnit(String code) { | 163 void indexTestUnit(String code) { |
| 149 resolveTestUnit(code); | 164 resolveTestUnit(code); |
| 150 index.indexUnit(testUnit); | 165 index.indexUnit(testUnit); |
| 151 } | 166 } |
| 152 | 167 |
| 153 void indexUnit(String file, String code) { | 168 void indexUnit(String file, String code) { |
| 154 Source source = addSource(file, code); | 169 Source source = addSource(file, code); |
| 155 CompilationUnit unit = resolveLibraryUnit(source); | 170 CompilationUnit unit = resolveLibraryUnit(source); |
| 156 index.indexUnit(unit); | 171 index.indexUnit(unit); |
| 157 } | 172 } |
| 158 | 173 |
| 159 void setUp() { | 174 void setUp() { |
| 160 super.setUp(); | 175 super.setUp(); |
| 161 index = createMemoryIndex(); | 176 index = createMemoryIndex(); |
| 162 searchEngine = new SearchEngineImpl(index); | 177 searchEngine = new SearchEngineImpl(index); |
| 163 } | 178 } |
| 164 } | 179 } |
| OLD | NEW |