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

Side by Side Diff: pkg/analyzer/test/generated/element_test.dart

Issue 1502213002: Remove deprecated code (Closed) Base URL: https://github.com/dart-lang/sdk.git@analyzer-breaking-0.27
Patch Set: Created 5 years 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library engine.element_test; 5 library engine.element_test;
6 6
7 import 'package:analyzer/src/generated/ast.dart'; 7 import 'package:analyzer/src/generated/ast.dart';
8 import 'package:analyzer/src/generated/element.dart'; 8 import 'package:analyzer/src/generated/element.dart';
9 import 'package:analyzer/src/generated/engine.dart' 9 import 'package:analyzer/src/generated/engine.dart'
10 show AnalysisContext, AnalysisOptionsImpl; 10 show AnalysisContext, AnalysisOptionsImpl;
(...skipping 14 matching lines...) Expand all
25 runReflectiveTests(ElementKindTest); 25 runReflectiveTests(ElementKindTest);
26 runReflectiveTests(FieldElementImplTest); 26 runReflectiveTests(FieldElementImplTest);
27 runReflectiveTests(FunctionTypeImplTest); 27 runReflectiveTests(FunctionTypeImplTest);
28 runReflectiveTests(InterfaceTypeImplTest); 28 runReflectiveTests(InterfaceTypeImplTest);
29 runReflectiveTests(TypeParameterTypeImplTest); 29 runReflectiveTests(TypeParameterTypeImplTest);
30 runReflectiveTests(VoidTypeImplTest); 30 runReflectiveTests(VoidTypeImplTest);
31 runReflectiveTests(ClassElementImplTest); 31 runReflectiveTests(ClassElementImplTest);
32 runReflectiveTests(CompilationUnitElementImplTest); 32 runReflectiveTests(CompilationUnitElementImplTest);
33 runReflectiveTests(ElementLocationImplTest); 33 runReflectiveTests(ElementLocationImplTest);
34 runReflectiveTests(ElementImplTest); 34 runReflectiveTests(ElementImplTest);
35 runReflectiveTests(HtmlElementImplTest);
36 runReflectiveTests(LibraryElementImplTest); 35 runReflectiveTests(LibraryElementImplTest);
37 runReflectiveTests(MethodElementImplTest); 36 runReflectiveTests(MethodElementImplTest);
38 runReflectiveTests(MultiplyDefinedElementImplTest); 37 runReflectiveTests(MultiplyDefinedElementImplTest);
39 runReflectiveTests(ParameterElementImplTest); 38 runReflectiveTests(ParameterElementImplTest);
40 } 39 }
41 40
42 @reflectiveTest 41 @reflectiveTest
43 class ClassElementImplTest extends EngineTestCase { 42 class ClassElementImplTest extends EngineTestCase {
44 void test_computeNode_ClassDeclaration() { 43 void test_computeNode_ClassDeclaration() {
45 AnalysisContextHelper contextHelper = new AnalysisContextHelper(); 44 AnalysisContextHelper contextHelper = new AnalysisContextHelper();
(...skipping 1836 matching lines...) Expand 10 before | Expand all | Expand 10 after
1882 ElementFactory.functionTypeAliasElement('f'); 1881 ElementFactory.functionTypeAliasElement('f');
1883 FunctionTypeAliasElementImpl g = 1882 FunctionTypeAliasElementImpl g =
1884 ElementFactory.functionTypeAliasElement('g'); 1883 ElementFactory.functionTypeAliasElement('g');
1885 f.typeParameters = [ElementFactory.typeParameterElement('T')]; 1884 f.typeParameters = [ElementFactory.typeParameterElement('T')];
1886 f.returnType = g.type; 1885 f.returnType = g.type;
1887 FunctionTypeImpl paramType = f.type.returnType; 1886 FunctionTypeImpl paramType = f.type.returnType;
1888 expect(paramType.prunedTypedefs, hasLength(1)); 1887 expect(paramType.prunedTypedefs, hasLength(1));
1889 expect(paramType.prunedTypedefs[0], same(f)); 1888 expect(paramType.prunedTypedefs[0], same(f));
1890 } 1889 }
1891 1890
1892 void test_withTypeArguments() {
1893 ClassElementImpl enclosingClass = ElementFactory.classElement2("C", ["E"]);
1894 MethodElementImpl methodElement =
1895 new MethodElementImpl.forNode(AstFactory.identifier3("m"));
1896 enclosingClass.methods = <MethodElement>[methodElement];
1897 FunctionTypeImpl type = new FunctionTypeImpl(methodElement);
1898 DartType expectedType = enclosingClass.typeParameters[0].type;
1899 List<DartType> arguments = type.typeArguments;
1900 expect(arguments, hasLength(1));
1901 expect(arguments[0], expectedType);
1902 }
1903
1904 void test_substitute2_equal() { 1891 void test_substitute2_equal() {
1905 ClassElementImpl definingClass = ElementFactory.classElement2("C", ["E"]); 1892 ClassElementImpl definingClass = ElementFactory.classElement2("C", ["E"]);
1906 TypeParameterType parameterType = definingClass.typeParameters[0].type; 1893 TypeParameterType parameterType = definingClass.typeParameters[0].type;
1907 MethodElementImpl functionElement = 1894 MethodElementImpl functionElement =
1908 new MethodElementImpl.forNode(AstFactory.identifier3("m")); 1895 new MethodElementImpl.forNode(AstFactory.identifier3("m"));
1909 String namedParameterName = "c"; 1896 String namedParameterName = "c";
1910 functionElement.parameters = <ParameterElement>[ 1897 functionElement.parameters = <ParameterElement>[
1911 ElementFactory.requiredParameter2("a", parameterType), 1898 ElementFactory.requiredParameter2("a", parameterType),
1912 ElementFactory.positionalParameter2("b", parameterType), 1899 ElementFactory.positionalParameter2("b", parameterType),
1913 ElementFactory.namedParameter2(namedParameterName, parameterType) 1900 ElementFactory.namedParameter2(namedParameterName, parameterType)
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1978 expect(t.type.toString(), '() \u2192 () \u2192 ...'); 1965 expect(t.type.toString(), '() \u2192 () \u2192 ...');
1979 } 1966 }
1980 1967
1981 void test_toString_recursive_via_interface_type() { 1968 void test_toString_recursive_via_interface_type() {
1982 FunctionTypeAliasElementImpl f = 1969 FunctionTypeAliasElementImpl f =
1983 ElementFactory.functionTypeAliasElement('f'); 1970 ElementFactory.functionTypeAliasElement('f');
1984 ClassElementImpl c = ElementFactory.classElement2('C', ['T']); 1971 ClassElementImpl c = ElementFactory.classElement2('C', ['T']);
1985 f.returnType = c.type.substitute4([f.type]); 1972 f.returnType = c.type.substitute4([f.type]);
1986 expect(f.type.toString(), '() \u2192 C<...>'); 1973 expect(f.type.toString(), '() \u2192 C<...>');
1987 } 1974 }
1988 }
1989 1975
1990 @reflectiveTest 1976 void test_withTypeArguments() {
1991 class HtmlElementImplTest extends EngineTestCase { 1977 ClassElementImpl enclosingClass = ElementFactory.classElement2("C", ["E"]);
1992 void test_equals_differentSource() { 1978 MethodElementImpl methodElement =
1993 AnalysisContext context = createAnalysisContext(); 1979 new MethodElementImpl.forNode(AstFactory.identifier3("m"));
1994 HtmlElementImpl elementA = ElementFactory.htmlUnit(context, "indexA.html"); 1980 enclosingClass.methods = <MethodElement>[methodElement];
1995 HtmlElementImpl elementB = ElementFactory.htmlUnit(context, "indexB.html"); 1981 FunctionTypeImpl type = new FunctionTypeImpl(methodElement);
1996 expect(elementA == elementB, isFalse); 1982 DartType expectedType = enclosingClass.typeParameters[0].type;
1997 } 1983 List<DartType> arguments = type.typeArguments;
1998 1984 expect(arguments, hasLength(1));
1999 void test_equals_null() { 1985 expect(arguments[0], expectedType);
2000 AnalysisContext context = createAnalysisContext();
2001 HtmlElementImpl element = ElementFactory.htmlUnit(context, "index.html");
2002 expect(element == null, isFalse);
2003 }
2004
2005 void test_equals_sameSource() {
2006 AnalysisContext context = createAnalysisContext();
2007 HtmlElementImpl elementA = ElementFactory.htmlUnit(context, "index.html");
2008 HtmlElementImpl elementB = ElementFactory.htmlUnit(context, "index.html");
2009 expect(elementA == elementB, isTrue);
2010 }
2011
2012 void test_equals_self() {
2013 AnalysisContext context = createAnalysisContext();
2014 HtmlElementImpl element = ElementFactory.htmlUnit(context, "index.html");
2015 expect(element == element, isTrue);
2016 } 1986 }
2017 } 1987 }
2018 1988
2019 @reflectiveTest 1989 @reflectiveTest
2020 class InterfaceTypeImplTest extends EngineTestCase { 1990 class InterfaceTypeImplTest extends EngineTestCase {
2021 /** 1991 /**
2022 * The type provider used to access the types. 1992 * The type provider used to access the types.
2023 */ 1993 */
2024 TestTypeProvider _typeProvider; 1994 TestTypeProvider _typeProvider;
2025 1995
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
2487 InterfaceType typeI = ElementFactory.classElement2("I").type; 2457 InterfaceType typeI = ElementFactory.classElement2("I").type;
2488 InterfaceTypeImpl typeBI = new InterfaceTypeImpl(classB); 2458 InterfaceTypeImpl typeBI = new InterfaceTypeImpl(classB);
2489 typeBI.typeArguments = <DartType>[typeI]; 2459 typeBI.typeArguments = <DartType>[typeI];
2490 List<InterfaceType> interfaces = typeBI.interfaces; 2460 List<InterfaceType> interfaces = typeBI.interfaces;
2491 expect(interfaces, hasLength(1)); 2461 expect(interfaces, hasLength(1));
2492 InterfaceType result = interfaces[0]; 2462 InterfaceType result = interfaces[0];
2493 expect(result.element, same(classA)); 2463 expect(result.element, same(classA));
2494 expect(result.typeArguments[0], same(typeI)); 2464 expect(result.typeArguments[0], same(typeI));
2495 } 2465 }
2496 2466
2497 void test_getLeastUpperBound_directInterfaceCase() {
2498 //
2499 // class A
2500 // class B implements A
2501 // class C implements B
2502 //
2503 ClassElementImpl classA = ElementFactory.classElement2("A");
2504 ClassElementImpl classB = ElementFactory.classElement2("B");
2505 ClassElementImpl classC = ElementFactory.classElement2("C");
2506 InterfaceType typeA = classA.type;
2507 InterfaceType typeB = classB.type;
2508 InterfaceType typeC = classC.type;
2509 classB.interfaces = <InterfaceType>[typeA];
2510 classC.interfaces = <InterfaceType>[typeB];
2511 expect(typeB.getLeastUpperBound(typeC), typeB);
2512 expect(typeC.getLeastUpperBound(typeB), typeB);
2513 }
2514
2515 void test_getLeastUpperBound_directSubclassCase() {
2516 //
2517 // class A
2518 // class B extends A
2519 // class C extends B
2520 //
2521 ClassElementImpl classA = ElementFactory.classElement2("A");
2522 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
2523 ClassElementImpl classC = ElementFactory.classElement("C", classB.type);
2524 InterfaceType typeB = classB.type;
2525 InterfaceType typeC = classC.type;
2526 expect(typeB.getLeastUpperBound(typeC), typeB);
2527 expect(typeC.getLeastUpperBound(typeB), typeB);
2528 }
2529
2530 void test_getLeastUpperBound_functionType() {
2531 DartType interfaceType = ElementFactory.classElement2("A").type;
2532 FunctionTypeImpl functionType = new FunctionTypeImpl(
2533 new FunctionElementImpl.forNode(AstFactory.identifier3("f")));
2534 expect(interfaceType.getLeastUpperBound(functionType), isNull);
2535 }
2536
2537 void test_getLeastUpperBound_mixinCase() {
2538 //
2539 // class A
2540 // class B extends A
2541 // class C extends A
2542 // class D extends B with M, N, O, P
2543 //
2544 ClassElement classA = ElementFactory.classElement2("A");
2545 ClassElement classB = ElementFactory.classElement("B", classA.type);
2546 ClassElement classC = ElementFactory.classElement("C", classA.type);
2547 ClassElementImpl classD = ElementFactory.classElement("D", classB.type);
2548 InterfaceType typeA = classA.type;
2549 InterfaceType typeC = classC.type;
2550 InterfaceType typeD = classD.type;
2551 classD.mixins = <InterfaceType>[
2552 ElementFactory.classElement2("M").type,
2553 ElementFactory.classElement2("N").type,
2554 ElementFactory.classElement2("O").type,
2555 ElementFactory.classElement2("P").type
2556 ];
2557 expect(typeD.getLeastUpperBound(typeC), typeA);
2558 expect(typeC.getLeastUpperBound(typeD), typeA);
2559 }
2560
2561 void test_getLeastUpperBound_null() {
2562 DartType interfaceType = ElementFactory.classElement2("A").type;
2563 expect(interfaceType.getLeastUpperBound(null), isNull);
2564 }
2565
2566 void test_getLeastUpperBound_object() {
2567 ClassElementImpl classA = ElementFactory.classElement2("A");
2568 ClassElementImpl classB = ElementFactory.classElement2("B");
2569 InterfaceType typeA = classA.type;
2570 InterfaceType typeB = classB.type;
2571 DartType typeObject = typeA.element.supertype;
2572 // assert that object does not have a super type
2573 expect((typeObject.element as ClassElement).supertype, isNull);
2574 // assert that both A and B have the same super type of Object
2575 expect(typeB.element.supertype, typeObject);
2576 // finally, assert that the only least upper bound of A and B is Object
2577 expect(typeA.getLeastUpperBound(typeB), typeObject);
2578 }
2579
2580 void test_getLeastUpperBound_self() {
2581 ClassElement classA = ElementFactory.classElement2("A");
2582 InterfaceType typeA = classA.type;
2583 expect(typeA.getLeastUpperBound(typeA), typeA);
2584 }
2585
2586 void test_getLeastUpperBound_sharedSuperclass1() {
2587 ClassElementImpl classA = ElementFactory.classElement2("A");
2588 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
2589 ClassElementImpl classC = ElementFactory.classElement("C", classA.type);
2590 InterfaceType typeA = classA.type;
2591 InterfaceType typeB = classB.type;
2592 InterfaceType typeC = classC.type;
2593 expect(typeB.getLeastUpperBound(typeC), typeA);
2594 expect(typeC.getLeastUpperBound(typeB), typeA);
2595 }
2596
2597 void test_getLeastUpperBound_sharedSuperclass2() {
2598 ClassElementImpl classA = ElementFactory.classElement2("A");
2599 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
2600 ClassElementImpl classC = ElementFactory.classElement("C", classA.type);
2601 ClassElementImpl classD = ElementFactory.classElement("D", classC.type);
2602 InterfaceType typeA = classA.type;
2603 InterfaceType typeB = classB.type;
2604 InterfaceType typeD = classD.type;
2605 expect(typeB.getLeastUpperBound(typeD), typeA);
2606 expect(typeD.getLeastUpperBound(typeB), typeA);
2607 }
2608
2609 void test_getLeastUpperBound_sharedSuperclass3() {
2610 ClassElementImpl classA = ElementFactory.classElement2("A");
2611 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
2612 ClassElementImpl classC = ElementFactory.classElement("C", classB.type);
2613 ClassElementImpl classD = ElementFactory.classElement("D", classB.type);
2614 InterfaceType typeB = classB.type;
2615 InterfaceType typeC = classC.type;
2616 InterfaceType typeD = classD.type;
2617 expect(typeC.getLeastUpperBound(typeD), typeB);
2618 expect(typeD.getLeastUpperBound(typeC), typeB);
2619 }
2620
2621 void test_getLeastUpperBound_sharedSuperclass4() {
2622 ClassElement classA = ElementFactory.classElement2("A");
2623 ClassElement classA2 = ElementFactory.classElement2("A2");
2624 ClassElement classA3 = ElementFactory.classElement2("A3");
2625 ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
2626 ClassElementImpl classC = ElementFactory.classElement("C", classA.type);
2627 InterfaceType typeA = classA.type;
2628 InterfaceType typeA2 = classA2.type;
2629 InterfaceType typeA3 = classA3.type;
2630 InterfaceType typeB = classB.type;
2631 InterfaceType typeC = classC.type;
2632 classB.interfaces = <InterfaceType>[typeA2];
2633 classC.interfaces = <InterfaceType>[typeA3];
2634 expect(typeB.getLeastUpperBound(typeC), typeA);
2635 expect(typeC.getLeastUpperBound(typeB), typeA);
2636 }
2637
2638 void test_getLeastUpperBound_sharedSuperinterface1() {
2639 ClassElementImpl classA = ElementFactory.classElement2("A");
2640 ClassElementImpl classB = ElementFactory.classElement2("B");
2641 ClassElementImpl classC = ElementFactory.classElement2("C");
2642 InterfaceType typeA = classA.type;
2643 InterfaceType typeB = classB.type;
2644 InterfaceType typeC = classC.type;
2645 classB.interfaces = <InterfaceType>[typeA];
2646 classC.interfaces = <InterfaceType>[typeA];
2647 expect(typeB.getLeastUpperBound(typeC), typeA);
2648 expect(typeC.getLeastUpperBound(typeB), typeA);
2649 }
2650
2651 void test_getLeastUpperBound_sharedSuperinterface2() {
2652 ClassElementImpl classA = ElementFactory.classElement2("A");
2653 ClassElementImpl classB = ElementFactory.classElement2("B");
2654 ClassElementImpl classC = ElementFactory.classElement2("C");
2655 ClassElementImpl classD = ElementFactory.classElement2("D");
2656 InterfaceType typeA = classA.type;
2657 InterfaceType typeB = classB.type;
2658 InterfaceType typeC = classC.type;
2659 InterfaceType typeD = classD.type;
2660 classB.interfaces = <InterfaceType>[typeA];
2661 classC.interfaces = <InterfaceType>[typeA];
2662 classD.interfaces = <InterfaceType>[typeC];
2663 expect(typeB.getLeastUpperBound(typeD), typeA);
2664 expect(typeD.getLeastUpperBound(typeB), typeA);
2665 }
2666
2667 void test_getLeastUpperBound_sharedSuperinterface3() {
2668 ClassElementImpl classA = ElementFactory.classElement2("A");
2669 ClassElementImpl classB = ElementFactory.classElement2("B");
2670 ClassElementImpl classC = ElementFactory.classElement2("C");
2671 ClassElementImpl classD = ElementFactory.classElement2("D");
2672 InterfaceType typeA = classA.type;
2673 InterfaceType typeB = classB.type;
2674 InterfaceType typeC = classC.type;
2675 InterfaceType typeD = classD.type;
2676 classB.interfaces = <InterfaceType>[typeA];
2677 classC.interfaces = <InterfaceType>[typeB];
2678 classD.interfaces = <InterfaceType>[typeB];
2679 expect(typeC.getLeastUpperBound(typeD), typeB);
2680 expect(typeD.getLeastUpperBound(typeC), typeB);
2681 }
2682
2683 void test_getLeastUpperBound_sharedSuperinterface4() {
2684 ClassElement classA = ElementFactory.classElement2("A");
2685 ClassElement classA2 = ElementFactory.classElement2("A2");
2686 ClassElement classA3 = ElementFactory.classElement2("A3");
2687 ClassElementImpl classB = ElementFactory.classElement2("B");
2688 ClassElementImpl classC = ElementFactory.classElement2("C");
2689 InterfaceType typeA = classA.type;
2690 InterfaceType typeA2 = classA2.type;
2691 InterfaceType typeA3 = classA3.type;
2692 InterfaceType typeB = classB.type;
2693 InterfaceType typeC = classC.type;
2694 classB.interfaces = <InterfaceType>[typeA, typeA2];
2695 classC.interfaces = <InterfaceType>[typeA, typeA3];
2696 expect(typeB.getLeastUpperBound(typeC), typeA);
2697 expect(typeC.getLeastUpperBound(typeB), typeA);
2698 }
2699
2700 void test_getLeastUpperBound_twoComparables() {
2701 InterfaceType string = _typeProvider.stringType;
2702 InterfaceType num = _typeProvider.numType;
2703 expect(string.getLeastUpperBound(num), _typeProvider.objectType);
2704 }
2705
2706 void test_getLeastUpperBound_typeParameters_different() {
2707 //
2708 // class List<int>
2709 // class List<double>
2710 //
2711 InterfaceType listType = _typeProvider.listType;
2712 InterfaceType intType = _typeProvider.intType;
2713 InterfaceType doubleType = _typeProvider.doubleType;
2714 InterfaceType listOfIntType = listType.substitute4(<DartType>[intType]);
2715 InterfaceType listOfDoubleType =
2716 listType.substitute4(<DartType>[doubleType]);
2717 expect(listOfIntType.getLeastUpperBound(listOfDoubleType),
2718 _typeProvider.objectType);
2719 }
2720
2721 void test_getLeastUpperBound_typeParameters_same() {
2722 //
2723 // List<int>
2724 // List<int>
2725 //
2726 InterfaceType listType = _typeProvider.listType;
2727 InterfaceType intType = _typeProvider.intType;
2728 InterfaceType listOfIntType = listType.substitute4(<DartType>[intType]);
2729 expect(listOfIntType.getLeastUpperBound(listOfIntType), listOfIntType);
2730 }
2731
2732 void test_getMethod_implemented() { 2467 void test_getMethod_implemented() {
2733 // 2468 //
2734 // class A { m() {} } 2469 // class A { m() {} }
2735 // 2470 //
2736 ClassElementImpl classA = ElementFactory.classElement2("A"); 2471 ClassElementImpl classA = ElementFactory.classElement2("A");
2737 String methodName = "m"; 2472 String methodName = "m";
2738 MethodElementImpl methodM = ElementFactory.methodElement(methodName, null); 2473 MethodElementImpl methodM = ElementFactory.methodElement(methodName, null);
2739 classA.methods = <MethodElement>[methodM]; 2474 classA.methods = <MethodElement>[methodM];
2740 InterfaceType typeA = classA.type; 2475 InterfaceType typeA = classA.type;
2741 expect(typeA.getMethod(methodName), same(methodM)); 2476 expect(typeA.getMethod(methodName), same(methodM));
(...skipping 1529 matching lines...) Expand 10 before | Expand all | Expand 10 after
4271 } 4006 }
4272 4007
4273 class _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction 4008 class _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction
4274 extends InterfaceTypeImpl { 4009 extends InterfaceTypeImpl {
4275 _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction(ClassElement arg0) 4010 _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction(ClassElement arg0)
4276 : super(arg0); 4011 : super(arg0);
4277 4012
4278 @override 4013 @override
4279 bool get isDartCoreFunction => true; 4014 bool get isDartCoreFunction => true;
4280 } 4015 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/all_the_rest_test.dart ('k') | pkg/analyzer/test/generated/engine_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698