Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 6e25b9b

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Add flutter.getChangeAddForDesignTimeConstructor to API.
R=brianwilkerson@google.com Change-Id: I91e40c447d32e603026de337ec2d36983174a8cd Reviewed-on: https://dart-review.googlesource.com/49826 Commit-Queue: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
1 parent a6bd6fe commit 6e25b9b

File tree

8 files changed

+352
-1
lines changed

8 files changed

+352
-1
lines changed

pkg/analysis_server/lib/protocol/protocol_constants.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,17 @@ const String FLUTTER_NOTIFICATION_OUTLINE_FILE = 'file';
211211
const String FLUTTER_NOTIFICATION_OUTLINE_INSTRUMENTED_CODE =
212212
'instrumentedCode';
213213
const String FLUTTER_NOTIFICATION_OUTLINE_OUTLINE = 'outline';
214+
const String FLUTTER_REQUEST_GET_CHANGE_ADD_FOR_DESIGN_TIME_CONSTRUCTOR =
215+
'flutter.getChangeAddForDesignTimeConstructor';
216+
const String FLUTTER_REQUEST_GET_CHANGE_ADD_FOR_DESIGN_TIME_CONSTRUCTOR_FILE =
217+
'file';
218+
const String FLUTTER_REQUEST_GET_CHANGE_ADD_FOR_DESIGN_TIME_CONSTRUCTOR_OFFSET =
219+
'offset';
214220
const String FLUTTER_REQUEST_SET_SUBSCRIPTIONS = 'flutter.setSubscriptions';
215221
const String FLUTTER_REQUEST_SET_SUBSCRIPTIONS_SUBSCRIPTIONS = 'subscriptions';
222+
const String
223+
FLUTTER_RESPONSE_GET_CHANGE_ADD_FOR_DESIGN_TIME_CONSTRUCTOR_CHANGE =
224+
'change';
216225
const String KYTHE_REQUEST_GET_KYTHE_ENTRIES = 'kythe.getKytheEntries';
217226
const String KYTHE_REQUEST_GET_KYTHE_ENTRIES_FILE = 'file';
218227
const String KYTHE_RESPONSE_GET_KYTHE_ENTRIES_ENTRIES = 'entries';

pkg/analysis_server/lib/protocol/protocol_generated.dart

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11071,6 +11071,210 @@ class FileKind implements Enum {
1107111071
String toJson() => name;
1107211072
}
1107311073

