Add signature param defaultValue and remove (unused) selectedParameterIndex

Bug: https://github.com/dart-lang/sdk/issues/27034
Change-Id: I3409ab544b79a7f64d6d41e5d091ca20418f248a
Reviewed-on: https://dart-review.googlesource.com/66562
Commit-Queue: Danny Tuppeny <dantup@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Danny Tuppeny 2018-07-25 15:42:44 +00:00 committed by commit-bot@chromium.org
parent e5a58158e3
commit d792809d6f
11 changed files with 143 additions and 67 deletions

View file

@ -100,8 +100,6 @@ const String ANALYSIS_RESPONSE_GET_REACHABLE_SOURCES_SOURCES = 'sources';
const String ANALYSIS_RESPONSE_GET_SIGNATURE_DARTDOC = 'dartdoc';
const String ANALYSIS_RESPONSE_GET_SIGNATURE_NAME = 'name';
const String ANALYSIS_RESPONSE_GET_SIGNATURE_PARAMETERS = 'parameters';
const String ANALYSIS_RESPONSE_GET_SIGNATURE_SELECTED_PARAMETER_INDEX =
'selectedParameterIndex';
const String ANALYTICS_REQUEST_ENABLE = 'analytics.enable';
const String ANALYTICS_REQUEST_ENABLE_VALUE = 'value';
const String ANALYTICS_REQUEST_IS_ENABLED = 'analytics.isEnabled';

View file

@ -2019,7 +2019,6 @@ class AnalysisGetSignatureParams implements RequestParams {
* "name": String
* "dartdoc": optional String
* "parameters": List<ParameterInfo>
* "selectedParameterIndex": int
* }
*
* Clients may not extend, implement or mix-in this class.
@ -2031,8 +2030,6 @@ class AnalysisGetSignatureResult implements ResponseResult {
List<ParameterInfo> _parameters;
int _selectedParameterIndex;
/**
* The name of the function being invoked at the given offset.
*/
@ -2081,28 +2078,11 @@ class AnalysisGetSignatureResult implements ResponseResult {
this._parameters = value;
}
/**
* The index of the paramter in the parameters collection at the specified
* offset.
*/
int get selectedParameterIndex => _selectedParameterIndex;
/**
* The index of the paramter in the parameters collection at the specified
* offset.
*/
void set selectedParameterIndex(int value) {
assert(value != null);
this._selectedParameterIndex = value;
}
AnalysisGetSignatureResult(
String name, List<ParameterInfo> parameters, int selectedParameterIndex,
AnalysisGetSignatureResult(String name, List<ParameterInfo> parameters,
{String dartdoc}) {
this.name = name;
this.dartdoc = dartdoc;
this.parameters = parameters;
this.selectedParameterIndex = selectedParameterIndex;
}
factory AnalysisGetSignatureResult.fromJson(
@ -2132,17 +2112,7 @@ class AnalysisGetSignatureResult implements ResponseResult {
} else {
throw jsonDecoder.mismatch(jsonPath, "parameters");
}
int selectedParameterIndex;
if (json.containsKey("selectedParameterIndex")) {
selectedParameterIndex = jsonDecoder.decodeInt(
jsonPath + ".selectedParameterIndex",
json["selectedParameterIndex"]);
} else {
throw jsonDecoder.mismatch(jsonPath, "selectedParameterIndex");
}
return new AnalysisGetSignatureResult(
name, parameters, selectedParameterIndex,
dartdoc: dartdoc);
return new AnalysisGetSignatureResult(name, parameters, dartdoc: dartdoc);
} else {
throw jsonDecoder.mismatch(
jsonPath, "analysis.getSignature result", json);
@ -2165,7 +2135,6 @@ class AnalysisGetSignatureResult implements ResponseResult {
}
result["parameters"] =
parameters.map((ParameterInfo value) => value.toJson()).toList();
result["selectedParameterIndex"] = selectedParameterIndex;
return result;
}
@ -2183,8 +2152,7 @@ class AnalysisGetSignatureResult implements ResponseResult {
return name == other.name &&
dartdoc == other.dartdoc &&
listEqual(parameters, other.parameters,
(ParameterInfo a, ParameterInfo b) => a == b) &&
selectedParameterIndex == other.selectedParameterIndex;
(ParameterInfo a, ParameterInfo b) => a == b);
}
return false;
}
@ -2195,7 +2163,6 @@ class AnalysisGetSignatureResult implements ResponseResult {
hash = JenkinsSmiHash.combine(hash, name.hashCode);
hash = JenkinsSmiHash.combine(hash, dartdoc.hashCode);
hash = JenkinsSmiHash.combine(hash, parameters.hashCode);
hash = JenkinsSmiHash.combine(hash, selectedParameterIndex.hashCode);
return JenkinsSmiHash.finish(hash);
}
}

