Skip to content

Miscellaneous generic function & head analyzer fixups #1509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions lib/src/element_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,17 @@ 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));
}

List<ElementType> get typeArguments {
var type = _type;
if (type is FunctionType) {
Iterable<DartType> 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);
Expand All @@ -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));
}
Expand Down Expand Up @@ -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));
}
Expand Down
25 changes: 12 additions & 13 deletions lib/src/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> locationParts = e.location.components[0].split(slashes);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 11 additions & 1 deletion test/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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(() {
Expand All @@ -1082,6 +1083,15 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
expect(getAFunctionReturningVoid.linkedReturnType, equals('Function(<span class="parameter" id="getAFunctionReturningVoid-param-"><span class="type-annotation">T1</span></span> <span class="parameter" id="getAFunctionReturningVoid-param-"><span class="type-annotation">T2</span></span>)'));
}, 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&lt;T4&gt;\\(<span class="parameter" id="getAFunctionReturningBool-param-"><span class="type-annotation">String</span></span> <span class="parameter" id="getAFunctionReturningBool-param-"><span class="type-annotation">[^<]*</span></span> <span class="parameter" id="getAFunctionReturningBool-param-"><span class="type-annotation">[^<]*</span></span>\\)');
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&lt;T4&gt;(<span class="parameter" id="getAFunctionReturningBool-param-"><span class="type-annotation">String</span></span> <span class="parameter" id="getAFunctionReturningBool-param-"><span class="type-annotation">T1</span></span> <span class="parameter" id="getAFunctionReturningBool-param-"><span class="type-annotation">T4</span></span>)'));
}, skip: 'blocked on https://github.com/dart-lang/sdk/issues/30146');

