@@ -1968,12 +1968,7 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl
19681968
19691969 @override
19701970 ClassElement getType (String className) {
1971- for (ClassElement type in types) {
1972- if (type.name == className) {
1973- return type;
1974- }
1975- }
1976- return null ;
1971+ return getTypeFromTypes (className, types);
19771972 }
19781973
19791974 /**
@@ -2013,6 +2008,16 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl
20132008 safelyVisitChildren (types, visitor);
20142009 safelyVisitChildren (topLevelVariables, visitor);
20152010 }
2011+
2012+ static ClassElement getTypeFromTypes (
2013+ String className, List <ClassElement > types) {
2014+ for (ClassElement type in types) {
2015+ if (type.name == className) {
2016+ return type;
2017+ }
2018+ }
2019+ return null ;
2020+ }
20162021}
20172022
20182023/**
@@ -6818,13 +6823,8 @@ class LibraryElementImpl extends ElementImpl implements LibraryElement {
68186823 * using types provided by [typeProvider] .
68196824 */
68206825 void createLoadLibraryFunction (TypeProvider typeProvider) {
6821- FunctionElementImpl function =
6822- new FunctionElementImpl (FunctionElement .LOAD_LIBRARY_NAME , - 1 );
6823- function.isSynthetic = true ;
6824- function.enclosingElement = this ;
6825- function.returnType = typeProvider.futureDynamicType;
6826- function.type = new FunctionTypeImpl (function);
6827- _loadLibraryFunction = function;
6826+ _loadLibraryFunction =
6827+ createLoadLibraryFunctionForLibrary (typeProvider, this );
68286828 }
68296829
68306830 @override
@@ -6870,30 +6870,12 @@ class LibraryElementImpl extends ElementImpl implements LibraryElement {
68706870
68716871 @override
68726872 List <ImportElement > getImportsWithPrefix (PrefixElement prefixElement) {
6873- var imports = this .imports;
6874- int count = imports.length;
6875- List <ImportElement > importList = new List <ImportElement >();
6876- for (int i = 0 ; i < count; i++ ) {
6877- if (identical (imports[i].prefix, prefixElement)) {
6878- importList.add (imports[i]);
6879- }
6880- }
6881- return importList;
6873+ return getImportsWithPrefixFromImports (prefixElement, imports);
68826874 }
68836875
68846876 @override
68856877 ClassElement getType (String className) {
6886- ClassElement type = _definingCompilationUnit.getType (className);
6887- if (type != null ) {
6888- return type;
6889- }
6890- for (CompilationUnitElement part in _parts) {
6891- type = part.getType (className);
6892- if (type != null ) {
6893- return type;
6894- }
6895- }
6896- return null ;
6878+ return getTypeFromParts (className, _definingCompilationUnit, _parts);
68976879 }
68986880
68996881 /** Given an update to this library which may have added or deleted edges
@@ -6988,6 +6970,17 @@ class LibraryElementImpl extends ElementImpl implements LibraryElement {
69886970 return prefixes.toList (growable: false );
69896971 }
69906972
6973+ static FunctionElementImpl createLoadLibraryFunctionForLibrary (
6974+ TypeProvider typeProvider, LibraryElement library) {
6975+ FunctionElementImpl function =
6976+ new FunctionElementImpl (FunctionElement .LOAD_LIBRARY_NAME , - 1 );
6977+ function.isSynthetic = true ;
6978+ function.enclosingElement = library;
6979+ function.returnType = typeProvider.futureDynamicType;
6980+ function.type = new FunctionTypeImpl (function);
6981+ return function;
6982+ }
6983+
69916984 /**
69926985 * Return the [LibraryElementImpl] of the given [element] .
69936986 */
@@ -6998,6 +6991,35 @@ class LibraryElementImpl extends ElementImpl implements LibraryElement {
69986991 return element as LibraryElementImpl ;
69996992 }
70006993
6994+ static List <ImportElement > getImportsWithPrefixFromImports (
6995+ PrefixElement prefixElement, List <ImportElement > imports) {
6996+ int count = imports.length;
6997+ List <ImportElement > importList = new List <ImportElement >();
6998+ for (int i = 0 ; i < count; i++ ) {
6999+ if (identical (imports[i].prefix, prefixElement)) {
7000+ importList.add (imports[i]);
7001+ }
7002+ }
7003+ return importList;
7004+ }
7005+
7006+ static ClassElement getTypeFromParts (
7007+ String className,
7008+ CompilationUnitElement definingCompilationUnit,
7009+ List <CompilationUnitElement > parts) {
7010+ ClassElement type = definingCompilationUnit.getType (className);
7011+ if (type != null ) {
7012+ return type;
7013+ }
7014+ for (CompilationUnitElement part in parts) {
7015+ type = part.getType (className);
7016+ if (type != null ) {
7017+ return type;
7018+ }
7019+ }
7020+ return null ;
7021+ }
7022+
70017023 /**
70027024 * Return `true` if the [library] has the given [capability] .
70037025 */
0 commit comments