View file

@ -61,7 +61,7 @@ class DartUnitSignatureComputer {
final parameters =
execElement.parameters.map((p) => _convertParam(p)).toList();
return new AnalysisGetSignatureResult(name, parameters, 0,
return new AnalysisGetSignatureResult(name, parameters,
dartdoc: DartUnitHoverComputer.computeDocumentation(execElement));
}
@ -71,6 +71,7 @@ class DartUnitSignatureComputer {
? ParameterKind.OPTIONAL
: param.isPositional ? ParameterKind.REQUIRED : ParameterKind.NAMED,
param.displayName,
param.type.displayName);
param.type.displayName,
defaultValue: param.defaultValueCode);
}
}

View file

@ -233,6 +233,46 @@ main() {
equals(new ParameterInfo(ParameterKind.NAMED, "length", "int")));
}
test_function_named_with_default_int() async {
addTestFile('''
/// one doc
one(String name, {int length = 1}) {}
main() {
one("Danny", /*^*/);
}
''');
var result = await prepareSignature('/*^*/');
expect(result.name, equals("one"));
expect(result.dartdoc, equals("one doc"));
expect(result.parameters, hasLength(2));
expect(result.parameters[0],
equals(new ParameterInfo(ParameterKind.REQUIRED, "name", "String")));
expect(
result.parameters[1],
equals(new ParameterInfo(ParameterKind.NAMED, "length", "int",
defaultValue: "1")));
}
test_function_named_with_default_string() async {
addTestFile('''
/// one doc
one(String name, {String email = "a@b.c"}) {}
main() {
one("Danny", /*^*/);
}
''');
var result = await prepareSignature('/*^*/');
expect(result.name, equals("one"));
expect(result.dartdoc, equals("one doc"));
expect(result.parameters, hasLength(2));
expect(result.parameters[0],
equals(new ParameterInfo(ParameterKind.REQUIRED, "name", "String")));
expect(
result.parameters[1],
equals(new ParameterInfo(ParameterKind.NAMED, "email", "String",
defaultValue: '"a@b.c"')));
}
test_function_nested_call_inner() async {
// eg. foo(bar(1, 2));
addTestFile('''
@ -306,6 +346,26 @@ main() {
equals(new ParameterInfo(ParameterKind.OPTIONAL, "length", "int")));
}
test_function_optional_with_default() async {
addTestFile('''
/// one doc
one(String name, [int length = 11]) {}
main() {
one("Danny", /*^*/);
}
''');
var result = await prepareSignature('/*^*/');
expect(result.name, equals("one"));
expect(result.dartdoc, equals("one doc"));
expect(result.parameters, hasLength(2));
expect(result.parameters[0],
equals(new ParameterInfo(ParameterKind.REQUIRED, "name", "String")));
expect(
result.parameters[1],
equals(new ParameterInfo(ParameterKind.OPTIONAL, "length", "int",
defaultValue: "11")));
}
test_function_required() async {
addTestFile('''
/// one doc

View file

@ -448,11 +448,6 @@ abstract class IntegrationTestMixin {
*
* A list of information about each of the parameters of the function being
* invoked.
*
* selectedParameterIndex: int
*
* The index of the paramter in the parameters collection at the specified
* offset.
*/
Future<AnalysisGetSignatureResult> sendAnalysisGetSignature(
String file, int offset) async {

View file

@ -1064,11 +1064,13 @@ final Matcher isOverride =
* "kind": ParameterKind
* "name": String
* "type": String
* "defaultValue": optional String
* }
*/
final Matcher isParameterInfo = new LazyMatcher(() => new MatchesJsonObject(
"ParameterInfo",
{"kind": isParameterKind, "name": isString, "type": isString}));
{"kind": isParameterKind, "name": isString, "type": isString},
optionalFields: {"defaultValue": isString}));
/**
* ParameterKind
@ -1723,17 +1725,12 @@ final Matcher isAnalysisGetSignatureParams = new LazyMatcher(() =>
* "name": String
* "dartdoc": optional String
* "parameters": List<ParameterInfo>
* "selectedParameterIndex": int
* }
*/
final Matcher isAnalysisGetSignatureResult = new LazyMatcher(
() => new MatchesJsonObject("analysis.getSignature result", {
"name": isString,
"parameters": isListOf(isParameterInfo),
"selectedParameterIndex": isInt
}, optionalFields: {
"dartdoc": isString
}));
final Matcher isAnalysisGetSignatureResult = new LazyMatcher(() =>
new MatchesJsonObject("analysis.getSignature result",
{"name": isString, "parameters": isListOf(isParameterInfo)},
optionalFields: {"dartdoc": isString}));
/**
* analysis.highlights params

View file

@ -50,13 +50,20 @@ public class ParameterInfo {
*/
private final String type;
/**
* The default value for this parameter. This value will be omitted if the parameter does not have
* a default value.
*/
private final String defaultValue;
/**
* Constructor for {@link ParameterInfo}.
*/
public ParameterInfo(String kind, String name, String type) {
public ParameterInfo(String kind, String name, String type, String defaultValue) {
this.kind = kind;
this.name = name;
this.type = type;
this.defaultValue = defaultValue;
}
@Override
@ -66,7 +73,8 @@ public class ParameterInfo {
return
ObjectUtilities.equals(other.kind, kind) &&
ObjectUtilities.equals(other.name, name) &&
ObjectUtilities.equals(other.type, type);
ObjectUtilities.equals(other.type, type) &&
ObjectUtilities.equals(other.defaultValue, defaultValue);
}
return false;
}
@ -75,7 +83,8 @@ public class ParameterInfo {
String kind = jsonObject.get("kind").getAsString();
String name = jsonObject.get("name").getAsString();
String type = jsonObject.get("type").getAsString();
return new ParameterInfo(kind, name, type);
String defaultValue = jsonObject.get("defaultValue") == null ? null : jsonObject.get("defaultValue").getAsString();
return new ParameterInfo(kind, name, type, defaultValue);
}
public static List<ParameterInfo> fromJsonArray(JsonArray jsonArray) {
@ -90,6 +99,14 @@ public class ParameterInfo {
return list;
}
/**
* The default value for this parameter. This value will be omitted if the parameter does not have
* a default value.
*/
public String getDefaultValue() {
return defaultValue;
}
/**
* The kind of the parameter.
*/
@ -117,6 +134,7 @@ public class ParameterInfo {
builder.append(kind);
builder.append(name);
builder.append(type);
builder.append(defaultValue);
return builder.toHashCode();
}
@ -125,6 +143,9 @@ public class ParameterInfo {
jsonObject.addProperty("kind", kind);
jsonObject.addProperty("name", name);
jsonObject.addProperty("type", type);
if (defaultValue != null) {
jsonObject.addProperty("defaultValue", defaultValue);
}
return jsonObject;
}
@ -137,7 +158,9 @@ public class ParameterInfo {
builder.append("name=");
builder.append(name + ", ");
builder.append("type=");
builder.append(type);
builder.append(type + ", ");
builder.append("defaultValue=");
builder.append(defaultValue);
builder.append("]");
return builder.toString();
}

View file

@ -709,10 +709,6 @@
</list>
<p>A list of information about each of the parameters of the function being invoked.</p>
</field>
<field name="selectedParameterIndex">
<ref>int</ref>
<p>The index of the paramter in the parameters collection at the specified offset.</p>
</field>
</result>
</request>
<request method="reanalyze">

View file

@ -4585,6 +4585,7 @@ class Outline implements HasToJson {
* "kind": ParameterKind
* "name": String
* "type": String
* "defaultValue": optional String
* }
*
* Clients may not extend, implement or mix-in this class.
@ -4596,6 +4597,8 @@ class ParameterInfo implements HasToJson {
String _type;
String _defaultValue;
/**
* The kind of the parameter.
*/
@ -4635,10 +4638,26 @@ class ParameterInfo implements HasToJson {
this._type = value;
}
ParameterInfo(ParameterKind kind, String name, String type) {
/**
* The default value for this parameter. This value will be omitted if the
* parameter does not have a default value.
*/
String get defaultValue => _defaultValue;
/**
* The default value for this parameter. This value will be omitted if the
* parameter does not have a default value.
*/
void set defaultValue(String value) {
this._defaultValue = value;
}
ParameterInfo(ParameterKind kind, String name, String type,
{String defaultValue}) {
this.kind = kind;
this.name = name;
this.type = type;
this.defaultValue = defaultValue;
}
factory ParameterInfo.fromJson(
@ -4666,7 +4685,12 @@ class ParameterInfo implements HasToJson {
} else {
throw jsonDecoder.mismatch(jsonPath, "type");
}
return new ParameterInfo(kind, name, type);
String defaultValue;
if (json.containsKey("defaultValue")) {
defaultValue = jsonDecoder.decodeString(
jsonPath + ".defaultValue", json["defaultValue"]);
}
return new ParameterInfo(kind, name, type, defaultValue: defaultValue);
} else {
throw jsonDecoder.mismatch(jsonPath, "ParameterInfo", json);
}
@ -4678,6 +4702,9 @@ class ParameterInfo implements HasToJson {
result["kind"] = kind.toJson();
result["name"] = name;
result["type"] = type;
if (defaultValue != null) {
result["defaultValue"] = defaultValue;
}
return result;
}
@ -4687,7 +4714,10 @@ class ParameterInfo implements HasToJson {
@override
bool operator ==(other) {
if (other is ParameterInfo) {
return kind == other.kind && name == other.name && type == other.type;
return kind == other.kind &&
name == other.name &&
type == other.type &&
defaultValue == other.defaultValue;
}
return false;
}
@ -4698,6 +4728,7 @@ class ParameterInfo implements HasToJson {
hash = JenkinsSmiHash.combine(hash, kind.hashCode);
hash = JenkinsSmiHash.combine(hash, name.hashCode);
hash = JenkinsSmiHash.combine(hash, type.hashCode);
hash = JenkinsSmiHash.combine(hash, defaultValue.hashCode);
return JenkinsSmiHash.finish(hash);
}
}

View file

@ -699,11 +699,13 @@ final Matcher isOutline =
* "kind": ParameterKind
* "name": String
* "type": String
* "defaultValue": optional String
* }
*/
final Matcher isParameterInfo = new LazyMatcher(() => new MatchesJsonObject(
"ParameterInfo",
{"kind": isParameterKind, "name": isString, "type": isString}));
{"kind": isParameterKind, "name": isString, "type": isString},
optionalFields: {"defaultValue": isString}));
/**
* ParameterKind

View file

@ -1191,6 +1191,12 @@
The type of the parameter.
</p>
</field>
<field name="defaultValue" optional="true">
<ref>String</ref>
<p>The default value for this parameter. This value will be omitted if the parameter
does not have a default value.
</p>
</field>
</object>
</type>
<type name="ParameterKind" experimental="true">