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

Unified Diff: pkg/analyzer/test/generated/resolver_test.dart

Issue 1217373005: Generic method support in element model (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 5 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
Index: pkg/analyzer/test/generated/resolver_test.dart
diff --git a/pkg/analyzer/test/generated/resolver_test.dart b/pkg/analyzer/test/generated/resolver_test.dart
index e07053da689a29c39eb0d6bb72d028d2f4538a55..cc66250e2e165eae199f5707287465a0a8334c3f 100644
--- a/pkg/analyzer/test/generated/resolver_test.dart
+++ b/pkg/analyzer/test/generated/resolver_test.dart
@@ -13376,26 +13376,11 @@ class TypeResolverVisitorTest extends EngineTestCase {
_listener.assertNoErrors();
}
- void fail_visitFunctionDeclaration() {
- fail("Not yet tested");
- _listener.assertNoErrors();
- }
-
void fail_visitFunctionTypeAlias() {
fail("Not yet tested");
_listener.assertNoErrors();
}
- void fail_visitFunctionTypedFormalParameter() {
- fail("Not yet tested");
- _listener.assertNoErrors();
- }
-
- void fail_visitMethodDeclaration() {
- fail("Not yet tested");
- _listener.assertNoErrors();
- }
-
void fail_visitVariableDeclaration() {
fail("Not yet tested");
ClassElement type = ElementFactory.classElement2("A");
@@ -13698,6 +13683,148 @@ class TypeResolverVisitorTest extends EngineTestCase {
_listener.assertNoErrors();
}
+ void test_visitFunctionDeclaration() {
+ // R f(P p) {}
+ // class R {}
+ // class P {}
+ ClassElement elementR = ElementFactory.classElement2('R');
+ ClassElement elementP = ElementFactory.classElement2('P');
+ FunctionElement elementF = ElementFactory.functionElement('f');
+ FunctionDeclaration declaration = AstFactory.functionDeclaration(
+ AstFactory.typeName4('R'), null, 'f', AstFactory.functionExpression2(
+ AstFactory.formalParameterList([
+ AstFactory.simpleFormalParameter4(AstFactory.typeName4('P'), 'p')
+ ]), null));
+ declaration.name.staticElement = elementF;
+ _resolveNode(declaration, [elementR, elementP]);
+ expect(declaration.returnType.type, elementR.type);
+ SimpleFormalParameter parameter =
+ declaration.functionExpression.parameters.parameters[0];
+ expect(parameter.type.type, elementP.type);
+ _listener.assertNoErrors();
+ }
+
+ void test_visitFunctionDeclaration_typeParameter() {
+ // E f<E>(E e) {}
+ TypeParameterElement elementE = ElementFactory.typeParameterElement('E');
+ FunctionElementImpl elementF = ElementFactory.functionElement('f');
+ elementF.typeParameters = <TypeParameterElement>[elementE];
+ FunctionDeclaration declaration = AstFactory.functionDeclaration(
+ AstFactory.typeName4('E'), null, 'f', AstFactory.functionExpression2(
+ AstFactory.formalParameterList([
+ AstFactory.simpleFormalParameter4(AstFactory.typeName4('E'), 'e')
+ ]), null));
+ declaration.name.staticElement = elementF;
+ _resolveNode(declaration, []);
+ expect(declaration.returnType.type, elementE.type);
+ SimpleFormalParameter parameter =
+ declaration.functionExpression.parameters.parameters[0];
+ expect(parameter.type.type, elementE.type);
+ _listener.assertNoErrors();
+ }
+
+ void test_visitFunctionTypedFormalParameter() {
+ // R f(R g(P p)) {}
+ // class R {}
+ // class P {}
+ ClassElement elementR = ElementFactory.classElement2('R');
+ ClassElement elementP = ElementFactory.classElement2('P');
+ FunctionElement elementF = ElementFactory.functionElement('f');
+ ParameterElementImpl requiredParameter =
+ ElementFactory.requiredParameter('p');
+ FunctionTypedFormalParameter parameterDeclaration = AstFactory
+ .functionTypedFormalParameter(AstFactory.typeName4('R'), 'g', [
+ AstFactory.simpleFormalParameter4(AstFactory.typeName4('P'), 'p')
+ ]);
+ parameterDeclaration.identifier.staticElement = requiredParameter;
+ FunctionDeclaration declaration = AstFactory.functionDeclaration(
+ AstFactory.typeName4('R'), null, 'f', AstFactory.functionExpression2(
+ AstFactory.formalParameterList([parameterDeclaration]), null));
+ declaration.name.staticElement = elementF;
+ _resolveNode(declaration, [elementR, elementP]);
+ expect(declaration.returnType.type, elementR.type);
+ FunctionTypedFormalParameter parameter =
+ declaration.functionExpression.parameters.parameters[0];
+ expect(parameter.returnType.type, elementR.type);
+ SimpleFormalParameter innerParameter = parameter.parameters.parameters[0];
+ expect(innerParameter.type.type, elementP.type);
+ _listener.assertNoErrors();
+ }
+
+ void test_visitFunctionTypedFormalParameter_typeParameter() {
+ // R f(R g<E>(E e)) {}
+ // class R {}
+ ClassElement elementR = ElementFactory.classElement2('R');
+ TypeParameterElement elementE = ElementFactory.typeParameterElement('E');
+ FunctionElement elementF = ElementFactory.functionElement('f');
+ ParameterElementImpl requiredParameter =
+ ElementFactory.requiredParameter('g');
+ requiredParameter.typeParameters = <TypeParameterElement>[elementE];
+ FunctionTypedFormalParameter parameterDeclaration = AstFactory
+ .functionTypedFormalParameter(AstFactory.typeName4('R'), 'g', [
+ AstFactory.simpleFormalParameter4(AstFactory.typeName4('E'), 'e')
+ ]);
+ parameterDeclaration.identifier.staticElement = requiredParameter;
+ FunctionDeclaration declaration = AstFactory.functionDeclaration(
+ AstFactory.typeName4('R'), null, 'f', AstFactory.functionExpression2(
+ AstFactory.formalParameterList([parameterDeclaration]), null));
+ declaration.name.staticElement = elementF;
+ _resolveNode(declaration, [elementR]);
+ expect(declaration.returnType.type, elementR.type);
+ FunctionTypedFormalParameter parameter =
+ declaration.functionExpression.parameters.parameters[0];
+ expect(parameter.returnType.type, elementR.type);
+ SimpleFormalParameter innerParameter = parameter.parameters.parameters[0];
+ expect(innerParameter.type.type, elementE.type);
+ _listener.assertNoErrors();
+ }
+
+ void test_visitMethodDeclaration() {
+ // class A {
+ // R m(P p) {}
+ // }
+ // class R {}
+ // class P {}
+ ClassElementImpl elementA = ElementFactory.classElement2('A');
+ ClassElement elementR = ElementFactory.classElement2('R');
+ ClassElement elementP = ElementFactory.classElement2('P');
+ MethodElement elementM = ElementFactory.methodElement('m', null);
+ elementA.methods = <MethodElement>[elementM];
+ MethodDeclaration declaration = AstFactory.methodDeclaration(null,
+ AstFactory.typeName4('R'), null, null, AstFactory.identifier3('m'),
+ AstFactory.formalParameterList([
+ AstFactory.simpleFormalParameter4(AstFactory.typeName4('P'), 'p')
+ ]));
+ declaration.name.staticElement = elementM;
+ _resolveNode(declaration, [elementA, elementR, elementP]);
+ expect(declaration.returnType.type, elementR.type);
+ SimpleFormalParameter parameter = declaration.parameters.parameters[0];
+ expect(parameter.type.type, elementP.type);
+ _listener.assertNoErrors();
+ }
+
+ void test_visitMethodDeclaration_typeParameter() {
+ // class A {
+ // E m<E>(E e) {}
+ // }
+ ClassElementImpl elementA = ElementFactory.classElement2('A');
+ TypeParameterElement elementE = ElementFactory.typeParameterElement('E');
+ MethodElementImpl elementM = ElementFactory.methodElement('m', null);
+ elementM.typeParameters = <TypeParameterElement>[elementE];
+ elementA.methods = <MethodElement>[elementM];
+ MethodDeclaration declaration = AstFactory.methodDeclaration(null,
+ AstFactory.typeName4('E'), null, null, AstFactory.identifier3('m'),
+ AstFactory.formalParameterList([
+ AstFactory.simpleFormalParameter4(AstFactory.typeName4('E'), 'e')
+ ]));
+ declaration.name.staticElement = elementM;
+ _resolveNode(declaration, [elementA]);
+ expect(declaration.returnType.type, elementE.type);
+ SimpleFormalParameter parameter = declaration.parameters.parameters[0];
+ expect(parameter.type.type, elementE.type);
+ _listener.assertNoErrors();
+ }
+
void test_visitSimpleFormalParameter_noType() {
// p
FormalParameter node = AstFactory.simpleFormalParameter3("p");

Powered by Google App Engine
This is Rietveld 408576698