Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Unified Diff: pkg/analyzer/test/src/summary/resynthesize_test.dart

Issue 1647553002: Add the ability to resynthesize class members from summaries. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/summary/resynthesize.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/src/summary/resynthesize_test.dart
diff --git a/pkg/analyzer/test/src/summary/resynthesize_test.dart b/pkg/analyzer/test/src/summary/resynthesize_test.dart
index 93ee530a66428c1eb76ef10517e0eb5ffca7ad56..796cea369d6c0226dde36024040eece8cfbff315 100644
--- a/pkg/analyzer/test/src/summary/resynthesize_test.dart
+++ b/pkg/analyzer/test/src/summary/resynthesize_test.dart
@@ -47,8 +47,9 @@ class ResynthTest extends ResolverTestCase {
void checkLibrary(String text, {bool allowErrors: false}) {
Source source = addSource(text);
LibraryElementImpl original = resolve2(source);
- LibraryElementImpl resynthesized =
- resynthesizeLibrary(source, original, allowErrors);
+ LibraryElementImpl resynthesized = resynthesizeLibraryElement(
+ encodeLibrary(source, original, allowErrors: allowErrors),
+ source.uri.toString());
checkLibraryElements(original, resynthesized);
}
@@ -511,33 +512,28 @@ class ResynthTest extends ResolverTestCase {
// TODO(paulberry): test initializer
}
- fail_library_hasExtUri() {
- checkLibrary('import "dart-ext:doesNotExist.dart";');
- }
-
- ElementImpl getActualElement(Element element, String desc) {
- if (element is ElementHandle) {
- return element.actualElement;
- } else if (element is ElementImpl) {
- return element;
- } else {
- fail('Unexpected type for resynthesized ($desc):'
- ' ${element.runtimeType}');
- return null;
- }
- }
-
- LibraryElementImpl resynthesizeLibrary(
- Source source, LibraryElementImpl original, bool allowErrors) {
+ /**
+ * Convert the given [source] into an element model and then serialize it
scheglov 2016/01/27 19:34:54 I don't quite understand this comment or the code.
Paul Berry 2016/01/27 20:34:41 You're right, this doesn't make sense. I've rewri
+ * into a summary. Then create a [_TestSummaryResynthesizer] which can
+ * deserialize it.
+ */
+ _TestSummaryResynthesizer encodeLibrary(
+ Source source, LibraryElementImpl original,
+ {bool allowErrors: false}) {
if (!allowErrors) {
assertNoErrors(source);
}
String uri = source.uri.toString();
addLibrary('dart:core');
- return resynthesizeLibraryElement(uri, original);
+ return encodeLibraryElement(uri, original);
}
- LibraryElementImpl resynthesizeLibraryElement(
+ /**
+ * Convert the library element [original], which resides at [uri], into a
+ * summary, and then create a [_TestSummaryResynthesizer] which can
+ * deserialize it.
+ */
+ _TestSummaryResynthesizer encodeLibraryElement(
String uri, LibraryElementImpl original) {
Map<String, UnlinkedUnit> unlinkedSummaries = <String, UnlinkedUnit>{};
LinkedLibrary getLinkedSummaryFor(LibraryElement lib) {
@@ -557,7 +553,7 @@ class ResynthTest extends ResolverTestCase {
String uri = source.uri.toString();
linkedSummaries[uri] = getLinkedSummaryFor(original);
}
- _TestSummaryResynthesizer resynthesizer = new _TestSummaryResynthesizer(
+ return new _TestSummaryResynthesizer(
null,
analysisContext,
analysisContext.typeProvider,
@@ -565,6 +561,31 @@ class ResynthTest extends ResolverTestCase {
unlinkedSummaries,
linkedSummaries,
options.strongMode);
+ }
+
+ fail_library_hasExtUri() {
+ checkLibrary('import "dart-ext:doesNotExist.dart";');
+ }
+
+ ElementImpl getActualElement(Element element, String desc) {
+ if (element is ElementHandle) {
+ return element.actualElement;
+ } else if (element is ElementImpl) {
+ return element;
+ } else {
+ fail('Unexpected type for resynthesized ($desc):'
+ ' ${element.runtimeType}');
+ return null;
+ }
+ }
+
+ /**
+ * Resynthesize the library element associated with [uri] using
+ * [resynthesizer], and verify that it only had to consult one summary in
+ * order to do so.
+ */
+ LibraryElementImpl resynthesizeLibraryElement(
+ _TestSummaryResynthesizer resynthesizer, String uri) {
LibraryElementImpl resynthesized = resynthesizer.getLibraryElement(uri);
// Check that no other summaries needed to be resynthesized to resynthesize
// the library element.
@@ -905,7 +926,7 @@ class C {
LibraryElementImpl original =
resolve2(analysisContext2.sourceFactory.forUri(uri));
LibraryElementImpl resynthesized =
- resynthesizeLibraryElement(uri, original);
+ resynthesizeLibraryElement(encodeLibraryElement(uri, original), uri);
checkLibraryElements(original, resynthesized);
}
@@ -1167,6 +1188,69 @@ f() {}''');
checkLibrary('f() {} g() {}');
}
+ test_getElement_constructor_named() {
+ ConstructorElement original = resolve2(addSource('class C { C.named(); }'))
+ .getType('C')
+ .getNamedConstructor('named');
+ expect(original, isNotNull);
+ ConstructorElement resynthesized = validateGetElement(original);
+ compareConstructorElements(resynthesized, original, 'C.constructor named');
+ }
+
+ test_getElement_constructor_unnamed() {
+ ConstructorElement original =
+ resolve2(addSource('class C { C(); }')).getType('C').unnamedConstructor;
+ expect(original, isNotNull);
+ ConstructorElement resynthesized = validateGetElement(original);
+ compareConstructorElements(resynthesized, original, 'C.constructor');
+ }
+
+ test_getElement_field() {
+ FieldElement original =
+ resolve2(addSource('class C { var f; }')).getType('C').getField('f');
+ expect(original, isNotNull);
+ FieldElement resynthesized = validateGetElement(original);
+ compareFieldElements(resynthesized, original, 'C.field f');
+ }
+
+ test_getElement_getter() {
+ PropertyAccessorElement original =
+ resolve2(addSource('class C { get f => null; }'))
+ .getType('C')
+ .getGetter('f');
+ expect(original, isNotNull);
+ PropertyAccessorElement resynthesized = validateGetElement(original);
+ comparePropertyAccessorElements(resynthesized, original, 'C.getter f');
+ }
+
+ test_getElement_method() {
+ MethodElement original =
+ resolve2(addSource('class C { f() {} }')).getType('C').getMethod('f');
+ expect(original, isNotNull);
+ MethodElement resynthesized = validateGetElement(original);
+ compareMethodElements(resynthesized, original, 'C.method f');
+ }
+
+ test_getElement_operator() {
+ MethodElement original =
+ resolve2(addSource('class C { operator+(x) => null; }'))
+ .getType('C')
+ .getMethod('+');
+ expect(original, isNotNull);
+ MethodElement resynthesized = validateGetElement(original);
+ compareMethodElements(resynthesized, original, 'C.operator+');
+ }
+
+ test_getElement_setter() {
+ PropertyAccessorElement original =
+ resolve2(addSource('class C { void set f(value) {} }'))
+ .getType('C')
+ .getSetter('f');
+ expect(original, isNotNull);
+ PropertyAccessorElement resynthesized = validateGetElement(original);
+ comparePropertyAccessorElements(resynthesized, original, 'C.setter f');
+ }
+
test_getter_documented() {
checkLibrary('''
// Extra comment so doc comment offset != 0
@@ -1719,6 +1803,25 @@ var x;''');
test_variables() {
checkLibrary('int i; int j;');
}
+
+ /**
+ * Encode the library containing [original] into a summary and then use
+ * [_TestSummaryResynthesizer.getElement] to retrieve just the original
+ * element from the resynthesized summary.
+ */
+ Element validateGetElement(Element original) {
+ LibraryElement originalLibrary = original.library;
+ Source source = originalLibrary.source;
+ _TestSummaryResynthesizer resynthesizer =
+ encodeLibrary(source, originalLibrary);
scheglov 2016/01/27 19:34:54 Do we expect passing other Source than library.sou
Paul Berry 2016/01/27 20:34:41 Acknowledged.
+ ElementLocationImpl location = original.location;
+ Element result = resynthesizer.getElement(location);
+ // Check that no other summaries needed to be resynthesized to resynthesize
+ // the library element.
+ expect(resynthesizer.resynthesisCount, 1);
+ expect(result.location, location);
+ return result;
+ }
}
class _TestSummaryResynthesizer extends SummaryResynthesizer {
« no previous file with comments | « pkg/analyzer/lib/src/summary/resynthesize.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698