Skip to content

Commit fab5d0a

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
In InheritanceManager remove unused, and deprecate used (in lints) methods.
Also, remove it from ErrorVerifier. R=brianwilkerson@google.com Change-Id: I35f6f7fd2f8c6680ec470e7bf7da4780a3c69df3 Reviewed-on: https://dart-review.googlesource.com/c/79360 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
1 parent 2989116 commit fab5d0a

5 files changed

Lines changed: 39 additions & 138 deletions

File tree

pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@ class LibraryAnalyzer {
335335
errorReporter,
336336
_libraryElement,
337337
_typeProvider,
338-
new InheritanceManager(_libraryElement),
339338
_inheritance,
340339
_analysisOptions.enableSuperMixins);
341340
unit.accept(errorVerifier);

pkg/analyzer/lib/src/dart/resolver/inheritance_manager.dart

Lines changed: 2 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class InheritanceManager {
125125
* @return the inherited executable element with the member name, or `null` if no such
126126
* member exists
127127
*/
128+
@deprecated
128129
ExecutableElement lookupInheritance(
129130
ClassElement classElt, String memberName) {
130131
if (memberName == null || memberName.isEmpty) {
@@ -149,6 +150,7 @@ class InheritanceManager {
149150
* @return the inherited executable element with the member name, or `null` if no such
150151
* member exists
151152
*/
153+
@deprecated
152154
ExecutableElement lookupMember(ClassElement classElt, String memberName) {
153155
ExecutableElement element = _lookupMemberInClass(classElt, memberName);
154156
if (element != null) {
@@ -193,47 +195,6 @@ class InheritanceManager {
193195
return result;
194196
}
195197

196-
/**
197-
* This method takes some inherited [FunctionType], and resolves all the parameterized types
198-
* in the function type, dependent on the class in which it is being overridden.
199-
*
200-
* @param baseFunctionType the function type that is being overridden
201-
* @param memberName the name of the member, this is used to lookup the inheritance path of the
202-
* override
203-
* @param definingType the type that is overriding the member
204-
* @return the passed function type with any parameterized types substituted
205-
*/
206-
// TODO(jmesserly): investigate why this is needed in ErrorVerifier's override
207-
// checking. There seems to be some rare cases where we get partially
208-
// substituted type arguments, and the function types don't compare equally.
209-
FunctionType substituteTypeArgumentsInMemberFromInheritance(
210-
FunctionType baseFunctionType,
211-
String memberName,
212-
InterfaceType definingType) {
213-
// if the baseFunctionType is null, or does not have any parameters,
214-
// return it.
215-
if (baseFunctionType == null || baseFunctionType.typeArguments.isEmpty) {
216-
return baseFunctionType;
217-
}
218-
// First, generate the path from the defining type to the overridden member
219-
Queue<InterfaceType> inheritancePath = new Queue<InterfaceType>();
220-
_computeInheritancePath(inheritancePath, definingType, memberName);
221-
if (inheritancePath == null || inheritancePath.isEmpty) {
222-
// TODO(jwren) log analysis engine error
223-
return baseFunctionType;
224-
}
225-
FunctionType functionTypeToReturn = baseFunctionType;
226-
// loop backward through the list substituting as we go:
227-
while (!inheritancePath.isEmpty) {
228-
InterfaceType lastType = inheritancePath.removeLast();
229-
List<DartType> parameterTypes = lastType.element.type.typeArguments;
230-
List<DartType> argumentTypes = lastType.typeArguments;
231-
functionTypeToReturn =
232-
functionTypeToReturn.substitute2(argumentTypes, parameterTypes);
233-
}
234-
return functionTypeToReturn;
235-
}
236-
237198
/**
238199
* Compute and return a mapping between the set of all string names of the members inherited from
239200
* the passed [ClassElement] superclass hierarchy, and the associated
@@ -336,78 +297,6 @@ class InheritanceManager {
336297
return resultMap;
337298
}
338299

339-
/**
340-
* Compute and return the inheritance path given the context of a type and a member that is
341-
* overridden in the inheritance path (for which the type is in the path).
342-
*
343-
* @param chain the inheritance path that is built up as this method calls itself recursively,
344-
* when this method is called an empty [Queue] should be provided
345-
* @param currentType the current type in the inheritance path
346-
* @param memberName the name of the member that is being looked up the inheritance path
347-
*/
348-
void _computeInheritancePath(Queue<InterfaceType> chain,
349-
InterfaceType currentType, String memberName) {
350-
// TODO (jwren) create a public version of this method which doesn't require
351-
// the initial chain to be provided, then provided tests for this
352-
// functionality in InheritanceManagerTest
353-
chain.add(currentType);
354-
ClassElement classElt = currentType.element;
355-
// Base case- reached Object
356-
if (currentType.isObject) {
357-
// Looked up the chain all the way to Object, return null.
358-
// This should never happen.
359-
return;
360-
}
361-
// If we are done, return the chain
362-
// We are not done if this is the first recursive call on this method.
363-
if (chain.length != 1) {
364-
// We are done however if the member is in this classElt
365-
if (_lookupMemberInClass(classElt, memberName) != null) {
366-
return;
367-
}
368-
}
369-
// Mixins- note that mixins call lookupMemberInClass, not lookupMember
370-
List<InterfaceType> mixins = classElt.mixins;
371-
for (int i = mixins.length - 1; i >= 0; i--) {
372-
ClassElement mixinElement = mixins[i].element;
373-
if (mixinElement != null) {
374-
ExecutableElement elt = _lookupMemberInClass(mixinElement, memberName);
375-
if (elt != null) {
376-
// this is equivalent (but faster than) calling this method
377-
// recursively
378-
// (return computeInheritancePath(chain, mixins[i], memberName);)
379-
chain.add(mixins[i]);
380-
return;
381-
}
382-
}
383-
}
384-
// Superclass
385-
InterfaceType supertype = classElt.supertype;
386-
if (supertype != null &&
387-
lookupMember(supertype.element, memberName) != null) {
388-
_computeInheritancePath(chain, supertype, memberName);
389-
return;
390-
}
391-
// Superclass constraints
392-
for (InterfaceType interfaceType in classElt.superclassConstraints) {
393-
ClassElement interfaceElement = interfaceType.element;
394-
if (interfaceElement != null &&
395-
lookupMember(interfaceElement, memberName) != null) {
396-
_computeInheritancePath(chain, interfaceType, memberName);
397-
return;
398-
}
399-
}
400-
// Interfaces
401-
for (InterfaceType interfaceType in classElt.interfaces) {
402-
ClassElement interfaceElement = interfaceType.element;
403-
if (interfaceElement != null &&
404-
lookupMember(interfaceElement, memberName) != null) {
405-
_computeInheritancePath(chain, interfaceType, memberName);
406-
return;
407-
}
408-
}
409-
}
410-
411300
/**
412301
* Compute and return a mapping between the set of all string names of the members inherited from
413302
* the passed [ClassElement] interface hierarchy, and the associated

pkg/analyzer/lib/src/generated/error_verifier.dart

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import 'package:analyzer/src/dart/element/element.dart';
1919
import 'package:analyzer/src/dart/element/inheritance_manager2.dart';
2020
import 'package:analyzer/src/dart/element/member.dart';
2121
import 'package:analyzer/src/dart/element/type.dart';
22-
import 'package:analyzer/src/dart/resolver/inheritance_manager.dart';
2322
import 'package:analyzer/src/error/codes.dart';
2423
import 'package:analyzer/src/error/pending_error.dart';
2524
import 'package:analyzer/src/generated/element_resolver.dart';
@@ -74,12 +73,7 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
7473
/**
7574
* The manager for the inheritance mappings.
7675
*/
77-
final InheritanceManager _inheritanceManager;
78-
79-
/**
80-
* The manager for the inheritance mappings.
81-
*/
82-
final InheritanceManager2 _inheritanceManager2;
76+
final InheritanceManager2 _inheritanceManager;
8377

8478
/**
8579
* A flag indicating whether the visitor is currently within a constructor
@@ -292,13 +286,8 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
292286
/**
293287
* Initialize a newly created error verifier.
294288
*/
295-
ErrorVerifier(
296-
ErrorReporter errorReporter,
297-
this._currentLibrary,
298-
this._typeProvider,
299-
this._inheritanceManager,
300-
this._inheritanceManager2,
301-
this.enableSuperMixins,
289+
ErrorVerifier(ErrorReporter errorReporter, this._currentLibrary,
290+
this._typeProvider, this._inheritanceManager, this.enableSuperMixins,
302291
{this.disableConflictingGenericsCheck: false})
303292
: _errorReporter = errorReporter,
304293
_uninstantiatedBoundChecker =
@@ -2449,10 +2438,10 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
24492438
String name = method.name;
24502439

24512440
// find inherited property accessor
2452-
ExecutableElement inherited = _inheritanceManager2
2441+
ExecutableElement inherited = _inheritanceManager
24532442
.getInherited(enclosingType, new Name(libraryUri, name))
24542443
?.element;
2455-
inherited ??= _inheritanceManager2
2444+
inherited ??= _inheritanceManager
24562445
.getInherited(enclosingType, new Name(libraryUri, '$name='))
24572446
?.element;
24582447

@@ -2478,10 +2467,10 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
24782467
String name = accessor.displayName;
24792468

24802469
// find inherited method or property accessor
2481-
ExecutableElement inherited = _inheritanceManager2
2470+
ExecutableElement inherited = _inheritanceManager
24822471
.getInherited(enclosingType, new Name(libraryUri, name))
24832472
?.element;
2484-
inherited ??= _inheritanceManager2
2473+
inherited ??= _inheritanceManager
24852474
.getInherited(enclosingType, new Name(libraryUri, '$name='))
24862475
?.element;
24872476

@@ -4163,7 +4152,7 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
41634152
for (var name in mixinElementImpl.superInvokedNames) {
41644153
var nameObject = new Name(mixinLibraryUri, name);
41654154

4166-
var superMemberType = _inheritanceManager2.getMember(
4155+
var superMemberType = _inheritanceManager.getMember(
41674156
enclosingType, nameObject,
41684157
forMixinIndex: mixinIndex, forSuper: true);
41694158

@@ -4177,7 +4166,7 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
41774166
}
41784167

41794168
FunctionType mixinMemberType =
4180-
_inheritanceManager2.getMember(mixinType, nameObject);
4169+
_inheritanceManager.getMember(mixinType, nameObject);
41814170

41824171
if (mixinMemberType != null &&
41834172
!_typeSystem.isOverrideSubtypeOf(superMemberType, mixinMemberType)) {

pkg/analyzer/lib/src/task/dart.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5571,9 +5571,9 @@ class VerifyUnitTask extends SourceBasedAnalysisTask {
55715571
// Compute inheritance and override errors.
55725572
//
55735573
var typeSystem = libraryElement.context.typeSystem;
5574-
var inheritanceManager2 = new InheritanceManager2(typeSystem);
5574+
var inheritanceManager = new InheritanceManager2(typeSystem);
55755575
var inheritanceOverrideVerifier = new InheritanceOverrideVerifier(
5576-
typeSystem, inheritanceManager2, errorReporter);
5576+
typeSystem, inheritanceManager, errorReporter);
55775577
inheritanceOverrideVerifier.verifyUnit(unit);
55785578

55795579
//
@@ -5583,8 +5583,7 @@ class VerifyUnitTask extends SourceBasedAnalysisTask {
55835583
errorReporter,
55845584
libraryElement,
55855585
typeProvider,
5586-
new InheritanceManager(libraryElement),
5587-
inheritanceManager2,
5586+
inheritanceManager,
55885587
context.analysisOptions.enableSuperMixins,
55895588
disableConflictingGenericsCheck: true);
55905589
unit.accept(errorVerifier);

0 commit comments

Comments
 (0)