Skip to content

Commit

Permalink
Version 2.17.0-95.0.dev
Browse files Browse the repository at this point in the history
Merge commit '7605a36ab3e1601ee561758fc6936c707c0f90c0' into 'dev'
  • Loading branch information
Dart CI committed Feb 10, 2022
2 parents a9cfcc2 + 7605a36 commit 0041431
Show file tree
Hide file tree
Showing 57 changed files with 7,445 additions and 7,298 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart';
import 'package:analysis_server/src/services/correction/fix.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
import 'package:analyzer_plugin/utilities/range_factory.dart';

class SortConstructorFirst extends CorrectionProducer {
@override
bool get canBeAppliedInBulk => true;

@override
bool get canBeAppliedToFile => true;

@override
FixKind get fixKind => DartFixKind.SORT_CONSTRUCTOR_FIRST;

@override
FixKind get multiFixKind => DartFixKind.SORT_CONSTRUCTOR_FIRST_MULTI;

@override
Future<void> compute(ChangeBuilder builder) async {
var constructor = coveredNode?.parent;
var clazz = constructor?.parent;
if (clazz is! ClassDeclaration || constructor is! ConstructorDeclaration) {
return;
}

await builder.addDartFileEdit(file, (builder) {
var deletionRange = range.endEnd(
constructor.beginToken.previous!,
constructor.endToken,
);

builder.addDeletion(deletionRange);
builder.addSimpleInsertion(
clazz.leftBracket.end,
utils.getRangeText(deletionRange),
);
});
}

/// Return an instance of this class. Used as a tear-off in `FixProcessor`.
static SortConstructorFirst newInstance() => SortConstructorFirst();
}
10 changes: 10 additions & 0 deletions pkg/analysis_server/lib/src/services/correction/fix.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,16 @@ class DartFixKind {
DartFixKindPriority.IN_FILE,
'Move child properties to ends of arguments everywhere in file',
);
static const SORT_CONSTRUCTOR_FIRST = FixKind(
'dart.fix.sort.sortConstructorFirst',
DartFixKindPriority.DEFAULT,
'Move before other members',
);
static const SORT_CONSTRUCTOR_FIRST_MULTI = FixKind(
'dart.fix.sort.sortConstructorFirst.multi',
DartFixKindPriority.DEFAULT,
'Move all constructors before other members',
);
static const SORT_UNNAMED_CONSTRUCTOR_FIRST = FixKind(
'dart.fix.sort.sortUnnamedConstructorFirst',
DartFixKindPriority.DEFAULT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ import 'package:analysis_server/src/services/correction/dart/replace_with_null_a
import 'package:analysis_server/src/services/correction/dart/replace_with_tear_off.dart';
import 'package:analysis_server/src/services/correction/dart/replace_with_var.dart';
import 'package:analysis_server/src/services/correction/dart/sort_child_property_last.dart';
import 'package:analysis_server/src/services/correction/dart/sort_constructor_first.dart';
import 'package:analysis_server/src/services/correction/dart/sort_unnamed_constructor_first.dart';
import 'package:analysis_server/src/services/correction/dart/update_sdk_constraints.dart';
import 'package:analysis_server/src/services/correction/dart/use_const.dart';
Expand Down Expand Up @@ -572,6 +573,9 @@ class FixProcessor extends BaseProcessor {
LintNames.sort_child_properties_last: [
SortChildPropertyLast.newInstance,
],
LintNames.sort_constructors_first: [
SortConstructorFirst.newInstance,
],
LintNames.sort_unnamed_constructors_first: [
SortUnnamedConstructorFirst.newInstance,
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:analysis_server/src/services/correction/fix.dart';
import 'package:analysis_server/src/services/linter/lint_names.dart';
import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';

import 'fix_processor.dart';

void main() {
defineReflectiveSuite(() {
defineReflectiveTests(SortConstructorFirstBulkTest);
defineReflectiveTests(SortConstructorFirstTest);
});
}

@reflectiveTest
class SortConstructorFirstBulkTest extends BulkFixProcessorTest {
@override
String get lintCode => LintNames.sort_constructors_first;

Future<void> test_multiple_classes() async {
await resolveTestCode('''
class A {
X() {}
A();
}
class B {
Y() {}
B();
}
''');
await assertHasFix('''
class A {
A();
X() {}
}
class B {
B();
Y() {}
}
''');
}

Future<void> test_single_class() async {
await resolveTestCode('''
class A {
X() {}
A();
Y() {}
A._();
}
''');
await assertHasFix('''
class A {
A();
A._();
X() {}
Y() {}
}
''');
}
}

@reflectiveTest
class SortConstructorFirstTest extends FixProcessorLintTest {
@override
FixKind get kind => DartFixKind.SORT_CONSTRUCTOR_FIRST;

@override
String get lintCode => LintNames.sort_constructors_first;

Future<void> test_one_fix() async {
await resolveTestCode('''
class A {
X() {}
A();
}
''');
await assertHasFix('''
class A {
A();
X() {}
}
''');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ import 'replace_with_null_aware_test.dart' as replace_with_null_aware;
import 'replace_with_tear_off_test.dart' as replace_with_tear_off;
import 'replace_with_var_test.dart' as replace_with_var;
import 'sort_child_property_last_test.dart' as sort_properties_last;
import 'sort_constructor_first_test.dart' as sort_constructor_first_test;
import 'sort_unnamed_constructor_first_test.dart'
as sort_unnamed_constructor_first_test;
import 'update_sdk_constraints_test.dart' as update_sdk_constraints;
Expand Down Expand Up @@ -400,6 +401,7 @@ void main() {
replace_with_tear_off.main();
replace_with_var.main();
sort_properties_last.main();
sort_constructor_first_test.main();
sort_unnamed_constructor_first_test.main();
update_sdk_constraints.main();
use_const.main();
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/constant/constant_verifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
.NON_CONSTANT_CASE_EXPRESSION_FROM_DEFERRED_LIBRARY,
);

var expressionValueType = _typeSystem.toLegacyType(
var expressionValueType = _typeSystem.toLegacyTypeIfOptOut(
expressionValue.type,
);

Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/constant/evaluation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2605,7 +2605,7 @@ extension RuntimeExtensions on TypeSystemImpl {
DartType type,
) {
if (!isNonNullableByDefault) {
type = toLegacyType(type);
type = toLegacyTypeIfOptOut(type);
}
var objType = obj.type;
return isSubtypeOf(objType, type);
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/element/class_hierarchy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class _ClassInterfaceType {
);
}
} else {
var legacyType = _typeSystem.toLegacyType(type) as InterfaceType;
var legacyType = _typeSystem.toLegacyTypeIfOptOut(type) as InterfaceType;
if (_currentResult == null) {
_currentResult = legacyType;
} else {
Expand Down
49 changes: 13 additions & 36 deletions pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1364,9 +1364,6 @@ class ConstructorElementImpl extends ExecutableElementImpl
setModifier(Modifier.FACTORY, isFactory);
}

@override
bool get isStatic => false;

@override
ElementKind get kind => ElementKind.CONSTRUCTOR;

Expand Down Expand Up @@ -2879,6 +2876,15 @@ abstract class ExecutableElementImpl extends _ExistingElementImpl
@override
bool get isOperator => false;

@override
bool get isStatic {
return hasModifier(Modifier.STATIC);
}

set isStatic(bool isStatic) {
setModifier(Modifier.STATIC, isStatic);
}

@override
bool get isSynchronous => !isAsynchronous;

Expand Down Expand Up @@ -3250,16 +3256,6 @@ class FieldElementImpl extends PropertyInducingElementImpl
return hasModifier(Modifier.EXTERNAL);
}

@override
bool get isStatic {
return hasModifier(Modifier.STATIC);
}

/// Set whether this field is static.
set isStatic(bool isStatic) {
setModifier(Modifier.STATIC, isStatic);
}

/// Return `true` if this element is a synthetic enum field.
///
/// It is synthetic because it is not written explicitly in code, but it
Expand Down Expand Up @@ -3352,9 +3348,6 @@ class FunctionElementImpl extends ExecutableElementImpl
return isStatic && displayName == FunctionElement.MAIN_FUNCTION_NAME;
}

@override
bool get isStatic => enclosingElement is CompilationUnitElement;

@override
ElementKind get kind => ElementKind.FUNCTION;

Expand Down Expand Up @@ -4208,16 +4201,6 @@ class MethodElementImpl extends ExecutableElementImpl implements MethodElement {
first == 0x24);
}

@override
bool get isStatic {
return hasModifier(Modifier.STATIC);
}

/// Set whether this method is static.
set isStatic(bool isStatic) {
setModifier(Modifier.STATIC, isStatic);
}

@override
ElementKind get kind => ElementKind.METHOD;

Expand Down Expand Up @@ -5047,16 +5030,6 @@ class PropertyAccessorElementImpl extends ExecutableElementImpl
setModifier(Modifier.SETTER, isSetter);
}

@override
bool get isStatic {
return hasModifier(Modifier.STATIC);
}

/// Set whether this accessor is static.
set isStatic(bool isStatic) {
setModifier(Modifier.STATIC, isStatic);
}

@override
ElementKind get kind {
if (isGetter) {
Expand Down Expand Up @@ -5931,6 +5904,10 @@ abstract class VariableElementImpl extends ElementImpl
@override
bool get isStatic => hasModifier(Modifier.STATIC);

set isStatic(bool isStatic) {
setModifier(Modifier.STATIC, isStatic);
}

@override
String get name => super.name!;

Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/element/least_upper_bound.dart
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class InterfaceLeastUpperBoundHelper {
return result;
} else {
return result.map((e) {
return e.mapArguments(typeSystem.toLegacyType);
return e.mapArguments(typeSystem.toLegacyTypeIfOptOut);
}).toSet();
}
}
Expand Down
17 changes: 5 additions & 12 deletions pkg/analyzer/lib/src/dart/element/type_system.dart
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ class TypeSystemImpl implements TypeSystem {
typeArguments: typeArguments,
nullabilitySuffix: nullabilitySuffix,
);
type = toLegacyType(type) as InterfaceType;
type = toLegacyTypeIfOptOut(type) as InterfaceType;
return type;
} else if (typeAliasElement != null) {
var typeParameters = typeAliasElement.typeParameters;
Expand All @@ -553,7 +553,7 @@ class TypeSystemImpl implements TypeSystem {
typeArguments: typeArguments,
nullabilitySuffix: nullabilitySuffix,
);
type = toLegacyType(type);
type = toLegacyTypeIfOptOut(type);
return type;
} else {
throw ArgumentError('Missing element');
Expand Down Expand Up @@ -1295,8 +1295,8 @@ class TypeSystemImpl implements TypeSystem {
// TODO(scheglov) waiting for the spec
// https://github.com/dart-lang/sdk/issues/42605
} else {
srcType = toLegacyType(srcType);
destType = toLegacyType(destType);
srcType = toLegacyTypeIfOptOut(srcType);
destType = toLegacyTypeIfOptOut(destType);
}
if (srcType != destType) {
// Failed to find an appropriate substitution
Expand Down Expand Up @@ -1480,17 +1480,10 @@ class TypeSystemImpl implements TypeSystem {
return RuntimeTypeEqualityHelper(this).equal(T1, T2);
}

DartType toLegacyType(DartType type) {
if (isNonNullableByDefault) return type;
return NullabilityEliminator.perform(typeProvider, type);
}

/// If a legacy library, return the legacy version of the [type].
/// Otherwise, return the original type.
DartType toLegacyTypeIfOptOut(DartType type) {
if (isNonNullableByDefault) {
return type;
}
if (isNonNullableByDefault) return type;
return NullabilityEliminator.perform(typeProvider, type);
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/element/well_bounded.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class TypeBoundedHelper {
continue;
}

bound = typeSystem.toLegacyType(bound);
bound = typeSystem.toLegacyTypeIfOptOut(bound);
bound = substitution.substituteType(bound);

if (!typeSystem.isSubtypeOf(typeArgument, bound)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class NamedTypeResolver {
typeArguments: typeArguments,
nullabilitySuffix: nullability,
);
type = typeSystem.toLegacyType(type);
type = typeSystem.toLegacyTypeIfOptOut(type);
return _verifyTypeAliasForContext(node, element, type);
} else if (_isInstanceCreation(node)) {
_ErrorHelper(errorReporter).reportNewWithNonType(node);
Expand Down
Loading

0 comments on commit 0041431

Please sign in to comment.