11074+
/**
11075+
* flutter.getChangeAddForDesignTimeConstructor params
11076+
*
11077+
* {
11078+
* "file": FilePath
11079+
* "offset": int
11080+
* }
11081+
*
11082+
* Clients may not extend, implement or mix-in this class.
11083+
*/
11084+
class FlutterGetChangeAddForDesignTimeConstructorParams
11085+
implements RequestParams {
11086+
String _file;
11087+
11088+
int _offset;
11089+
11090+
/**
11091+
* The file containing the code of the class.
11092+
*/
11093+
String get file => _file;
11094+
11095+
/**
11096+
* The file containing the code of the class.
11097+
*/
11098+
void set file(String value) {
11099+
assert(value != null);
11100+
this._file = value;
11101+
}
11102+
11103+
/**
11104+
* The offset of the class in the code.
11105+
*/
11106+
int get offset => _offset;
11107+
11108+
/**
11109+
* The offset of the class in the code.
11110+
*/
11111+
void set offset(int value) {
11112+
assert(value != null);
11113+
this._offset = value;
11114+
}
11115+
11116+
FlutterGetChangeAddForDesignTimeConstructorParams(String file, int offset) {
11117+
this.file = file;
11118+
this.offset = offset;
11119+
}
11120+
11121+
factory FlutterGetChangeAddForDesignTimeConstructorParams.fromJson(
11122+
JsonDecoder jsonDecoder, String jsonPath, Object json) {
11123+
if (json == null) {
11124+
json = {};
11125+
}
11126+
if (json is Map) {
11127+
String file;
11128+
if (json.containsKey("file")) {
11129+
file = jsonDecoder.decodeString(jsonPath + ".file", json["file"]);
11130+
} else {
11131+
throw jsonDecoder.mismatch(jsonPath, "file");
11132+
}
11133+
int offset;
11134+
if (json.containsKey("offset")) {
11135+
offset = jsonDecoder.decodeInt(jsonPath + ".offset", json["offset"]);
11136+
} else {
11137+
throw jsonDecoder.mismatch(jsonPath, "offset");
11138+
}
11139+
return new FlutterGetChangeAddForDesignTimeConstructorParams(
11140+
file, offset);
11141+
} else {
11142+
throw jsonDecoder.mismatch(jsonPath,
11143+
"flutter.getChangeAddForDesignTimeConstructor params", json);
11144+
}
11145+
}
11146+
11147+
factory FlutterGetChangeAddForDesignTimeConstructorParams.fromRequest(
11148+
Request request) {
11149+
return new FlutterGetChangeAddForDesignTimeConstructorParams.fromJson(
11150+
new RequestDecoder(request), "params", request.params);
11151+
}
11152+
11153+
@override
11154+
Map<String, dynamic> toJson() {
11155+
Map<String, dynamic> result = {};
11156+
result["file"] = file;
11157+
result["offset"] = offset;
11158+
return result;
11159+
}
11160+
11161+
@override
11162+
Request toRequest(String id) {
11163+
return new Request(
11164+
id, "flutter.getChangeAddForDesignTimeConstructor", toJson());
11165+
}
11166+
11167+
@override
11168+
String toString() => json.encode(toJson());
11169+
11170+
@override
11171+
bool operator ==(other) {
11172+
if (other is FlutterGetChangeAddForDesignTimeConstructorParams) {
11173+
return file == other.file && offset == other.offset;
11174+
}
11175+
return false;
11176+
}
11177+
11178+
@override
11179+
int get hashCode {
11180+
int hash = 0;
11181+
hash = JenkinsSmiHash.combine(hash, file.hashCode);
11182+
hash = JenkinsSmiHash.combine(hash, offset.hashCode);
11183+
return JenkinsSmiHash.finish(hash);
11184+
}
11185+
}
11186+
11187+
/**
11188+
* flutter.getChangeAddForDesignTimeConstructor result
11189+
*
11190+
* {
11191+
* "change": SourceChange
11192+
* }
11193+
*
11194+
* Clients may not extend, implement or mix-in this class.
11195+
*/
11196+
class FlutterGetChangeAddForDesignTimeConstructorResult
11197+
implements ResponseResult {
11198+
SourceChange _change;
11199+
11200+
/**
11201+
* The change that adds the forDesignTime() constructor. If the change cannot
11202+
* be produced, an error is returned.
11203+
*/
11204+
SourceChange get change => _change;
11205+
11206+
/**
11207+
* The change that adds the forDesignTime() constructor. If the change cannot
11208+
* be produced, an error is returned.
11209+
*/
11210+
void set change(SourceChange value) {
11211+
assert(value != null);
11212+
this._change = value;
11213+
}
11214+
11215+
FlutterGetChangeAddForDesignTimeConstructorResult(SourceChange change) {
11216+
this.change = change;
11217+
}
11218+
11219+
factory FlutterGetChangeAddForDesignTimeConstructorResult.fromJson(
11220+
JsonDecoder jsonDecoder, String jsonPath, Object json) {
11221+
if (json == null) {
11222+
json = {};
11223+
}
11224+
if (json is Map) {
11225+
SourceChange change;
11226+
if (json.containsKey("change")) {
11227+
change = new SourceChange.fromJson(
11228+
jsonDecoder, jsonPath + ".change", json["change"]);
11229+
} else {
11230+
throw jsonDecoder.mismatch(jsonPath, "change");
11231+
}
11232+
return new FlutterGetChangeAddForDesignTimeConstructorResult(change);
11233+
} else {
11234+
throw jsonDecoder.mismatch(jsonPath,
11235+
"flutter.getChangeAddForDesignTimeConstructor result", json);
11236+
}
11237+
}
11238+
11239+
factory FlutterGetChangeAddForDesignTimeConstructorResult.fromResponse(
11240+
Response response) {
11241+
return new FlutterGetChangeAddForDesignTimeConstructorResult.fromJson(
11242+
new ResponseDecoder(REQUEST_ID_REFACTORING_KINDS.remove(response.id)),
11243+
"result",
11244+
response.result);
11245+
}
11246+
11247+
@override
11248+
Map<String, dynamic> toJson() {
11249+
Map<String, dynamic> result = {};
11250+
result["change"] = change.toJson();
11251+
return result;
11252+
}
11253+
11254+
@override
11255+
Response toResponse(String id) {
11256+
return new Response(id, result: toJson());
11257+
}
11258+
11259+
@override
11260+
String toString() => json.encode(toJson());
11261+
11262+
@override
11263+
bool operator ==(other) {
11264+
if (other is FlutterGetChangeAddForDesignTimeConstructorResult) {
11265+
return change == other.change;
11266+
}
11267+
return false;
11268+
}
11269+
11270+
@override
11271+
int get hashCode {
11272+
int hash = 0;
11273+
hash = JenkinsSmiHash.combine(hash, change.hashCode);
11274+
return JenkinsSmiHash.finish(hash);
11275+
}
11276+
}
11277+
1107411278
/**
1107511279
* FlutterOutline
1107611280
*

pkg/analysis_server/lib/src/flutter/flutter_domain.dart

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'dart:core';
5+
import 'dart:async';
66

77
import 'package:analysis_server/protocol/protocol_constants.dart';
88
import 'package:analysis_server/src/analysis_server.dart';
99
import 'package:analysis_server/src/domain_abstract.dart';
10+
import 'package:analysis_server/src/flutter/flutter_correction.dart';
1011
import 'package:analysis_server/src/protocol/protocol_internal.dart';
1112
import 'package:analysis_server/src/protocol_server.dart';
13+
import 'package:analyzer/dart/analysis/results.dart';
1214

1315
/**
1416
* A [RequestHandler] that handles requests in the `flutter` domain.
@@ -23,6 +25,11 @@ class FlutterDomainHandler extends AbstractRequestHandler {
2325
Response handleRequest(Request request) {
2426
try {
2527
String requestName = request.method;
28+
if (requestName ==
29+
FLUTTER_REQUEST_GET_CHANGE_ADD_FOR_DESIGN_TIME_CONSTRUCTOR) {
30+
getChangeAddForDesignTimeConstructor(request);
31+
return Response.DELAYED_RESPONSE;
32+
}
2633
if (requestName == FLUTTER_REQUEST_SET_SUBSCRIPTIONS) {
2734
return setSubscriptions(request);
2835
}
@@ -42,4 +49,35 @@ class FlutterDomainHandler extends AbstractRequestHandler {
4249
server.setFlutterSubscriptions(subMap);
4350
return new FlutterSetSubscriptionsResult().toResponse(request.id);
4451
}
52+
53+
/**
54+
* Implement the 'flutter.getChangeAddForDesignTimeConstructor' request.
55+
*/
56+
Future getChangeAddForDesignTimeConstructor(Request request) async {
57+
var params =
58+
new FlutterGetChangeAddForDesignTimeConstructorParams.fromRequest(
59+
request);
60+
String file = params.file;
61+
int offset = params.offset;
62+
63+
ResolveResult result = await server.getAnalysisResult(file);
64+
if (result != null) {
65+
var corrections = new FlutterCorrections(
66+
file: file,
67+
fileContent: result.content,
68+
selectionOffset: offset,
69+
selectionLength: 0,
70+
session: result.session,
71+
unit: result.unit);
72+
SourceChange change = await corrections.addForDesignTimeConstructor();
73+
if (change != null) {
74+
server.sendResponse(
75+
new FlutterGetChangeAddForDesignTimeConstructorResult(change)
76+
.toResponse(request.id));
77+
return;
78+
}
79+
}
80+
server.sendResponse(
81+
new Response.invalidParameter(request, 'file', 'No change'));
82+
}
4583
}

