From 671bb192ab12ebdfcd3b65cdb105e6ebee173a51 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Fri, 21 Oct 2022 17:03:29 +0000 Subject: [PATCH] Remove domain 'kythe' from DAS. Change-Id: I66f0e538dce6eead6ba1c98b9cf0e3d747450130 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/264895 Commit-Queue: Konstantin Shcheglov Reviewed-by: Brian Wilkerson --- pkg/analysis_server/doc/api.html | 80 +- .../lib/protocol/protocol.dart | 7 - .../lib/protocol/protocol_constants.dart | 4 - .../lib/protocol/protocol_generated.dart | 161 -- .../legacy/kythe_get_kythe_entries.dart | 73 - .../lib/src/legacy_analysis_server.dart | 3 - .../lib/src/plugin/result_merger.dart | 17 - .../src/services/kythe/kythe_visitors.dart | 1302 +---------------- .../test/integration/coverage.md | 3 - .../kythe/get_kythe_entries_test.dart | 38 - .../test/integration/kythe/test_all.dart | 13 - .../support/integration_test_methods.dart | 35 - .../support/protocol_matchers.dart | 55 - .../test/integration/test_all.dart | 2 - .../spec/generated/java/AnalysisServer.java | 14 - .../spec/generated/java/types/KytheEntry.java | 194 --- .../spec/generated/java/types/KytheVName.java | 192 --- .../java/types/RequestErrorCode.java | 6 - pkg/analysis_server/tool/spec/spec_input.html | 55 - .../lib/src/protocol/protocol_base.dart | 7 - .../lib/src/protocol/protocol_common.dart | 223 --- .../lib/src/protocol/protocol_constants.dart | 4 - .../lib/src/protocol/protocol_generated.dart | 161 -- pkg/analyzer_plugin/doc/api.html | 76 +- pkg/analyzer_plugin/doc/tutorial/kythe.md | 86 -- .../lib/plugin/kythe_mixin.dart | 56 - pkg/analyzer_plugin/lib/plugin/plugin.dart | 12 - .../lib/protocol/protocol_common.dart | 223 --- .../lib/protocol/protocol_constants.dart | 4 - .../lib/protocol/protocol_generated.dart | 152 -- .../lib/src/utilities/kythe/entries.dart | 37 - .../lib/utilities/kythe/entries.dart | 80 - .../support/integration_test_methods.dart | 30 - .../support/protocol_matchers.dart | 53 - .../test/plugin/kythe_mixin_test.dart | 92 -- pkg/analyzer_plugin/test/plugin/test_all.dart | 2 - .../tool/spec/common_types_spec.html | 87 -- .../tool/spec/plugin_spec.html | 42 - 38 files changed, 24 insertions(+), 3657 deletions(-) delete mode 100644 pkg/analysis_server/lib/src/handler/legacy/kythe_get_kythe_entries.dart delete mode 100644 pkg/analysis_server/test/integration/kythe/get_kythe_entries_test.dart delete mode 100644 pkg/analysis_server/test/integration/kythe/test_all.dart delete mode 100644 pkg/analysis_server/tool/spec/generated/java/types/KytheEntry.java delete mode 100644 pkg/analysis_server/tool/spec/generated/java/types/KytheVName.java delete mode 100644 pkg/analyzer_plugin/doc/tutorial/kythe.md delete mode 100644 pkg/analyzer_plugin/lib/plugin/kythe_mixin.dart delete mode 100644 pkg/analyzer_plugin/lib/src/utilities/kythe/entries.dart delete mode 100644 pkg/analyzer_plugin/lib/utilities/kythe/entries.dart delete mode 100644 pkg/analyzer_plugin/test/plugin/kythe_mixin_test.dart diff --git a/pkg/analysis_server/doc/api.html b/pkg/analysis_server/doc/api.html index ac30ecc4e40..e3dec08ec05 100644 --- a/pkg/analysis_server/doc/api.html +++ b/pkg/analysis_server/doc/api.html @@ -3139,7 +3139,6 @@ a:focus, a:hover {

The diagnostic server port.

-

flutter domain

The analysis domain contains API's related to Flutter support. @@ -4879,77 +4878,6 @@ a:focus, a:hover { import directives will use relative URIs, which are short, so we probably want to display such relative URIs to the user.

-
KytheEntry: object
-

- This object matches the format and documentation of the Entry object - documented in the - Kythe Storage - Model. -

- -
source: KytheVName
- -

- The ticket of the source node. -

-
kind: String (optional)
- -

- An edge label. The schema defines which labels are meaningful. -

-
target: KytheVName (optional)
- -

- The ticket of the target node. -

-
fact: String
- -

- A fact label. The schema defines which fact labels are meaningful. -

-
value: List<int> (optional)
- -

- The String value of the fact. -

-
KytheVName: object
-

- This object matches the format and documentation of the Vector-Name object - documented in the - Kythe - Storage Model. -

- -
signature: String
- -

- An opaque signature generated by the analyzer. -

-
corpus: String
- -

- The corpus of source code this KytheVName belongs to. - Loosely, a corpus is a collection of related files, such as the - contents of a given source repository. -

-
root: String
- -

- A corpus-specific root label, typically a directory path or project - identifier, denoting a distinct subset of the corpus. This may also be - used to designate virtual collections like generated files. -

-
path: String
- -

- A path-structured label describing the “location” of the named object - relative to the corpus and the root. -

-
language: String
- -

- The language this name belongs to. -

LibraryPathSet: object

A list of associations between paths and the libraries that should be @@ -5530,12 +5458,6 @@ a:focus, a:hover { An "analysis.getImportedElements" request specified a FilePath that does not match a file currently subject to analysis.

-
GET_KYTHE_ENTRIES_INVALID_FILE
- -

- An "analysis.getKytheEntries" request specified a FilePath that does - not match a file that is currently subject to analysis. -

GET_NAVIGATION_INVALID_FILE

@@ -6361,6 +6283,6 @@ a:focus, a:hover { TODO: TBD

Index

-

Domains

server ()

analysis ()

completion ()

search ()

edit ()

execution ()

diagnostic ()

flutter ()

Requests
Notifications

Types ()

Refactorings ()

+

Domains

server ()

analysis ()

completion ()

search ()

edit ()

execution ()

diagnostic ()

flutter ()

Requests
Notifications

Types ()

Refactorings ()

diff --git a/pkg/analysis_server/lib/protocol/protocol.dart b/pkg/analysis_server/lib/protocol/protocol.dart index 27ea0150142..d719acb3f0f 100644 --- a/pkg/analysis_server/lib/protocol/protocol.dart +++ b/pkg/analysis_server/lib/protocol/protocol.dart @@ -375,13 +375,6 @@ class Response { RequestErrorCode.GET_IMPORTED_ELEMENTS_INVALID_FILE, 'Error during `analysis.getImportedElements`: invalid file.')); - /// Initialize a newly created instance to represent the - /// GET_KYTHE_ENTRIES_INVALID_FILE error condition. - Response.getKytheEntriesInvalidFile(Request request) - : this(request.id, - error: RequestError(RequestErrorCode.GET_KYTHE_ENTRIES_INVALID_FILE, - 'Error during `analysis.getKytheEntries`: invalid file.')); - /// Initialize a newly created instance to represent the /// GET_NAVIGATION_INVALID_FILE error condition. Response.getNavigationInvalidFile(Request request) diff --git a/pkg/analysis_server/lib/protocol/protocol_constants.dart b/pkg/analysis_server/lib/protocol/protocol_constants.dart index 560ec40d3e9..3b76a6e1e83 100644 --- a/pkg/analysis_server/lib/protocol/protocol_constants.dart +++ b/pkg/analysis_server/lib/protocol/protocol_constants.dart @@ -313,10 +313,6 @@ const String FLUTTER_REQUEST_SET_WIDGET_PROPERTY_VALUE_ID = 'id'; const String FLUTTER_REQUEST_SET_WIDGET_PROPERTY_VALUE_VALUE = 'value'; const String FLUTTER_RESPONSE_GET_WIDGET_DESCRIPTION_PROPERTIES = 'properties'; const String FLUTTER_RESPONSE_SET_WIDGET_PROPERTY_VALUE_CHANGE = 'change'; -const String KYTHE_REQUEST_GET_KYTHE_ENTRIES = 'kythe.getKytheEntries'; -const String KYTHE_REQUEST_GET_KYTHE_ENTRIES_FILE = 'file'; -const String KYTHE_RESPONSE_GET_KYTHE_ENTRIES_ENTRIES = 'entries'; -const String KYTHE_RESPONSE_GET_KYTHE_ENTRIES_FILES = 'files'; const String SEARCH_NOTIFICATION_RESULTS = 'search.results'; const String SEARCH_NOTIFICATION_RESULTS_ID = 'id'; const String SEARCH_NOTIFICATION_RESULTS_IS_LAST = 'isLast'; diff --git a/pkg/analysis_server/lib/protocol/protocol_generated.dart b/pkg/analysis_server/lib/protocol/protocol_generated.dart index 889e138688a..e63a02cb680 100644 --- a/pkg/analysis_server/lib/protocol/protocol_generated.dart +++ b/pkg/analysis_server/lib/protocol/protocol_generated.dart @@ -12941,158 +12941,6 @@ class InlineMethodOptions extends RefactoringOptions { ); } -/// kythe.getKytheEntries params -/// -/// { -/// "file": FilePath -/// } -/// -/// Clients may not extend, implement or mix-in this class. -class KytheGetKytheEntriesParams implements RequestParams { - /// The file containing the code for which the Kythe Entry objects are being - /// requested. - String file; - - KytheGetKytheEntriesParams(this.file); - - factory KytheGetKytheEntriesParams.fromJson( - JsonDecoder jsonDecoder, String jsonPath, Object? json) { - json ??= {}; - if (json is Map) { - String file; - if (json.containsKey('file')) { - file = jsonDecoder.decodeString('$jsonPath.file', json['file']); - } else { - throw jsonDecoder.mismatch(jsonPath, 'file'); - } - return KytheGetKytheEntriesParams(file); - } else { - throw jsonDecoder.mismatch( - jsonPath, 'kythe.getKytheEntries params', json); - } - } - - factory KytheGetKytheEntriesParams.fromRequest(Request request) { - return KytheGetKytheEntriesParams.fromJson( - RequestDecoder(request), 'params', request.params); - } - - @override - Map toJson() { - var result = {}; - result['file'] = file; - return result; - } - - @override - Request toRequest(String id) { - return Request(id, 'kythe.getKytheEntries', toJson()); - } - - @override - String toString() => json.encode(toJson()); - - @override - bool operator ==(other) { - if (other is KytheGetKytheEntriesParams) { - return file == other.file; - } - return false; - } - - @override - int get hashCode => file.hashCode; -} - -/// kythe.getKytheEntries result -/// -/// { -/// "entries": List -/// "files": List -/// } -/// -/// Clients may not extend, implement or mix-in this class. -class KytheGetKytheEntriesResult implements ResponseResult { - /// The list of KytheEntry objects for the queried file. - List entries; - - /// The set of files paths that were required, but not in the file system, to - /// give a complete and accurate Kythe graph for the file. This could be due - /// to a referenced file that does not exist or generated files not being - /// generated or passed before the call to "getKytheEntries". - List files; - - KytheGetKytheEntriesResult(this.entries, this.files); - - factory KytheGetKytheEntriesResult.fromJson( - JsonDecoder jsonDecoder, String jsonPath, Object? json) { - json ??= {}; - if (json is Map) { - List entries; - if (json.containsKey('entries')) { - entries = jsonDecoder.decodeList( - '$jsonPath.entries', - json['entries'], - (String jsonPath, Object? json) => - KytheEntry.fromJson(jsonDecoder, jsonPath, json)); - } else { - throw jsonDecoder.mismatch(jsonPath, 'entries'); - } - List files; - if (json.containsKey('files')) { - files = jsonDecoder.decodeList( - '$jsonPath.files', json['files'], jsonDecoder.decodeString); - } else { - throw jsonDecoder.mismatch(jsonPath, 'files'); - } - return KytheGetKytheEntriesResult(entries, files); - } else { - throw jsonDecoder.mismatch( - jsonPath, 'kythe.getKytheEntries result', json); - } - } - - factory KytheGetKytheEntriesResult.fromResponse(Response response) { - return KytheGetKytheEntriesResult.fromJson( - ResponseDecoder(REQUEST_ID_REFACTORING_KINDS.remove(response.id)), - 'result', - response.result); - } - - @override - Map toJson() { - var result = {}; - result['entries'] = - entries.map((KytheEntry value) => value.toJson()).toList(); - result['files'] = files; - return result; - } - - @override - Response toResponse(String id) { - return Response(id, result: toJson()); - } - - @override - String toString() => json.encode(toJson()); - - @override - bool operator ==(other) { - if (other is KytheGetKytheEntriesResult) { - return listEqual( - entries, other.entries, (KytheEntry a, KytheEntry b) => a == b) && - listEqual(files, other.files, (String a, String b) => a == b); - } - return false; - } - - @override - int get hashCode => Object.hash( - Object.hashAll(entries), - Object.hashAll(files), - ); -} - /// LibraryPathSet /// /// { @@ -13866,7 +13714,6 @@ class RequestError implements HasToJson { /// GET_ERRORS_INVALID_FILE /// GET_FIXES_INVALID_FILE /// GET_IMPORTED_ELEMENTS_INVALID_FILE -/// GET_KYTHE_ENTRIES_INVALID_FILE /// GET_NAVIGATION_INVALID_FILE /// GET_REACHABLE_SOURCES_INVALID_FILE /// GET_SIGNATURE_INVALID_FILE @@ -13955,11 +13802,6 @@ class RequestErrorCode implements Enum { static const RequestErrorCode GET_IMPORTED_ELEMENTS_INVALID_FILE = RequestErrorCode._('GET_IMPORTED_ELEMENTS_INVALID_FILE'); - /// An "analysis.getKytheEntries" request specified a FilePath that does not - /// match a file that is currently subject to analysis. - static const RequestErrorCode GET_KYTHE_ENTRIES_INVALID_FILE = - RequestErrorCode._('GET_KYTHE_ENTRIES_INVALID_FILE'); - /// An "analysis.getNavigation" request specified a FilePath which does not /// match a file currently subject to analysis. static const RequestErrorCode GET_NAVIGATION_INVALID_FILE = @@ -14079,7 +13921,6 @@ class RequestErrorCode implements Enum { GET_ERRORS_INVALID_FILE, GET_FIXES_INVALID_FILE, GET_IMPORTED_ELEMENTS_INVALID_FILE, - GET_KYTHE_ENTRIES_INVALID_FILE, GET_NAVIGATION_INVALID_FILE, GET_REACHABLE_SOURCES_INVALID_FILE, GET_SIGNATURE_INVALID_FILE, @@ -14135,8 +13976,6 @@ class RequestErrorCode implements Enum { return GET_FIXES_INVALID_FILE; case 'GET_IMPORTED_ELEMENTS_INVALID_FILE': return GET_IMPORTED_ELEMENTS_INVALID_FILE; - case 'GET_KYTHE_ENTRIES_INVALID_FILE': - return GET_KYTHE_ENTRIES_INVALID_FILE; case 'GET_NAVIGATION_INVALID_FILE': return GET_NAVIGATION_INVALID_FILE; case 'GET_REACHABLE_SOURCES_INVALID_FILE': diff --git a/pkg/analysis_server/lib/src/handler/legacy/kythe_get_kythe_entries.dart b/pkg/analysis_server/lib/src/handler/legacy/kythe_get_kythe_entries.dart deleted file mode 100644 index 998f49e9713..00000000000 --- a/pkg/analysis_server/lib/src/handler/legacy/kythe_get_kythe_entries.dart +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:async'; - -import 'package:analysis_server/protocol/protocol.dart'; -import 'package:analysis_server/protocol/protocol_generated.dart'; -import 'package:analysis_server/src/handler/legacy/legacy_handler.dart'; -import 'package:analysis_server/src/legacy_analysis_server.dart'; -import 'package:analysis_server/src/plugin/result_merger.dart'; -import 'package:analysis_server/src/request_handler_mixin.dart'; -import 'package:analysis_server/src/services/kythe/kythe_visitors.dart'; -import 'package:analyzer/src/dart/element/inheritance_manager3.dart'; -import 'package:analyzer_plugin/protocol/protocol_common.dart'; -import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin; - -/// The handler for the `kythe.getKytheEntries` request. -class KytheGetKytheEntriesHandler extends LegacyHandler - with RequestHandlerMixin { - /// Initialize a newly created handler to be able to service requests for the - /// [server]. - KytheGetKytheEntriesHandler( - super.server, super.request, super.cancellationToken); - - @override - Future handle() async { - var file = KytheGetKytheEntriesParams.fromRequest(request).file; - var driver = server.getAnalysisDriver(file); - if (driver == null) { - sendResponse(Response.getKytheEntriesInvalidFile(request)); - } else { - // - // Allow plugins to start computing entries. - // - var requestParams = plugin.KytheGetKytheEntriesParams(file); - var pluginFutures = server.pluginManager.broadcastRequest( - requestParams, - contextRoot: driver.analysisContext!.contextRoot, - ); - // - // Compute entries generated by server. - // - var allResults = []; - var result = await server.getResolvedUnit(file); - if (result != null) { - var entries = []; - // TODO(brianwilkerson) Figure out how to get the list of files. - var files = []; - result.unit.accept(KytheDartVisitor(server.resourceProvider, entries, - file, InheritanceManager3(), result.content)); - allResults.add(KytheGetKytheEntriesResult(entries, files)); - } - // - // Add the entries produced by plugins to the server-generated entries. - // - var responses = await waitForResponses(pluginFutures, - requestParameters: requestParams); - for (var response in responses) { - var result = plugin.KytheGetKytheEntriesResult.fromResponse(response); - allResults - .add(KytheGetKytheEntriesResult(result.entries, result.files)); - } - // - // Return the result. - // - var merger = ResultMerger(); - var mergedResults = merger.mergeKytheEntries(allResults); - sendResult(KytheGetKytheEntriesResult( - mergedResults.entries, mergedResults.files)); - } - } -} diff --git a/pkg/analysis_server/lib/src/legacy_analysis_server.dart b/pkg/analysis_server/lib/src/legacy_analysis_server.dart index bbd92562e7f..6a0817cd2da 100644 --- a/pkg/analysis_server/lib/src/legacy_analysis_server.dart +++ b/pkg/analysis_server/lib/src/legacy_analysis_server.dart @@ -64,7 +64,6 @@ import 'package:analysis_server/src/handler/legacy/execution_set_subscriptions.d import 'package:analysis_server/src/handler/legacy/flutter_get_widget_description.dart'; import 'package:analysis_server/src/handler/legacy/flutter_set_subscriptions.dart'; import 'package:analysis_server/src/handler/legacy/flutter_set_widget_property_value.dart'; -import 'package:analysis_server/src/handler/legacy/kythe_get_kythe_entries.dart'; import 'package:analysis_server/src/handler/legacy/legacy_handler.dart'; import 'package:analysis_server/src/handler/legacy/search_find_element_references.dart'; import 'package:analysis_server/src/handler/legacy/search_find_member_declarations.dart'; @@ -235,8 +234,6 @@ class LegacyAnalysisServer extends AnalysisServer { FlutterSetWidgetPropertyValueHandler.new, FLUTTER_REQUEST_SET_SUBSCRIPTIONS: FlutterSetSubscriptionsHandler.new, // - KYTHE_REQUEST_GET_KYTHE_ENTRIES: KytheGetKytheEntriesHandler.new, - // SEARCH_REQUEST_FIND_ELEMENT_REFERENCES: SearchFindElementReferencesHandler.new, SEARCH_REQUEST_FIND_MEMBER_DECLARATIONS: diff --git a/pkg/analysis_server/lib/src/plugin/result_merger.dart b/pkg/analysis_server/lib/src/plugin/result_merger.dart index e8e51f3a6f4..aef7ec3a9c2 100644 --- a/pkg/analysis_server/lib/src/plugin/result_merger.dart +++ b/pkg/analysis_server/lib/src/plugin/result_merger.dart @@ -183,23 +183,6 @@ class ResultMerger { return mergedRegions; } - /// Return kythe entry result parameters composed by merging the parameters in - /// the [partialResultList]. - /// - /// The resulting list will contain all of the kythe entries from all of the - /// plugins. If a plugin contributes a kythe entry that is the same as the - /// entry from a different plugin, the entry will appear twice in the list. - KytheGetKytheEntriesResult mergeKytheEntries( - List partialResultList) { - var mergedEntries = []; - var mergedFiles = {}; - for (var partialResult in partialResultList) { - mergedEntries.addAll(partialResult.entries); - mergedFiles.addAll(partialResult.files); - } - return KytheGetKytheEntriesResult(mergedEntries, mergedFiles.toList()); - } - /// Return navigation notification parameters composed by merging the /// parameters in the [partialResultList]. /// diff --git a/pkg/analysis_server/lib/src/services/kythe/kythe_visitors.dart b/pkg/analysis_server/lib/src/services/kythe/kythe_visitors.dart index e437efe66da..0dc64cb5528 100644 --- a/pkg/analysis_server/lib/src/services/kythe/kythe_visitors.dart +++ b/pkg/analysis_server/lib/src/services/kythe/kythe_visitors.dart @@ -2,27 +2,14 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'dart:convert'; - -import 'package:analyzer/dart/ast/ast.dart'; -import 'package:analyzer/dart/ast/syntactic_entity.dart'; -import 'package:analyzer/dart/ast/token.dart'; -import 'package:analyzer/dart/ast/visitor.dart'; import 'package:analyzer/dart/element/element.dart'; -import 'package:analyzer/dart/element/type.dart'; import 'package:analyzer/dart/element/visitor.dart'; import 'package:analyzer/file_system/file_system.dart'; -import 'package:analyzer/src/dart/ast/extensions.dart'; -import 'package:analyzer/src/dart/element/inheritance_manager3.dart'; import 'package:analyzer/src/workspace/blaze.dart'; -import 'package:analyzer_plugin/protocol/protocol_common.dart' - show KytheEntry, KytheVName; import 'package:path/path.dart' show relative; import 'schema.dart' as schema; -const int _notFound = -1; - /// Given some [ConstructorElement], this method returns '' as the /// name of the constructor, unless the constructor is a named constructor in /// which '.' is returned. @@ -35,11 +22,6 @@ String _computeConstructorElementName(ConstructorElement element) { return name; } -/// Create an anchor signature of the form '-'. -String _getAnchorSignature(int start, int end) { - return '$start-$end'; -} - String? _getNodeKind(Element e) { if (e is FieldElement && e.isEnumConstant) { // FieldElement is a kind of VariableElement, so this test case must be @@ -95,7 +77,7 @@ String _getPath(ResourceProvider provider, Element? e, return path; } -/// If a non-null element is passed, the [SignatureElementVisitor] is used to +/// If a non-null element is passed, the [_SignatureElementVisitor] is used to /// generate and return a [String] signature, otherwise [schema.DYNAMIC_KIND] is /// returned. String _getSignature( @@ -109,7 +91,7 @@ String _getSignature( return _getPath(provider, element, sdkRootPath: sdkRootPath, corpus: corpus); } - return '$nodeKind:${element.accept(SignatureElementVisitor.instance)}'; + return '$nodeKind:${element.accept(_SignatureElementVisitor.instance)}'; } /// A helper class for getting the Kythe uri's for elements for querying @@ -128,1271 +110,28 @@ class CiderKytheHelper { return 'kythe://$corpus?lang=dart?path=${vname.path}#${vname.signature}'; } - /// Given all parameters for a [KytheVName] this method creates and returns a - /// [KytheVName]. - KytheVName _vName(String signature, String root, String path, - [String language = schema.DART_LANG]) { - return KytheVName(signature, corpus, root, path, language); - } - /// Given some [Element] and Kythe node kind, this method generates and - /// returns the [KytheVName]. - KytheVName _vNameFromElement(Element? e, String nodeKind) { + /// returns the [_KytheVName]. + _KytheVName _vNameFromElement(Element? e, String nodeKind) { assert(nodeKind != schema.FILE_KIND); // general case - return _vName( - _getSignature(resourceProvider, e, nodeKind, corpus, - sdkRootPath: sdkRootPath), - '', - _getPath(resourceProvider, e, - sdkRootPath: sdkRootPath, corpus: corpus)); + return _KytheVName( + path: _getPath(resourceProvider, e, + sdkRootPath: sdkRootPath, corpus: corpus), + signature: _getSignature(resourceProvider, e, nodeKind, corpus, + sdkRootPath: sdkRootPath), + ); } } -/// This visitor writes out Kythe facts and edges as specified by the Kythe -/// Schema here https://kythe.io/docs/schema/. This visitor handles all nodes, -/// facts and edges. -class KytheDartVisitor extends GeneralizingAstVisitor with OutputUtils { - @override - final ResourceProvider resourceProvider; - @override - final List entries; - @override - final String corpus; - final InheritanceManager3 _inheritanceManager; - final String _contents; - - late String _enclosingFilePath = ''; - Element? _enclosingElement; - InterfaceElement? _enclosingClassElement; - KytheVName? _enclosingVName; - KytheVName? _enclosingFileVName; - KytheVName? _enclosingClassVName; - - KytheDartVisitor(this.resourceProvider, this.entries, this.corpus, - this._inheritanceManager, this._contents); - - @override - String get enclosingFilePath => _enclosingFilePath; - - @override - void visitAnnotation(Annotation node) { - // TODO(jwren) To get the full set of cross refs correct, additional ref - // edges are needed, example: from "A" in "A.namedConstructor()" - - var start = node.name.offset; - var end = node.name.end; - - var constructorName = node.constructorName; - if (constructorName != null) { - end = constructorName.end; - } - - var refVName = _handleRefEdge( - node.element, - const [schema.REF_EDGE], - start: start, - end: end, - ); - if (refVName != null) { - var parentNode = node.parent; - if (parentNode is Declaration) { - var parentElement = parentNode.declaredElement; - if (parentNode is TopLevelVariableDeclaration) { - _handleVariableDeclarationListAnnotations( - parentNode.variables, refVName); - } else if (parentNode is FieldDeclaration) { - _handleVariableDeclarationListAnnotations( - parentNode.fields, refVName); - } else if (parentElement != null) { - var nodeKind = _getNodeKind(parentElement); - if (nodeKind != null) { - var parentVName = _vNameFromElement(parentElement, nodeKind); - addEdge(parentVName, schema.ANNOTATED_BY_EDGE, refVName); - } - } else { - // parentAstNode is not a variable declaration node and - // parentElement == null - assert(false); - } - } else { - // parentAstNode is not a Declaration - // TODO(jwren) investigate -// throw new Exception('parentAstNode.runtimeType = ${parentAstNode.runtimeType}'); -// assert(false); - } - } - - // visit children - _safelyVisit(node.arguments); - } - - @override - void visitAssignmentExpression(AssignmentExpression node) { - // - // operator - // NOTE: usage node only written out if assignment is not the '=' operator, - // we are looking for an operator such as +=, -=, *=, /= - // - var operator = node.operator; - var element = node.staticElement; - if (operator.type != TokenType.EQ && element != null) { - // method - _vNameFromElement(element, schema.FUNCTION_KIND); - - // anchor- ref/call - _handleRefCallEdge(element, - syntacticEntity: node.operator, enclosingTarget: _enclosingVName); - - // TODO (jwren) Add function type information - } - // visit children - _safelyVisit(node.leftHandSide); - _safelyVisit(node.rightHandSide); - } - - @override - void visitBinaryExpression(BinaryExpression node) { - // - // operators such as +, -, *, / - // - var element = node.staticElement; - if (element != null) { - // method - _vNameFromElement(element, schema.FUNCTION_KIND); - - // anchor- ref/call - _handleRefCallEdge(element, - syntacticEntity: node.operator, enclosingTarget: _enclosingVName); - - // TODO (jwren) Add function type information - } - // visit children - _safelyVisit(node.leftOperand); - _safelyVisit(node.rightOperand); - } - - @override - void visitClassDeclaration(ClassDeclaration node) { - return _withEnclosingElement(node.declaredElement!, () { - // record/ class node - addNodeAndFacts(schema.RECORD_KIND, - nodeVName: _enclosingClassVName, - subKind: schema.CLASS_SUBKIND, - completeFact: schema.DEFINITION); - - // anchor- defines/binding - addAnchorEdgesContainingEdge( - syntacticEntity: node.name, - edges: [ - schema.DEFINES_BINDING_EDGE, - ], - target: _enclosingClassVName, - enclosingTarget: _enclosingFileVName); - - // anchor- defines - addAnchorEdgesContainingEdge( - syntacticEntity: node, - edges: [ - schema.DEFINES_EDGE, - ], - target: _enclosingClassVName); - - // extends - var supertype = _enclosingClassElement!.supertype; - var supertypeElement = supertype?.element; - if (supertypeElement != null) { - var recordSupertypeVName = - _vNameFromElement(supertypeElement, schema.RECORD_KIND); - addEdge( - _enclosingClassVName!, schema.EXTENDS_EDGE, recordSupertypeVName); - } - - // implements - var interfaces = _enclosingClassElement!.interfaces; - for (var interface in interfaces) { - var recordInterfaceVName = - _vNameFromElement(interface.element, schema.RECORD_KIND); - addEdge( - _enclosingClassVName!, schema.EXTENDS_EDGE, recordInterfaceVName); - } - - // mixins - var mixins = _enclosingClassElement!.mixins; - for (var mixin in mixins) { - var recordMixinVName = - _vNameFromElement(mixin.element, schema.RECORD_KIND); - addEdge(_enclosingClassVName!, schema.EXTENDS_EDGE, recordMixinVName); - } - - // TODO (jwren) type parameters - - // visit children - _safelyVisit(node.documentationComment); - _safelyVisitList(node.metadata); - _safelyVisit(node.extendsClause); - _safelyVisit(node.implementsClause); - _safelyVisit(node.withClause); - _safelyVisit(node.nativeClause); - _safelyVisitList(node.members); - _safelyVisit(node.typeParameters); - }); - } - - @override - void visitClassTypeAlias(ClassTypeAlias node) { - return _withEnclosingElement(node.declaredElement!, () { - // record/ class node - addNodeAndFacts(schema.RECORD_KIND, - nodeVName: _enclosingClassVName, - subKind: schema.CLASS_SUBKIND, - completeFact: schema.DEFINITION); - - // anchor - addAnchorEdgesContainingEdge( - syntacticEntity: node.name, - edges: [ - schema.DEFINES_BINDING_EDGE, - ], - target: _enclosingClassVName, - enclosingTarget: _enclosingFileVName); - - // - // superclass - // The super type is not in an ExtendsClause (as is the case with - // ClassDeclarations) and super.visitClassTypeAlias is not sufficient. - // - _handleRefEdge( - node.superclass.name.staticElement, - const [schema.REF_EDGE], - syntacticEntity: node.superclass, - ); - // TODO(jwren) refactor the following lines into a method that can be used - // by visitClassDeclaration() - // extends - var recordSupertypeVName = _vNameFromElement( - node.superclass.name.staticElement, schema.RECORD_KIND); - addEdge(_enclosingClassVName!, schema.EXTENDS_EDGE, recordSupertypeVName); - - // implements - var interfaces = _enclosingClassElement!.interfaces; - for (var interface in interfaces) { - var recordInterfaceVName = - _vNameFromElement(interface.element, schema.RECORD_KIND); - addEdge( - _enclosingClassVName!, schema.EXTENDS_EDGE, recordInterfaceVName); - } - - // mixins - var mixins = _enclosingClassElement!.mixins; - for (var mixin in mixins) { - var recordMixinVName = - _vNameFromElement(mixin.element, schema.RECORD_KIND); - addEdge(_enclosingClassVName!, schema.EXTENDS_EDGE, recordMixinVName); - } - - // visit children - _safelyVisit(node.documentationComment); - _safelyVisitList(node.metadata); - _safelyVisit(node.typeParameters); - _safelyVisit(node.withClause); - _safelyVisit(node.implementsClause); - }); - } - - @override - void visitCompilationUnit(CompilationUnit node) { - var declaredElement = node.declaredElement!; - _enclosingFilePath = _getPath(resourceProvider, declaredElement); - return _withEnclosingElement(declaredElement, () { - addFact(_enclosingFileVName!, schema.NODE_KIND_FACT, - _encode(schema.FILE_KIND)); - addFact(_enclosingFileVName!, schema.TEXT_FACT, _encode(_contents)); - addFact(_enclosingFileVName!, schema.TEXT_ENCODING_FACT, - _encode(schema.DEFAULT_TEXT_ENCODING)); - - // handle LibraryDirective: - - // A "package" VName in Kythe, schema.PACKAGE_KIND, is a Dart "library". - - // Don't use visitLibraryDirective as this won't generate a package - // VName for libraries that don't have a library directive. - var libraryElement = declaredElement.library; - if (libraryElement.definingCompilationUnit == declaredElement) { - LibraryDirective? libraryDirective; - for (var directive in node.directives) { - if (directive is LibraryDirective) { - libraryDirective = directive; - break; - } - } - - final libraryName = libraryDirective?.name2; - final start = libraryName?.offset ?? 0; - final end = libraryName?.end ?? 0; - - // package node - var packageVName = addNodeAndFacts(schema.PACKAGE_KIND, - element: libraryElement, completeFact: schema.DEFINITION); - - // anchor - addAnchorEdgesContainingEdge( - start: start, - end: end, - edges: [ - schema.DEFINES_BINDING_EDGE, - ], - target: packageVName, - enclosingTarget: _enclosingFileVName); - } - - super.visitCompilationUnit(node); - }); - } - - @override - void visitConstructorDeclaration(ConstructorDeclaration node) { - var declaredElement = node.declaredElement!; - return _withEnclosingElement(declaredElement, () { - // function/ constructor node - var constructorVName = addNodeAndFacts(schema.FUNCTION_KIND, - element: declaredElement, - subKind: schema.CONSTRUCTOR_SUBKIND, - completeFact: schema.DEFINITION); - - // anchor - var start = node.returnType.offset; - var end = node.returnType.end; - var nameToken = node.name; - if (nameToken != null) { - end = nameToken.end; - } - addAnchorEdgesContainingEdge( - start: start, - end: end, - edges: [ - schema.DEFINES_BINDING_EDGE, - ], - target: constructorVName, - enclosingTarget: _enclosingClassVName); - - // function type - addFunctionType(declaredElement, node.parameters, constructorVName, - returnNode: node.returnType); - - // TODO(jwren) handle implicit constructor case - // TODO(jwren) handle redirected constructor case - - // visit children - _safelyVisit(node.documentationComment); - _safelyVisitList(node.metadata); - _safelyVisit(node.parameters); - _safelyVisitList(node.initializers); - _safelyVisit(node.body); - }); - } - - @override - void visitDeclaredIdentifier(DeclaredIdentifier node) { - var declaredElement = node.declaredElement!; - _handleVariableDeclaration(declaredElement, node.name, - subKind: schema.LOCAL_SUBKIND, type: declaredElement.type); - - // no children - } - - @override - void visitEnumConstantDeclaration(EnumConstantDeclaration node) { - // constant node - var constDeclVName = - addNodeAndFacts(schema.CONSTANT_KIND, element: node.declaredElement); - - // anchor- defines/binding, defines - addAnchorEdgesContainingEdge( - syntacticEntity: node.name, - edges: [ - schema.DEFINES_BINDING_EDGE, - schema.DEFINES_EDGE, - ], - target: constDeclVName, - enclosingTarget: _enclosingClassVName); - - // no children - } - - @override - void visitEnumDeclaration(EnumDeclaration node) { - return _withEnclosingElement(node.declaredElement!, () { - // record/ enum node - addNodeAndFacts(schema.RECORD_KIND, - nodeVName: _enclosingClassVName, - subKind: schema.ENUM_CLASS_SUBKIND, - completeFact: schema.DEFINITION); - - // anchor- defines/binding - addAnchorEdgesContainingEdge( - syntacticEntity: node.name, - edges: [ - schema.DEFINES_BINDING_EDGE, - ], - target: _enclosingClassVName, - enclosingTarget: _enclosingFileVName); - - // anchor- defines - addAnchorEdgesContainingEdge( - syntacticEntity: node, - edges: [ - schema.DEFINES_EDGE, - ], - target: _enclosingClassVName); - - // visit children - _safelyVisitList(node.constants); - }); - } - - @override - void visitExportDirective(ExportDirective node) { - _handleUriReference(node.uri, node.element?.exportedLibrary); - - super.visitExportDirective(node); - } - - @override - void visitFieldFormalParameter(FieldFormalParameter node) { - // identifier - // Specified as Element, not var, so that the type can be changed in the - // if-block. - Element? element = node.declaredElement; - if (element is FieldFormalParameterElement) { - element = element.field; - } - _handleRefEdge( - element, - const [schema.REF_EDGE], - syntacticEntity: node.name, - ); - - // visit children - _safelyVisit(node.documentationComment); - _safelyVisitList(node.metadata); - _safelyVisit(node.type); - _safelyVisit(node.typeParameters); - _safelyVisit(node.parameters); - } - - @override - void visitFunctionDeclaration(FunctionDeclaration node) { - var declaredElement = node.declaredElement!; - return _withEnclosingElement(declaredElement, () { - // function node - var functionVName = addNodeAndFacts(schema.FUNCTION_KIND, - element: declaredElement, completeFact: schema.DEFINITION); - - // anchor- defines/binding - addAnchorEdgesContainingEdge( - syntacticEntity: node.name, - edges: [ - schema.DEFINES_BINDING_EDGE, - ], - target: functionVName, - enclosingTarget: _enclosingFileVName); - - // anchor- defines - addAnchorEdgesContainingEdge( - syntacticEntity: node, - edges: [ - schema.DEFINES_EDGE, - ], - target: functionVName); - - // function type - addFunctionType( - declaredElement, node.functionExpression.parameters, functionVName, - returnNode: node.returnType); - - _safelyVisit(node.documentationComment); - _safelyVisitList(node.metadata); - _safelyVisit(node.returnType); - _safelyVisit(node.functionExpression); - }); - } - - @override - void visitFunctionExpression(FunctionExpression node) { - return _withEnclosingElement( - node.declaredElement!, () => super.visitFunctionExpression(node)); - } - - @override - void visitFunctionTypeAlias(FunctionTypeAlias node) { - // - // return type - // - var returnType = node.returnType; - if (returnType is NamedType) { - _handleRefEdge( - returnType.name.staticElement, - const [schema.REF_EDGE], - syntacticEntity: returnType.name, - ); - } else if (returnType is GenericFunctionType) { - // TODO(jwren): add support for generic function types. - throw UnimplementedError(); - } else if (returnType != null) { - throw StateError( - 'Unexpected TypeAnnotation subtype: ${returnType.runtimeType}'); - } - - // visit children - _safelyVisit(node.documentationComment); - _safelyVisitList(node.metadata); - _safelyVisit(node.typeParameters); - _safelyVisit(node.parameters); - } - - @override - void visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { - // TODO(jwren) Missing graph coverage on FunctionTypedFormalParameters - // visit children - _safelyVisit(node.documentationComment); - _safelyVisitList(node.metadata); - _safelyVisit(node.typeParameters); - _safelyVisit(node.parameters); - } - - @override - void visitImportDirective(ImportDirective node) { - _handleUriReference(node.uri, node.element?.importedLibrary); - - // prefix - var prefixIdentifier = node.prefix; - - if (prefixIdentifier != null) { - // variable - _handleVariableDeclaration( - prefixIdentifier.staticElement, prefixIdentifier); - } - - // visit children - _safelyVisit(node.documentationComment); - _safelyVisitList(node.metadata); - _safelyVisitList(node.combinators); - _safelyVisitList(node.configurations); - _safelyVisit(node.uri); - } - - @override - void visitIndexExpression(IndexExpression node) { - // - // index method ref/call - // - var element = node.staticElement; - var start = node.leftBracket.offset; - var end = node.rightBracket.end; - - // anchor- ref/call - _handleRefCallEdge(element, - start: start, end: end, enclosingTarget: _enclosingVName); - - // visit children - _safelyVisit(node.target); - _safelyVisit(node.index); - } - - @override - void visitInstanceCreationExpression(InstanceCreationExpression node) { - // - // constructorName - // - var constructorName = node.constructorName; - var constructorElement = constructorName.staticElement; - if (constructorElement != null) { - // anchor- ref/call - _handleRefCallEdge(constructorElement, - syntacticEntity: constructorName, enclosingTarget: _enclosingVName); - - // Now write out a ref edge from the same anchor (constructorName) to the - // enclosing class of the called constructor, this will make the - // invocation of a constructor discoverable when someone inquires about - // references to the class. - // - // We can't call _handleRefEdge as the anchor node has already been - // written out. - var enclosingEltVName = _vNameFromElement( - constructorElement.enclosingElement, schema.RECORD_KIND); - var anchorVName = - _vNameAnchor(constructorName.offset, constructorName.end); - addEdge(anchorVName, schema.REF_EDGE, enclosingEltVName); - - // TODO(jwren): investigate - // assert (element.enclosingElement3 != null); - } - // visit children - _safelyVisitList(constructorName.type.typeArguments?.arguments); - _safelyVisit(node.argumentList); - } - - @override - void visitMethodDeclaration(MethodDeclaration node) { - var declaredElement = node.declaredElement!; - return _withEnclosingElement(declaredElement, () { - // function node - var methodVName = addNodeAndFacts(schema.FUNCTION_KIND, - element: declaredElement, completeFact: schema.DEFINITION); - - // anchor- defines/binding - addAnchorEdgesContainingEdge( - syntacticEntity: node.name, - edges: [ - schema.DEFINES_BINDING_EDGE, - ], - target: methodVName, - enclosingTarget: _enclosingClassVName); - - // anchor- defines - addAnchorEdgesContainingEdge( - syntacticEntity: node, - edges: [ - schema.DEFINES_EDGE, - ], - target: methodVName); - - // function type - addFunctionType(declaredElement, node.parameters, methodVName, - returnNode: node.returnType); - - // override edges - var overriddenList = _inheritanceManager.getOverridden2( - _enclosingClassElement!, - Name( - _enclosingClassElement!.library.source.uri, - declaredElement.name, - ), - ); - if (overriddenList != null) { - for (var overridden in overriddenList) { - addEdge( - methodVName, - schema.OVERRIDES_EDGE, - _vNameFromElement(overridden, schema.FUNCTION_KIND), - ); - } - } - - // visit children - _safelyVisit(node.documentationComment); - _safelyVisitList(node.metadata); - _safelyVisit(node.returnType); - _safelyVisit(node.typeParameters); - _safelyVisit(node.parameters); - _safelyVisit(node.body); - }); - } - - @override - void visitMethodInvocation(MethodInvocation node) { - var element = node.methodName.staticElement; - - // anchor- ref/call - _handleRefCallEdge(element, syntacticEntity: node.methodName); - - // visit children - _safelyVisit(node.target); - _safelyVisit(node.typeArguments); - _safelyVisit(node.argumentList); - } - - @override - void visitSimpleFormalParameter(SimpleFormalParameter node) { - // parameter node - var declaredElement = node.declaredElement!; - var paramVName = addNodeAndFacts(schema.VARIABLE_KIND, - element: declaredElement, - subKind: schema.LOCAL_PARAMETER_SUBKIND, - completeFact: schema.DEFINITION); - - // node.identifier can be null in cases with the new generic function type - // syntax - // TODO(jwren) add test cases for this situation - var identifier = node.name; - if (identifier != null) { - // The anchor and anchor edges generation are broken into two cases, the - // first case is "method(parameter_name) ...", where the parameter - // character range only includes a parameter name. The second case is for - // parameter declarations which are prefixed with a type, 'var', or - // 'dynamic', as in "method(var parameter_name) ...". - // - // With the first case a single anchor range is created, for the second - // case an anchor is created on parameter_name, as well as the range - // including any prefixes. - if (node.offset == identifier.offset && - node.length == identifier.length) { - // anchor- defines/binding, defines - addAnchorEdgesContainingEdge( - syntacticEntity: identifier, - edges: [ - schema.DEFINES_BINDING_EDGE, - schema.DEFINES_EDGE, - ], - target: paramVName, - enclosingTarget: _enclosingVName); - } else { - // anchor- defines/binding - addAnchorEdgesContainingEdge( - syntacticEntity: identifier, - edges: [ - schema.DEFINES_BINDING_EDGE, - ], - target: paramVName, - enclosingTarget: _enclosingVName); - - // anchor- defines - addAnchorEdgesContainingEdge( - syntacticEntity: node, - edges: [ - schema.DEFINES_EDGE, - ], - target: paramVName); - } - } - - // type - addEdge( - paramVName, schema.TYPED_EDGE, _vNameFromType(declaredElement.type)); - - // visit children - _safelyVisit(node.documentationComment); - _safelyVisitList(node.metadata); - _safelyVisit(node.type); - } - - @override - void visitSimpleIdentifier(SimpleIdentifier node) { - // Most simple identifiers are "ref" edges. In cases some cases, there may - // be other ref/* edges. - - if (node.thisOrAncestorOfType() != null) { - // The identifier is in a comment, add just the "ref" edge. - _handleRefEdge( - node.staticElement, - const [schema.REF_EDGE], - syntacticEntity: node, - ); - } else if (node.inDeclarationContext()) { - // The node is in a declaration context, and should have - // "ref/defines/binding" edge as well as the default "ref" edge. - _handleRefEdge( - node.staticElement, - const [schema.DEFINES_BINDING_EDGE, schema.REF_EDGE], - syntacticEntity: node, - ); - } else { - _handleRefCallEdge(node.staticElement, syntacticEntity: node); - } - - // no children to visit - } - - @override - void visitSuperExpression(SuperExpression node) { - _handleThisOrSuper(node); - } - - @override - void visitThisExpression(ThisExpression node) { - _handleThisOrSuper(node); - } - - @override - void visitVariableDeclaration(VariableDeclaration node) { - var isLocal = _enclosingVName != _enclosingClassVName && - _enclosingVName != _enclosingFileVName; - - // variable - var declaredElement = node.declaredElement!; - _handleVariableDeclaration(declaredElement, node.name, - subKind: isLocal ? schema.LOCAL_SUBKIND : schema.FIELD_SUBKIND, - type: declaredElement.type); - - // visit children - _safelyVisit(node.initializer); - } - - Element? _findNonSyntheticElement(Element? element) { - if (element == null || !element.isSynthetic) { - return element; - } - if (element is PropertyAccessorElement) { - if (!element.variable.isSynthetic) { - return element.variable; - } - - var correspondingGetter = element.correspondingGetter; - if (correspondingGetter != null && !correspondingGetter.isSynthetic) { - return correspondingGetter; - } - - var correspondingSetter = element.correspondingSetter; - if (correspondingSetter != null && !correspondingSetter.isSynthetic) { - return correspondingSetter; - } - } - return null; - } - - void _handleRefCallEdge( - Element? element, { - SyntacticEntity? syntacticEntity, - int start = _notFound, - int end = _notFound, - KytheVName? enclosingTarget, - }) { - if (element is ExecutableElement && - _enclosingVName != _enclosingFileVName) { - _handleRefEdge( - element, - const [schema.REF_CALL_EDGE, schema.REF_EDGE], - syntacticEntity: syntacticEntity, - start: start, - end: end, - enclosingTarget: enclosingTarget, - enclosingAnchor: _enclosingVName, - ); - } else { - _handleRefEdge( - element, - const [schema.REF_EDGE], - syntacticEntity: syntacticEntity, - start: start, - end: end, - enclosingTarget: enclosingTarget, - ); - } - } - - /// This is a convenience method for adding ref edges. If the [start] and - /// [end] offsets are provided, they are used, otherwise the offsets are - /// computed by using the [syntacticEntity]. The list of edges is assumed to - /// be non-empty, and are added from the anchor to the target generated using - /// the passed [Element]. The created [KytheVName] is returned, if not `null` - /// is returned. - KytheVName? _handleRefEdge( - Element? element, - List refEdgeTypes, { - SyntacticEntity? syntacticEntity, - int start = _notFound, - int end = _notFound, - KytheVName? enclosingTarget, - KytheVName? enclosingAnchor, - }) { - assert(refEdgeTypes.isNotEmpty); - element = _findNonSyntheticElement(element); - if (element == null) { - return null; - } - - // vname - var nodeKind = _getNodeKind(element); - if (nodeKind == null || nodeKind.isEmpty) { - return null; - } - var vName = _vNameFromElement(element, nodeKind); - - // anchor - addAnchorEdgesContainingEdge( - start: start, - end: end, - syntacticEntity: syntacticEntity, - edges: refEdgeTypes, - target: vName, - enclosingTarget: enclosingTarget, - enclosingAnchor: enclosingAnchor, - ); - - return vName; - } - - void _handleThisOrSuper(Expression thisOrSuperNode) { - var type = thisOrSuperNode.staticType; - if (type is InterfaceType) { - // Expected SuperExpression.staticType to return the type of the - // supertype, but it returns the type of the enclosing class (same as - // ThisExpression), do some additional work to correct assumption: - if (thisOrSuperNode is SuperExpression && type.element is ClassElement) { - var supertype = (type.element as ClassElement).supertype; - if (supertype != null) { - type = supertype; - } - } - // vname - var vName = _vNameFromElement(type.element, schema.RECORD_KIND); - - // anchor - var anchorVName = addAnchorEdgesContainingEdge( - syntacticEntity: thisOrSuperNode, - edges: [schema.REF_EDGE], - target: vName); - - // childof from the anchor - addEdge(anchorVName, schema.CHILD_OF_EDGE, _enclosingVName!); - } - - // no children to visit - } - - /// Add a "ref/imports" edge from the passed [uriNode] location to the - /// [referencedElement] [Element]. If the passed element is null, the edge is - /// not written out. - void _handleUriReference(StringLiteral uriNode, Element? referencedElement) { - if (referencedElement != null) { - var start = uriNode.offset; - var end = uriNode.end; - - // The following is the expected and common case. - // The contents between the quotes is used as the location to work well - // with CodeSearch. - if (uriNode is SimpleStringLiteral) { - start = uriNode.contentsOffset; - end = uriNode.contentsEnd; - } - - // package node - var packageVName = - _vNameFromElement(referencedElement, schema.PACKAGE_KIND); - - // anchor - addAnchorEdgesContainingEdge( - start: start, - end: end, - edges: [schema.REF_IMPORTS_EDGE], - target: packageVName, - enclosingTarget: _enclosingFileVName); - } - } - - void _handleVariableDeclaration( - Element? element, SyntacticEntity syntacticEntity, - {String? subKind, DartType? type}) { - // variable - var variableVName = addNodeAndFacts(schema.VARIABLE_KIND, - element: element, subKind: subKind, completeFact: schema.DEFINITION); - - // anchor - addAnchorEdgesContainingEdge( - syntacticEntity: syntacticEntity, - edges: [ - schema.DEFINES_BINDING_EDGE, - ], - target: variableVName, - enclosingTarget: _enclosingVName); - - // type - if (type != null) { - addEdge(variableVName, schema.TYPED_EDGE, _vNameFromType(type)); - } - } - - void _handleVariableDeclarationListAnnotations( - VariableDeclarationList variableDeclarationList, KytheVName refVName) { - for (var varDecl in variableDeclarationList.variables) { - if (varDecl.declaredElement != null) { - var parentVName = - _vNameFromElement(varDecl.declaredElement, schema.VARIABLE_KIND); - addEdge(parentVName, schema.ANNOTATED_BY_EDGE, refVName); - } else { - // The element out of the VarDeclarationList is null - assert(false); - } - } - } - - /// If the given [node] is not `null`, accept this visitor. - void _safelyVisit(AstNode? node) { - if (node != null) { - node.accept(this); - } - } - - /// If the given [nodeList] is not `null`, accept this visitor. - void _safelyVisitList(NodeList? nodeList) { - if (nodeList != null) { - nodeList.accept(this); - } - } - - void _withEnclosingElement(Element element, Function() f) { - var outerEnclosingElement = _enclosingElement; - var outerEnclosingClassElement = _enclosingClassElement; - var outerEnclosingVName = _enclosingVName; - var outerEnclosingClassVName = _enclosingClassVName; - try { - _enclosingElement = element; - if (element is CompilationUnitElement) { - _enclosingFileVName = _enclosingVName = _vNameFile(); - } else if (element is InterfaceElement) { - _enclosingClassElement = element; - _enclosingClassVName = _enclosingVName = - _vNameFromElement(_enclosingClassElement, schema.RECORD_KIND); - } else if (element is MethodElement || - element is FunctionElement || - element is ConstructorElement) { - _enclosingVName = - _vNameFromElement(_enclosingElement, schema.FUNCTION_KIND); - } - f(); - } finally { - _enclosingElement = outerEnclosingElement; - _enclosingClassElement = outerEnclosingClassElement; - _enclosingClassVName = outerEnclosingClassVName; - _enclosingVName = outerEnclosingVName; - } - } -} - -/// This class is meant to be a mixin to concrete visitor methods to walk the -/// [Element] or [AstNode]s produced by the Dart Analyzer to output Kythe -/// [KytheEntry] protos. -mixin OutputUtils { - /// A set of [String]s which have already had a name [KytheVName] created. - final Set nameNodes = {}; - - String get corpus; - - KytheVName get dynamicBuiltin => _vName(schema.DYNAMIC_KIND, '', '', ''); - - String get enclosingFilePath; - - List get entries; - - KytheVName get fnBuiltin => _vName(schema.FN_BUILTIN, '', '', ''); - - ResourceProvider get resourceProvider; - - KytheVName get voidBuiltin => _vName(schema.VOID_BUILTIN, '', '', ''); - - /// This is a convenience method for adding anchors. If the [start] and [end] - /// offsets are provided, they are used, otherwise the offsets are computed by - /// using the [syntacticEntity]. If a non-empty list of edges is provided, as - /// well as a target, then this method also adds the edges from the anchor to - /// target. The anchor [KytheVName] is returned. - /// - /// If a [target] and [enclosingTarget] are provided, a childof edge is - /// written out from the target to the enclosing target. - /// - /// If an [enclosingAnchor] is provided a childof edge is written out from the - /// anchor to the enclosing anchor. In cases where ref/call is an edge, this - /// is required to generate the callgraph. - /// - /// Finally, for all anchors, a childof edge with a target of the enclosing - /// file is written out. - KytheVName addAnchorEdgesContainingEdge({ - SyntacticEntity? syntacticEntity, - int start = _notFound, - int end = _notFound, - List edges = const [], - KytheVName? target, - KytheVName? enclosingTarget, - KytheVName? enclosingAnchor, - }) { - if (start == _notFound && end == _notFound) { - if (syntacticEntity != null) { - start = syntacticEntity.offset; - end = syntacticEntity.end; - } else { - throw Exception('Offset positions were not provided when calling ' - 'addAnchorEdgesContainingEdge'); - } - } - // TODO(jwren) investigate -// assert(start < end); - var anchorVName = _vNameAnchor(start, end); - addFact(anchorVName, schema.NODE_KIND_FACT, _encode(schema.ANCHOR_KIND)); - addFact(anchorVName, schema.ANCHOR_START_FACT, _encodeInt(start)); - addFact(anchorVName, schema.ANCHOR_END_FACT, _encodeInt(end)); - if (target != null) { - for (var edge in edges) { - addEdge(anchorVName, edge, target); - } - if (enclosingTarget != null) { - addEdge(target, schema.CHILD_OF_EDGE, enclosingTarget); - } - } - // If provided, write out the childof edge to the enclosing anchor - if (enclosingAnchor != null) { - addEdge(anchorVName, schema.CHILD_OF_EDGE, enclosingAnchor); - } - - // Assert that if ref/call is one of the edges, that and enclosing anchor - // was provided for the callgraph. - // Documentation at http://kythe.io/docs/schema/callgraph.html - if (edges.contains(schema.REF_CALL_EDGE)) { - assert(enclosingAnchor != null); - } - - // Finally add the childof edge to the enclosing file VName. - addEdge(anchorVName, schema.CHILD_OF_EDGE, _vNameFile()); - return anchorVName; - } - - /// TODO(jwren): for cases where the target is a name, we need the same kind - /// of logic as [addNameFact] to prevent the edge from being written out. - /// This is a convenience method for visitors to add an edge Entry. - KytheEntry addEdge(KytheVName source, String edgeKind, KytheVName target, - {int ordinalIntValue = _notFound}) { - if (ordinalIntValue == _notFound) { - return addEntry(source, edgeKind, target, '/', []); - } else { - return addEntry(source, edgeKind, target, schema.ORDINAL, - _encodeInt(ordinalIntValue)); - } - } - - KytheEntry addEntry(KytheVName source, String? edgeKind, KytheVName? target, - String factName, List factValue) { - // factValue may be an empty array, the fact may be that a file text or - // document text is empty - if (edgeKind == null || edgeKind.isEmpty) { - edgeKind = null; - target = null; - } - var entry = KytheEntry(source, factName, - kind: edgeKind, target: target, value: factValue); - entries.add(entry); - return entry; - } - - /// This is a convenience method for visitors to add a fact [KytheEntry]. - KytheEntry addFact(KytheVName source, String factName, List factValue) { - return addEntry(source, null, null, factName, factValue); - } - - /// This is a convenience method for adding function types. - KytheVName addFunctionType( - Element functionElement, - FormalParameterList? paramNodes, - KytheVName functionVName, { - AstNode? returnNode, - }) { - var i = 0; - var funcTypeVName = - addNodeAndFacts(schema.TAPP_KIND, element: functionElement); - addEdge(funcTypeVName, schema.PARAM_EDGE, fnBuiltin, ordinalIntValue: i++); - - KytheVName? returnTypeVName; - if (returnNode is NamedType) { - // MethodDeclaration and FunctionDeclaration both return a TypeName from - // returnType - if (returnNode.typeOrThrow.isVoid) { - returnTypeVName = voidBuiltin; - } else { - returnTypeVName = - _vNameFromElement(returnNode.name.staticElement, schema.TAPP_KIND); - } - } else if (returnNode is Identifier) { - // ConstructorDeclaration returns an Identifier from returnType - if (returnNode.typeOrThrow.isVoid) { - returnTypeVName = voidBuiltin; - } else { - returnTypeVName = - _vNameFromElement(returnNode.staticElement, schema.TAPP_KIND); - } - } - // else: return type is null, void, unresolved. - - if (returnTypeVName != null) { - addEdge(funcTypeVName, schema.PARAM_EDGE, returnTypeVName, - ordinalIntValue: i++); - } - - if (paramNodes != null) { - for (var paramNode in paramNodes.parameters) { - var paramTypeVName = dynamicBuiltin; - var declaredElement = paramNode.declaredElement!; - var type = declaredElement.type; - if (type is InterfaceType) { - paramTypeVName = _vNameFromElement(type.element, schema.TAPP_KIND); - } - addEdge(funcTypeVName, schema.PARAM_EDGE, paramTypeVName, - ordinalIntValue: i++); - } - } - addEdge(functionVName, schema.TYPED_EDGE, funcTypeVName); - return funcTypeVName; - } - - /// This is a convenience method for adding nodes with facts. - /// If an [KytheVName] is passed, it is used, otherwise an element is required - /// which is used to create a [KytheVName]. Either [nodeVName] must be non-null or - /// [element] must be non-null. Other optional parameters if passed are then - /// used to set the associated facts on the [KytheVName]. This method does not - /// currently guarantee that the inputs to these fact kinds are valid for the - /// associated nodeKind- if a non-null, then it will set. - KytheVName addNodeAndFacts(String nodeKind, - {Element? element, - KytheVName? nodeVName, - String? subKind, - String? completeFact}) { - nodeVName ??= _vNameFromElement(element, nodeKind); - addFact(nodeVName, schema.NODE_KIND_FACT, _encode(nodeKind)); - if (subKind != null) { - addFact(nodeVName, schema.SUBKIND_FACT, _encode(subKind)); - } - if (completeFact != null) { - addFact(nodeVName, schema.COMPLETE_FACT, _encode(completeFact)); - } - return nodeVName; - } - - List _encode(String str) { - return utf8.encode(str); - } - - List _encodeInt(int i) { - return utf8.encode(i.toString()); - } - - /// Given all parameters for a [KytheVName] this method creates and returns a - /// [KytheVName]. - KytheVName _vName(String signature, String corpus, String root, String path, - [String language = schema.DART_LANG]) { - return KytheVName(signature, corpus, root, path, language); - } - - /// Returns an anchor [KytheVName] corresponding to the given start and end - /// offsets. - KytheVName _vNameAnchor(int start, int end) { - return _vName( - _getAnchorSignature(start, end), corpus, '', enclosingFilePath); - } - - /// Return the [KytheVName] for this file. - KytheVName _vNameFile() { - // file vnames, the signature and language are not set - return _vName('', corpus, '', enclosingFilePath, ''); - } - - /// Given some [Element] and Kythe node kind, this method generates and - /// returns the [KytheVName]. - KytheVName _vNameFromElement(Element? e, String nodeKind) { - assert(nodeKind != schema.FILE_KIND); - // general case - return _vName(_getSignature(resourceProvider, e, nodeKind, corpus), corpus, - '', _getPath(resourceProvider, e)); - } - - /// Returns a [KytheVName] corresponding to the given [DartType]. - KytheVName _vNameFromType(DartType? type) { - if (type == null || type.isDynamic) { - return dynamicBuiltin; - } else if (type.isVoid) { - return voidBuiltin; - } else if (type is InterfaceType) { - return _vNameFromElement(type.element, schema.RECORD_KIND); - } else { - return dynamicBuiltin; - } - } +class _KytheVName { + final String path; + final String signature; + + _KytheVName({ + required this.path, + required this.signature, + }); } /// This visitor class should be used by [_getSignature]. @@ -1400,8 +139,9 @@ mixin OutputUtils { /// This visitor is an [GeneralizingElementVisitor] which builds up a [String] /// signature for a given [Element], uniqueness is guaranteed within the /// enclosing file. -class SignatureElementVisitor extends GeneralizingElementVisitor { - static SignatureElementVisitor instance = SignatureElementVisitor(); +class _SignatureElementVisitor + extends GeneralizingElementVisitor { + static _SignatureElementVisitor instance = _SignatureElementVisitor(); @override StringBuffer visitCompilationUnitElement(CompilationUnitElement element) { diff --git a/pkg/analysis_server/test/integration/coverage.md b/pkg/analysis_server/test/integration/coverage.md index c8b21e4e33a..5bb8866e866 100644 --- a/pkg/analysis_server/test/integration/coverage.md +++ b/pkg/analysis_server/test/integration/coverage.md @@ -93,9 +93,6 @@ server calls. This file is validated by `coverage_test.dart`. - [x] analytics.sendEvent - [x] analytics.sendTiming -## kythe domain -- [x] kythe.getKytheEntries - ## flutter domain - [ ] flutter.getChangeAddForDesignTimeConstructor - [ ] flutter.setSubscriptions diff --git a/pkg/analysis_server/test/integration/kythe/get_kythe_entries_test.dart b/pkg/analysis_server/test/integration/kythe/get_kythe_entries_test.dart deleted file mode 100644 index c16ed78f4d3..00000000000 --- a/pkg/analysis_server/test/integration/kythe/get_kythe_entries_test.dart +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:analyzer/src/util/file_paths.dart' as file_paths; -import 'package:test/test.dart'; -import 'package:test_reflective_loader/test_reflective_loader.dart'; - -import '../support/integration_tests.dart'; - -void main() { - defineReflectiveSuite(() { - defineReflectiveTests(GetKytheEntriesTest); - }); -} - -@reflectiveTest -class GetKytheEntriesTest extends AbstractAnalysisServerIntegrationTest { - Future test_getKytheEntries() async { - writeFile(sourcePath(file_paths.blazeWorkspaceMarker), ''); - var pathname = sourcePath('pkg/test.dart'); - var text = r''' -class Foo {} - -class Bar { - Foo foo; -} -'''; - writeFile(pathname, text); - await standardAnalysisSetup(); - - await analysisFinished; - - var result = await sendKytheGetKytheEntries(pathname); - expect(result.entries, isNotEmpty); - expect(result.files, isEmpty); - } -} diff --git a/pkg/analysis_server/test/integration/kythe/test_all.dart b/pkg/analysis_server/test/integration/kythe/test_all.dart deleted file mode 100644 index c50b940d801..00000000000 --- a/pkg/analysis_server/test/integration/kythe/test_all.dart +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:test_reflective_loader/test_reflective_loader.dart'; - -import 'get_kythe_entries_test.dart' as get_kythe_entries_test; - -void main() { - defineReflectiveSuite(() { - get_kythe_entries_test.main(); - }, name: 'kythe'); -} diff --git a/pkg/analysis_server/test/integration/support/integration_test_methods.dart b/pkg/analysis_server/test/integration/support/integration_test_methods.dart index 250ed36a017..1e6d434b8ff 100644 --- a/pkg/analysis_server/test/integration/support/integration_test_methods.dart +++ b/pkg/analysis_server/test/integration/support/integration_test_methods.dart @@ -2469,41 +2469,6 @@ abstract class IntegrationTestMixin { return null; } - /// Return the list of KytheEntry objects for some file, given the current - /// state of the file system populated by "analysis.updateContent". - /// - /// If a request is made for a file that does not exist, or that is not - /// currently subject to analysis (e.g. because it is not associated with any - /// analysis root specified to analysis.setAnalysisRoots), an error of type - /// GET_KYTHE_ENTRIES_INVALID_FILE will be generated. - /// - /// Parameters - /// - /// file: FilePath - /// - /// The file containing the code for which the Kythe Entry objects are - /// being requested. - /// - /// Returns - /// - /// entries: List - /// - /// The list of KytheEntry objects for the queried file. - /// - /// files: List - /// - /// The set of files paths that were required, but not in the file system, - /// to give a complete and accurate Kythe graph for the file. This could be - /// due to a referenced file that does not exist or generated files not - /// being generated or passed before the call to "getKytheEntries". - Future sendKytheGetKytheEntries( - String file) async { - var params = KytheGetKytheEntriesParams(file).toJson(); - var result = await server.send('kythe.getKytheEntries', params); - var decoder = ResponseDecoder(null); - return KytheGetKytheEntriesResult.fromJson(decoder, 'result', result); - } - /// Return the description of the widget instance at the given location. /// /// If the location does not have a support widget, an error of type diff --git a/pkg/analysis_server/test/integration/support/protocol_matchers.dart b/pkg/analysis_server/test/integration/support/protocol_matchers.dart index 6e6bfd485bb..81fb80280dd 100644 --- a/pkg/analysis_server/test/integration/support/protocol_matchers.dart +++ b/pkg/analysis_server/test/integration/support/protocol_matchers.dart @@ -1055,41 +1055,6 @@ final Matcher isIncludedSuggestionSet = LazyMatcher(() => MatchesJsonObject( 'IncludedSuggestionSet', {'id': isInt, 'relevance': isInt}, optionalFields: {'displayUri': isString})); -/// KytheEntry -/// -/// { -/// "source": KytheVName -/// "kind": optional String -/// "target": optional KytheVName -/// "fact": String -/// "value": optional List -/// } -final Matcher isKytheEntry = LazyMatcher(() => MatchesJsonObject('KytheEntry', { - 'source': isKytheVName, - 'fact': isString - }, optionalFields: { - 'kind': isString, - 'target': isKytheVName, - 'value': isListOf(isInt) - })); - -/// KytheVName -/// -/// { -/// "signature": String -/// "corpus": String -/// "root": String -/// "path": String -/// "language": String -/// } -final Matcher isKytheVName = LazyMatcher(() => MatchesJsonObject('KytheVName', { - 'signature': isString, - 'corpus': isString, - 'root': isString, - 'path': isString, - 'language': isString - })); - /// LibraryPathSet /// /// { @@ -1430,7 +1395,6 @@ final Matcher isRequestError = LazyMatcher(() => MatchesJsonObject( /// GET_ERRORS_INVALID_FILE /// GET_FIXES_INVALID_FILE /// GET_IMPORTED_ELEMENTS_INVALID_FILE -/// GET_KYTHE_ENTRIES_INVALID_FILE /// GET_NAVIGATION_INVALID_FILE /// GET_REACHABLE_SOURCES_INVALID_FILE /// GET_SIGNATURE_INVALID_FILE @@ -1466,7 +1430,6 @@ final Matcher isRequestErrorCode = MatchesEnum('RequestErrorCode', [ 'GET_ERRORS_INVALID_FILE', 'GET_FIXES_INVALID_FILE', 'GET_IMPORTED_ELEMENTS_INVALID_FILE', - 'GET_KYTHE_ENTRIES_INVALID_FILE', 'GET_NAVIGATION_INVALID_FILE', 'GET_REACHABLE_SOURCES_INVALID_FILE', 'GET_SIGNATURE_INVALID_FILE', @@ -2884,24 +2847,6 @@ final Matcher isInlineMethodFeedback = LazyMatcher(() => MatchesJsonObject( final Matcher isInlineMethodOptions = LazyMatcher(() => MatchesJsonObject( 'inlineMethod options', {'deleteSource': isBool, 'inlineAll': isBool})); -/// kythe.getKytheEntries params -/// -/// { -/// "file": FilePath -/// } -final Matcher isKytheGetKytheEntriesParams = LazyMatcher(() => - MatchesJsonObject('kythe.getKytheEntries params', {'file': isFilePath})); - -/// kythe.getKytheEntries result -/// -/// { -/// "entries": List -/// "files": List -/// } -final Matcher isKytheGetKytheEntriesResult = LazyMatcher(() => - MatchesJsonObject('kythe.getKytheEntries result', - {'entries': isListOf(isKytheEntry), 'files': isListOf(isFilePath)})); - /// moveFile feedback final Matcher isMoveFileFeedback = isNull; diff --git a/pkg/analysis_server/test/integration/test_all.dart b/pkg/analysis_server/test/integration/test_all.dart index 9ef661b80e0..0581afe600b 100644 --- a/pkg/analysis_server/test/integration/test_all.dart +++ b/pkg/analysis_server/test/integration/test_all.dart @@ -11,7 +11,6 @@ import 'coverage_test.dart' as coverage_test; import 'diagnostic/test_all.dart' as diagnostic; import 'edit/test_all.dart' as edit; import 'execution/test_all.dart' as execution; -import 'kythe/test_all.dart' as kythe; import 'linter/test_all.dart' as linter; import 'lsp_server/test_all.dart' as lsp_server; import 'search/test_all.dart' as search; @@ -26,7 +25,6 @@ void main() { diagnostic.main(); edit.main(); execution.main(); - kythe.main(); linter.main(); lsp_server.main(); search.main(); diff --git a/pkg/analysis_server/tool/spec/generated/java/AnalysisServer.java b/pkg/analysis_server/tool/spec/generated/java/AnalysisServer.java index 4f7e7722dcf..5788b871dc4 100644 --- a/pkg/analysis_server/tool/spec/generated/java/AnalysisServer.java +++ b/pkg/analysis_server/tool/spec/generated/java/AnalysisServer.java @@ -881,20 +881,6 @@ public interface AnalysisServer { */ public boolean isSocketOpen(); - /** - * {@code kythe.getKytheEntries} - * - * Return the list of KytheEntry objects for some file, given the current state of the file system - * populated by "analysis.updateContent". - * - * If a request is made for a file that does not exist, or that is not currently subject to - * analysis (e.g. because it is not associated with any analysis root specified to - * analysis.setAnalysisRoots), an error of type GET_KYTHE_ENTRIES_INVALID_FILE will be generated. - * - * @param file The file containing the code for which the Kythe Entry objects are being requested. - */ - public void kythe_getKytheEntries(String file, GetKytheEntriesConsumer consumer); - /** * Remove the given listener from the list of listeners that will receive notification when new * analysis results become available. diff --git a/pkg/analysis_server/tool/spec/generated/java/types/KytheEntry.java b/pkg/analysis_server/tool/spec/generated/java/types/KytheEntry.java deleted file mode 100644 index 9efb62a228b..00000000000 --- a/pkg/analysis_server/tool/spec/generated/java/types/KytheEntry.java +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file - * for details. All rights reserved. Use of this source code is governed by a - * BSD-style license that can be found in the LICENSE file. - * - * This file has been automatically generated. Please do not edit it manually. - * To regenerate the file, use the script "pkg/analysis_server/tool/spec/generate_files". - */ -package org.dartlang.analysis.server.protocol; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import com.google.common.collect.Lists; -import com.google.dart.server.utilities.general.JsonUtilities; -import com.google.dart.server.utilities.general.ObjectUtilities; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import java.util.ArrayList; -import java.util.Iterator; -import org.apache.commons.lang3.StringUtils; - -/** - * This object matches the format and documentation of the Entry object documented in the Kythe - * Storage Model. - * - * @coverage dart.server.generated.types - */ -@SuppressWarnings("unused") -public class KytheEntry { - - public static final KytheEntry[] EMPTY_ARRAY = new KytheEntry[0]; - - public static final List EMPTY_LIST = Lists.newArrayList(); - - /** - * The ticket of the source node. - */ - private final KytheVName source; - - /** - * An edge label. The schema defines which labels are meaningful. - */ - private final String kind; - - /** - * The ticket of the target node. - */ - private final KytheVName target; - - /** - * A fact label. The schema defines which fact labels are meaningful. - */ - private final String fact; - - /** - * The String value of the fact. - */ - private final int[] value; - - /** - * Constructor for {@link KytheEntry}. - */ - public KytheEntry(KytheVName source, String kind, KytheVName target, String fact, int[] value) { - this.source = source; - this.kind = kind; - this.target = target; - this.fact = fact; - this.value = value; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof KytheEntry) { - KytheEntry other = (KytheEntry) obj; - return - ObjectUtilities.equals(other.source, source) && - ObjectUtilities.equals(other.kind, kind) && - ObjectUtilities.equals(other.target, target) && - ObjectUtilities.equals(other.fact, fact) && - Arrays.equals(other.value, value); - } - return false; - } - - public static KytheEntry fromJson(JsonObject jsonObject) { - KytheVName source = KytheVName.fromJson(jsonObject.get("source").getAsJsonObject()); - String kind = jsonObject.get("kind") == null ? null : jsonObject.get("kind").getAsString(); - KytheVName target = jsonObject.get("target") == null ? null : KytheVName.fromJson(jsonObject.get("target").getAsJsonObject()); - String fact = jsonObject.get("fact").getAsString(); - int[] value = jsonObject.get("value") == null ? null : JsonUtilities.decodeIntArray(jsonObject.get("value").getAsJsonArray()); - return new KytheEntry(source, kind, target, fact, value); - } - - public static List fromJsonArray(JsonArray jsonArray) { - if (jsonArray == null) { - return EMPTY_LIST; - } - ArrayList list = new ArrayList(jsonArray.size()); - Iterator iterator = jsonArray.iterator(); - while (iterator.hasNext()) { - list.add(fromJson(iterator.next().getAsJsonObject())); - } - return list; - } - - /** - * A fact label. The schema defines which fact labels are meaningful. - */ - public String getFact() { - return fact; - } - - /** - * An edge label. The schema defines which labels are meaningful. - */ - public String getKind() { - return kind; - } - - /** - * The ticket of the source node. - */ - public KytheVName getSource() { - return source; - } - - /** - * The ticket of the target node. - */ - public KytheVName getTarget() { - return target; - } - - /** - * The String value of the fact. - */ - public int[] getValue() { - return value; - } - - @Override - public int hashCode() { - HashCodeBuilder builder = new HashCodeBuilder(); - builder.append(source); - builder.append(kind); - builder.append(target); - builder.append(fact); - builder.append(value); - return builder.toHashCode(); - } - - public JsonObject toJson() { - JsonObject jsonObject = new JsonObject(); - jsonObject.add("source", source.toJson()); - if (kind != null) { - jsonObject.addProperty("kind", kind); - } - if (target != null) { - jsonObject.add("target", target.toJson()); - } - jsonObject.addProperty("fact", fact); - if (value != null) { - JsonArray jsonArrayValue = new JsonArray(); - for (int elt : value) { - jsonArrayValue.add(new JsonPrimitive(elt)); - } - jsonObject.add("value", jsonArrayValue); - } - return jsonObject; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("["); - builder.append("source="); - builder.append(source + ", "); - builder.append("kind="); - builder.append(kind + ", "); - builder.append("target="); - builder.append(target + ", "); - builder.append("fact="); - builder.append(fact + ", "); - builder.append("value="); - builder.append(StringUtils.join(value, ", ")); - builder.append("]"); - return builder.toString(); - } - -} diff --git a/pkg/analysis_server/tool/spec/generated/java/types/KytheVName.java b/pkg/analysis_server/tool/spec/generated/java/types/KytheVName.java deleted file mode 100644 index eeda6472f2c..00000000000 --- a/pkg/analysis_server/tool/spec/generated/java/types/KytheVName.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file - * for details. All rights reserved. Use of this source code is governed by a - * BSD-style license that can be found in the LICENSE file. - * - * This file has been automatically generated. Please do not edit it manually. - * To regenerate the file, use the script "pkg/analysis_server/tool/spec/generate_files". - */ -package org.dartlang.analysis.server.protocol; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import com.google.common.collect.Lists; -import com.google.dart.server.utilities.general.JsonUtilities; -import com.google.dart.server.utilities.general.ObjectUtilities; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonPrimitive; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import java.util.ArrayList; -import java.util.Iterator; -import org.apache.commons.lang3.StringUtils; - -/** - * This object matches the format and documentation of the Vector-Name object documented in the - * Kythe Storage Model. - * - * @coverage dart.server.generated.types - */ -@SuppressWarnings("unused") -public class KytheVName { - - public static final KytheVName[] EMPTY_ARRAY = new KytheVName[0]; - - public static final List EMPTY_LIST = Lists.newArrayList(); - - /** - * An opaque signature generated by the analyzer. - */ - private final String signature; - - /** - * The corpus of source code this KytheVName belongs to. Loosely, a corpus is a collection of - * related files, such as the contents of a given source repository. - */ - private final String corpus; - - /** - * A corpus-specific root label, typically a directory path or project identifier, denoting a - * distinct subset of the corpus. This may also be used to designate virtual collections like - * generated files. - */ - private final String root; - - /** - * A path-structured label describing the “location” of the named object relative to the corpus and - * the root. - */ - private final String path; - - /** - * The language this name belongs to. - */ - private final String language; - - /** - * Constructor for {@link KytheVName}. - */ - public KytheVName(String signature, String corpus, String root, String path, String language) { - this.signature = signature; - this.corpus = corpus; - this.root = root; - this.path = path; - this.language = language; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof KytheVName) { - KytheVName other = (KytheVName) obj; - return - ObjectUtilities.equals(other.signature, signature) && - ObjectUtilities.equals(other.corpus, corpus) && - ObjectUtilities.equals(other.root, root) && - ObjectUtilities.equals(other.path, path) && - ObjectUtilities.equals(other.language, language); - } - return false; - } - - public static KytheVName fromJson(JsonObject jsonObject) { - String signature = jsonObject.get("signature").getAsString(); - String corpus = jsonObject.get("corpus").getAsString(); - String root = jsonObject.get("root").getAsString(); - String path = jsonObject.get("path").getAsString(); - String language = jsonObject.get("language").getAsString(); - return new KytheVName(signature, corpus, root, path, language); - } - - public static List fromJsonArray(JsonArray jsonArray) { - if (jsonArray == null) { - return EMPTY_LIST; - } - ArrayList list = new ArrayList(jsonArray.size()); - Iterator iterator = jsonArray.iterator(); - while (iterator.hasNext()) { - list.add(fromJson(iterator.next().getAsJsonObject())); - } - return list; - } - - /** - * The corpus of source code this KytheVName belongs to. Loosely, a corpus is a collection of - * related files, such as the contents of a given source repository. - */ - public String getCorpus() { - return corpus; - } - - /** - * The language this name belongs to. - */ - public String getLanguage() { - return language; - } - - /** - * A path-structured label describing the “location” of the named object relative to the corpus and - * the root. - */ - public String getPath() { - return path; - } - - /** - * A corpus-specific root label, typically a directory path or project identifier, denoting a - * distinct subset of the corpus. This may also be used to designate virtual collections like - * generated files. - */ - public String getRoot() { - return root; - } - - /** - * An opaque signature generated by the analyzer. - */ - public String getSignature() { - return signature; - } - - @Override - public int hashCode() { - HashCodeBuilder builder = new HashCodeBuilder(); - builder.append(signature); - builder.append(corpus); - builder.append(root); - builder.append(path); - builder.append(language); - return builder.toHashCode(); - } - - public JsonObject toJson() { - JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty("signature", signature); - jsonObject.addProperty("corpus", corpus); - jsonObject.addProperty("root", root); - jsonObject.addProperty("path", path); - jsonObject.addProperty("language", language); - return jsonObject; - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("["); - builder.append("signature="); - builder.append(signature + ", "); - builder.append("corpus="); - builder.append(corpus + ", "); - builder.append("root="); - builder.append(root + ", "); - builder.append("path="); - builder.append(path + ", "); - builder.append("language="); - builder.append(language); - builder.append("]"); - return builder.toString(); - } - -} diff --git a/pkg/analysis_server/tool/spec/generated/java/types/RequestErrorCode.java b/pkg/analysis_server/tool/spec/generated/java/types/RequestErrorCode.java index 66c62101018..41bc4e75729 100644 --- a/pkg/analysis_server/tool/spec/generated/java/types/RequestErrorCode.java +++ b/pkg/analysis_server/tool/spec/generated/java/types/RequestErrorCode.java @@ -88,12 +88,6 @@ public class RequestErrorCode { */ public static final String GET_IMPORTED_ELEMENTS_INVALID_FILE = "GET_IMPORTED_ELEMENTS_INVALID_FILE"; - /** - * An "analysis.getKytheEntries" request specified a FilePath that does not match a file that is - * currently subject to analysis. - */ - public static final String GET_KYTHE_ENTRIES_INVALID_FILE = "GET_KYTHE_ENTRIES_INVALID_FILE"; - /** * An "analysis.getNavigation" request specified a FilePath which does not match a file currently * subject to analysis. diff --git a/pkg/analysis_server/tool/spec/spec_input.html b/pkg/analysis_server/tool/spec/spec_input.html index e57fb70a137..77cd7ec866c 100644 --- a/pkg/analysis_server/tool/spec/spec_input.html +++ b/pkg/analysis_server/tool/spec/spec_input.html @@ -3304,54 +3304,6 @@ - -

- The kythe domain contains APIs related to generating Dart content in the - Kythe format. -

- -

- Return the list of KytheEntry objects for some file, given the - current state of the file system populated by "analysis.updateContent". -

-

- If a request is made for a file that does not exist, or that is not - currently subject to analysis (e.g. because it is not associated with any - analysis root specified to analysis.setAnalysisRoots), an error of type - GET_KYTHE_ENTRIES_INVALID_FILE will be generated. -

- - - FilePath -

- The file containing the code for which the Kythe Entry objects are - being requested. -

-
-
- - - - KytheEntry - -

- The list of KytheEntry objects for the queried file. -

-
- - - FilePath - -

- The set of files paths that were required, but not in the file system, - to give a complete and accurate Kythe graph for the file. This could - be due to a referenced file that does not exist or generated files not - being generated or passed before the call to "getKytheEntries". -

-
-
-
-

The analysis domain contains API's related to Flutter support. @@ -5205,13 +5157,6 @@ does not match a file currently subject to analysis.

- - GET_KYTHE_ENTRIES_INVALID_FILE -

- An "analysis.getKytheEntries" request specified a FilePath that does - not match a file that is currently subject to analysis. -

-
GET_NAVIGATION_INVALID_FILE

diff --git a/pkg/analysis_server_client/lib/src/protocol/protocol_base.dart b/pkg/analysis_server_client/lib/src/protocol/protocol_base.dart index b89d0cdc6f3..722be536c05 100644 --- a/pkg/analysis_server_client/lib/src/protocol/protocol_base.dart +++ b/pkg/analysis_server_client/lib/src/protocol/protocol_base.dart @@ -357,13 +357,6 @@ class Response { RequestErrorCode.GET_IMPORTED_ELEMENTS_INVALID_FILE, 'Error during `analysis.getImportedElements`: invalid file.')); - /// Initialize a newly created instance to represent the - /// GET_KYTHE_ENTRIES_INVALID_FILE error condition. - Response.getKytheEntriesInvalidFile(Request request) - : this(request.id, - error: RequestError(RequestErrorCode.GET_KYTHE_ENTRIES_INVALID_FILE, - 'Error during `analysis.getKytheEntries`: invalid file.')); - /// Initialize a newly created instance to represent the /// GET_NAVIGATION_INVALID_FILE error condition. Response.getNavigationInvalidFile(Request request) diff --git a/pkg/analysis_server_client/lib/src/protocol/protocol_common.dart b/pkg/analysis_server_client/lib/src/protocol/protocol_common.dart index 1829c858a4c..626781d42c3 100644 --- a/pkg/analysis_server_client/lib/src/protocol/protocol_common.dart +++ b/pkg/analysis_server_client/lib/src/protocol/protocol_common.dart @@ -2492,229 +2492,6 @@ class HighlightRegionType implements Enum { String toJson() => name; } -/// KytheEntry -/// -/// { -/// "source": KytheVName -/// "kind": optional String -/// "target": optional KytheVName -/// "fact": String -/// "value": optional List -/// } -/// -/// Clients may not extend, implement or mix-in this class. -class KytheEntry implements HasToJson { - /// The ticket of the source node. - KytheVName source; - - /// An edge label. The schema defines which labels are meaningful. - String? kind; - - /// The ticket of the target node. - KytheVName? target; - - /// A fact label. The schema defines which fact labels are meaningful. - String fact; - - /// The String value of the fact. - List? value; - - KytheEntry(this.source, this.fact, {this.kind, this.target, this.value}); - - factory KytheEntry.fromJson( - JsonDecoder jsonDecoder, String jsonPath, Object? json) { - json ??= {}; - if (json is Map) { - KytheVName source; - if (json.containsKey('source')) { - source = KytheVName.fromJson( - jsonDecoder, '$jsonPath.source', json['source']); - } else { - throw jsonDecoder.mismatch(jsonPath, 'source'); - } - String? kind; - if (json.containsKey('kind')) { - kind = jsonDecoder.decodeString('$jsonPath.kind', json['kind']); - } - KytheVName? target; - if (json.containsKey('target')) { - target = KytheVName.fromJson( - jsonDecoder, '$jsonPath.target', json['target']); - } - String fact; - if (json.containsKey('fact')) { - fact = jsonDecoder.decodeString('$jsonPath.fact', json['fact']); - } else { - throw jsonDecoder.mismatch(jsonPath, 'fact'); - } - List? value; - if (json.containsKey('value')) { - value = jsonDecoder.decodeList( - '$jsonPath.value', json['value'], jsonDecoder.decodeInt); - } - return KytheEntry(source, fact, kind: kind, target: target, value: value); - } else { - throw jsonDecoder.mismatch(jsonPath, 'KytheEntry', json); - } - } - - @override - Map toJson() { - var result = {}; - result['source'] = source.toJson(); - var kind = this.kind; - if (kind != null) { - result['kind'] = kind; - } - var target = this.target; - if (target != null) { - result['target'] = target.toJson(); - } - result['fact'] = fact; - var value = this.value; - if (value != null) { - result['value'] = value; - } - return result; - } - - @override - String toString() => json.encode(toJson()); - - @override - bool operator ==(other) { - if (other is KytheEntry) { - return source == other.source && - kind == other.kind && - target == other.target && - fact == other.fact && - listEqual(value, other.value, (int a, int b) => a == b); - } - return false; - } - - @override - int get hashCode => Object.hash( - source, - kind, - target, - fact, - Object.hashAll(value ?? []), - ); -} - -/// KytheVName -/// -/// { -/// "signature": String -/// "corpus": String -/// "root": String -/// "path": String -/// "language": String -/// } -/// -/// Clients may not extend, implement or mix-in this class. -class KytheVName implements HasToJson { - /// An opaque signature generated by the analyzer. - String signature; - - /// The corpus of source code this KytheVName belongs to. Loosely, a corpus - /// is a collection of related files, such as the contents of a given source - /// repository. - String corpus; - - /// A corpus-specific root label, typically a directory path or project - /// identifier, denoting a distinct subset of the corpus. This may also be - /// used to designate virtual collections like generated files. - String root; - - /// A path-structured label describing the “location” of the named object - /// relative to the corpus and the root. - String path; - - /// The language this name belongs to. - String language; - - KytheVName(this.signature, this.corpus, this.root, this.path, this.language); - - factory KytheVName.fromJson( - JsonDecoder jsonDecoder, String jsonPath, Object? json) { - json ??= {}; - if (json is Map) { - String signature; - if (json.containsKey('signature')) { - signature = - jsonDecoder.decodeString('$jsonPath.signature', json['signature']); - } else { - throw jsonDecoder.mismatch(jsonPath, 'signature'); - } - String corpus; - if (json.containsKey('corpus')) { - corpus = jsonDecoder.decodeString('$jsonPath.corpus', json['corpus']); - } else { - throw jsonDecoder.mismatch(jsonPath, 'corpus'); - } - String root; - if (json.containsKey('root')) { - root = jsonDecoder.decodeString('$jsonPath.root', json['root']); - } else { - throw jsonDecoder.mismatch(jsonPath, 'root'); - } - String path; - if (json.containsKey('path')) { - path = jsonDecoder.decodeString('$jsonPath.path', json['path']); - } else { - throw jsonDecoder.mismatch(jsonPath, 'path'); - } - String language; - if (json.containsKey('language')) { - language = - jsonDecoder.decodeString('$jsonPath.language', json['language']); - } else { - throw jsonDecoder.mismatch(jsonPath, 'language'); - } - return KytheVName(signature, corpus, root, path, language); - } else { - throw jsonDecoder.mismatch(jsonPath, 'KytheVName', json); - } - } - - @override - Map toJson() { - var result = {}; - result['signature'] = signature; - result['corpus'] = corpus; - result['root'] = root; - result['path'] = path; - result['language'] = language; - return result; - } - - @override - String toString() => json.encode(toJson()); - - @override - bool operator ==(other) { - if (other is KytheVName) { - return signature == other.signature && - corpus == other.corpus && - root == other.root && - path == other.path && - language == other.language; - } - return false; - } - - @override - int get hashCode => Object.hash( - signature, - corpus, - root, - path, - language, - ); -} - /// LinkedEditGroup /// /// { diff --git a/pkg/analysis_server_client/lib/src/protocol/protocol_constants.dart b/pkg/analysis_server_client/lib/src/protocol/protocol_constants.dart index 560ec40d3e9..3b76a6e1e83 100644 --- a/pkg/analysis_server_client/lib/src/protocol/protocol_constants.dart +++ b/pkg/analysis_server_client/lib/src/protocol/protocol_constants.dart @@ -313,10 +313,6 @@ const String FLUTTER_REQUEST_SET_WIDGET_PROPERTY_VALUE_ID = 'id'; const String FLUTTER_REQUEST_SET_WIDGET_PROPERTY_VALUE_VALUE = 'value'; const String FLUTTER_RESPONSE_GET_WIDGET_DESCRIPTION_PROPERTIES = 'properties'; const String FLUTTER_RESPONSE_SET_WIDGET_PROPERTY_VALUE_CHANGE = 'change'; -const String KYTHE_REQUEST_GET_KYTHE_ENTRIES = 'kythe.getKytheEntries'; -const String KYTHE_REQUEST_GET_KYTHE_ENTRIES_FILE = 'file'; -const String KYTHE_RESPONSE_GET_KYTHE_ENTRIES_ENTRIES = 'entries'; -const String KYTHE_RESPONSE_GET_KYTHE_ENTRIES_FILES = 'files'; const String SEARCH_NOTIFICATION_RESULTS = 'search.results'; const String SEARCH_NOTIFICATION_RESULTS_ID = 'id'; const String SEARCH_NOTIFICATION_RESULTS_IS_LAST = 'isLast'; diff --git a/pkg/analysis_server_client/lib/src/protocol/protocol_generated.dart b/pkg/analysis_server_client/lib/src/protocol/protocol_generated.dart index 983875fbb98..4286136b965 100644 --- a/pkg/analysis_server_client/lib/src/protocol/protocol_generated.dart +++ b/pkg/analysis_server_client/lib/src/protocol/protocol_generated.dart @@ -12941,158 +12941,6 @@ class InlineMethodOptions extends RefactoringOptions { ); } -/// kythe.getKytheEntries params -/// -/// { -/// "file": FilePath -/// } -/// -/// Clients may not extend, implement or mix-in this class. -class KytheGetKytheEntriesParams implements RequestParams { - /// The file containing the code for which the Kythe Entry objects are being - /// requested. - String file; - - KytheGetKytheEntriesParams(this.file); - - factory KytheGetKytheEntriesParams.fromJson( - JsonDecoder jsonDecoder, String jsonPath, Object? json) { - json ??= {}; - if (json is Map) { - String file; - if (json.containsKey('file')) { - file = jsonDecoder.decodeString('$jsonPath.file', json['file']); - } else { - throw jsonDecoder.mismatch(jsonPath, 'file'); - } - return KytheGetKytheEntriesParams(file); - } else { - throw jsonDecoder.mismatch( - jsonPath, 'kythe.getKytheEntries params', json); - } - } - - factory KytheGetKytheEntriesParams.fromRequest(Request request) { - return KytheGetKytheEntriesParams.fromJson( - RequestDecoder(request), 'params', request.params); - } - - @override - Map toJson() { - var result = {}; - result['file'] = file; - return result; - } - - @override - Request toRequest(String id) { - return Request(id, 'kythe.getKytheEntries', toJson()); - } - - @override - String toString() => json.encode(toJson()); - - @override - bool operator ==(other) { - if (other is KytheGetKytheEntriesParams) { - return file == other.file; - } - return false; - } - - @override - int get hashCode => file.hashCode; -} - -/// kythe.getKytheEntries result -/// -/// { -/// "entries": List -/// "files": List -/// } -/// -/// Clients may not extend, implement or mix-in this class. -class KytheGetKytheEntriesResult implements ResponseResult { - /// The list of KytheEntry objects for the queried file. - List entries; - - /// The set of files paths that were required, but not in the file system, to - /// give a complete and accurate Kythe graph for the file. This could be due - /// to a referenced file that does not exist or generated files not being - /// generated or passed before the call to "getKytheEntries". - List files; - - KytheGetKytheEntriesResult(this.entries, this.files); - - factory KytheGetKytheEntriesResult.fromJson( - JsonDecoder jsonDecoder, String jsonPath, Object? json) { - json ??= {}; - if (json is Map) { - List entries; - if (json.containsKey('entries')) { - entries = jsonDecoder.decodeList( - '$jsonPath.entries', - json['entries'], - (String jsonPath, Object? json) => - KytheEntry.fromJson(jsonDecoder, jsonPath, json)); - } else { - throw jsonDecoder.mismatch(jsonPath, 'entries'); - } - List files; - if (json.containsKey('files')) { - files = jsonDecoder.decodeList( - '$jsonPath.files', json['files'], jsonDecoder.decodeString); - } else { - throw jsonDecoder.mismatch(jsonPath, 'files'); - } - return KytheGetKytheEntriesResult(entries, files); - } else { - throw jsonDecoder.mismatch( - jsonPath, 'kythe.getKytheEntries result', json); - } - } - - factory KytheGetKytheEntriesResult.fromResponse(Response response) { - return KytheGetKytheEntriesResult.fromJson( - ResponseDecoder(REQUEST_ID_REFACTORING_KINDS.remove(response.id)), - 'result', - response.result); - } - - @override - Map toJson() { - var result = {}; - result['entries'] = - entries.map((KytheEntry value) => value.toJson()).toList(); - result['files'] = files; - return result; - } - - @override - Response toResponse(String id) { - return Response(id, result: toJson()); - } - - @override - String toString() => json.encode(toJson()); - - @override - bool operator ==(other) { - if (other is KytheGetKytheEntriesResult) { - return listEqual( - entries, other.entries, (KytheEntry a, KytheEntry b) => a == b) && - listEqual(files, other.files, (String a, String b) => a == b); - } - return false; - } - - @override - int get hashCode => Object.hash( - Object.hashAll(entries), - Object.hashAll(files), - ); -} - /// LibraryPathSet /// /// { @@ -13866,7 +13714,6 @@ class RequestError implements HasToJson { /// GET_ERRORS_INVALID_FILE /// GET_FIXES_INVALID_FILE /// GET_IMPORTED_ELEMENTS_INVALID_FILE -/// GET_KYTHE_ENTRIES_INVALID_FILE /// GET_NAVIGATION_INVALID_FILE /// GET_REACHABLE_SOURCES_INVALID_FILE /// GET_SIGNATURE_INVALID_FILE @@ -13955,11 +13802,6 @@ class RequestErrorCode implements Enum { static const RequestErrorCode GET_IMPORTED_ELEMENTS_INVALID_FILE = RequestErrorCode._('GET_IMPORTED_ELEMENTS_INVALID_FILE'); - /// An "analysis.getKytheEntries" request specified a FilePath that does not - /// match a file that is currently subject to analysis. - static const RequestErrorCode GET_KYTHE_ENTRIES_INVALID_FILE = - RequestErrorCode._('GET_KYTHE_ENTRIES_INVALID_FILE'); - /// An "analysis.getNavigation" request specified a FilePath which does not /// match a file currently subject to analysis. static const RequestErrorCode GET_NAVIGATION_INVALID_FILE = @@ -14079,7 +13921,6 @@ class RequestErrorCode implements Enum { GET_ERRORS_INVALID_FILE, GET_FIXES_INVALID_FILE, GET_IMPORTED_ELEMENTS_INVALID_FILE, - GET_KYTHE_ENTRIES_INVALID_FILE, GET_NAVIGATION_INVALID_FILE, GET_REACHABLE_SOURCES_INVALID_FILE, GET_SIGNATURE_INVALID_FILE, @@ -14135,8 +13976,6 @@ class RequestErrorCode implements Enum { return GET_FIXES_INVALID_FILE; case 'GET_IMPORTED_ELEMENTS_INVALID_FILE': return GET_IMPORTED_ELEMENTS_INVALID_FILE; - case 'GET_KYTHE_ENTRIES_INVALID_FILE': - return GET_KYTHE_ENTRIES_INVALID_FILE; case 'GET_NAVIGATION_INVALID_FILE': return GET_NAVIGATION_INVALID_FILE; case 'GET_REACHABLE_SOURCES_INVALID_FILE': diff --git a/pkg/analyzer_plugin/doc/api.html b/pkg/analyzer_plugin/doc/api.html index b4930096978..82bc04611c6 100644 --- a/pkg/analyzer_plugin/doc/api.html +++ b/pkg/analyzer_plugin/doc/api.html @@ -826,7 +826,6 @@ a:focus, a:hover {

-

Types

This section contains descriptions of the data types referenced in the API's @@ -1459,78 +1458,7 @@ a:focus, a:hover {

TOP_LEVEL_VARIABLE

Deprecated - no longer sent.

-
PARAMETER_DECLARATION
PARAMETER_REFERENCE
STATIC_FIELD_DECLARATION
STATIC_GETTER_DECLARATION
STATIC_GETTER_REFERENCE
STATIC_METHOD_DECLARATION
STATIC_METHOD_REFERENCE
STATIC_METHOD_TEAR_OFF
STATIC_SETTER_DECLARATION
STATIC_SETTER_REFERENCE
TOP_LEVEL_FUNCTION_DECLARATION
TOP_LEVEL_FUNCTION_REFERENCE
TOP_LEVEL_FUNCTION_TEAR_OFF
TOP_LEVEL_GETTER_DECLARATION
TOP_LEVEL_GETTER_REFERENCE
TOP_LEVEL_SETTER_DECLARATION
TOP_LEVEL_SETTER_REFERENCE
TOP_LEVEL_VARIABLE_DECLARATION
TYPE_ALIAS
TYPE_NAME_DYNAMIC
TYPE_PARAMETER
UNRESOLVED_INSTANCE_MEMBER_REFERENCE
VALID_STRING_ESCAPE
KytheEntry: object
-

- This object matches the format and documentation of the Entry object - documented in the - Kythe Storage - Model. -

- -
source: KytheVName
- -

- The ticket of the source node. -

-
kind: String (optional)
- -

- An edge label. The schema defines which labels are meaningful. -

-
target: KytheVName (optional)
- -

- The ticket of the target node. -

-
fact: String
- -

- A fact label. The schema defines which fact labels are meaningful. -

-
value: List<int> (optional)
- -

- The String value of the fact. -

-
KytheVName: object
-

- This object matches the format and documentation of the Vector-Name object - documented in the - Kythe - Storage Model. -

- -
signature: String
- -

- An opaque signature generated by the analyzer. -

-
corpus: String
- -

- The corpus of source code this KytheVName belongs to. - Loosely, a corpus is a collection of related files, such as the - contents of a given source repository. -

-
root: String
- -

- A corpus-specific root label, typically a directory path or project - identifier, denoting a distinct subset of the corpus. This may also be - used to designate virtual collections like generated files. -

-
path: String
- -

- A path-structured label describing the “location” of the named object - relative to the corpus and the root. -

-
language: String
- -

- The language this name belongs to. -

-
LinkedEditGroup: object
+
PARAMETER_DECLARATION
PARAMETER_REFERENCE
STATIC_FIELD_DECLARATION
STATIC_GETTER_DECLARATION
STATIC_GETTER_REFERENCE
STATIC_METHOD_DECLARATION
STATIC_METHOD_REFERENCE
STATIC_METHOD_TEAR_OFF
STATIC_SETTER_DECLARATION
STATIC_SETTER_REFERENCE
TOP_LEVEL_FUNCTION_DECLARATION
TOP_LEVEL_FUNCTION_REFERENCE
TOP_LEVEL_FUNCTION_TEAR_OFF
TOP_LEVEL_GETTER_DECLARATION
TOP_LEVEL_GETTER_REFERENCE
TOP_LEVEL_SETTER_DECLARATION
TOP_LEVEL_SETTER_REFERENCE
TOP_LEVEL_VARIABLE_DECLARATION
TYPE_ALIAS
TYPE_NAME_DYNAMIC
TYPE_PARAMETER
UNRESOLVED_INSTANCE_MEMBER_REFERENCE
VALID_STRING_ESCAPE
LinkedEditGroup: object

A collection of positions that should be linked (edited simultaneously) for the purposes of updating code after a source change. For example, if a @@ -2427,6 +2355,6 @@ a:focus, a:hover {

Index

-

Domains

plugin ()

Requests
Notifications

analysis ()

completion ()

edit ()

Types ()

Refactorings ()

+

Domains

plugin ()

Requests
Notifications

analysis ()

completion ()

edit ()

Types ()

Refactorings ()

diff --git a/pkg/analyzer_plugin/doc/tutorial/kythe.md b/pkg/analyzer_plugin/doc/tutorial/kythe.md deleted file mode 100644 index 58e1706a21c..00000000000 --- a/pkg/analyzer_plugin/doc/tutorial/kythe.md +++ /dev/null @@ -1,86 +0,0 @@ -# Providing Kythe Data - -**Note:** Kythe support is experimental and might be removed or changed without -notice. - -[Kythe][kythe] is, in their own words, "A pluggable, (mostly) language-agnostic -ecosystem for building tools that work with code." The analysis server can be -used to produce the data that should be sent to Kythe. In other words, the -analysis server is (almost) a Kythe indexer. (The data needs to be converted -from a Json representation to a protobuf format before being sent to Kythe.) - -## Implementation details - -When appropriate, the analysis server will send your plugin a -`kythe.getKytheEntries` request. The request includes the `file` for which data -should be generated. The data consists of a list of `KytheEntry`s. - -When a `kythe.getKytheEntries` request is received, the method -`handleKytheGetKytheEntries` will be invoked. This method is responsible for -returning a response that contains the entries to be sent to Kythe. - -The easiest way to implement this method is by adding the classes `EntryMixin` -and `DartEntryMixin` (from `package:analyzer_plugin/plugin/kythe_mixin.dart`) to -the list of mixins for your subclass of `ServerPlugin`. This will leave you with -one abstract method that you need to implement: `getEntryContributors`. That -method is responsible for returning a list of `EntryContributor`s. It is the -entry contributors that produce the actual entries. (Most plugins will only need -a single entry contributor.) - -To write an entry contributor, create a class that implements -`EntryContributor`. The interface defines a single method named -`computeEntries`. The method has two arguments: an `EntryRequest` that describes -the file to be indexed and an `EntryCollector` through which entries are to be -added. - -If you mix in the class `DartEntryMixin`, then the request will be an instance -of `DartEntryRequest`, which also has analysis results. - -## Example - -Start by creating a class that implements `EntryContributor`, then implement the -method `computeEntries`. This method is typically implemented by creating a -visitor (such as an AstVisitor) that can visit the results of the analysis (such -as a CompilationUnit) and extract the navigation information from the analysis -result. - -For example, your contributor might look something like the following: - -```dart -class MyEntryContributor implements EntryContributor { - @override - void computeEntries(EntryRequest request, EntryCollector collector) { - if (request is DartEntryRequest) { - EntryVisitor visitor = new EntryVisitor(collector); - request.result.unit.accept(visitor); - } - } -} - -class EntryVisitor extends RecursiveAstVisitor { - final EntryCollector collector; - - EntryVisitor(this.collector); - - @override - void visitSimpleIdentifier(SimpleIdentifier node) { - // ... - } -} -``` - -Given a contributor like the one above, you can implement your plugin similar to -the following: - -```dart -class MyPlugin extends ServerPlugin with EntryMixin, DartEntryMixin { - // ... - - @override - List getEntryContributors(String path) { - return [new MyEntryContributor()]; - } -} -``` - -[kythe]: http://kythe.io/ diff --git a/pkg/analyzer_plugin/lib/plugin/kythe_mixin.dart b/pkg/analyzer_plugin/lib/plugin/kythe_mixin.dart deleted file mode 100644 index d452e0d0a21..00000000000 --- a/pkg/analyzer_plugin/lib/plugin/kythe_mixin.dart +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:analyzer/src/dart/analysis/driver.dart'; -import 'package:analyzer_plugin/plugin/plugin.dart'; -import 'package:analyzer_plugin/protocol/protocol.dart'; -import 'package:analyzer_plugin/protocol/protocol_generated.dart'; -import 'package:analyzer_plugin/src/utilities/kythe/entries.dart'; -import 'package:analyzer_plugin/utilities/kythe/entries.dart'; - -/// A mixin that can be used when creating a subclass of [ServerPlugin] and -/// mixing in [KytheMixin]. This implements the creation of the kythe.getEntries -/// request based on the assumption that the driver being created is an -/// [AnalysisDriver]. -/// -/// Clients may not implement this mixin, but are allowed to use it as a mix-in -/// when creating a subclass of [ServerPlugin] that also uses [KytheMixin] as a -/// mix-in. -mixin DartEntryMixin implements EntryMixin { - @override - Future getEntryRequest( - KytheGetKytheEntriesParams parameters) async { - var path = parameters.file; - var result = await getResolvedUnitResult(path); - return DartEntryRequestImpl(resourceProvider, result); - } -} - -/// A mixin that can be used when creating a subclass of [ServerPlugin] to -/// provide most of the implementation for handling kythe.getEntries requests. -/// -/// Clients may not implement this mixin, but are allowed to use it as a mix-in -/// when creating a subclass of [ServerPlugin]. -mixin EntryMixin implements ServerPlugin { - /// Return a list containing the entry contributors that should be used to - /// create entries for the file with the given [path] - List getEntryContributors(String path); - - /// Return the entries request that should be passes to the contributors - /// returned from [getEntryContributors]. - /// - /// Throw a [RequestFailure] if the request could not be created. - Future getEntryRequest(KytheGetKytheEntriesParams parameters); - - @override - Future handleKytheGetKytheEntries( - KytheGetKytheEntriesParams parameters) async { - var path = parameters.file; - var request = await getEntryRequest(parameters); - var generator = EntryGenerator(getEntryContributors(path)); - var result = generator.generateGetEntriesResponse(request); - result.sendNotifications(channel); - return result.result; - } -} diff --git a/pkg/analyzer_plugin/lib/plugin/plugin.dart b/pkg/analyzer_plugin/lib/plugin/plugin.dart index a7218651c9d..21e778cc15b 100644 --- a/pkg/analyzer_plugin/lib/plugin/plugin.dart +++ b/pkg/analyzer_plugin/lib/plugin/plugin.dart @@ -397,14 +397,6 @@ abstract class ServerPlugin { return null; } - /// Handle a 'kythe.getKytheEntries' request. - /// - /// Throw a [RequestFailure] if the request could not be handled. - Future handleKytheGetKytheEntries( - KytheGetKytheEntriesParams parameters) async { - return null; - } - /// Handle a 'plugin.shutdown' request. Subclasses can override this method to /// perform any required clean-up, but cannot prevent the plugin from shutting /// down. @@ -575,10 +567,6 @@ abstract class ServerPlugin { var params = EditGetRefactoringParams.fromRequest(request); result = await handleEditGetRefactoring(params); break; - case KYTHE_REQUEST_GET_KYTHE_ENTRIES: - var params = KytheGetKytheEntriesParams.fromRequest(request); - result = await handleKytheGetKytheEntries(params); - break; case PLUGIN_REQUEST_SHUTDOWN: var params = PluginShutdownParams(); result = await handlePluginShutdown(params); diff --git a/pkg/analyzer_plugin/lib/protocol/protocol_common.dart b/pkg/analyzer_plugin/lib/protocol/protocol_common.dart index d5b44d4c91d..6405463c9e4 100644 --- a/pkg/analyzer_plugin/lib/protocol/protocol_common.dart +++ b/pkg/analyzer_plugin/lib/protocol/protocol_common.dart @@ -2492,229 +2492,6 @@ class HighlightRegionType implements Enum { String toJson() => name; } -/// KytheEntry -/// -/// { -/// "source": KytheVName -/// "kind": optional String -/// "target": optional KytheVName -/// "fact": String -/// "value": optional List -/// } -/// -/// Clients may not extend, implement or mix-in this class. -class KytheEntry implements HasToJson { - /// The ticket of the source node. - KytheVName source; - - /// An edge label. The schema defines which labels are meaningful. - String? kind; - - /// The ticket of the target node. - KytheVName? target; - - /// A fact label. The schema defines which fact labels are meaningful. - String fact; - - /// The String value of the fact. - List? value; - - KytheEntry(this.source, this.fact, {this.kind, this.target, this.value}); - - factory KytheEntry.fromJson( - JsonDecoder jsonDecoder, String jsonPath, Object? json) { - json ??= {}; - if (json is Map) { - KytheVName source; - if (json.containsKey('source')) { - source = KytheVName.fromJson( - jsonDecoder, '$jsonPath.source', json['source']); - } else { - throw jsonDecoder.mismatch(jsonPath, 'source'); - } - String? kind; - if (json.containsKey('kind')) { - kind = jsonDecoder.decodeString('$jsonPath.kind', json['kind']); - } - KytheVName? target; - if (json.containsKey('target')) { - target = KytheVName.fromJson( - jsonDecoder, '$jsonPath.target', json['target']); - } - String fact; - if (json.containsKey('fact')) { - fact = jsonDecoder.decodeString('$jsonPath.fact', json['fact']); - } else { - throw jsonDecoder.mismatch(jsonPath, 'fact'); - } - List? value; - if (json.containsKey('value')) { - value = jsonDecoder.decodeList( - '$jsonPath.value', json['value'], jsonDecoder.decodeInt); - } - return KytheEntry(source, fact, kind: kind, target: target, value: value); - } else { - throw jsonDecoder.mismatch(jsonPath, 'KytheEntry', json); - } - } - - @override - Map toJson() { - var result = {}; - result['source'] = source.toJson(); - var kind = this.kind; - if (kind != null) { - result['kind'] = kind; - } - var target = this.target; - if (target != null) { - result['target'] = target.toJson(); - } - result['fact'] = fact; - var value = this.value; - if (value != null) { - result['value'] = value; - } - return result; - } - - @override - String toString() => json.encode(toJson()); - - @override - bool operator ==(other) { - if (other is KytheEntry) { - return source == other.source && - kind == other.kind && - target == other.target && - fact == other.fact && - listEqual(value, other.value, (int a, int b) => a == b); - } - return false; - } - - @override - int get hashCode => Object.hash( - source, - kind, - target, - fact, - Object.hashAll(value ?? []), - ); -} - -/// KytheVName -/// -/// { -/// "signature": String -/// "corpus": String -/// "root": String -/// "path": String -/// "language": String -/// } -/// -/// Clients may not extend, implement or mix-in this class. -class KytheVName implements HasToJson { - /// An opaque signature generated by the analyzer. - String signature; - - /// The corpus of source code this KytheVName belongs to. Loosely, a corpus - /// is a collection of related files, such as the contents of a given source - /// repository. - String corpus; - - /// A corpus-specific root label, typically a directory path or project - /// identifier, denoting a distinct subset of the corpus. This may also be - /// used to designate virtual collections like generated files. - String root; - - /// A path-structured label describing the “location” of the named object - /// relative to the corpus and the root. - String path; - - /// The language this name belongs to. - String language; - - KytheVName(this.signature, this.corpus, this.root, this.path, this.language); - - factory KytheVName.fromJson( - JsonDecoder jsonDecoder, String jsonPath, Object? json) { - json ??= {}; - if (json is Map) { - String signature; - if (json.containsKey('signature')) { - signature = - jsonDecoder.decodeString('$jsonPath.signature', json['signature']); - } else { - throw jsonDecoder.mismatch(jsonPath, 'signature'); - } - String corpus; - if (json.containsKey('corpus')) { - corpus = jsonDecoder.decodeString('$jsonPath.corpus', json['corpus']); - } else { - throw jsonDecoder.mismatch(jsonPath, 'corpus'); - } - String root; - if (json.containsKey('root')) { - root = jsonDecoder.decodeString('$jsonPath.root', json['root']); - } else { - throw jsonDecoder.mismatch(jsonPath, 'root'); - } - String path; - if (json.containsKey('path')) { - path = jsonDecoder.decodeString('$jsonPath.path', json['path']); - } else { - throw jsonDecoder.mismatch(jsonPath, 'path'); - } - String language; - if (json.containsKey('language')) { - language = - jsonDecoder.decodeString('$jsonPath.language', json['language']); - } else { - throw jsonDecoder.mismatch(jsonPath, 'language'); - } - return KytheVName(signature, corpus, root, path, language); - } else { - throw jsonDecoder.mismatch(jsonPath, 'KytheVName', json); - } - } - - @override - Map toJson() { - var result = {}; - result['signature'] = signature; - result['corpus'] = corpus; - result['root'] = root; - result['path'] = path; - result['language'] = language; - return result; - } - - @override - String toString() => json.encode(toJson()); - - @override - bool operator ==(other) { - if (other is KytheVName) { - return signature == other.signature && - corpus == other.corpus && - root == other.root && - path == other.path && - language == other.language; - } - return false; - } - - @override - int get hashCode => Object.hash( - signature, - corpus, - root, - path, - language, - ); -} - /// LinkedEditGroup /// /// { diff --git a/pkg/analyzer_plugin/lib/protocol/protocol_constants.dart b/pkg/analyzer_plugin/lib/protocol/protocol_constants.dart index 51700b4fd88..d739d6beff8 100644 --- a/pkg/analyzer_plugin/lib/protocol/protocol_constants.dart +++ b/pkg/analyzer_plugin/lib/protocol/protocol_constants.dart @@ -82,10 +82,6 @@ const String EDIT_RESPONSE_GET_REFACTORING_FINAL_PROBLEMS = 'finalProblems'; const String EDIT_RESPONSE_GET_REFACTORING_INITIAL_PROBLEMS = 'initialProblems'; const String EDIT_RESPONSE_GET_REFACTORING_OPTIONS_PROBLEMS = 'optionsProblems'; const String EDIT_RESPONSE_GET_REFACTORING_POTENTIAL_EDITS = 'potentialEdits'; -const String KYTHE_REQUEST_GET_KYTHE_ENTRIES = 'kythe.getKytheEntries'; -const String KYTHE_REQUEST_GET_KYTHE_ENTRIES_FILE = 'file'; -const String KYTHE_RESPONSE_GET_KYTHE_ENTRIES_ENTRIES = 'entries'; -const String KYTHE_RESPONSE_GET_KYTHE_ENTRIES_FILES = 'files'; const String PLUGIN_NOTIFICATION_ERROR = 'plugin.error'; const String PLUGIN_NOTIFICATION_ERROR_IS_FATAL = 'isFatal'; const String PLUGIN_NOTIFICATION_ERROR_MESSAGE = 'message'; diff --git a/pkg/analyzer_plugin/lib/protocol/protocol_generated.dart b/pkg/analyzer_plugin/lib/protocol/protocol_generated.dart index 1644405382e..edc73db17c0 100644 --- a/pkg/analyzer_plugin/lib/protocol/protocol_generated.dart +++ b/pkg/analyzer_plugin/lib/protocol/protocol_generated.dart @@ -3179,158 +3179,6 @@ class InlineMethodOptions extends RefactoringOptions { ); } -/// kythe.getKytheEntries params -/// -/// { -/// "file": FilePath -/// } -/// -/// Clients may not extend, implement or mix-in this class. -class KytheGetKytheEntriesParams implements RequestParams { - /// The file containing the code for which the Kythe Entry objects are being - /// requested. - String file; - - KytheGetKytheEntriesParams(this.file); - - factory KytheGetKytheEntriesParams.fromJson( - JsonDecoder jsonDecoder, String jsonPath, Object? json) { - json ??= {}; - if (json is Map) { - String file; - if (json.containsKey('file')) { - file = jsonDecoder.decodeString('$jsonPath.file', json['file']); - } else { - throw jsonDecoder.mismatch(jsonPath, 'file'); - } - return KytheGetKytheEntriesParams(file); - } else { - throw jsonDecoder.mismatch( - jsonPath, 'kythe.getKytheEntries params', json); - } - } - - factory KytheGetKytheEntriesParams.fromRequest(Request request) { - return KytheGetKytheEntriesParams.fromJson( - RequestDecoder(request), 'params', request.params); - } - - @override - Map toJson() { - var result = {}; - result['file'] = file; - return result; - } - - @override - Request toRequest(String id) { - return Request(id, 'kythe.getKytheEntries', toJson()); - } - - @override - String toString() => json.encode(toJson()); - - @override - bool operator ==(other) { - if (other is KytheGetKytheEntriesParams) { - return file == other.file; - } - return false; - } - - @override - int get hashCode => file.hashCode; -} - -/// kythe.getKytheEntries result -/// -/// { -/// "entries": List -/// "files": List -/// } -/// -/// Clients may not extend, implement or mix-in this class. -class KytheGetKytheEntriesResult implements ResponseResult { - /// The list of KytheEntry objects for the queried file. - List entries; - - /// The set of files paths that were required, but not in the file system, to - /// give a complete and accurate Kythe graph for the file. This could be due - /// to a referenced file that does not exist or generated files not being - /// generated or passed before the call to "getKytheEntries". - List files; - - KytheGetKytheEntriesResult(this.entries, this.files); - - factory KytheGetKytheEntriesResult.fromJson( - JsonDecoder jsonDecoder, String jsonPath, Object? json) { - json ??= {}; - if (json is Map) { - List entries; - if (json.containsKey('entries')) { - entries = jsonDecoder.decodeList( - '$jsonPath.entries', - json['entries'], - (String jsonPath, Object? json) => - KytheEntry.fromJson(jsonDecoder, jsonPath, json)); - } else { - throw jsonDecoder.mismatch(jsonPath, 'entries'); - } - List files; - if (json.containsKey('files')) { - files = jsonDecoder.decodeList( - '$jsonPath.files', json['files'], jsonDecoder.decodeString); - } else { - throw jsonDecoder.mismatch(jsonPath, 'files'); - } - return KytheGetKytheEntriesResult(entries, files); - } else { - throw jsonDecoder.mismatch( - jsonPath, 'kythe.getKytheEntries result', json); - } - } - - factory KytheGetKytheEntriesResult.fromResponse(Response response) { - return KytheGetKytheEntriesResult.fromJson( - ResponseDecoder(REQUEST_ID_REFACTORING_KINDS.remove(response.id)), - 'result', - response.result); - } - - @override - Map toJson() { - var result = {}; - result['entries'] = - entries.map((KytheEntry value) => value.toJson()).toList(); - result['files'] = files; - return result; - } - - @override - Response toResponse(String id, int requestTime) { - return Response(id, requestTime, result: toJson()); - } - - @override - String toString() => json.encode(toJson()); - - @override - bool operator ==(other) { - if (other is KytheGetKytheEntriesResult) { - return listEqual( - entries, other.entries, (KytheEntry a, KytheEntry b) => a == b) && - listEqual(files, other.files, (String a, String b) => a == b); - } - return false; - } - - @override - int get hashCode => Object.hash( - Object.hashAll(entries), - Object.hashAll(files), - ); -} - /// moveFile feedback /// /// Clients may not extend, implement or mix-in this class. diff --git a/pkg/analyzer_plugin/lib/src/utilities/kythe/entries.dart b/pkg/analyzer_plugin/lib/src/utilities/kythe/entries.dart deleted file mode 100644 index 684e9e76622..00000000000 --- a/pkg/analyzer_plugin/lib/src/utilities/kythe/entries.dart +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:analyzer/dart/analysis/results.dart'; -import 'package:analyzer/file_system/file_system.dart'; -import 'package:analyzer_plugin/protocol/protocol_common.dart'; -import 'package:analyzer_plugin/utilities/kythe/entries.dart'; - -/// A concrete implementation of [EntryRequest]. -class DartEntryRequestImpl implements DartEntryRequest { - @override - final ResourceProvider resourceProvider; - - @override - final ResolvedUnitResult result; - - /// Initialize a newly create request with the given data. - DartEntryRequestImpl(this.resourceProvider, this.result); - - @override - String get path => result.path; -} - -/// A concrete implementation of [EntryCollector]. -class EntryCollectorImpl implements EntryCollector { - /// A list of entries. - final List entries = []; - - /// A list of paths to files. - final List files = []; - - @override - void addEntry(KytheEntry entry) { - entries.add(entry); - } -} diff --git a/pkg/analyzer_plugin/lib/utilities/kythe/entries.dart b/pkg/analyzer_plugin/lib/utilities/kythe/entries.dart deleted file mode 100644 index 1cd649bb966..00000000000 --- a/pkg/analyzer_plugin/lib/utilities/kythe/entries.dart +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:analyzer/dart/analysis/results.dart'; -import 'package:analyzer/file_system/file_system.dart'; -import 'package:analyzer_plugin/protocol/protocol.dart'; -import 'package:analyzer_plugin/protocol/protocol_common.dart' show KytheEntry; -import 'package:analyzer_plugin/protocol/protocol_generated.dart'; -import 'package:analyzer_plugin/src/utilities/kythe/entries.dart'; -import 'package:analyzer_plugin/utilities/generator.dart'; - -/// The information about a requested set of entries when computing entries in a -/// `.dart` file. -/// -/// Clients may not extend, implement or mix-in this class. -abstract class DartEntryRequest implements EntryRequest { - /// The analysis result for the file in which the entries are being requested. - ResolvedUnitResult get result; -} - -/// An object that [EntryContributor]s use to record entries. -/// -/// Clients may not extend, implement or mix-in this class. -abstract class EntryCollector { - /// Record a new [entry]. - void addEntry(KytheEntry entry); -} - -/// An object used to produce entries. -/// -/// Clients may implement this class when implementing plugins. -abstract class EntryContributor { - /// Contribute entries for the file specified by the given [request] into the - /// given [collector]. - void computeEntries(EntryRequest request, EntryCollector collector); -} - -/// A generator that will generate a 'kythe.getEntries' response. -/// -/// Clients may not extend, implement or mix-in this class. -class EntryGenerator { - /// The contributors to be used to generate the entries. - final List contributors; - - /// Initialize a newly created entry generator to use the given - /// [contributors]. - EntryGenerator(this.contributors); - - /// Create a 'kythe.getEntries' response for the file specified by the given - /// [request]. If any of the contributors throws an exception, also create a - /// non-fatal 'plugin.error' notification. - GeneratorResult generateGetEntriesResponse( - EntryRequest request) { - var notifications = []; - var collector = EntryCollectorImpl(); - for (var contributor in contributors) { - try { - contributor.computeEntries(request, collector); - } catch (exception, stackTrace) { - notifications.add(PluginErrorParams( - false, exception.toString(), stackTrace.toString()) - .toNotification()); - } - } - var result = KytheGetKytheEntriesResult(collector.entries, collector.files); - return GeneratorResult(result, notifications); - } -} - -/// The information about a requested set of entries. -/// -/// Clients may not extend, implement or mix-in this class. -abstract class EntryRequest { - /// Return the path of the file in which entries are being requested. - String get path; - - /// Return the resource provider associated with this request. - ResourceProvider get resourceProvider; -} diff --git a/pkg/analyzer_plugin/test/integration/support/integration_test_methods.dart b/pkg/analyzer_plugin/test/integration/support/integration_test_methods.dart index 309521c2e1c..2b6b3163516 100644 --- a/pkg/analyzer_plugin/test/integration/support/integration_test_methods.dart +++ b/pkg/analyzer_plugin/test/integration/support/integration_test_methods.dart @@ -654,36 +654,6 @@ abstract class IntegrationTestMixin { return EditGetRefactoringResult.fromJson(decoder, 'result', result); } - /// Return the list of KytheEntry objects for some file, given the current - /// state of the file system populated by "analysis.updateContent". - /// - /// Parameters - /// - /// file: FilePath - /// - /// The file containing the code for which the Kythe Entry objects are - /// being requested. - /// - /// Returns - /// - /// entries: List - /// - /// The list of KytheEntry objects for the queried file. - /// - /// files: List - /// - /// The set of files paths that were required, but not in the file system, - /// to give a complete and accurate Kythe graph for the file. This could be - /// due to a referenced file that does not exist or generated files not - /// being generated or passed before the call to "getKytheEntries". - Future sendKytheGetKytheEntries( - String file) async { - var params = KytheGetKytheEntriesParams(file).toJson(); - var result = await server.send('kythe.getKytheEntries', params); - var decoder = ResponseDecoder(null); - return KytheGetKytheEntriesResult.fromJson(decoder, 'result', result); - } - /// Initialize the fields in InttestMixin, and ensure that notifications will /// be handled. void initializeInttestMixin() { diff --git a/pkg/analyzer_plugin/test/integration/support/protocol_matchers.dart b/pkg/analyzer_plugin/test/integration/support/protocol_matchers.dart index 79b4ac3bd97..0838868f014 100644 --- a/pkg/analyzer_plugin/test/integration/support/protocol_matchers.dart +++ b/pkg/analyzer_plugin/test/integration/support/protocol_matchers.dart @@ -533,41 +533,6 @@ final Matcher isHighlightRegionType = MatchesEnum('HighlightRegionType', [ 'VALID_STRING_ESCAPE' ]); -/// KytheEntry -/// -/// { -/// "source": KytheVName -/// "kind": optional String -/// "target": optional KytheVName -/// "fact": String -/// "value": optional List -/// } -final Matcher isKytheEntry = LazyMatcher(() => MatchesJsonObject('KytheEntry', { - 'source': isKytheVName, - 'fact': isString - }, optionalFields: { - 'kind': isString, - 'target': isKytheVName, - 'value': isListOf(isInt) - })); - -/// KytheVName -/// -/// { -/// "signature": String -/// "corpus": String -/// "root": String -/// "path": String -/// "language": String -/// } -final Matcher isKytheVName = LazyMatcher(() => MatchesJsonObject('KytheVName', { - 'signature': isString, - 'corpus': isString, - 'root': isString, - 'path': isString, - 'language': isString - })); - /// LinkedEditGroup /// /// { @@ -1322,24 +1287,6 @@ final Matcher isInlineMethodFeedback = LazyMatcher(() => MatchesJsonObject( final Matcher isInlineMethodOptions = LazyMatcher(() => MatchesJsonObject( 'inlineMethod options', {'deleteSource': isBool, 'inlineAll': isBool})); -/// kythe.getKytheEntries params -/// -/// { -/// "file": FilePath -/// } -final Matcher isKytheGetKytheEntriesParams = LazyMatcher(() => - MatchesJsonObject('kythe.getKytheEntries params', {'file': isFilePath})); - -/// kythe.getKytheEntries result -/// -/// { -/// "entries": List -/// "files": List -/// } -final Matcher isKytheGetKytheEntriesResult = LazyMatcher(() => - MatchesJsonObject('kythe.getKytheEntries result', - {'entries': isListOf(isKytheEntry), 'files': isListOf(isFilePath)})); - /// moveFile feedback final Matcher isMoveFileFeedback = isNull; diff --git a/pkg/analyzer_plugin/test/plugin/kythe_mixin_test.dart b/pkg/analyzer_plugin/test/plugin/kythe_mixin_test.dart deleted file mode 100644 index 59fccaa64d1..00000000000 --- a/pkg/analyzer_plugin/test/plugin/kythe_mixin_test.dart +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:analyzer/file_system/file_system.dart'; -import 'package:analyzer_plugin/plugin/kythe_mixin.dart'; -import 'package:analyzer_plugin/plugin/plugin.dart'; -import 'package:analyzer_plugin/protocol/protocol_common.dart'; -import 'package:analyzer_plugin/protocol/protocol_generated.dart'; -import 'package:analyzer_plugin/src/utilities/kythe/entries.dart'; -import 'package:analyzer_plugin/utilities/kythe/entries.dart'; -import 'package:test/test.dart'; -import 'package:test_reflective_loader/test_reflective_loader.dart'; - -import 'mocks.dart'; -import 'plugin_test.dart'; - -void main() { - defineReflectiveTests(KytheMixinTest); -} - -@reflectiveTest -class KytheMixinTest extends AbstractPluginTest { - late String packagePath1; - late String filePath1; - late ContextRoot contextRoot1; - - @override - ServerPlugin createPlugin() { - return _TestServerPlugin(resourceProvider); - } - - @override - Future setUp() async { - await super.setUp(); - packagePath1 = convertPath('/package1'); - filePath1 = join(packagePath1, 'lib', 'test.dart'); - newFile(filePath1, ''); - contextRoot1 = ContextRoot(packagePath1, []); - } - - Future test_handleEditGetAssists() async { - await plugin.handleAnalysisSetContextRoots( - AnalysisSetContextRootsParams([contextRoot1])); - - var result = await plugin - .handleKytheGetKytheEntries(KytheGetKytheEntriesParams(filePath1)); - result!; - expect(result.entries, hasLength(3)); - } -} - -class _TestEntryContributor implements EntryContributor { - List entries; - - _TestEntryContributor(this.entries); - - @override - void computeEntries(EntryRequest request, EntryCollector collector) { - for (var entry in entries) { - collector.addEntry(entry); - } - } -} - -class _TestServerPlugin extends MockServerPlugin with EntryMixin { - _TestServerPlugin(ResourceProvider resourceProvider) - : super(resourceProvider); - - PrioritizedSourceChange createChange() { - return PrioritizedSourceChange(0, SourceChange('')); - } - - @override - List getEntryContributors(String path) { - var vName = KytheVName('', '', '', '', ''); - return [ - _TestEntryContributor([ - KytheEntry(vName, '', target: vName), - KytheEntry(vName, '', target: vName) - ]), - _TestEntryContributor([KytheEntry(vName, '', target: vName)]) - ]; - } - - @override - Future getEntryRequest( - KytheGetKytheEntriesParams parameters) async { - var result = MockResolvedUnitResult(); - return DartEntryRequestImpl(resourceProvider, result); - } -} diff --git a/pkg/analyzer_plugin/test/plugin/test_all.dart b/pkg/analyzer_plugin/test/plugin/test_all.dart index 5d10fe617c1..7b0a20b0f8e 100644 --- a/pkg/analyzer_plugin/test/plugin/test_all.dart +++ b/pkg/analyzer_plugin/test/plugin/test_all.dart @@ -9,7 +9,6 @@ import 'completion_mixin_test.dart' as completion_mixin_test; import 'fix_mixin_test.dart' as fix_mixin_test; import 'folding_mixin_test.dart' as folding_mixin_test; import 'highlights_mixin_test.dart' as highlights_mixin_test; -import 'kythe_mixin_test.dart' as kythe_mixin_test; import 'navigation_mixin_test.dart' as navigation_mixin_test; import 'occurrences_mixin_test.dart' as occurrences_mixin_test; import 'outline_mixin_test.dart' as outline_mixin_test; @@ -22,7 +21,6 @@ void main() { fix_mixin_test.main(); folding_mixin_test.main(); highlights_mixin_test.main(); - kythe_mixin_test.main(); navigation_mixin_test.main(); occurrences_mixin_test.main(); outline_mixin_test.main(); diff --git a/pkg/analyzer_plugin/tool/spec/common_types_spec.html b/pkg/analyzer_plugin/tool/spec/common_types_spec.html index 93acba19d19..ef7bc5fbf11 100644 --- a/pkg/analyzer_plugin/tool/spec/common_types_spec.html +++ b/pkg/analyzer_plugin/tool/spec/common_types_spec.html @@ -913,93 +913,6 @@ - -

- This object matches the format and documentation of the Entry object - documented in the - Kythe Storage - Model. -

- - - KytheVName -

- The ticket of the source node. -

-
- - String -

- An edge label. The schema defines which labels are meaningful. -

-
- - KytheVName -

- The ticket of the target node. -

-
- - String -

- A fact label. The schema defines which fact labels are meaningful. -

-
- - - int - -

- The String value of the fact. -

-
-
-
- -

- This object matches the format and documentation of the Vector-Name object - documented in the - Kythe - Storage Model. -

- - - String -

- An opaque signature generated by the analyzer. -

-
- - String -

- The corpus of source code this KytheVName belongs to. - Loosely, a corpus is a collection of related files, such as the - contents of a given source repository. -

-
- - String -

- A corpus-specific root label, typically a directory path or project - identifier, denoting a distinct subset of the corpus. This may also be - used to designate virtual collections like generated files. -

-
- - String -

- A path-structured label describing the “location” of the named object - relative to the corpus and the root. -

-
- - String -

- The language this name belongs to. -

-
-
-

A collection of positions that should be linked (edited simultaneously) diff --git a/pkg/analyzer_plugin/tool/spec/plugin_spec.html b/pkg/analyzer_plugin/tool/spec/plugin_spec.html index e0e59278ab7..006d5f19113 100644 --- a/pkg/analyzer_plugin/tool/spec/plugin_spec.html +++ b/pkg/analyzer_plugin/tool/spec/plugin_spec.html @@ -829,48 +829,6 @@ - -

- The kythe domain contains APIs related to generating Dart content in the - Kythe format. -

- -

- Return the list of KytheEntry objects for some file, given the - current state of the file system populated by "analysis.updateContent". -

- - - FilePath -

- The file containing the code for which the Kythe Entry objects are - being requested. -

-
-
- - - - KytheEntry - -

- The list of KytheEntry objects for the queried file. -

-
- - - FilePath - -

- The set of files paths that were required, but not in the file system, - to give a complete and accurate Kythe graph for the file. This could - be due to a referenced file that does not exist or generated files not - being generated or passed before the call to "getKytheEntries". -

-
-
-
-

Types