|
| 1 | +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +part of 'fragment.dart'; |
| 6 | + |
| 7 | +enum DeclarationFragmentKind { |
| 8 | + classDeclaration, |
| 9 | + mixinDeclaration, |
| 10 | + enumDeclaration, |
| 11 | + extensionDeclaration, |
| 12 | + extensionTypeDeclaration, |
| 13 | +} |
| 14 | + |
| 15 | +abstract class DeclarationFragmentImpl implements DeclarationFragment { |
| 16 | + final Uri fileUri; |
| 17 | + |
| 18 | + /// The scope in which the declaration is declared. |
| 19 | + /// |
| 20 | + /// This is the scope of the enclosing compilation unit and it's used for |
| 21 | + /// resolving metadata on the declaration. |
| 22 | + final LookupScope enclosingScope; |
| 23 | + |
| 24 | + final LookupScope typeParameterScope; |
| 25 | + final DeclarationBuilderScope bodyScope; |
| 26 | + final List<Fragment> _fragments = []; |
| 27 | + |
| 28 | + @override |
| 29 | + final List<TypeParameterFragment>? typeParameters; |
| 30 | + |
| 31 | + final NominalParameterNameSpace nominalParameterNameSpace; |
| 32 | + |
| 33 | + final LibraryFragment enclosingCompilationUnit; |
| 34 | + |
| 35 | + DeclarationFragmentImpl({ |
| 36 | + required this.fileUri, |
| 37 | + required this.typeParameters, |
| 38 | + required this.enclosingScope, |
| 39 | + required this.typeParameterScope, |
| 40 | + required NominalParameterNameSpace nominalParameterNameSpace, |
| 41 | + required this.enclosingCompilationUnit, |
| 42 | + }) : nominalParameterNameSpace = nominalParameterNameSpace, |
| 43 | + bodyScope = new DeclarationBuilderScope(typeParameterScope); |
| 44 | + |
| 45 | + String get name; |
| 46 | + |
| 47 | + DeclarationFragmentKind get kind; |
| 48 | + |
| 49 | + bool declaresConstConstructor = false; |
| 50 | + |
| 51 | + DeclarationBuilder get builder; |
| 52 | + |
| 53 | + UriOffsetLength get uriOffset; |
| 54 | + |
| 55 | + void addPrimaryConstructorField(PrimaryConstructorFieldFragment fragment) { |
| 56 | + throw new UnsupportedError( |
| 57 | + "Unexpected primary constructor field in $this."); |
| 58 | + } |
| 59 | + |
| 60 | + void addEnumElement(EnumElementFragment fragment) { |
| 61 | + throw new UnsupportedError("Unexpected enum element in $this."); |
| 62 | + } |
| 63 | + |
| 64 | + void addFragment(Fragment fragment) { |
| 65 | + _fragments.add(fragment); |
| 66 | + } |
| 67 | + |
| 68 | + DeclarationNameSpaceBuilder toDeclarationNameSpaceBuilder() { |
| 69 | + return new DeclarationNameSpaceBuilder( |
| 70 | + nominalParameterNameSpace, _fragments); |
| 71 | + } |
| 72 | +} |
0 commit comments