Add fields codeOffset/codeLength to FlutterOutline.

R=brianwilkerson@google.com

Change-Id: I917a780704882fcd7537a9334febc21098aabd4f
Reviewed-on: https://dart-review.googlesource.com/46579
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2018-03-15 21:01:14 +00:00 committed by commit-bot@chromium.org
parent 02ac20deb0
commit 64e092d4a3
8 changed files with 167 additions and 19 deletions

View file

@ -109,7 +109,7 @@ a:focus, a:hover {
<body>
<h1>Analysis Server API Specification</h1>
<h1 style="color:#999999">Version
1.19.0
1.20.0
</h1>
<p>
This document contains a specification of the API provided by the

View file

@ -10952,6 +10952,8 @@ class FileKind implements Enum {
* "kind": FlutterOutlineKind
* "offset": int
* "length": int
* "codeOffset": int
* "codeLength": int
* "label": optional String
* "dartElement": optional Element
* "attributes": optional List<FlutterOutlineAttribute>
@ -10974,6 +10976,10 @@ class FlutterOutline implements HasToJson {
int _length;
int _codeOffset;
int _codeLength;
String _label;
Element _dartElement;
@ -11041,6 +11047,34 @@ class FlutterOutline implements HasToJson {
this._length = value;
}
/**
* The offset of the first character of the element code, which is neither
* documentation, nor annotation.
*/
int get codeOffset => _codeOffset;
/**
* The offset of the first character of the element code, which is neither
* documentation, nor annotation.
*/
void set codeOffset(int value) {
assert(value != null);
this._codeOffset = value;
}
/**
* The length of the element code.
*/
int get codeLength => _codeLength;
/**
* The length of the element code.
*/
void set codeLength(int value) {
assert(value != null);
this._codeLength = value;
}
/**
* The text label of the node children of the node. It is provided for any
* FlutterOutlineKind.GENERIC node, where better information is not
@ -11206,6 +11240,7 @@ class FlutterOutline implements HasToJson {
}
FlutterOutline(FlutterOutlineKind kind, int offset, int length,
int codeOffset, int codeLength,
{String label,
Element dartElement,
List<FlutterOutlineAttribute> attributes,
@ -11220,6 +11255,8 @@ class FlutterOutline implements HasToJson {
this.kind = kind;
this.offset = offset;
this.length = length;
this.codeOffset = codeOffset;
this.codeLength = codeLength;
this.label = label;
this.dartElement = dartElement;
this.attributes = attributes;
@ -11258,6 +11295,20 @@ class FlutterOutline implements HasToJson {
} else {
throw jsonDecoder.mismatch(jsonPath, "length");
}
int codeOffset;
if (json.containsKey("codeOffset")) {
codeOffset =
jsonDecoder.decodeInt(jsonPath + ".codeOffset", json["codeOffset"]);
} else {
throw jsonDecoder.mismatch(jsonPath, "codeOffset");
}
int codeLength;
if (json.containsKey("codeLength")) {
codeLength =
jsonDecoder.decodeInt(jsonPath + ".codeLength", json["codeLength"]);
} else {
throw jsonDecoder.mismatch(jsonPath, "codeLength");
}
String label;
if (json.containsKey("label")) {
label = jsonDecoder.decodeString(jsonPath + ".label", json["label"]);
@ -11319,7 +11370,7 @@ class FlutterOutline implements HasToJson {
stateLength = jsonDecoder.decodeInt(
jsonPath + ".stateLength", json["stateLength"]);
}
return new FlutterOutline(kind, offset, length,
return new FlutterOutline(kind, offset, length, codeOffset, codeLength,
label: label,
dartElement: dartElement,
attributes: attributes,
@ -11342,6 +11393,8 @@ class FlutterOutline implements HasToJson {
result["kind"] = kind.toJson();
result["offset"] = offset;
result["length"] = length;
result["codeOffset"] = codeOffset;
result["codeLength"] = codeLength;
if (label != null) {
result["label"] = label;
}
@ -11390,6 +11443,8 @@ class FlutterOutline implements HasToJson {
return kind == other.kind &&
offset == other.offset &&
length == other.length &&
codeOffset == other.codeOffset &&
codeLength == other.codeLength &&
label == other.label &&
dartElement == other.dartElement &&
listEqual(
@ -11416,6 +11471,8 @@ class FlutterOutline implements HasToJson {
hash = JenkinsSmiHash.combine(hash, kind.hashCode);
hash = JenkinsSmiHash.combine(hash, offset.hashCode);
hash = JenkinsSmiHash.combine(hash, length.hashCode);
hash = JenkinsSmiHash.combine(hash, codeOffset.hashCode);
hash = JenkinsSmiHash.combine(hash, codeLength.hashCode);
hash = JenkinsSmiHash.combine(hash, label.hashCode);
hash = JenkinsSmiHash.combine(hash, dartElement.hashCode);
hash = JenkinsSmiHash.combine(hash, attributes.hashCode);

View file

@ -108,7 +108,7 @@ class AnalysisServer {
* The version of the analysis server. The value should be replaced
* automatically during the build.
*/
static final String VERSION = '1.19.0';
static final String VERSION = '1.20.0';
/**
* The options of this server instance.

View file

@ -135,6 +135,8 @@ T _registerWidgetInstance<T extends Widget>(int id, T widget) {
protocol.FlutterOutlineKind.DART_ELEMENT,
dartOutline.offset,
dartOutline.length,
dartOutline.codeOffset,
dartOutline.codeLength,
dartElement: dartOutline.element);
if (dartOutline.children != null) {
flutterOutline.children = dartOutline.children.map(_convert).toList();
@ -206,7 +208,11 @@ T _registerWidgetInstance<T extends Widget>(int id, T widget) {
}
return new protocol.FlutterOutline(
protocol.FlutterOutlineKind.NEW_INSTANCE, node.offset, node.length,
protocol.FlutterOutlineKind.NEW_INSTANCE,
node.offset,
node.length,
node.offset,
node.length,
className: className,
attributes: attributes,
children: children,
@ -229,7 +235,8 @@ T _registerWidgetInstance<T extends Widget>(int id, T widget) {
}
int id = _addInstrumentationEdits(node);
return new protocol.FlutterOutline(kind, node.offset, node.length,
return new protocol.FlutterOutline(
kind, node.offset, node.length, node.offset, node.length,
className: className,
variableName: variableName,
label: label,

View file

@ -477,6 +477,8 @@ final Matcher isFilePath = isString;
* "kind": FlutterOutlineKind
* "offset": int
* "length": int
* "codeOffset": int
* "codeLength": int
* "label": optional String
* "dartElement": optional Element
* "attributes": optional List<FlutterOutlineAttribute>
@ -494,7 +496,9 @@ final Matcher isFlutterOutline =
new LazyMatcher(() => new MatchesJsonObject("FlutterOutline", {
"kind": isFlutterOutlineKind,
"offset": isInt,
"length": isInt
"length": isInt,
"codeOffset": isInt,
"codeLength": isInt
}, optionalFields: {
"label": isString,
"dartElement": isElement,

View file

@ -8,7 +8,6 @@ import 'package:analysis_server/src/flutter/flutter_outline_computer.dart';
import 'package:analysis_server/src/protocol_server.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/dart/analysis/driver.dart';
import 'package:meta/meta.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
@ -183,24 +182,58 @@ class MyWidget extends StatelessWidget {
{
int offset = testCode.indexOf('new Column');
int length = testCode.indexOf('; // Column') - offset;
_expect(columnOutline, offset: offset, length: length);
expect(columnOutline.offset, offset);
expect(columnOutline.length, length);
}
{
var textOutline = columnOutline.children[0];
String text = "const Text('aaa')";
int offset = testCode.indexOf(text);
_expect(textOutline, offset: offset, length: text.length);
expect(textOutline.offset, offset);
expect(textOutline.length, text.length);
}
{
var textOutline = columnOutline.children[1];
String text = "const Text('bbb')";
int offset = testCode.indexOf(text);
_expect(textOutline, offset: offset, length: text.length);
expect(textOutline.offset, offset);
expect(textOutline.length, text.length);
}
}
test_codeOffsetLength() async {
FlutterOutline unitOutline = await _computeOutline('''
import 'package:flutter/widgets.dart';
/// Comment
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Container();
}
}
''');
var myWidget = unitOutline.children[0];
expect(myWidget.offset, 40);
expect(myWidget.length, 137);
expect(myWidget.codeOffset, 52);
expect(myWidget.codeLength, 125);
var build = myWidget.children[0];
expect(build.offset, 95);
expect(build.length, 80);
expect(build.codeOffset, 107);
expect(build.codeLength, 68);
var container = build.children[0];
expect(container.offset, 155);
expect(container.length, 15);
expect(container.codeOffset, 155);
expect(container.codeLength, 15);
}
test_genericLabel_invocation() async {
FlutterOutline unitOutline = await _computeOutline(r'''
import 'package:flutter/widgets.dart';
@ -492,12 +525,6 @@ class MyWidget extends StatelessWidget {
return computer.compute();
}
void _expect(FlutterOutline outline,
{@required int offset, @required int length}) {
expect(outline.offset, offset);
expect(outline.length, length);
}
Future<FlutterOutlineAttribute> _getAttribute(
String name, String value) async {
FlutterOutline unitOutline = await _computeOutline('''

View file

@ -52,6 +52,17 @@ public class FlutterOutline {
*/
private final int length;
/**
* The offset of the first character of the element code, which is neither documentation, nor
* annotation.
*/
private final int codeOffset;
/**
* The length of the element code.
*/
private final int codeLength;
/**
* The text label of the node children of the node. It is provided for any
* FlutterOutlineKind.GENERIC node, where better information is not available.
@ -120,10 +131,12 @@ public class FlutterOutline {
/**
* Constructor for {@link FlutterOutline}.
*/
public FlutterOutline(String kind, int offset, int length, String label, Element dartElement, List<FlutterOutlineAttribute> attributes, String className, String parentAssociationLabel, String variableName, List<FlutterOutline> children, Integer id, String renderConstructor, Integer stateOffset, Integer stateLength) {
public FlutterOutline(String kind, int offset, int length, int codeOffset, int codeLength, String label, Element dartElement, List<FlutterOutlineAttribute> attributes, String className, String parentAssociationLabel, String variableName, List<FlutterOutline> children, Integer id, String renderConstructor, Integer stateOffset, Integer stateLength) {
this.kind = kind;
this.offset = offset;
this.length = length;
this.codeOffset = codeOffset;
this.codeLength = codeLength;
this.label = label;
this.dartElement = dartElement;
this.attributes = attributes;
@ -145,6 +158,8 @@ public class FlutterOutline {
ObjectUtilities.equals(other.kind, kind) &&
other.offset == offset &&
other.length == length &&
other.codeOffset == codeOffset &&
other.codeLength == codeLength &&
ObjectUtilities.equals(other.label, label) &&
ObjectUtilities.equals(other.dartElement, dartElement) &&
ObjectUtilities.equals(other.attributes, attributes) &&
@ -164,6 +179,8 @@ public class FlutterOutline {
String kind = jsonObject.get("kind").getAsString();
int offset = jsonObject.get("offset").getAsInt();
int length = jsonObject.get("length").getAsInt();
int codeOffset = jsonObject.get("codeOffset").getAsInt();
int codeLength = jsonObject.get("codeLength").getAsInt();
String label = jsonObject.get("label") == null ? null : jsonObject.get("label").getAsString();
Element dartElement = jsonObject.get("dartElement") == null ? null : Element.fromJson(jsonObject.get("dartElement").getAsJsonObject());
List<FlutterOutlineAttribute> attributes = jsonObject.get("attributes") == null ? null : FlutterOutlineAttribute.fromJsonArray(jsonObject.get("attributes").getAsJsonArray());
@ -175,7 +192,7 @@ public class FlutterOutline {
String renderConstructor = jsonObject.get("renderConstructor") == null ? null : jsonObject.get("renderConstructor").getAsString();
Integer stateOffset = jsonObject.get("stateOffset") == null ? null : jsonObject.get("stateOffset").getAsInt();
Integer stateLength = jsonObject.get("stateLength") == null ? null : jsonObject.get("stateLength").getAsInt();
return new FlutterOutline(kind, offset, length, label, dartElement, attributes, className, parentAssociationLabel, variableName, children, id, renderConstructor, stateOffset, stateLength);
return new FlutterOutline(kind, offset, length, codeOffset, codeLength, label, dartElement, attributes, className, parentAssociationLabel, variableName, children, id, renderConstructor, stateOffset, stateLength);
}
public static List<FlutterOutline> fromJsonArray(JsonArray jsonArray) {
@ -214,6 +231,21 @@ public class FlutterOutline {
return className;
}
/**
* The length of the element code.
*/
public int getCodeLength() {
return codeLength;
}
/**
* The offset of the first character of the element code, which is neither documentation, nor
* annotation.
*/
public int getCodeOffset() {
return codeOffset;
}
/**
* If this node is a Dart element, the description of it; omitted otherwise.
*/
@ -306,6 +338,8 @@ public class FlutterOutline {
builder.append(kind);
builder.append(offset);
builder.append(length);
builder.append(codeOffset);
builder.append(codeLength);
builder.append(label);
builder.append(dartElement);
builder.append(attributes);
@ -325,6 +359,8 @@ public class FlutterOutline {
jsonObject.addProperty("kind", kind);
jsonObject.addProperty("offset", offset);
jsonObject.addProperty("length", length);
jsonObject.addProperty("codeOffset", codeOffset);
jsonObject.addProperty("codeLength", codeLength);
if (label != null) {
jsonObject.addProperty("label", label);
}
@ -379,6 +415,10 @@ public class FlutterOutline {
builder.append(offset + ", ");
builder.append("length=");
builder.append(length + ", ");
builder.append("codeOffset=");
builder.append(codeOffset + ", ");
builder.append("codeLength=");
builder.append(codeLength + ", ");
builder.append("label=");
builder.append(label + ", ");
builder.append("dartElement=");

View file

@ -7,7 +7,7 @@
<body>
<h1>Analysis Server API Specification</h1>
<h1 style="color:#999999">Version
<version>1.19.0</version>
<version>1.20.0</version>
</h1>
<p>
This document contains a specification of the API provided by the
@ -3097,6 +3097,19 @@
The length of the element.
</p>
</field>
<field name="codeOffset">
<ref>int</ref>
<p>
The offset of the first character of the element code, which is
neither documentation, nor annotation.
</p>
</field>
<field name="codeLength">
<ref>int</ref>
<p>
The length of the element code.
</p>
</field>
<field name="label" optional="true">
<ref>String</ref>
<p>