|
| 1 | +import 'package:analyzer/dart/element/element.dart'; |
| 2 | +import 'package:scip_dart/src/gen/scip.pbenum.dart'; |
| 3 | + |
| 4 | +SymbolInformation_Kind symbolKindFor(Element el) { |
| 5 | + // These mappings are declared in the same order as their symbol parsing |
| 6 | + // counterpart is declared within SymbolGenerator._getDescriptor. Ensure |
| 7 | + // this order stays consistent to ensure the correct kinds are included. |
| 8 | + // |
| 9 | + // Note, we cannot declare this dynamically via a lookup map since the actual |
| 10 | + // type of [el], is the Impl counterpart (`ClassElementImpl`). runtimeType |
| 11 | + // type checking _does not_ take inheritance into account and `is` cannot |
| 12 | + // be used with variables. Hence the large list of if statements. |
| 13 | + if (el is ClassElement) { |
| 14 | + return SymbolInformation_Kind.Class; |
| 15 | + } else if (el is MixinElement) { |
| 16 | + // Pending: https://github.com/sourcegraph/scip/pull/277 |
| 17 | + // return SymbolInformation_Kind.Mixin; |
| 18 | + } else if (el is EnumElement) { |
| 19 | + return SymbolInformation_Kind.Enum; |
| 20 | + } else if (el is TypeAliasElement) { |
| 21 | + return SymbolInformation_Kind.TypeAlias; |
| 22 | + } else if (el is ExtensionElement) { |
| 23 | + // Pending: https://github.com/sourcegraph/scip/pull/277 |
| 24 | + // return SymbolInformation_Kind.Extension; |
| 25 | + } else if (el is ConstructorElement) { |
| 26 | + return SymbolInformation_Kind.Constructor; |
| 27 | + } else if (el is MethodElement) { |
| 28 | + return SymbolInformation_Kind.Method; |
| 29 | + } else if (el is FunctionElement) { |
| 30 | + return SymbolInformation_Kind.Function; |
| 31 | + } else if (el is TopLevelVariableElement) { |
| 32 | + return SymbolInformation_Kind.Variable; |
| 33 | + } else if (el is PrefixElement) { |
| 34 | + return SymbolInformation_Kind.Namespace; |
| 35 | + } else if (el is TypeParameterElement) { |
| 36 | + return SymbolInformation_Kind.TypeParameter; |
| 37 | + } else if (el is ParameterElement) { |
| 38 | + return SymbolInformation_Kind.Parameter; |
| 39 | + } else if (el is PropertyAccessorElement) { |
| 40 | + return SymbolInformation_Kind.Property; |
| 41 | + } else if (el is FieldElement) { |
| 42 | + return SymbolInformation_Kind.Field; |
| 43 | + } |
| 44 | + |
| 45 | + return SymbolInformation_Kind.UnspecifiedKind; |
| 46 | +} |
0 commit comments