| 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 | 10 show |
| 11 RefactoringProblem, | 11 RefactoringProblem, |
| 12 RefactoringProblemSeverity, | 12 RefactoringProblemSeverity, |
| 13 SourceChange, | 13 SourceChange, |
| 14 SourceEdit, | 14 SourceEdit, |
| 15 SourceFileEdit; | 15 SourceFileEdit; |
| 16 import 'package:analysis_server/src/services/correction/status.dart'; | 16 import 'package:analysis_server/src/services/correction/status.dart'; |
| 17 import 'package:analysis_server/src/services/index/index.dart'; | 17 import 'package:analysis_server/src/services/index/index.dart'; |
| 18 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 18 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| 19 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 19 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; | 20 import 'package:analysis_server/src/services/search/search_engine_internal.dart'
; |
| 21 import 'package:analysis_server/src/services/search/search_engine_internal2.dart
'; |
| 20 import 'package:analyzer/dart/ast/ast.dart'; | 22 import 'package:analyzer/dart/ast/ast.dart'; |
| 21 import 'package:analyzer/dart/element/element.dart' show Element; | 23 import 'package:analyzer/dart/element/element.dart' show Element; |
| 22 import 'package:analyzer/file_system/file_system.dart'; | 24 import 'package:analyzer/file_system/file_system.dart'; |
| 23 import 'package:analyzer/src/generated/source.dart'; | 25 import 'package:analyzer/src/generated/source.dart'; |
| 24 import 'package:test/test.dart'; | 26 import 'package:test/test.dart'; |
| 25 | 27 |
| 26 import '../../abstract_single_unit.dart'; | 28 import '../../abstract_single_unit.dart'; |
| 27 | 29 |
| 28 int findIdentifierLength(String search) { | 30 int findIdentifierLength(String search) { |
| 29 int length = 0; | 31 int length = 0; |
| 30 while (length < search.length) { | 32 while (length < search.length) { |
| 31 int c = search.codeUnitAt(length); | 33 int c = search.codeUnitAt(length); |
| 32 if (!(c >= 'a'.codeUnitAt(0) && c <= 'z'.codeUnitAt(0) || | 34 if (!(c >= 'a'.codeUnitAt(0) && c <= 'z'.codeUnitAt(0) || |
| 33 c >= 'A'.codeUnitAt(0) && c <= 'Z'.codeUnitAt(0) || | 35 c >= 'A'.codeUnitAt(0) && c <= 'Z'.codeUnitAt(0) || |
| 34 c >= '0'.codeUnitAt(0) && c <= '9'.codeUnitAt(0))) { | 36 c >= '0'.codeUnitAt(0) && c <= '9'.codeUnitAt(0))) { |
| 35 break; | 37 break; |
| 36 } | 38 } |
| 37 length++; | 39 length++; |
| 38 } | 40 } |
| 39 return length; | 41 return length; |
| 40 } | 42 } |
| 41 | 43 |
| 42 /** | 44 /** |
| 43 * The base class for all [Refactoring] tests. | 45 * The base class for all [Refactoring] tests. |
| 44 */ | 46 */ |
| 45 abstract class RefactoringTest extends AbstractSingleUnitTest { | 47 abstract class RefactoringTest extends AbstractSingleUnitTest { |
| 46 Index index; | 48 Index index; |
| 47 SearchEngineImpl searchEngine; | 49 SearchEngine searchEngine; |
| 48 | 50 |
| 49 SourceChange refactoringChange; | 51 SourceChange refactoringChange; |
| 50 | 52 |
| 51 Refactoring get refactoring; | 53 Refactoring get refactoring; |
| 52 | 54 |
| 53 /** | 55 /** |
| 54 * Asserts that [refactoringChange] contains a [FileEdit] for the file | 56 * Asserts that [refactoringChange] contains a [FileEdit] for the file |
| 55 * with the given [path], and it results the [expectedCode]. | 57 * with the given [path], and it results the [expectedCode]. |
| 56 */ | 58 */ |
| 57 void assertFileChangeResult(String path, String expectedCode) { | 59 void assertFileChangeResult(String path, String expectedCode) { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 /** | 157 /** |
| 156 * Completes with a fully resolved unit that contains the [element]. | 158 * Completes with a fully resolved unit that contains the [element]. |
| 157 */ | 159 */ |
| 158 Future<CompilationUnit> getResolvedUnitWithElement(Element element) async { | 160 Future<CompilationUnit> getResolvedUnitWithElement(Element element) async { |
| 159 return element.context | 161 return element.context |
| 160 .resolveCompilationUnit(element.source, element.library); | 162 .resolveCompilationUnit(element.source, element.library); |
| 161 } | 163 } |
| 162 | 164 |
| 163 Future<Null> indexTestUnit(String code) async { | 165 Future<Null> indexTestUnit(String code) async { |
| 164 await resolveTestUnit(code); | 166 await resolveTestUnit(code); |
| 165 index.indexUnit(testUnit); | 167 if (!enableNewAnalysisDriver) { |
| 168 index.indexUnit(testUnit); |
| 169 } |
| 166 } | 170 } |
| 167 | 171 |
| 168 Future<Null> indexUnit(String file, String code) async { | 172 Future<Null> indexUnit(String file, String code) async { |
| 169 Source source = addSource(file, code); | 173 Source source = addSource(file, code); |
| 170 CompilationUnit unit = await resolveLibraryUnit(source); | 174 if (!enableNewAnalysisDriver) { |
| 171 index.indexUnit(unit); | 175 CompilationUnit unit = await resolveLibraryUnit(source); |
| 176 index.indexUnit(unit); |
| 177 } |
| 172 } | 178 } |
| 173 | 179 |
| 174 void setUp() { | 180 void setUp() { |
| 175 super.setUp(); | 181 super.setUp(); |
| 176 index = createMemoryIndex(); | 182 if (enableNewAnalysisDriver) { |
| 177 searchEngine = new SearchEngineImpl(index); | 183 searchEngine = new SearchEngineImpl2([driver]); |
| 184 } else { |
| 185 index = createMemoryIndex(); |
| 186 searchEngine = new SearchEngineImpl(index); |
| 187 } |
| 178 } | 188 } |
| 179 } | 189 } |
| OLD | NEW |