Skip to content

Commit

Permalink
Version 3.7.0-134.0.dev
Browse files Browse the repository at this point in the history
Merge 8e0198f into dev
  • Loading branch information
Dart CI committed Nov 12, 2024
2 parents 35b329e + 8e0198f commit ce043b2
Show file tree
Hide file tree
Showing 20 changed files with 158 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:analysis_server/src/lsp/constants.dart';
import 'package:analysis_server/src/lsp/error_or.dart';
import 'package:analysis_server/src/lsp/handlers/handlers.dart';
import 'package:analysis_server/src/lsp/mapping.dart';
import 'package:analyzer/src/dart/ast/ast.dart';
import 'package:analyzer/src/dart/ast/ast.dart' as ast;
import 'package:analyzer/src/utilities/extensions/ast.dart';

class AugmentationHandler
Expand Down Expand Up @@ -44,7 +44,7 @@ class AugmentationHandler
var node =
unit.unit
.nodeCovering(offset: offset)
?.thisOrAncestorOfType<FragmentDeclaration>();
?.thisOrAncestorOfType<ast.Declaration>();

var location = fragmentToLocation(
uriConverter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:analysis_server/src/lsp/constants.dart';
import 'package:analysis_server/src/lsp/error_or.dart';
import 'package:analysis_server/src/lsp/handlers/handlers.dart';
import 'package:analysis_server/src/lsp/mapping.dart';
import 'package:analyzer/src/dart/ast/ast.dart';
import 'package:analyzer/src/dart/ast/ast.dart' as ast;
import 'package:analyzer/src/utilities/extensions/ast.dart';

class AugmentedHandler
Expand Down Expand Up @@ -44,7 +44,7 @@ class AugmentedHandler
var node =
unit.unit
.nodeCovering(offset: offset)
?.thisOrAncestorOfType<FragmentDeclaration>();
?.thisOrAncestorOfType<ast.Declaration>();

var location = fragmentToLocation(
uriConverter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class RemoveUnusedElement extends _RemoveUnused {
}

Element2? element;
if (node is FragmentDeclaration) {
if (node is Declaration) {
element = node.declaredFragment?.element;
}
if (element == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class RenameMethodParameter extends ResolvedCorrectionProducer {
if (methodParameters == null) return;

Fragment? declaredFragment;
if (method.parent case FragmentDeclaration declaration) {
if (method.parent case Declaration declaration) {
declaredFragment = declaration.declaredFragment;
}

Expand Down
65 changes: 29 additions & 36 deletions pkg/analyzer/lib/src/dart/ast/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2684,8 +2684,7 @@ class ChildEntity {
/// classModifiers ::= 'sealed'
/// | 'abstract'? ('base' | 'interface' | 'final')?
/// | 'abstract'? 'base'? 'mixin'
abstract final class ClassDeclaration
implements NamedCompilationUnitMember, FragmentDeclaration {
abstract final class ClassDeclaration implements NamedCompilationUnitMember {
/// The `abstract` keyword, or `null` if the keyword was absent.
Token? get abstractKeyword;

Expand Down Expand Up @@ -2921,7 +2920,7 @@ sealed class ClassMemberImpl extends DeclarationImpl implements ClassMember {
///
/// mixinApplication ::=
/// [NamedType] [WithClause] [ImplementsClause]? ';'
abstract final class ClassTypeAlias implements TypeAlias, FragmentDeclaration {
abstract final class ClassTypeAlias implements TypeAlias {
/// The token for the `abstract` keyword, or `null` if this isn't defining an
/// abstract class.
Token? get abstractKeyword;
Expand Down Expand Up @@ -4062,8 +4061,7 @@ final class ConstantPatternImpl extends DartPatternImpl
///
/// initializerList ::=
/// ':' [ConstructorInitializer] (',' [ConstructorInitializer])*
abstract final class ConstructorDeclaration
implements ClassMember, FragmentDeclaration {
abstract final class ConstructorDeclaration implements ClassMember {
/// The `augment` keyword, or `null` if the keyword was absent.
Token? get augmentKeyword;

Expand Down Expand Up @@ -4797,6 +4795,12 @@ abstract final class Declaration implements AnnotatedNode {
/// node corresponds to a list of declarations or if the AST structure hasn't
/// been resolved.
Element? get declaredElement;

/// The fragment declared by this declaration.
///
/// Returns `null` if the AST structure hasn't been resolved.
@experimental
Fragment? get declaredFragment;
}

sealed class DeclarationImpl extends AnnotatedNodeImpl implements Declaration {
Expand Down Expand Up @@ -4859,6 +4863,9 @@ final class DeclaredIdentifierImpl extends DeclarationImpl
@override
LocalVariableElementImpl? declaredElement;

@override
LocalVariableElementImpl? declaredFragment;

/// Initializes a newly created formal parameter.
///
/// Either or both of the [comment] and [metadata] can be `null` if the
Expand Down Expand Up @@ -5539,7 +5546,7 @@ final class EnumConstantArgumentsImpl extends AstNodeImpl
}

/// The declaration of an enum constant.
abstract final class EnumConstantDeclaration implements FragmentDeclaration {
abstract final class EnumConstantDeclaration implements Declaration {
/// The explicit arguments (there are always implicit `index` and `name`
/// leading arguments) to the invoked constructor, or `null` if this constant
/// doesn't provide any explicit arguments.
Expand Down Expand Up @@ -5641,8 +5648,7 @@ final class EnumConstantDeclarationImpl extends DeclarationImpl
/// metadata 'enum' name [TypeParameterList]?
/// [WithClause]? [ImplementsClause]? '{' [SimpleIdentifier]
/// (',' [SimpleIdentifier])* (';' [ClassMember]+)? '}'
abstract final class EnumDeclaration
implements NamedCompilationUnitMember, FragmentDeclaration {
abstract final class EnumDeclaration implements NamedCompilationUnitMember {
/// The `augment` keyword, or `null` if the keyword was absent.
@experimental
Token? get augmentKeyword;
Expand Down Expand Up @@ -6364,8 +6370,7 @@ final class ExtendsClauseImpl extends AstNodeImpl implements ExtendsClause {
/// 'extension' [SimpleIdentifier]? [TypeParameterList]?
/// 'on' [TypeAnnotation] [ShowClause]? [HideClause]?
/// '{' [ClassMember]* '}'
abstract final class ExtensionDeclaration
implements CompilationUnitMember, FragmentDeclaration {
abstract final class ExtensionDeclaration implements CompilationUnitMember {
/// The `augment` keyword, or `null` if the keyword was absent.
@experimental
Token? get augmentKeyword;
Expand Down Expand Up @@ -6694,7 +6699,7 @@ final class ExtensionOverrideImpl extends ExpressionImpl
/// '}'
@experimental
abstract final class ExtensionTypeDeclaration
implements NamedCompilationUnitMember, FragmentDeclaration {
implements NamedCompilationUnitMember {
/// The `augment` keyword, or `null` if the keyword was absent.
@experimental
Token? get augmentKeyword;
Expand Down Expand Up @@ -6923,6 +6928,9 @@ final class FieldDeclarationImpl extends ClassMemberImpl
@override
Element? get declaredElement => null;

@override
Fragment? get declaredFragment => null;

@override
Token get endToken => semicolon;

Expand Down Expand Up @@ -8073,18 +8081,6 @@ final class ForStatementImpl extends StatementImpl
}
}

/// A declaration of a fragment of an element.
@experimental
abstract final class FragmentDeclaration implements Declaration {
// TODO(pq): move `declaredFragment` into `Declaration` and remove this class.

/// The fragment declared by this declaration.
///
/// Returns `null` if the AST structure hasn't been resolved.
@experimental
Fragment? get declaredFragment;
}

/// A node representing the body of a function or method.
///
/// functionBody ::=
Expand Down Expand Up @@ -8203,8 +8199,7 @@ sealed class FunctionBodyImpl extends AstNodeImpl implements FunctionBody {
// augmented and declarations that can't be augmented. This results in getters
// that are only sometimes applicable. Consider changing the class hierarchy so
// that these two kinds of variables can be distinguished.
abstract final class FunctionDeclaration
implements NamedCompilationUnitMember, FragmentDeclaration {
abstract final class FunctionDeclaration implements NamedCompilationUnitMember {
/// The `augment` keyword, or `null` if there is no `augment` keyword.
@experimental
Token? get augmentKeyword;
Expand Down Expand Up @@ -8742,8 +8737,7 @@ final class FunctionReferenceImpl extends CommentReferableExpressionImpl
///
/// functionPrefix ::=
/// [TypeAnnotation]? [SimpleIdentifier]
abstract final class FunctionTypeAlias
implements TypeAlias, FragmentDeclaration {
abstract final class FunctionTypeAlias implements TypeAlias {
@override
TypeAliasElement? get declaredElement;

Expand Down Expand Up @@ -9104,8 +9098,7 @@ final class GenericFunctionTypeImpl extends TypeAnnotationImpl
/// functionTypeAlias ::=
/// 'typedef' [SimpleIdentifier] [TypeParameterList]? =
/// [FunctionType] ';'
abstract final class GenericTypeAlias
implements TypeAlias, FragmentDeclaration {
abstract final class GenericTypeAlias implements TypeAlias {
/// The equal sign separating the name being defined from the function type.
Token get equals;

Expand Down Expand Up @@ -11798,8 +11791,7 @@ final class MapPatternImpl extends DartPatternImpl implements MapPattern {
/// Prior to the 'extension-methods' experiment, these nodes were always
/// children of a class declaration. When the experiment is enabled, these nodes
/// can also be children of an extension declaration.
abstract final class MethodDeclaration
implements ClassMember, FragmentDeclaration {
abstract final class MethodDeclaration implements ClassMember {
/// The token for the `augment` keyword.
Token? get augmentKeyword;

Expand Down Expand Up @@ -12195,8 +12187,7 @@ abstract final class MethodReferenceExpression implements Expression {
/// mixinDeclaration ::=
/// 'base'? 'mixin' name [TypeParameterList]?
/// [OnClause]? [ImplementsClause]? '{' [ClassMember]* '}'
abstract final class MixinDeclaration
implements NamedCompilationUnitMember, FragmentDeclaration {
abstract final class MixinDeclaration implements NamedCompilationUnitMember {
/// The `augment` keyword, or `null` if the keyword was absent.
Token? get augmentKeyword;

Expand Down Expand Up @@ -17652,6 +17643,9 @@ final class TopLevelVariableDeclarationImpl extends CompilationUnitMemberImpl
@override
Element? get declaredElement => null;

@override
Fragment? get declaredFragment => null;

@override
Token get endToken => semicolon;

Expand Down Expand Up @@ -18052,7 +18046,7 @@ final class TypeLiteralImpl extends CommentReferableExpressionImpl
///
/// typeParameter ::=
/// name ('extends' [TypeAnnotation])?
abstract final class TypeParameter implements Declaration, FragmentDeclaration {
abstract final class TypeParameter implements Declaration {
/// The upper bound for legal arguments, or `null` if there's no explicit
/// upper bound.
TypeAnnotation? get bound;
Expand Down Expand Up @@ -18302,8 +18296,7 @@ class UriValidationCode {
// augmented and declarations that can't be augmented. This results in getters
// that are only sometimes applicable. Consider changing the class hierarchy so
// that these two kinds of variables can be distinguished.
abstract final class VariableDeclaration
implements Declaration, FragmentDeclaration {
abstract final class VariableDeclaration implements Declaration {
/// The element declared by this declaration.
///
/// Returns `null` if the AST structure hasn't been resolved or if this node
Expand Down
62 changes: 53 additions & 9 deletions pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5340,9 +5340,6 @@ abstract class InstanceElementImpl2 extends ElementImpl2
@override
List<PropertyAccessorElement> accessors = [];

@override
List<MethodElement> methods = [];

@override
List<MethodElementImpl2> methods2 = [];

Expand Down Expand Up @@ -5409,6 +5406,42 @@ abstract class InstanceElementImpl2 extends ElementImpl2
@override
Metadata get metadata2 => firstFragment.metadata2;

@override
List<MethodElement> get methods {
return methods2.map((element) {
var firstTypeParameters = firstFragment.typeParameters;

var lastFragment = element.lastFragment;
var lastInstance = lastFragment.enclosingFragment;
if (identical(lastInstance, firstFragment)) {
return lastFragment;
}

var lastTypeParameters = lastInstance.typeParameters2;
if (firstTypeParameters.isEmpty && lastTypeParameters.isEmpty) {
return lastFragment;
}

MapSubstitution toFirstFragment;
if (lastTypeParameters.length == firstTypeParameters.length) {
toFirstFragment = Substitution.fromPairs(
lastTypeParameters,
firstTypeParameters.instantiateNone(),
);
} else {
toFirstFragment = Substitution.fromPairs(
lastTypeParameters,
List.filled(
lastTypeParameters.length,
InvalidTypeImpl.instance,
),
);
}

return MethodMember(lastFragment, toFirstFragment, Substitution.empty);
}).toList();
}

@override
String? get name3 => firstFragment.name;

Expand Down Expand Up @@ -7640,8 +7673,8 @@ class MethodElementImpl extends ExecutableElementImpl
}

@override
InstanceFragment? get enclosingFragment =>
enclosingElement3 as InstanceFragment;
InstanceElementImpl get enclosingFragment =>
enclosingElement3 as InstanceElementImpl;

/// Set whether this class is abstract.
set isAbstract(bool isAbstract) {
Expand Down Expand Up @@ -7674,7 +7707,7 @@ class MethodElementImpl extends ExecutableElementImpl
}

@override
MethodFragment? get nextFragment => augmentation;
MethodElementImpl? get nextFragment => augmentation;

@override
Element get nonSynthetic {
Expand All @@ -7685,7 +7718,7 @@ class MethodElementImpl extends ExecutableElementImpl
}

@override
MethodFragment? get previousFragment => augmentationTarget;
MethodElementImpl? get previousFragment => augmentationTarget;

@override
T? accept<T>(ElementVisitor<T> visitor) => visitor.visitMethodElement(this);
Expand Down Expand Up @@ -7726,6 +7759,17 @@ class MethodElementImpl2 extends ExecutableElementImpl2
@override
ElementKind get kind => ElementKind.METHOD;

MethodElementImpl get lastFragment {
var lastFragment = firstFragment;
while (true) {
if (lastFragment.nextFragment case var nextFragment?) {
lastFragment = nextFragment;
} else {
return lastFragment;
}
}
}

@override
T? accept2<T>(ElementVisitor2<T> visitor) {
return visitor.visitMethodElement(this);
Expand Down Expand Up @@ -10583,8 +10627,8 @@ mixin TypeParameterizedElementMixin on ElementImpl
}

@override
List<TypeParameterFragment> get typeParameters2 =>
typeParameters.cast<TypeParameterFragment>();
List<TypeParameterElementImpl> get typeParameters2 =>
typeParameters.cast<TypeParameterElementImpl>();

List<TypeParameterElement> get typeParameters_unresolved {
return _typeParameters;
Expand Down
11 changes: 0 additions & 11 deletions pkg/analyzer/lib/src/summary2/augmentation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ abstract class InstanceElementBuilder<E extends InstanceElementImpl2,

augmented.fields.addAll(firstFragment.fields);
augmented.accessors.addAll(firstFragment.accessors);
augmented.methods.addAll(firstFragment.methods);

if (augmented is InterfaceElementImpl2) {
if (firstFragment is InterfaceElementImpl) {
Expand Down Expand Up @@ -359,16 +358,6 @@ abstract class InstanceElementBuilder<E extends InstanceElementImpl2,
element, toFirstFragment, Substitution.empty);
}),
];

element.methods = [
...element.methods.notAugmented,
...augmentation.methods.notAugmented.map((element) {
if (toFirstFragment.map.isEmpty) {
return element;
}
return MethodMember(element, toFirstFragment, Substitution.empty);
}),
];
}
}

Expand Down
Loading

0 comments on commit ce043b2

Please sign in to comment.