diff --git a/lib/src/element_type.dart b/lib/src/element_type.dart index c2bee91dc0..f9ee455aea 100644 --- a/lib/src/element_type.dart +++ b/lib/src/element_type.dart @@ -67,10 +67,7 @@ class ElementType { if (e == null || e.library == null) { return null; } - Library lib = element.package.findLibraryFor(e); - if (lib == null) { - lib = new Library(e.library, element.package); - } + Library lib = new ModelElement.from(e.library, element.library); return (new ModelElement.from(e, lib)); } @@ -78,11 +75,9 @@ class ElementType { var type = _type; if (type is FunctionType) { Iterable typeArguments; - if (type.element is FunctionTypeAliasElement && - type.typeFormals.isEmpty) { - // TODO(jmesserly): simplify check above; we should have a way - // to find instantiated typedefs without consulting the element. - // Also, it will not work if we support typedefs declared inside classes. + if (element is! ModelFunctionAnonymous && type.typeFormals.isEmpty) { + // TODO(jcollins-g): replace with if (FunctionType.isInstantiated) once + // that's reliable and revealed through the interface. typeArguments = type.typeArguments; } else { typeArguments = type.typeFormals.map((f) => f.type); @@ -100,7 +95,7 @@ class ElementType { var rt = _returnTypeCore; Library lib = element.package.findLibraryFor(rt.element); if (lib == null) { - lib = new Library(rt.element.library, element.package); + lib = new ModelElement.from(rt.element.library, element.library); } return new ElementType(rt, new ModelElement.from(rt.element, lib)); } @@ -132,9 +127,8 @@ class ElementType { ElementType _getElementTypeFrom(DartType f) { Library lib; // can happen if element is dynamic - lib = element.package.findLibraryFor(f.element); - if (lib == null && f.element.library != null) { - lib = new Library(f.element.library, element.package); + if (f.element.library != null) { + lib = new ModelElement.from(f.element.library, element.library); } return new ElementType(f, new ModelElement.from(f.element, lib)); } diff --git a/lib/src/model.dart b/lib/src/model.dart index 76a595bcb4..0bb4e90a38 100644 --- a/lib/src/model.dart +++ b/lib/src/model.dart @@ -2221,8 +2221,13 @@ abstract class ModelElement extends Nameable assert(e.name != ''); newModelElement = new ModelFunctionTypedef(e, library); } else { - assert(e.name == ''); - newModelElement = new ModelFunctionAnonymous(e, library); + if (e.enclosingElement is GenericTypeAliasElement) { + assert(e.enclosingElement.name != ''); + newModelElement = new ModelFunctionTypedef(e, library); + } else { + assert(e.name == ''); + newModelElement = new ModelFunctionAnonymous(e, library); + } } } if (e is FunctionTypeAliasElement) { @@ -2294,7 +2299,6 @@ abstract class ModelElement extends Nameable } } - if (newModelElement == null) throw "Unknown type ${e.runtimeType}"; if (enclosingClass != null) assert(newModelElement is Inheritable); if (library != null) { @@ -2902,7 +2906,8 @@ abstract class ModelElement extends Nameable } if (param.modelType.isFunctionType) { var returnTypeName; - bool isTypedef = param.modelType.element is Typedef; + bool isTypedef = (param.modelType.element is Typedef || + param.modelType.element is ModelFunctionTypedef); if (isTypedef) { returnTypeName = param.modelType.linkedName; } else { @@ -3218,13 +3223,6 @@ class ModelFunction extends ModelFunctionTyped { return _func.isStatic; } - @override - String get name { - if (element.enclosingElement is ParameterElement && super.name.isEmpty) - return element.enclosingElement.name; - return super.name; - } - @override FunctionElement get _func => (element as FunctionElement); } @@ -3250,13 +3248,14 @@ class ModelFunctionAnonymous extends ModelFunctionTyped { /// explicit typedef. class ModelFunctionTypedef extends ModelFunctionTyped { ModelFunctionTypedef(FunctionTypedElement element, Library library) - : super(element, library) {} + : super(element, library); @override String get name { Element e = element; while (e != null) { - if (e is FunctionTypeAliasElement) return e.name; + if (e is FunctionTypeAliasElement || e is GenericTypeAliasElement) + return e.name; e = e.enclosingElement; } assert(false); diff --git a/lib/src/model_utils.dart b/lib/src/model_utils.dart index ef809d98b2..970e7e69a4 100644 --- a/lib/src/model_utils.dart +++ b/lib/src/model_utils.dart @@ -60,7 +60,7 @@ bool hasPrivateName(Element e) { if (e is LibraryElement && (e.identifier.startsWith('dart:_') || ['dart:nativewrappers'].contains(e.identifier))) { - return true; + return true; } if (e is LibraryElement) { List locationParts = e.location.components[0].split(slashes); diff --git a/pubspec.yaml b/pubspec.yaml index 826af267ab..7a84a4b547 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -28,6 +28,6 @@ dev_dependencies: http: ^0.11.0 meta: ^1.0.0 pub_semver: ^1.0.0 - test: '^0.12.20+24' + test: '^0.12.24' executables: dartdoc: null diff --git a/test/model_test.dart b/test/model_test.dart index a871805cef..decac3ab51 100644 --- a/test/model_test.dart +++ b/test/model_test.dart @@ -1030,7 +1030,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, Class classB, klass, HasGenerics, Cat, CatString, TypedFunctionsWithoutTypedefs; Method m1, isGreaterThan, m4, m5, m6, m7, convertToMap, abstractMethod; Method inheritedClear, testGeneric, testGenericMethod; - Method getAFunctionReturningVoid; + Method getAFunctionReturningVoid, getAFunctionReturningBool; setUp(() { klass = exLibrary.classes.singleWhere((c) => c.name == 'Klass'); @@ -1064,6 +1064,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, .singleWhere((m) => m.name == 'convertToMap'); TypedFunctionsWithoutTypedefs = exLibrary.classes.singleWhere((c) => c.name == 'TypedFunctionsWithoutTypedefs'); getAFunctionReturningVoid = TypedFunctionsWithoutTypedefs.instanceMethods.singleWhere((m) => m.name == 'getAFunctionReturningVoid'); + getAFunctionReturningBool = TypedFunctionsWithoutTypedefs.instanceMethods.singleWhere((m) => m.name == 'getAFunctionReturningBool'); }); tearDown(() { @@ -1082,6 +1083,15 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans, expect(getAFunctionReturningVoid.linkedReturnType, equals('Function(T1 T2)')); }, skip: 'blocked on https://github.com/dart-lang/sdk/issues/30146'); + test('verify type parameters to anonymous functions are distinct from normal parameters and instantiated type parameters from method', () { + var matcher = new RegExp('Function<T4>\\(String [^<]* [^<]*\\)'); + expect(matcher.hasMatch(getAFunctionReturningBool.linkedReturnType), isTrue); + }); + + test('verify type parameters to anonymous functions are distinct from normal parameters and instantiated type parameters from method, displayed correctly', () { + expect(getAFunctionReturningBool.linkedReturnType, equals('Function<T4>(String T1 T4)')); + }, skip: 'blocked on https://github.com/dart-lang/sdk/issues/30146'); + test('has a fully qualified name', () { expect(m1.fullyQualifiedName, 'ex.B.m1'); }); diff --git a/testing/test_package/lib/example.dart b/testing/test_package/lib/example.dart index fd107e5d9d..3605a17515 100644 --- a/testing/test_package/lib/example.dart +++ b/testing/test_package/lib/example.dart @@ -434,6 +434,10 @@ abstract class TypedFunctionsWithoutTypedefs { void Function(T1, T2) getAFunctionReturningVoid( void callback(T1 argument1, T2 argument2)); + /// This helps us make sure we get both the empty and the non-empty + /// case right for anonymous functions. + bool Function(String, T1, T4) getAFunctionReturningBool(); + /// Returns a complex typedef that includes some anonymous typed functions. aComplexTypedef getAComplexTypedef(); } \ No newline at end of file diff --git a/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs-class.html b/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs-class.html index 69c464a3e5..4eee53f254 100644 --- a/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs-class.html +++ b/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs-class.html @@ -148,12 +148,22 @@

Methods

getAComplexTypedef<A4, A5, A6>() - → Function(A3 A3) + aComplexTypedef
Returns a complex typedef that includes some anonymous typed functions. +
+
+ getAFunctionReturningBool<T1, T2, T3>() + → Function<T4>(String String String) + +
+
+ This helps us make sure we get both the empty and the non-empty +case right for anonymous functions. +
getAFunctionReturningVoid<T1, T2>(void callback(T1 argument1, T2 argument2)) @@ -219,6 +229,7 @@
class TypedFunctionsWithoutTypedefs
  • Methods
  • getAComplexTypedef
  • +
  • getAFunctionReturningBool
  • getAFunctionReturningVoid
  • noSuchMethod
  • toString
  • diff --git a/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/TypedFunctionsWithoutTypedefs.html b/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/TypedFunctionsWithoutTypedefs.html index 81cdb960a7..3e7c0f4b3c 100644 --- a/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/TypedFunctionsWithoutTypedefs.html +++ b/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/TypedFunctionsWithoutTypedefs.html @@ -50,6 +50,7 @@
    class TypedFunctionsWithoutTypedefs
  • Methods
  • getAComplexTypedef
  • +
  • getAFunctionReturningBool
  • getAFunctionReturningVoid
  • noSuchMethod
  • toString
  • diff --git a/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/getAComplexTypedef.html b/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/getAComplexTypedef.html index d0e11e4f51..ce46e09b90 100644 --- a/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/getAComplexTypedef.html +++ b/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/getAComplexTypedef.html @@ -50,6 +50,7 @@
    class TypedFunctionsWithoutTypedefs
  • Methods
  • getAComplexTypedef
  • +
  • getAFunctionReturningBool
  • getAFunctionReturningVoid
  • noSuchMethod
  • toString
  • @@ -64,7 +65,7 @@
    class TypedFunctionsWithoutTypedefs
    - Function(A3 A3) + aComplexTypedef getAComplexTypedef<A4, A5, A6>()
    diff --git a/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/getAFunctionReturningBool.html b/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/getAFunctionReturningBool.html new file mode 100644 index 0000000000..e39aa85055 --- /dev/null +++ b/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/getAFunctionReturningBool.html @@ -0,0 +1,106 @@ + + + + + + + + getAFunctionReturningBool method - TypedFunctionsWithoutTypedefs class - ex library - Dart API + + + + + + + + + + + + +
    + +
    + + +
    getAFunctionReturningBool
    + +
    + +
    + + + +
    +
    + Function<T4>(String String String) + getAFunctionReturningBool<T1, T2, T3>() +
    +
    +

    This helps us make sure we get both the empty and the non-empty +case right for anonymous functions.

    +
    + + + +
    + + + +
    + +
    + + test_package 0.0.1 + + • + + cc license + + +
    + + + + + + + + + + + diff --git a/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/getAFunctionReturningVoid.html b/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/getAFunctionReturningVoid.html index 209bd83047..7a55b9b073 100644 --- a/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/getAFunctionReturningVoid.html +++ b/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/getAFunctionReturningVoid.html @@ -50,6 +50,7 @@
    class TypedFunctionsWithoutTypedefs
  • Methods
  • getAComplexTypedef
  • +
  • getAFunctionReturningBool
  • getAFunctionReturningVoid
  • noSuchMethod
  • toString
  • diff --git a/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/hashCode.html b/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/hashCode.html index d6e5f193c2..b510d45b0e 100644 --- a/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/hashCode.html +++ b/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/hashCode.html @@ -50,6 +50,7 @@
    class TypedFunctionsWithoutTypedefs
  • Methods
  • getAComplexTypedef
  • +
  • getAFunctionReturningBool
  • getAFunctionReturningVoid
  • noSuchMethod
  • toString
  • diff --git a/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/noSuchMethod.html b/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/noSuchMethod.html index 066eb75c3d..785a97c02b 100644 --- a/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/noSuchMethod.html +++ b/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/noSuchMethod.html @@ -50,6 +50,7 @@
    class TypedFunctionsWithoutTypedefs
  • Methods
  • getAComplexTypedef
  • +
  • getAFunctionReturningBool
  • getAFunctionReturningVoid
  • noSuchMethod
  • toString
  • diff --git a/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/operator_equals.html b/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/operator_equals.html index e515e6d5c6..e7e961854c 100644 --- a/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/operator_equals.html +++ b/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/operator_equals.html @@ -50,6 +50,7 @@
    class TypedFunctionsWithoutTypedefs
  • Methods
  • getAComplexTypedef
  • +
  • getAFunctionReturningBool
  • getAFunctionReturningVoid
  • noSuchMethod
  • toString
  • diff --git a/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/runtimeType.html b/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/runtimeType.html index 396376fbf4..527241a8d9 100644 --- a/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/runtimeType.html +++ b/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/runtimeType.html @@ -50,6 +50,7 @@
    class TypedFunctionsWithoutTypedefs
  • Methods
  • getAComplexTypedef
  • +
  • getAFunctionReturningBool
  • getAFunctionReturningVoid
  • noSuchMethod
  • toString
  • diff --git a/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/toString.html b/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/toString.html index 3323be9ccc..d0dfa37113 100644 --- a/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/toString.html +++ b/testing/test_package_docs/ex/TypedFunctionsWithoutTypedefs/toString.html @@ -50,6 +50,7 @@
    class TypedFunctionsWithoutTypedefs
  • Methods
  • getAComplexTypedef
  • +
  • getAFunctionReturningBool
  • getAFunctionReturningVoid
  • noSuchMethod
  • toString
  • diff --git a/testing/test_package_docs/index.json b/testing/test_package_docs/index.json index 6a4afcd845..f0aa63a07a 100644 --- a/testing/test_package_docs/index.json +++ b/testing/test_package_docs/index.json @@ -2751,6 +2751,17 @@ "type": "class" } }, + { + "name": "getAFunctionReturningBool", + "qualifiedName": "ex.TypedFunctionsWithoutTypedefs.getAFunctionReturningBool", + "href": "ex/TypedFunctionsWithoutTypedefs/getAFunctionReturningBool.html", + "type": "method", + "overriddenDepth": 0, + "enclosedBy": { + "name": "TypedFunctionsWithoutTypedefs", + "type": "class" + } + }, { "name": "getAFunctionReturningVoid", "qualifiedName": "ex.TypedFunctionsWithoutTypedefs.getAFunctionReturningVoid",