mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 14:32:24 +00:00
Library Dependencies Analysis service API.
R=brianwilkerson@google.com, scheglov@google.com Review URL: https://codereview.chromium.org//861893003 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@43077 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
8a5429c0a0
commit
03aa9c33e5
8 changed files with 222 additions and 2 deletions
|
@ -363,6 +363,7 @@ dt.typeDefinition {
|
|||
|
||||
|
||||
|
||||
|
||||
<h3>Requests</h3><dl><dt class="request">analysis.getErrors</dt><dd><div class="box"><pre>request: {
|
||||
"id": String
|
||||
"method": "analysis.getErrors"
|
||||
|
@ -457,7 +458,28 @@ dt.typeDefinition {
|
|||
in multiple contexts in conflicting ways (such as a
|
||||
part that is included in multiple libraries).
|
||||
</p>
|
||||
</dd></dl></dd><dt class="request">analysis.getNavigation</dt><dd><div class="box"><pre>request: {
|
||||
</dd></dl></dd><dt class="request">analysis.getLibraryDependencies</dt><dd><div class="box"><pre>request: {
|
||||
"id": String
|
||||
"method": "analysis.getLibraryDependencies"
|
||||
}</pre><br><pre>response: {
|
||||
"id": String
|
||||
"error": <span style="color:#999999">optional</span> <a href="#type_RequestError">RequestError</a>
|
||||
"result": {
|
||||
"<b>libraries</b>": List<<a href="#type_FilePath">FilePath</a>>
|
||||
}
|
||||
}</pre></div>
|
||||
<p>
|
||||
Return a list of all of the libraries referenced by any files in
|
||||
existing analysis roots.
|
||||
</p>
|
||||
|
||||
<h4>Returns</h4><dl><dt class="field"><b><i>libraries ( List<<a href="#type_FilePath">FilePath</a>> )</i></b></dt><dd>
|
||||
|
||||
<p>
|
||||
A list of the paths of library elements referenced by
|
||||
files in existing analysis roots.
|
||||
</p>
|
||||
</dd></dl></dd><dt class="request">analysis.getNavigation</dt><dd><div class="box"><pre>request: {
|
||||
"id": String
|
||||
"method": "analysis.getNavigation"
|
||||
"params": {
|
||||
|
|
|
@ -23,6 +23,8 @@ const String SERVER_STATUS = 'server.status';
|
|||
//
|
||||
const String ANALYSIS_GET_ERRORS = 'analysis.getErrors';
|
||||
const String ANALYSIS_GET_HOVER = 'analysis.getHover';
|
||||
const String ANALYSIS_GET_LIBRARY_DEPENDENCIES =
|
||||
'analysis.getLibraryDependencies';
|
||||
const String ANALYSIS_REANALYZE = 'analysis.reanalyze';
|
||||
const String ANALYSIS_SET_ANALYSIS_ROOTS = 'analysis.setAnalysisRoots';
|
||||
const String ANALYSIS_SET_PRIORITY_FILES = 'analysis.setPriorityFiles';
|
||||
|
@ -56,7 +58,8 @@ const String COMPLETION_RESULTS = 'completion.results';
|
|||
const String SEARCH_FIND_ELEMENT_REFERENCES = 'search.findElementReferences';
|
||||
const String SEARCH_FIND_MEMBER_DECLARATIONS = 'search.findMemberDeclarations';
|
||||
const String SEARCH_FIND_MEMBER_REFERENCES = 'search.findMemberReferences';
|
||||
const String SEARCH_FIND_TOP_LEVEL_DECLARATIONS = 'search.findTopLevelDeclarations';
|
||||
const String SEARCH_FIND_TOP_LEVEL_DECLARATIONS =
|
||||
'search.findTopLevelDeclarations';
|
||||
const String SEARCH_GET_TYPE_HIERARCHY = 'search.getTypeHierarchy';
|
||||
|
||||
//
|
||||
|
|
|
@ -10,6 +10,7 @@ import 'package:analysis_server/src/analysis_server.dart';
|
|||
import 'package:analysis_server/src/computer/computer_hover.dart';
|
||||
import 'package:analysis_server/src/constants.dart';
|
||||
import 'package:analysis_server/src/protocol_server.dart';
|
||||
import 'package:analysis_server/src/services/dependencies/library_dependencies.dart';
|
||||
import 'package:analyzer/src/generated/ast.dart';
|
||||
import 'package:analyzer/src/generated/engine.dart' as engine;
|
||||
|
||||
|
@ -87,6 +88,14 @@ class AnalysisDomainHandler implements RequestHandler {
|
|||
return new AnalysisGetHoverResult(hovers).toResponse(request.id);
|
||||
}
|
||||
|
||||
/// Implement the `analysis.getLibraryDependencies` request.
|
||||
Response getLibraryDependencies(Request request) {
|
||||
Set<String> libraries = new LibraryDependencyCollector(
|
||||
server.getAnalysisContexts()).collectLibraryDependencies();
|
||||
return new AnalysisGetLibraryDependenciesResult(
|
||||
libraries.toList(growable: false)).toResponse(request.id);
|
||||
}
|
||||
|
||||
@override
|
||||
Response handleRequest(Request request) {
|
||||
try {
|
||||
|
@ -95,6 +104,8 @@ class AnalysisDomainHandler implements RequestHandler {
|
|||
return getErrors(request);
|
||||
} else if (requestName == ANALYSIS_GET_HOVER) {
|
||||
return getHover(request);
|
||||
} else if (requestName == ANALYSIS_GET_LIBRARY_DEPENDENCIES) {
|
||||
return getLibraryDependencies(request);
|
||||
} else if (requestName == ANALYSIS_REANALYZE) {
|
||||
return reanalyze(request);
|
||||
} else if (requestName == ANALYSIS_SET_ANALYSIS_ROOTS) {
|
||||
|
|
|
@ -708,6 +708,94 @@ class AnalysisGetHoverResult implements HasToJson {
|
|||
return _JenkinsSmiHash.finish(hash);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* analysis.getLibraryDependencies params
|
||||
*/
|
||||
class AnalysisGetLibraryDependenciesParams {
|
||||
Request toRequest(String id) {
|
||||
return new Request(id, "analysis.getLibraryDependencies", null);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator==(other) {
|
||||
if (other is AnalysisGetLibraryDependenciesParams) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return 246577680;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* analysis.getLibraryDependencies result
|
||||
*
|
||||
* {
|
||||
* "libraries": List<FilePath>
|
||||
* }
|
||||
*/
|
||||
class AnalysisGetLibraryDependenciesResult implements HasToJson {
|
||||
/**
|
||||
* A list of the paths of library elements referenced by files in existing
|
||||
* analysis roots.
|
||||
*/
|
||||
List<String> libraries;
|
||||
|
||||
AnalysisGetLibraryDependenciesResult(this.libraries);
|
||||
|
||||
factory AnalysisGetLibraryDependenciesResult.fromJson(JsonDecoder jsonDecoder, String jsonPath, Object json) {
|
||||
if (json == null) {
|
||||
json = {};
|
||||
}
|
||||
if (json is Map) {
|
||||
List<String> libraries;
|
||||
if (json.containsKey("libraries")) {
|
||||
libraries = jsonDecoder._decodeList(jsonPath + ".libraries", json["libraries"], jsonDecoder._decodeString);
|
||||
} else {
|
||||
throw jsonDecoder.missingKey(jsonPath, "libraries");
|
||||
}
|
||||
return new AnalysisGetLibraryDependenciesResult(libraries);
|
||||
} else {
|
||||
throw jsonDecoder.mismatch(jsonPath, "analysis.getLibraryDependencies result");
|
||||
}
|
||||
}
|
||||
|
||||
factory AnalysisGetLibraryDependenciesResult.fromResponse(Response response) {
|
||||
return new AnalysisGetLibraryDependenciesResult.fromJson(
|
||||
new ResponseDecoder(REQUEST_ID_REFACTORING_KINDS.remove(response.id)), "result", response._result);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
Map<String, dynamic> result = {};
|
||||
result["libraries"] = libraries;
|
||||
return result;
|
||||
}
|
||||
|
||||
Response toResponse(String id) {
|
||||
return new Response(id, result: toJson());
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() => JSON.encode(toJson());
|
||||
|
||||
@override
|
||||
bool operator==(other) {
|
||||
if (other is AnalysisGetLibraryDependenciesResult) {
|
||||
return _listEqual(libraries, other.libraries, (String a, String b) => a == b);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
int hash = 0;
|
||||
hash = _JenkinsSmiHash.combine(hash, libraries.hashCode);
|
||||
return _JenkinsSmiHash.finish(hash);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* analysis.getNavigation params
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
// Copyright (c) 2015, 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.
|
||||
|
||||
library services.dependencies.library;
|
||||
|
||||
import 'package:analyzer/src/generated/element.dart';
|
||||
import 'package:analyzer/src/generated/engine.dart';
|
||||
import 'package:analyzer/src/generated/source.dart';
|
||||
|
||||
class LibraryDependencyCollector {
|
||||
|
||||
final Set<LibraryElement> _visitedLibraries = new Set<LibraryElement>();
|
||||
final Set<String> _dependencies = new Set<String>();
|
||||
|
||||
final List<AnalysisContext> _contexts;
|
||||
|
||||
LibraryDependencyCollector(this._contexts);
|
||||
|
||||
Set<String> collectLibraryDependencies() {
|
||||
_contexts.forEach(
|
||||
(AnalysisContext context) =>
|
||||
context.librarySources.forEach(
|
||||
(Source source) => _addDependencies(context.getLibraryElement(source))));
|
||||
return _dependencies;
|
||||
}
|
||||
|
||||
void _addDependencies(LibraryElement libraryElement) {
|
||||
if (libraryElement == null) {
|
||||
return;
|
||||
}
|
||||
if (_visitedLibraries.add(libraryElement)) {
|
||||
for (CompilationUnitElement cu in libraryElement.units) {
|
||||
String path = cu.source.fullName;
|
||||
if (path != null) {
|
||||
_dependencies.add(path);
|
||||
}
|
||||
}
|
||||
libraryElement.imports.forEach(
|
||||
(ImportElement import) => _addDependencies(import.importedLibrary));
|
||||
libraryElement.exports.forEach(
|
||||
(ExportElement export) => _addDependencies(export.exportedLibrary));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -230,6 +230,25 @@ abstract class IntegrationTestMixin {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of all of the libraries referenced by any files in existing
|
||||
* analysis roots.
|
||||
*
|
||||
* Returns
|
||||
*
|
||||
* libraries ( List<FilePath> )
|
||||
*
|
||||
* A list of the paths of library elements referenced by files in existing
|
||||
* analysis roots.
|
||||
*/
|
||||
Future<AnalysisGetLibraryDependenciesResult> sendAnalysisGetLibraryDependencies() {
|
||||
return server.send("analysis.getLibraryDependencies", null)
|
||||
.then((result) {
|
||||
ResponseDecoder decoder = new ResponseDecoder(null);
|
||||
return new AnalysisGetLibraryDependenciesResult.fromJson(decoder, 'result', result);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the navigation information associated with the given region of the
|
||||
* given file. If the navigation information for the given file has not yet
|
||||
|
|
|
@ -145,6 +145,23 @@ final Matcher isAnalysisGetHoverResult = new LazyMatcher(() => new MatchesJsonOb
|
|||
"hovers": isListOf(isHoverInformation)
|
||||
}));
|
||||
|
||||
/**
|
||||
* analysis.getLibraryDependencies params
|
||||
*/
|
||||
final Matcher isAnalysisGetLibraryDependenciesParams = isNull;
|
||||
|
||||
/**
|
||||
* analysis.getLibraryDependencies result
|
||||
*
|
||||
* {
|
||||
* "libraries": List<FilePath>
|
||||
* }
|
||||
*/
|
||||
final Matcher isAnalysisGetLibraryDependenciesResult = new LazyMatcher(() => new MatchesJsonObject(
|
||||
"analysis.getLibraryDependencies result", {
|
||||
"libraries": isListOf(isFilePath)
|
||||
}));
|
||||
|
||||
/**
|
||||
* analysis.getNavigation params
|
||||
*
|
||||
|
|
|
@ -359,6 +359,21 @@
|
|||
</field>
|
||||
</result>
|
||||
</request>
|
||||
<request method="getLibraryDependencies">
|
||||
<p>
|
||||
Return a list of all of the libraries referenced by any files in
|
||||
existing analysis roots.
|
||||
</p>
|
||||
<result>
|
||||
<field name="libraries">
|
||||
<list><ref>FilePath</ref></list>
|
||||
<p>
|
||||
A list of the paths of library elements referenced by
|
||||
files in existing analysis roots.
|
||||
</p>
|
||||
</field>
|
||||
</result>
|
||||
</request>
|
||||
<request method="getNavigation">
|
||||
<p>
|
||||
Return the navigation information associated with the given region of
|
||||
|
|
Loading…
Reference in a new issue