Consider adding DynamicElement, NeverElement, DynamicFragment, and NeverFragment classes #60279
Labels
analyzer-api
Issues that impact the public API of the analyzer package
area-devexp
Developer experience items (DevTools, IDEs, analysis server, completions, refactorings, ...).
As far as I can tell, all of the values in the pseudo-enum
ElementKind
(which is defined as part of element model 1 but also exposed via element model 2) have a correspondingElement2
-derived class in the analyzer public API, except for:CLASS_AUGMENTATION
COMPILATION_UNIT
DYNAMIC
EXPORT
IMPORT
NAME
NEVER
PART
RECORD
FUNCTION_TYPE_ALIAS
UNIVERSE
Of these 11, 4 are unused and should perhaps be removed (though it would technically be a breaking change to remove them, so perhaps they should simply be deprecated for now):
CLASS_AUGMENTATION
NAME
RECORD
UNIVERSE
A further 4 will be unused once element model 1 is removed because they aren't elements in element model 2:
COMPILATION_UNIT
EXPORT
IMPORT
PART
FUNCTION_TYPE_ALIAS
will also be unused once element model 1 is removed, but that may be a bug (TypeAliasElementImpl
, which is part of element model 1, has kindTYPE_ALIAS
ifnonfunction_type_aliases
is enabled, andFUNCTION_TYPE_ALIAS
otherwise; butTypeAliasElementImpl2
, which is part of element model 2, always has kindTYPE_ALIAS
)Excluding all those, just 2 kinds remain:
DYNAMIC
NEVER
Both of these kinds have an associated
Impl
class (DynamicElementImpl2
andNeverElementImpl2
), but no associatedElement2
-derived class in the analyzer public API.As a result of this discrepancy, client code can match nearly every kind of
Element2
using a simple object pattern (e.g. the patternTypeParameterElement2
matches any type parameter element). But to match the elements fordynamic
orNever
, client code has to do something awkward likeElement2(kind: ElementKind.DYNAMIC)
.A similar issue applies to fragments.
I think we should consider adding API classes
DynamicElement
,NeverElement
,DynamicFragment
, andNeverFragment
, so that the elements fordynamic
andNever
can be pattern-matched in the same way as all the other kinds of elements and fragments.We should also consider adding
visitDynamicElement
andvisitNeverElement
methods toElementVisitor2
.I discovered this issue while migrating Dart Kythe support to the new element model.
The text was updated successfully, but these errors were encountered: