Skip to content

Commit

Permalink
Version 3.6.0-292.0.dev
Browse files Browse the repository at this point in the history
Merge dfe15b1 into dev
  • Loading branch information
Dart CI committed Sep 27, 2024
2 parents 1881c66 + dfe15b1 commit d672f2e
Show file tree
Hide file tree
Showing 33 changed files with 436 additions and 331 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ vars = {
"path_rev": "e969f42ed112dd702a9453beb9df6c12ae2d3805",
"pool_rev": "924fb04353cec915d927f9f1aed88e2eda92b98a",
"protobuf_rev": "ccf104dbc36929c0f8708285d5f3a8fae206343e",
"pub_rev": "23e3d4f4a761867b1e3eded9a92a4290a01daadb", # disable tools/rev_sdk_deps.dart
"pub_rev": "9adca58e4fa8e1d94924e64a184532231826496c", # disable tools/rev_sdk_deps.dart
"pub_semver_rev": "d9e5ee68a350fbf4319bd4dfcb895fc016337d3a",
"shelf_rev": "d53a8f9a98ccbe69078d397d45c2c6b3e7c243b6",
"source_maps_rev": "5f82c613664ade03c7a6d0e6c59687c69dec894b",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1887,7 +1887,7 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
var target = node.realTarget;
var type = target?.staticType;
if (type != null) {
_forMemberAccess(node, node.parent, type);
_forMemberAccess(node, type);
}
if ((type == null || type is InvalidType || type.isDartCoreType) &&
target is Identifier &&
Expand Down Expand Up @@ -2192,7 +2192,7 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
var target = node.prefix;
var type = target.staticType;
if (type != null) {
_forMemberAccess(node, node.parent, type);
_forMemberAccess(node, type, onlySuper: target is SuperExpression);
} else {
var element = target.staticElement;
if (element != null) {
Expand Down Expand Up @@ -2244,8 +2244,7 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
}
var type = target.staticType;
if (type != null) {
_forMemberAccess(node, parent, type,
onlySuper: target is SuperExpression);
_forMemberAccess(node, type, onlySuper: target is SuperExpression);
}
if ((type == null || type is InvalidType || type.isDartCoreType) &&
target is Identifier &&
Expand Down Expand Up @@ -3165,6 +3164,19 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
return null;
}

bool _computeMustBeAssignable(Expression node) {
var request = state.request;
var lineInfo = request.fileState.lineInfo;
if (node.parent case AssignmentExpression assignment) {
if (assignment.leftHandSide == node) {
var requestLoc = lineInfo.getLocation(request.offset);
var opLoc = lineInfo.getLocation(assignment.operator.offset);
return requestLoc.lineNumber == opLoc.lineNumber;
}
}
return false;
}

/// Adds the suggestions that are appropriate at the beginning of an
/// annotation.
void _forAnnotation(AstNode node) {
Expand Down Expand Up @@ -3407,19 +3419,24 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
return false;
}

/// Adds the suggestions that are appropriate when the [expression] is
/// referencing a member of the given [type]. The [parent] is the parent of
/// the [node].
void _forMemberAccess(Expression node, AstNode? parent, DartType type,
{bool onlySuper = false}) {
/// Adds the suggestions that are appropriate when the [node] is
/// referencing a member of the given [type].
void _forMemberAccess(
Expression node,
DartType type, {
bool onlySuper = false,
}) {
var parent = node.parent;
// TODO(brianwilkerson): Handle the case of static member accesses.
var mustBeAssignable =
parent is AssignmentExpression && node == parent.leftHandSide;
var mustBeAssignable = _computeMustBeAssignable(node);
declarationHelper(
mustBeAssignable: mustBeAssignable,
mustBeConstant: node.inConstantContext,
mustBeNonVoid: parent is ArgumentList)
.addInstanceMembersOfType(type, onlySuper: onlySuper);
mustBeAssignable: mustBeAssignable,
mustBeConstant: node.inConstantContext,
mustBeNonVoid: parent is ArgumentList,
).addInstanceMembersOfType(
type,
onlySuper: onlySuper,
);
}

/// Adds the suggestions that are appropriate when the selection is at the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ class AddCallSuper extends ResolvedCorrectionProducer {
Future<void> compute(ChangeBuilder builder) async {
var methodDeclaration = node;
if (methodDeclaration is! MethodDeclaration) return;
var classElement = methodDeclaration

var classFragment = methodDeclaration
.thisOrAncestorOfType<ClassDeclaration>()
?.declaredElement;
if (classElement == null) return;
?.declaredFragment;
if (classFragment == null) return;
var classElement = classFragment.element;

var name = methodDeclaration.name.lexeme;
var nameObj = Name(classElement.library.source.uri, name);
var overridden = InheritanceManager3().getInherited2(classElement, nameObj);
var nameObj = Name.forLibrary(classElement.library2, name);
var overridden = InheritanceManager3().getInherited4(classElement, nameObj);
if (overridden == null) return;
var overriddenParameters = overridden.parameters.map((p) => p.name);
var overriddenParameters = overridden.formalParameters.map((p) => p.name);

var body = methodDeclaration.body;
var parameters = methodDeclaration.parameters?.parameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:analysis_server/src/services/linter/lint_names.dart';
import 'package:analysis_server/src/utilities/extensions/flutter.dart';
import 'package:analysis_server_plugin/edit/dart/correction_producer.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/error/error.dart';
import 'package:analyzer/src/dart/ast/utilities.dart';
Expand Down Expand Up @@ -48,13 +48,19 @@ class AddDiagnosticPropertyReference extends ResolvedCorrectionProducer {
}

var classDeclaration = node.thisOrAncestorOfType<ClassDeclaration>();
if (classDeclaration == null ||
// TODO(dantup): Remove this and update this fix to handle
// augmenting the method once augmented() expressions are
// fully implemented.
// https://github.com/dart-lang/sdk/issues/55326
classDeclaration.declaredElement!.isAugmentation ||
!classDeclaration.declaredElement!.thisType.isDiagnosticable) {
if (classDeclaration == null) {
return;
}

var classFragment = classDeclaration.declaredFragment!;
var classElement = classFragment.element;

// TODO(dantup): Remove this and update this fix to handle
// augmenting the method once augmented() expressions are
// fully implemented.
// https://github.com/dart-lang/sdk/issues/55326
if (classFragment.isAugmentation ||
!classElement.thisType.isDiagnosticable) {
return;
}

Expand Down Expand Up @@ -418,24 +424,23 @@ class AddDiagnosticPropertyReference extends ResolvedCorrectionProducer {

/// Return the return type of the given [node].
DartType? _getReturnType(AstNode node) {
if (node is MethodDeclaration) {
// Getter.
var element = node.declaredElement;
if (element is PropertyAccessorElement) {
return element.returnType;
}
} else if (node is VariableDeclaration) {
// Field.
var element = node.declaredElement;
if (element is FieldElement) {
return element.type;
}
switch (node) {
case MethodDeclaration():
var element = node.declaredFragment?.element;
if (element is GetterElement) {
return element.returnType;
}
case VariableDeclaration():
var element = node.declaredFragment?.element;
if (element is FieldElement2) {
return element.type;
}
}
return null;
}

bool _isEnum(DartType type) {
return type is InterfaceType && type.element is EnumElement;
return type is InterfaceType && type.element3 is EnumElement2;
}

bool _isIterable(DartType type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,20 @@ class ConvertToCascade extends ResolvedCorrectionProducer {
if (block is! Block) return;

var previous = _getPrevious(block, node);
if (previous is! ExpressionStatement) return;
var previousOperator = _getTargetAndOperator(previous.expression)?.operator;
Token? previousOperator;
Token? semicolon;
if (previous is ExpressionStatement) {
semicolon = previous.semicolon;
previousOperator = _getTargetAndOperator(previous.expression)?.operator;
} else if (previous is VariableDeclarationStatement) {
// Single variable declaration.
if (previous.variables.variables.length != 1) {
return;
}
semicolon = previous.endToken;
} else {
return;
}

var expression = node.expression;
var target = _getTargetAndOperator(expression)?.target;
Expand All @@ -43,7 +55,9 @@ class ConvertToCascade extends ResolvedCorrectionProducer {
if (previousOperator != null) {
builder.addSimpleInsertion(previousOperator.offset, '.');
}
builder.addDeletion(range.token(previous.semicolon!));
if (semicolon != null) {
builder.addDeletion(range.token(semicolon));
}
builder.addSimpleReplacement(range.node(target), targetReplacement);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,50 @@ suggestions
''');
}

Future<void> test_property_assignmentLeft_newLine() async {
await computeSuggestions('''
class A {
int? f01;
void m01() {}
}
void f(A? a, Object? v01) {
a.^
v01 = null;
}
''');

assertResponse(r'''
suggestions
f01
kind: field
m01
kind: methodInvocation
''');
}

Future<void> test_property_assignmentLeft_newLine2() async {
await computeSuggestions('''
class A {
int? f01;
void m01() {}
}
void f(A? a, Object? v01) {
(a).^
v01 = null;
}
''');

assertResponse(r'''
suggestions
f01
kind: field
m01
kind: methodInvocation
''');
}

Future<void> test_target_assignmentLeft() async {
await computeSuggestions('''
void f(Object v01) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@ void f(A a) {
''');
}

Future<void> test_declaration_method() async {
await resolveTestCode('''
class A {
void m() {}
}
void f() {
final a = A();
a.m();
}
''');
await assertHasFix('''
class A {
void m() {}
}
void f() {
final a = A()
..m();
}
''');
}

Future<void> test_method_method() async {
await resolveTestCode('''
class A {
Expand Down Expand Up @@ -96,6 +117,32 @@ void f(A a) {
''');
}

Future<void> test_multipleDeclaration_first_method() async {
await resolveTestCode('''
class A {
void m() {}
}
void f() {
final a = A(), a2 = A();
a.m();
}
''');
await assertNoFix();
}

Future<void> test_multipleDeclaration_last_method() async {
await resolveTestCode('''
class A {
void m() {}
}
void f() {
final a = A(), a2 = A();
a2.m();
}
''');
await assertNoFix();
}

Future<void> test_property_cascade() async {
await resolveTestCode('''
class A {
Expand Down
13 changes: 13 additions & 0 deletions pkg/analyzer/lib/src/dart/ast/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18409,6 +18409,13 @@ abstract final class VariableDeclaration
@override
VariableElement? get declaredElement;

/// The element declared by this declaration.
///
/// Returns `null` if the AST structure hasn't been resolved or if this node
/// represents the declaration of a top-level variable or a field.
@experimental
LocalVariableElement2? get declaredElement2;

/// The fragment declared by this declaration.
///
/// Returns `null` if the AST structure hasn't been resolved or if this node
Expand Down Expand Up @@ -18472,6 +18479,12 @@ final class VariableDeclarationImpl extends DeclarationImpl
_becomeParentOf(_initializer);
}

@experimental
@override
LocalVariableElement2? get declaredElement2 {
return declaredElement.asElement2 as LocalVariableElement2;
}

@experimental
@override
VariableFragment? get declaredFragment {
Expand Down
5 changes: 5 additions & 0 deletions pkg/analyzer/lib/src/dart/element/inheritance_manager3.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,11 @@ class Name {
}
}

factory Name.forLibrary(LibraryElement2 library, String name) {
var uri = library.firstFragment.source.uri;
return Name(uri, name);
}

Name._internal(this.libraryUri, this.name, this.isPublic, this.hashCode);

Name get forGetter {
Expand Down
Loading

0 comments on commit d672f2e

Please sign in to comment.