Index: pkg/analysis_server/test/services/index/store/codec_test.dart |
diff --git a/pkg/analysis_server/test/services/index/store/codec_test.dart b/pkg/analysis_server/test/services/index/store/codec_test.dart |
index 7c134ed4137f5412a6377a779b5ec41d9ccbb81f..3c0eb1ab6b38bb127ccfeeb9563917776e4c8a4b 100644 |
--- a/pkg/analysis_server/test/services/index/store/codec_test.dart |
+++ b/pkg/analysis_server/test/services/index/store/codec_test.dart |
@@ -4,7 +4,9 @@ |
library test.services.src.index.store.codec; |
+import 'package:analysis_server/analysis/index/index_core.dart'; |
import 'package:analysis_server/src/services/index/index.dart'; |
+import 'package:analysis_server/src/services/index/indexable_element.dart'; |
import 'package:analysis_server/src/services/index/store/codec.dart'; |
import 'package:analyzer/src/generated/element.dart'; |
import 'package:analyzer/src/generated/engine.dart'; |
@@ -83,29 +85,27 @@ part 'my_part.dart'; |
{ |
Element element = testLibraryElement.definingCompilationUnit; |
expect(element.source.fullName, '/test.dart'); |
- int id1 = codec.encode1(element); |
- int id2 = codec.encode2(element); |
- int id3 = codec.encode3(element); |
+ IndexableObject indexable = new IndexableElement(element); |
+ int id1 = codec.encode1(indexable); |
+ int id2 = codec.encode2(indexable); |
+ int id3 = codec.encode3(indexable); |
expect(id1, isNonNegative); |
- expect(id2, element.nameOffset); |
- expect(id3, ElementKind.COMPILATION_UNIT.ordinal); |
- // decode |
- Element element2 = codec.decode(context, id1, id2, id3); |
- expect(element2, element); |
+ expect(id2, isNonNegative); |
+ expect(id3, IndexableElementKind.forElement(element).index); |
+ validateDecode(id1, id2, id3, element); |
} |
// part |
{ |
Element element = testLibraryElement.parts[0]; |
expect(element.source.fullName, '/my_part.dart'); |
- int id1 = codec.encode1(element); |
- int id2 = codec.encode2(element); |
- int id3 = codec.encode3(element); |
+ IndexableObject indexable = new IndexableElement(element); |
+ int id1 = codec.encode1(indexable); |
+ int id2 = codec.encode2(indexable); |
+ int id3 = codec.encode3(indexable); |
expect(id1, isNonNegative); |
- expect(id2, element.nameOffset); |
- expect(id3, ElementKind.COMPILATION_UNIT.ordinal); |
- // decode |
- Element element2 = codec.decode(context, id1, id2, id3); |
- expect(element2, element); |
+ expect(id2, isNonNegative); |
+ expect(id3, IndexableElementKind.forElement(element).index); |
+ validateDecode(id1, id2, id3, element); |
} |
} |
@@ -117,15 +117,14 @@ class A { |
'''); |
ClassElement classA = findElement('A'); |
ConstructorElement element = classA.constructors[0]; |
- int id1 = codec.encode1(element); |
- int id2 = codec.encode2(element); |
- int id3 = codec.encode3(element); |
+ IndexableObject indexable = new IndexableElement(element); |
+ int id1 = codec.encode1(indexable); |
+ int id2 = codec.encode2(indexable); |
+ int id3 = codec.encode3(indexable); |
expect(id1, isNonNegative); |
expect(id2, classA.nameOffset); |
- expect(id3, -100); |
- // decode |
- Element element2 = codec.decode(context, id1, id2, id3); |
- expect(element2, element); |
+ expect(id3, IndexableElementKind.forElement(element).index); |
+ validateDecode(id1, id2, id3, element); |
} |
void test_encode_ConstructorElement_default_synthetic() { |
@@ -135,15 +134,14 @@ class A { |
'''); |
ClassElement classA = findElement('A'); |
ConstructorElement element = classA.constructors[0]; |
- int id1 = codec.encode1(element); |
- int id2 = codec.encode2(element); |
- int id3 = codec.encode3(element); |
+ IndexableObject indexable = new IndexableElement(element); |
+ int id1 = codec.encode1(indexable); |
+ int id2 = codec.encode2(indexable); |
+ int id3 = codec.encode3(indexable); |
expect(id1, isNonNegative); |
expect(id2, classA.nameOffset); |
- expect(id3, -100); |
- // decode |
- Element element2 = codec.decode(context, id1, id2, id3); |
- expect(element2, element); |
+ expect(id3, IndexableElementKind.forElement(element).index); |
+ validateDecode(id1, id2, id3, element); |
} |
void test_encode_ConstructorElement_named_real() { |
@@ -157,28 +155,26 @@ class A { |
// A.aaa() |
{ |
ConstructorElement element = classA.getNamedConstructor('aaa'); |
- int id1 = codec.encode1(element); |
- int id2 = codec.encode2(element); |
- int id3 = codec.encode3(element); |
+ IndexableObject indexable = new IndexableElement(element); |
+ int id1 = codec.encode1(indexable); |
+ int id2 = codec.encode2(indexable); |
+ int id3 = codec.encode3(indexable); |
expect(id1, isNonNegative); |
expect(id2, classA.nameOffset); |
- expect(id3, -100); |
- // decode |
- Element element2 = codec.decode(context, id1, id2, id3); |
- expect(element2, element); |
+ expect(id3, IndexableElementKind.forElement(element).index); |
+ validateDecode(id1, id2, id3, element); |
} |
// A.bbb() |
{ |
ConstructorElement element = classA.getNamedConstructor('bbb'); |
- int id1 = codec.encode1(element); |
- int id2 = codec.encode2(element); |
- int id3 = codec.encode3(element); |
+ IndexableObject indexable = new IndexableElement(element); |
+ int id1 = codec.encode1(indexable); |
+ int id2 = codec.encode2(indexable); |
+ int id3 = codec.encode3(indexable); |
expect(id1, isNonNegative); |
expect(id2, classA.nameOffset); |
- expect(id3, -101); |
- // decode |
- Element element2 = codec.decode(context, id1, id2, id3); |
- expect(element2, element); |
+ expect(id3, IndexableElementKind.forElement(element).index); |
+ validateDecode(id1, id2, id3, element); |
} |
} |
@@ -195,28 +191,26 @@ class X = A with M; |
// X.aaa() |
{ |
ConstructorElement element = classX.getNamedConstructor('aaa'); |
- int id1 = codec.encode1(element); |
- int id2 = codec.encode2(element); |
- int id3 = codec.encode3(element); |
+ IndexableObject indexable = new IndexableElement(element); |
+ int id1 = codec.encode1(indexable); |
+ int id2 = codec.encode2(indexable); |
+ int id3 = codec.encode3(indexable); |
expect(id1, isNonNegative); |
expect(id2, classX.nameOffset); |
- expect(id3, -100); |
- // decode |
- Element element2 = codec.decode(context, id1, id2, id3); |
- expect(element2, element); |
+ expect(id3, IndexableElementKind.forElement(element).index); |
+ validateDecode(id1, id2, id3, element); |
} |
// X.bbb() |
{ |
ConstructorElement element = classX.getNamedConstructor('bbb'); |
- int id1 = codec.encode1(element); |
- int id2 = codec.encode2(element); |
- int id3 = codec.encode3(element); |
+ IndexableObject indexable = new IndexableElement(element); |
+ int id1 = codec.encode1(indexable); |
+ int id2 = codec.encode2(indexable); |
+ int id3 = codec.encode3(indexable); |
expect(id1, isNonNegative); |
expect(id2, classX.nameOffset); |
- expect(id3, -101); |
- // decode |
- Element element2 = codec.decode(context, id1, id2, id3); |
- expect(element2, element); |
+ expect(id3, IndexableElementKind.forElement(element).index); |
+ validateDecode(id1, id2, id3, element); |
} |
} |
@@ -227,15 +221,14 @@ class A { |
} |
'''); |
PropertyAccessorElement element = findElement('test', ElementKind.GETTER); |
- int id1 = codec.encode1(element); |
- int id2 = codec.encode2(element); |
- int id3 = codec.encode3(element); |
+ IndexableObject indexable = new IndexableElement(element); |
+ int id1 = codec.encode1(indexable); |
+ int id2 = codec.encode2(indexable); |
+ int id3 = codec.encode3(indexable); |
expect(id1, isNonNegative); |
expect(id2, element.nameOffset); |
- expect(id3, ElementKind.GETTER.ordinal); |
- // decode |
- Element element2 = codec.decode(context, id1, id2, id3); |
- expect(element2, element); |
+ expect(id3, IndexableElementKind.forElement(element).index); |
+ validateDecode(id1, id2, id3, element); |
} |
void test_encode_getter_synthetic() { |
@@ -246,15 +239,14 @@ class A { |
'''); |
FieldElement field = findElement('test', ElementKind.FIELD); |
PropertyAccessorElement element = field.getter; |
- int id1 = codec.encode1(element); |
- int id2 = codec.encode2(element); |
- int id3 = codec.encode3(element); |
+ IndexableObject indexable = new IndexableElement(element); |
+ int id1 = codec.encode1(indexable); |
+ int id2 = codec.encode2(indexable); |
+ int id3 = codec.encode3(indexable); |
expect(id1, isNonNegative); |
expect(id2, element.nameOffset); |
- expect(id3, ElementKind.GETTER.ordinal); |
- // decode |
- Element element2 = codec.decode(context, id1, id2, id3); |
- expect(element2, element); |
+ expect(id3, IndexableElementKind.forElement(element).index); |
+ validateDecode(id1, id2, id3, element); |
} |
void test_encode_LibraryElement() { |
@@ -264,15 +256,14 @@ class A { |
} |
'''); |
Element element = testLibraryElement; |
- int id1 = codec.encode1(element); |
- int id2 = codec.encode2(element); |
- int id3 = codec.encode3(element); |
+ IndexableObject indexable = new IndexableElement(element); |
+ int id1 = codec.encode1(indexable); |
+ int id2 = codec.encode2(indexable); |
+ int id3 = codec.encode3(indexable); |
expect(id1, isNonNegative); |
- expect(id2, element.nameOffset); |
- expect(id3, ElementKind.LIBRARY.ordinal); |
- // decode |
- Element element2 = codec.decode(context, id1, id2, id3); |
- expect(element2, element); |
+ expect(id2, isNonNegative); |
+ expect(id3, IndexableElementKind.forElement(element).index); |
+ validateDecode(id1, id2, id3, element); |
} |
void test_encode_MethodElement() { |
@@ -282,25 +273,25 @@ class A { |
} |
'''); |
Element element = findElement('test'); |
- int id1 = codec.encode1(element); |
- int id2 = codec.encode2(element); |
- int id3 = codec.encode3(element); |
+ IndexableObject indexable = new IndexableElement(element); |
+ int id1 = codec.encode1(indexable); |
+ int id2 = codec.encode2(indexable); |
+ int id3 = codec.encode3(indexable); |
expect(id1, isNonNegative); |
expect(id2, element.nameOffset); |
- expect(id3, ElementKind.METHOD.ordinal); |
- // decode |
- Element element2 = codec.decode(context, id1, id2, id3); |
- expect(element2, element); |
+ expect(id3, IndexableElementKind.forElement(element).index); |
+ validateDecode(id1, id2, id3, element); |
} |
void test_encode_NameElement() { |
Element element = new NameElement('test'); |
- int id1 = codec.encode1(element); |
- int id2 = codec.encode2(element); |
- int id3 = codec.encode3(element); |
+ IndexableObject indexable = new IndexableElement(element); |
+ int id1 = codec.encode1(indexable); |
+ int id2 = codec.encode2(indexable); |
+ int id3 = codec.encode3(indexable); |
expect(id1, -1); |
expect(id2, isNonNegative); |
- expect(id3, ElementKind.NAME.ordinal); |
+ expect(id3, IndexableElementKind.forElement(element).index); |
} |
void test_encode_nullLibraryElement() { |
@@ -308,13 +299,13 @@ class A { |
test() {} |
'''); |
Element element = findElement('test'); |
- int id1 = codec.encode1(element); |
- int id2 = codec.encode2(element); |
- int id3 = codec.encode3(element); |
+ IndexableObject indexable = new IndexableElement(element); |
+ int id1 = codec.encode1(indexable); |
+ int id2 = codec.encode2(indexable); |
+ int id3 = codec.encode3(indexable); |
context.setContents(testSource, ''); |
- // decode |
- Element element2 = codec.decode(context, id1, id2, id3); |
- expect(element2, isNull); |
+ IndexableObject object2 = codec.decode(context, id1, id2, id3); |
+ expect(object2, isNull); |
} |
void test_encode_setter_real() { |
@@ -324,15 +315,14 @@ class A { |
} |
'''); |
PropertyAccessorElement element = findElement('test=', ElementKind.SETTER); |
- int id1 = codec.encode1(element); |
- int id2 = codec.encode2(element); |
- int id3 = codec.encode3(element); |
+ IndexableObject indexable = new IndexableElement(element); |
+ int id1 = codec.encode1(indexable); |
+ int id2 = codec.encode2(indexable); |
+ int id3 = codec.encode3(indexable); |
expect(id1, isNonNegative); |
expect(id2, element.nameOffset); |
- expect(id3, ElementKind.SETTER.ordinal); |
- // decode |
- Element element2 = codec.decode(context, id1, id2, id3); |
- expect(element2, element); |
+ expect(id3, IndexableElementKind.forElement(element).index); |
+ validateDecode(id1, id2, id3, element); |
} |
void test_encode_setter_synthetic() { |
@@ -343,15 +333,14 @@ class A { |
'''); |
FieldElement field = findElement('test', ElementKind.FIELD); |
PropertyAccessorElement element = field.setter; |
- int id1 = codec.encode1(element); |
- int id2 = codec.encode2(element); |
- int id3 = codec.encode3(element); |
+ IndexableObject indexable = new IndexableElement(element); |
+ int id1 = codec.encode1(indexable); |
+ int id2 = codec.encode2(indexable); |
+ int id3 = codec.encode3(indexable); |
expect(id1, isNonNegative); |
expect(id2, element.nameOffset); |
- expect(id3, ElementKind.SETTER.ordinal); |
- // decode |
- Element element2 = codec.decode(context, id1, id2, id3); |
- expect(element2, element); |
+ expect(id3, IndexableElementKind.forElement(element).index); |
+ validateDecode(id1, id2, id3, element); |
} |
void test_encodeHash_notLocal() { |
@@ -371,12 +360,19 @@ class A { |
Element fooA = mainA.localVariables[0]; |
Element fooB = mainB.localVariables[0]; |
Element bar = mainB.localVariables[1]; |
- int id_fooA = codec.encodeHash(fooA); |
- int id_fooB = codec.encodeHash(fooB); |
- int id_bar = codec.encodeHash(bar); |
+ int id_fooA = codec.encodeHash(new IndexableElement(fooA)); |
+ int id_fooB = codec.encodeHash(new IndexableElement(fooB)); |
+ int id_bar = codec.encodeHash(new IndexableElement(bar)); |
expect(id_fooA == id_fooB, isTrue); |
expect(id_fooA == id_bar, isFalse); |
} |
+ |
+ void validateDecode(int id1, int id2, int id3, Element element) { |
+ IndexableObject object2 = codec.decode(context, id1, id2, id3); |
+ expect(object2, new isInstanceOf<IndexableElement>()); |
+ Element element2 = (object2 as IndexableElement).element; |
+ expect(element2, element); |
+ } |
} |
@reflectiveTest |