pkg/analysis_server/test/integration/coverage.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,6 @@ server calls. This file is validated by `coverage_test.dart`.
8484
- [x] kythe.getKytheEntries
8585

8686
## flutter domain
87+
- [ ] flutter.getChangeAddForDesignTimeConstructor
8788
- [ ] flutter.setSubscriptions
8889
- [ ] flutter.outline

pkg/analysis_server/test/integration/support/integration_test_methods.dart

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,6 +2117,40 @@ abstract class IntegrationTestMixin {
21172117
return new KytheGetKytheEntriesResult.fromJson(decoder, 'result', result);
21182118
}
21192119

2120+
/**
2121+
* Return the change that adds the forDesignTime() constructor for the widget
2122+
* class at the given offset.
2123+
*
2124+
* Parameters
2125+
*
2126+
* file: FilePath
2127+
*
2128+
* The file containing the code of the class.
2129+
*
2130+
* offset: int
2131+
*
2132+
* The offset of the class in the code.
2133+
*
2134+
* Returns
2135+
*
2136+
* change: SourceChange
2137+
*
2138+
* The change that adds the forDesignTime() constructor. If the change
2139+
* cannot be produced, an error is returned.
2140+
*/
2141+
Future<FlutterGetChangeAddForDesignTimeConstructorResult>
2142+
sendFlutterGetChangeAddForDesignTimeConstructor(
2143+
String file, int offset) async {
2144+
var params =
2145+
new FlutterGetChangeAddForDesignTimeConstructorParams(file, offset)
2146+
.toJson();
2147+
var result = await server.send(
2148+
"flutter.getChangeAddForDesignTimeConstructor", params);
2149+
ResponseDecoder decoder = new ResponseDecoder(null);
2150+
return new FlutterGetChangeAddForDesignTimeConstructorResult.fromJson(
2151+
decoder, 'result', result);
2152+
}
2153+
21202154
/**
21212155
* Subscribe for services that are specific to individual files. All previous
21222156
* subscriptions are replaced by the current set of subscriptions. If a given

pkg/analysis_server/test/integration/support/protocol_matchers.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,6 +2485,31 @@ final Matcher isExtractWidgetFeedback = new LazyMatcher(
24852485
final Matcher isExtractWidgetOptions = new LazyMatcher(
24862486
() => new MatchesJsonObject("extractWidget options", {"name": isString}));
24872487

2488+
/**
2489+
* flutter.getChangeAddForDesignTimeConstructor params
2490+
*
2491+
* {
2492+
* "file": FilePath
2493+
* "offset": int
2494+
* }
2495+
*/
2496+
final Matcher isFlutterGetChangeAddForDesignTimeConstructorParams =
2497+
new LazyMatcher(() => new MatchesJsonObject(
2498+
"flutter.getChangeAddForDesignTimeConstructor params",
2499+
{"file": isFilePath, "offset": isInt}));
2500+
2501+
/**
2502+
* flutter.getChangeAddForDesignTimeConstructor result
2503+
*
2504+
* {
2505+
* "change": SourceChange
2506+
* }
2507+
*/
2508+
final Matcher isFlutterGetChangeAddForDesignTimeConstructorResult =
2509+
new LazyMatcher(() => new MatchesJsonObject(
2510+
"flutter.getChangeAddForDesignTimeConstructor result",
2511+
{"change": isSourceChange}));
2512+
24882513
/**
24892514
* flutter.outline params
24902515
*

pkg/analysis_server/tool/spec/generated/java/AnalysisServer.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,17 @@ public interface AnalysisServer {
618618
*/
619619
public void execution_setSubscriptions(List<String> subscriptions);
620620

621+
/**
622+
* {@code flutter.getChangeAddForDesignTimeConstructor}
623+
*
624+
* Return the change that adds the forDesignTime() constructor for the widget class at the given
625+
* offset.
626+
*
627+
* @param file The file containing the code of the class.
628+
* @param offset The offset of the class in the code.
629+
*/
630+
public void flutter_getChangeAddForDesignTimeConstructor(String file, int offset, GetChangeAddForDesignTimeConstructorConsumer consumer);
631+
621632
/**
622633
* {@code flutter.setSubscriptions}
623634
*

0 commit comments

Comments
 (0)