| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 analyzer.src.generated.bazel; | 5 library analyzer.src.generated.bazel; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:core'; | 8 import 'dart:core'; |
| 9 | 9 |
| 10 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 // If the path either starts with a slash or has no slash, it is invalid. | 66 // If the path either starts with a slash or has no slash, it is invalid. |
| 67 if (slash < 1) { | 67 if (slash < 1) { |
| 68 return null; | 68 return null; |
| 69 } | 69 } |
| 70 | 70 |
| 71 String packageName = uriPath.substring(0, slash); | 71 String packageName = uriPath.substring(0, slash); |
| 72 String fileUriPart = uriPath.substring(slash + 1); | 72 String fileUriPart = uriPath.substring(slash + 1); |
| 73 String filePath = fileUriPart.replaceAll('/', _context.separator); | 73 String filePath = fileUriPart.replaceAll('/', _context.separator); |
| 74 | 74 |
| 75 if (packageName.indexOf('.') == -1) { | 75 if (packageName.indexOf('.') == -1) { |
| 76 String path = | 76 String path = _context.join(_workspace.root, 'third_party', 'dart', |
| 77 _context.join('third_party', 'dart', packageName, 'lib', filePath); | 77 packageName, 'lib', filePath); |
| 78 File file = _workspace.getFile(path); | 78 File file = _workspace.findFile(path); |
| 79 return file?.createSource(uri); | 79 return file?.createSource(uri); |
| 80 } else { | 80 } else { |
| 81 String packagePath = packageName.replaceAll('.', _context.separator); | 81 String packagePath = packageName.replaceAll('.', _context.separator); |
| 82 String path = | 82 String path = |
| 83 _context.join(_workspace.root, packagePath, 'lib', filePath); | 83 _context.join(_workspace.root, packagePath, 'lib', filePath); |
| 84 File file = _workspace.findFile(path); | 84 File file = _workspace.findFile(path); |
| 85 return file?.createSource(uri); | 85 return file?.createSource(uri); |
| 86 } | 86 } |
| 87 }); | 87 }); |
| 88 } | 88 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 // Not generated, return the default one. | 159 // Not generated, return the default one. |
| 160 return provider.getFile(absolutePath); | 160 return provider.getFile(absolutePath); |
| 161 } catch (_) { | 161 } catch (_) { |
| 162 return null; | 162 return null; |
| 163 } | 163 } |
| 164 } | 164 } |
| 165 | 165 |
| 166 /** | 166 /** |
| 167 * Return the file for the given [pathInWorkspace]. The file is returned even | |
| 168 * if it does not exist. | |
| 169 */ | |
| 170 File getFile(String pathInWorkspace) { | |
| 171 return provider.getFile(provider.pathContext.join(root, pathInWorkspace)); | |
| 172 } | |
| 173 | |
| 174 /** | |
| 175 * Find the Bazel workspace that contains the given [path]. | 167 * Find the Bazel workspace that contains the given [path]. |
| 176 * | 168 * |
| 177 * Return `null` if a workspace markers, such as the `WORKSPACE` file, or | 169 * Return `null` if a workspace markers, such as the `WORKSPACE` file, or |
| 178 * the sibling `READONLY` folder cannot be found. | 170 * the sibling `READONLY` folder cannot be found. |
| 179 * | 171 * |
| 180 * Return `null` if the workspace does not have `bazel-genfiles` or | 172 * Return `null` if the workspace does not have `bazel-genfiles` or |
| 181 * `blaze-genfiles` folders, so we don't know where to search generated files. | 173 * `blaze-genfiles` folders, so we don't know where to search generated files. |
| 182 * | 174 * |
| 183 * Return `null` if there is a folder 'foo' with the sibling `READONLY` | 175 * Return `null` if there is a folder 'foo' with the sibling `READONLY` |
| 184 * folder, but there is corresponding folder 'foo' in `READONLY`, i.e. the | 176 * folder, but there is corresponding folder 'foo' in `READONLY`, i.e. the |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 Context context = provider.pathContext; | 240 Context context = provider.pathContext; |
| 249 if (provider.getFolder(context.join(root, 'blaze-genfiles')).exists) { | 241 if (provider.getFolder(context.join(root, 'blaze-genfiles')).exists) { |
| 250 return 'blaze'; | 242 return 'blaze'; |
| 251 } | 243 } |
| 252 if (provider.getFolder(context.join(root, 'bazel-genfiles')).exists) { | 244 if (provider.getFolder(context.join(root, 'bazel-genfiles')).exists) { |
| 253 return 'bazel'; | 245 return 'bazel'; |
| 254 } | 246 } |
| 255 return null; | 247 return null; |
| 256 } | 248 } |
| 257 } | 249 } |
| OLD | NEW |