| Index: pkg/analysis_server/lib/src/services/refactoring/rename.dart
|
| diff --git a/pkg/analysis_server/lib/src/services/refactoring/rename.dart b/pkg/analysis_server/lib/src/services/refactoring/rename.dart
|
| index bd975270c773e85aa48662ed8160af4e01639d15..a9bdb749b5d46b5294981b231ff2d06fadba6312 100644
|
| --- a/pkg/analysis_server/lib/src/services/refactoring/rename.dart
|
| +++ b/pkg/analysis_server/lib/src/services/refactoring/rename.dart
|
| @@ -17,6 +17,7 @@ import 'package:analyzer/src/generated/element.dart';
|
| import 'package:analyzer/src/generated/engine.dart';
|
| import 'package:analyzer/src/generated/java_core.dart';
|
| import 'package:analyzer/src/generated/source.dart';
|
| +import 'package:path/path.dart' as pathos;
|
|
|
| /**
|
| * Returns `true` if two given [Element]s are [LocalElement]s and have
|
| @@ -52,6 +53,18 @@ bool isDefinedInLibrary(
|
| return librarySourcesOfSource.contains(librarySourceOfElement);
|
| }
|
|
|
| +bool isElementInPubCache(Element element) {
|
| + Source source = element.source;
|
| + String path = source.fullName;
|
| + return isPathInPubCache(path);
|
| +}
|
| +
|
| +bool isElementInSdkOrPubCache(Element element) {
|
| + Source source = element.source;
|
| + String path = source.fullName;
|
| + return source.isInSystemLibrary || isPathInPubCache(path);
|
| +}
|
| +
|
| /**
|
| * Checks if the given [Element] is in the given [AnalysisContext].
|
| */
|
| @@ -59,6 +72,23 @@ bool isInContext(Element element, AnalysisContext context) {
|
| return element.context == context;
|
| }
|
|
|
| +bool isPathInPubCache(String path) {
|
| + List<String> parts = pathos.split(path);
|
| + if (parts.contains('.pub-cache')) {
|
| + return true;
|
| + }
|
| + for (int i = 0; i < parts.length - 1; i++) {
|
| + if (parts[i] == 'Pub' && parts[i + 1] == 'Cache') {
|
| + return true;
|
| + }
|
| + if (parts[i] == 'third_party' &&
|
| + (parts[i + 1] == 'pkg' || parts[i + 1] == 'pkg_tested')) {
|
| + return true;
|
| + }
|
| + }
|
| + return false;
|
| +}
|
| +
|
| /**
|
| * Checks if the given unqualified [SearchMatch] intersects with visibility
|
| * range of [localElement].
|
| @@ -145,6 +175,13 @@ abstract class RenameRefactoringImpl extends RefactoringImpl
|
| getElementQualifiedName(element));
|
| result.addFatalError(message);
|
| }
|
| + if (isElementInPubCache(element)) {
|
| + String message = format(
|
| + "The {0} '{1}' is defined in a pub package, so cannot be renamed.",
|
| + getElementKindName(element),
|
| + getElementQualifiedName(element));
|
| + result.addFatalError(message);
|
| + }
|
| return new Future.value(result);
|
| }
|
|
|
|
|