test('has a fully qualified name', () {
expect(m1.fullyQualifiedName, 'ex.B.m1');
});
Expand Down
4 changes: 4 additions & 0 deletions testing/test_package/lib/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,10 @@ abstract class TypedFunctionsWithoutTypedefs {
void Function(T1, T2) getAFunctionReturningVoid<T1, T2>(
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<T4>(String, T1, T4) getAFunctionReturningBool<T1, T2, T3>();

/// Returns a complex typedef that includes some anonymous typed functions.
aComplexTypedef getAComplexTypedef<A4, A5, A6>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,22 @@ <h2>Methods</h2>
<dl class="callables">
<dt id="getAComplexTypedef" class="callable">
<span class="name"><a href="ex/TypedFunctionsWithoutTypedefs/getAComplexTypedef.html">getAComplexTypedef</a></span><span class="signature">&lt;A4, A5, A6&gt;(<wbr>)
<span class="returntype parameter">&#8594; Function(<span class="parameter" id="aComplexTypedef-param-"><span class="type-annotation">A3</span></span> <span class="parameter" id="aComplexTypedef-param-"><span class="type-annotation">A3</span></span>)</span>
<span class="returntype parameter">&#8594; <a href="ex/aComplexTypedef.html">aComplexTypedef</a></span>
</span>
</dt>
<dd>
Returns a complex typedef that includes some anonymous typed functions.

</dd>
<dt id="getAFunctionReturningBool" class="callable">
<span class="name"><a href="ex/TypedFunctionsWithoutTypedefs/getAFunctionReturningBool.html">getAFunctionReturningBool</a></span><span class="signature">&lt;T1, T2, T3&gt;(<wbr>)
<span class="returntype parameter">&#8594; Function&lt;T4&gt;(<span class="parameter" id="getAFunctionReturningBool-param-"><span class="type-annotation">String</span></span> <span class="parameter" id="getAFunctionReturningBool-param-"><span class="type-annotation">String</span></span> <span class="parameter" id="getAFunctionReturningBool-param-"><span class="type-annotation">String</span></span>)</span>
</span>
</dt>
<dd>
This helps us make sure we get both the empty and the non-empty
case right for anonymous functions.

</dd>
<dt id="getAFunctionReturningVoid" class="callable">
<span class="name"><a href="ex/TypedFunctionsWithoutTypedefs/getAFunctionReturningVoid.html">getAFunctionReturningVoid</a></span><span class="signature">&lt;T1, T2&gt;(<wbr><span class="parameter" id="getAFunctionReturningVoid-param-callback"><span class="type-annotation">void</span> <span class="parameter-name">callback</span>(<span class="parameter" id="callback-param-argument1"><span class="type-annotation">T1</span> <span class="parameter-name">argument1</span>, </span> <span class="parameter" id="callback-param-argument2"><span class="type-annotation">T2</span> <span class="parameter-name">argument2</span></span>)</span>)
Expand Down Expand Up @@ -219,6 +229,7 @@ <h5>class TypedFunctionsWithoutTypedefs</h5>

<li class="section-title"><a href="ex/TypedFunctionsWithoutTypedefs-class.html#instance-methods">Methods</a></li>
<li><a href="ex/TypedFunctionsWithoutTypedefs/getAComplexTypedef.html">getAComplexTypedef</a></li>
<li><a href="ex/TypedFunctionsWithoutTypedefs/getAFunctionReturningBool.html">getAFunctionReturningBool</a></li>
<li><a href="ex/TypedFunctionsWithoutTypedefs/getAFunctionReturningVoid.html">getAFunctionReturningVoid</a></li>
<li class="inherited"><a href="ex/TypedFunctionsWithoutTypedefs/noSuchMethod.html">noSuchMethod</a></li>
<li class="inherited"><a href="ex/TypedFunctionsWithoutTypedefs/toString.html">toString</a></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ <h5>class TypedFunctionsWithoutTypedefs</h5>

<li class="section-title"><a href="ex/TypedFunctionsWithoutTypedefs-class.html#instance-methods">Methods</a></li>
<li><a href="ex/TypedFunctionsWithoutTypedefs/getAComplexTypedef.html">getAComplexTypedef</a></li>
<li><a href="ex/TypedFunctionsWithoutTypedefs/getAFunctionReturningBool.html">getAFunctionReturningBool</a></li>
<li><a href="ex/TypedFunctionsWithoutTypedefs/getAFunctionReturningVoid.html">getAFunctionReturningVoid</a></li>
<li class="inherited"><a href="ex/TypedFunctionsWithoutTypedefs/noSuchMethod.html">noSuchMethod</a></li>
<li class="inherited"><a href="ex/TypedFunctionsWithoutTypedefs/toString.html">toString</a></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ <h5>class TypedFunctionsWithoutTypedefs</h5>

<li class="section-title"><a href="ex/TypedFunctionsWithoutTypedefs-class.html#instance-methods">Methods</a></li>
<li><a href="ex/TypedFunctionsWithoutTypedefs/getAComplexTypedef.html">getAComplexTypedef</a></li>
<li><a href="ex/TypedFunctionsWithoutTypedefs/getAFunctionReturningBool.html">getAFunctionReturningBool</a></li>
<li><a href="ex/TypedFunctionsWithoutTypedefs/getAFunctionReturningVoid.html">getAFunctionReturningVoid</a></li>
<li class="inherited"><a href="ex/TypedFunctionsWithoutTypedefs/noSuchMethod.html">noSuchMethod</a></li>
<li class="inherited"><a href="ex/TypedFunctionsWithoutTypedefs/toString.html">toString</a></li>
Expand All @@ -64,7 +65,7 @@ <h5>class TypedFunctionsWithoutTypedefs</h5>

<div class="col-xs-12 col-sm-9 col-md-8 main-content">
<section class="multi-line-signature">
<span class="returntype">Function(<span class="parameter" id="aComplexTypedef-param-"><span class="type-annotation">A3</span></span> <span class="parameter" id="aComplexTypedef-param-"><span class="type-annotation">A3</span></span>)</span>
<span class="returntype"><a href="ex/aComplexTypedef.html">aComplexTypedef</a></span>
<span class="name ">getAComplexTypedef</span>&lt;A4, A5, A6&gt;(<wbr>)
</section>
<section class="desc markdown">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="API docs for the getAFunctionReturningBool method from the TypedFunctionsWithoutTypedefs class, for the Dart programming language.">
<title>getAFunctionReturningBool method - TypedFunctionsWithoutTypedefs class - ex library - Dart API</title>
<!-- required because all the links are pseudo-absolute -->
<base href="../..">

<link href="https://fonts.googleapis.com/css?family=Source+Code+Pro:500,400i,400,300|Source+Sans+Pro:400,300,700" rel="stylesheet">
<link rel="stylesheet" href="static-assets/github.css">
<link rel="stylesheet" href="static-assets/styles.css">
<link rel="icon" href="static-assets/favicon.png">

</head>

<body>

<div id="overlay-under-drawer"></div>

<header id="title">
<button id="sidenav-left-toggle" type="button">&nbsp;</button>
<ol class="breadcrumbs gt-separated dark hidden-xs">
<li><a href="index.html">test_package</a></li>
<li><a href="ex/ex-library.html">ex</a></li>
<li><a href="ex/TypedFunctionsWithoutTypedefs-class.html">TypedFunctionsWithoutTypedefs</a></li>
<li class="self-crumb">abstract method getAFunctionReturningBool&lt;T1, T2, T3&gt;</li>
</ol>
<div class="self-name">getAFunctionReturningBool</div>
<form class="search navbar-right" role="search">
<input type="text" id="search-box" autocomplete="off" disabled class="form-control typeahead" placeholder="Loading search...">
</form>
</header>

<main>

<div class="col-xs-6 col-sm-3 col-md-2 sidebar sidebar-offcanvas-left">
<h5>class TypedFunctionsWithoutTypedefs</h5>
<ol>
<li class="section-title"><a href="ex/TypedFunctionsWithoutTypedefs-class.html#constructors">Constructors</a></li>
<li><a href="ex/TypedFunctionsWithoutTypedefs/TypedFunctionsWithoutTypedefs.html">TypedFunctionsWithoutTypedefs</a></li>

<li class="section-title inherited">
<a href="ex/TypedFunctionsWithoutTypedefs-class.html#instance-properties">Properties</a>
</li>
<li class="inherited"><a href="ex/TypedFunctionsWithoutTypedefs/hashCode.html">hashCode</a></li>
<li class="inherited"><a href="ex/TypedFunctionsWithoutTypedefs/runtimeType.html">runtimeType</a></li>

<li class="section-title"><a href="ex/TypedFunctionsWithoutTypedefs-class.html#instance-methods">Methods</a></li>
<li><a href="ex/TypedFunctionsWithoutTypedefs/getAComplexTypedef.html">getAComplexTypedef</a></li>
<li><a href="ex/TypedFunctionsWithoutTypedefs/getAFunctionReturningBool.html">getAFunctionReturningBool</a></li>
<li><a href="ex/TypedFunctionsWithoutTypedefs/getAFunctionReturningVoid.html">getAFunctionReturningVoid</a></li>
<li class="inherited"><a href="ex/TypedFunctionsWithoutTypedefs/noSuchMethod.html">noSuchMethod</a></li>
<li class="inherited"><a href="ex/TypedFunctionsWithoutTypedefs/toString.html">toString</a></li>

<li class="section-title inherited"><a href="ex/TypedFunctionsWithoutTypedefs-class.html#operators">Operators</a></li>
<li class="inherited"><a href="ex/TypedFunctionsWithoutTypedefs/operator_equals.html">operator ==</a></li>



</ol>
</div><!--/.sidebar-offcanvas-->

<div class="col-xs-12 col-sm-9 col-md-8 main-content">
<section class="multi-line-signature">
<span class="returntype">Function&lt;T4&gt;(<span class="parameter" id="getAFunctionReturningBool-param-"><span class="type-annotation">String</span></span> <span class="parameter" id="getAFunctionReturningBool-param-"><span class="type-annotation">String</span></span> <span class="parameter" id="getAFunctionReturningBool-param-"><span class="type-annotation">String</span></span>)</span>
<span class="name ">getAFunctionReturningBool</span>&lt;T1, T2, T3&gt;(<wbr>)
</section>
<section class="desc markdown">
<p>This helps us make sure we get both the empty and the non-empty
case right for anonymous functions.</p>
</section>



</div> <!-- /.main-content -->

<div class="col-xs-6 col-sm-6 col-md-2 sidebar sidebar-offcanvas-right">
<h5>method getAFunctionReturningBool</h5>
</div><!--/.sidebar-offcanvas-->

</main>

<footer>
<span class="no-break">
test_package 0.0.1
</span>
&bull;
<span class="copyright no-break">
<a href="http://creativecommons.org/licenses/by-sa/4.0/">cc license</a>
</span>

</footer>

<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="static-assets/typeahead.bundle.min.js"></script>
<script src="static-assets/highlight.pack.js"></script>
<script src="static-assets/URI.js"></script>
<script src="static-assets/script.js"></script>


</body>

</html>
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ <h5>class TypedFunctionsWithoutTypedefs</h5>

<li class="section-title"><a href="ex/TypedFunctionsWithoutTypedefs-class.html#instance-methods">Methods</a></li>
<li><a href="ex/TypedFunctionsWithoutTypedefs/getAComplexTypedef.html">getAComplexTypedef</a></li>
<li><a href="ex/TypedFunctionsWithoutTypedefs/getAFunctionReturningBool.html">getAFunctionReturningBool</a></li>
<li><a href="ex/TypedFunctionsWithoutTypedefs/getAFunctionReturningVoid.html">getAFunctionReturningVoid</a></li>
<li class="inherited"><a href="ex/TypedFunctionsWithoutTypedefs/noSuchMethod.html">noSuchMethod</a></li>
<li class="inherited"><a href="ex/TypedFunctionsWithoutTypedefs/toString.html">toString</a></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ <h5>class TypedFunctionsWithoutTypedefs</h5>

<li class="section-title"><a href="ex/TypedFunctionsWithoutTypedefs-class.html#instance-methods">Methods</a></li>
<li><a href="ex/TypedFunctionsWithoutTypedefs/getAComplexTypedef.html">getAComplexTypedef</a></li>
<li><a href="ex/TypedFunctionsWithoutTypedefs/getAFunctionReturningBool.html">getAFunctionReturningBool</a></li>
<li><a href="ex/TypedFunctionsWithoutTypedefs/getAFunctionReturningVoid.html">getAFunctionReturningVoid</a></li>
<li class="inherited"><a href="ex/TypedFunctionsWithoutTypedefs/noSuchMethod.html">noSuchMethod</a></li>
<li class="inherited"><a href="ex/TypedFunctionsWithoutTypedefs/toString.html">toString</a></li>
Expand Down
Loading