Skip to content

Commit

Permalink
Version 3.7.0-172.0.dev
Browse files Browse the repository at this point in the history
Merge b9e7cb6 into dev
  • Loading branch information
Dart CI committed Nov 21, 2024
2 parents 5580b1d + b9e7cb6 commit 26cc983
Show file tree
Hide file tree
Showing 29 changed files with 430 additions and 184 deletions.
2 changes: 1 addition & 1 deletion pkg/_fe_analyzer_shared/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: _fe_analyzer_shared
version: 76.0.0
version: 77.0.0
description: Logic that is shared between the front_end and analyzer packages.
repository: https://github.com/dart-lang/sdk/tree/main/pkg/_fe_analyzer_shared

Expand Down
1 change: 0 additions & 1 deletion pkg/analysis_server/analyzer_use_new_elements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ lib/src/protocol_server.dart
lib/src/search/element_references.dart
lib/src/search/type_hierarchy.dart
lib/src/services/completion/dart/completion_manager.dart
lib/src/services/completion/dart/completion_state.dart
lib/src/services/completion/dart/declaration_helper.dart
lib/src/services/completion/dart/feature_computer.dart
lib/src/services/completion/dart/identifier_helper.dart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,8 @@ class DartCompletionRequest {
return analysisSession.inheritanceManager;
}

/// Getter for the [Element2] repersentation of [libraryElement].
LibraryElement2 get libraryElement2 =>
libraryElement.asElement2 as LibraryElement2;
/// Getter for the [Element2] representation of [libraryElement].
LibraryElement2 get libraryElement2 => libraryElement.asElement2;

/// Answer the [DartType] for Object in dart:core
InterfaceType get objectType => libraryElement.typeProvider.objectType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:analysis_server_plugin/src/utilities/selection.dart';
import 'package:analyzer/dart/analysis/code_style_options.dart';
import 'package:analyzer/dart/analysis/features.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/src/utilities/completion_matcher.dart';

Expand Down Expand Up @@ -58,7 +58,7 @@ class CompletionState {
}

/// The element of the library containing the completion location.
LibraryElement get libraryElement => request.libraryElement;
LibraryElement2 get libraryElement => request.libraryElement2;

/// The type of quotes preferred for [String]s as specified in [CodeStyleOptions].
String get preferredQuoteForStrings =>
Expand All @@ -75,19 +75,19 @@ class CompletionState {
while (node != null) {
switch (node) {
case ClassDeclaration():
var element = node.declaredElement;
var element = node.declaredFragment?.element;
if (element != null) {
return element.thisType;
}
case EnumDeclaration():
var element = node.declaredElement;
var element = node.declaredFragment?.element;
if (element != null) {
return element.thisType;
}
case ExtensionDeclaration():
return node.onClause?.extendedType.type;
case MixinDeclaration():
var element = node.declaredElement;
var element = node.declaredFragment?.element;
if (element != null) {
return element.thisType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ class DeclarationHelper {
if (matcherScore != -1) {
collector.addSuggestion(
ImportPrefixSuggestion(
libraryElement: importedLibrary.asElement2 as LibraryElement2,
prefixElement: prefixElement.asElement2 as PrefixElement2,
libraryElement: importedLibrary.asElement2,
prefixElement: prefixElement.asElement2,
matcherScore: matcherScore,
),
);
Expand Down Expand Up @@ -902,17 +902,17 @@ class DeclarationHelper {
var suggestion = switch (element) {
ClassElement() => ClassSuggestion(
importData: null,
element: element.asElement2 as ClassElement2,
element: element.asElement2,
matcherScore: matcherScore,
),
EnumElement() => EnumSuggestion(
importData: null,
element: element.asElement2 as EnumElement2,
element: element.asElement2,
matcherScore: matcherScore,
),
ExtensionElement() => ExtensionSuggestion(
importData: null,
element: element.asElement2 as ExtensionElement2,
element: element.asElement2,
matcherScore: matcherScore,
),
ExtensionTypeElement() => ExtensionTypeSuggestion(
Expand All @@ -928,7 +928,7 @@ class DeclarationHelper {
),
MixinElement() => MixinSuggestion(
importData: null,
element: element.asElement2 as MixinElement2,
element: element.asElement2,
matcherScore: matcherScore,
),
PropertyAccessorElement() => _createSuggestionFromTopLevelProperty(
Expand All @@ -937,7 +937,7 @@ class DeclarationHelper {
),
TopLevelVariableElement() => TopLevelVariableSuggestion(
importData: null,
element: element.asElement2 as TopLevelVariableElement2,
element: element.asElement2,
matcherScore: matcherScore,
),
TypeAliasElement() => TypeAliasSuggestion(
Expand Down Expand Up @@ -1498,7 +1498,7 @@ class DeclarationHelper {
if (variable is TopLevelVariableElement) {
return TopLevelVariableSuggestion(
importData: importData,
element: variable.asElement2 as TopLevelVariableElement2,
element: variable.asElement2,
matcherScore: matcherScore,
);
}
Expand Down Expand Up @@ -1559,7 +1559,7 @@ class DeclarationHelper {
if (matcherScore != -1) {
var suggestion = ClassSuggestion(
importData: importData,
element: element.asElement2 as ClassElement2,
element: element.asElement2,
matcherScore: matcherScore,
);
collector.addSuggestion(suggestion);
Expand Down Expand Up @@ -1667,7 +1667,7 @@ class DeclarationHelper {
if (matcherScore != -1) {
var suggestion = EnumSuggestion(
importData: importData,
element: element.asElement2 as EnumElement2,
element: element.asElement2,
matcherScore: matcherScore,
);
collector.addSuggestion(suggestion);
Expand Down Expand Up @@ -1696,7 +1696,7 @@ class DeclarationHelper {
if (matcherScore != -1) {
var suggestion = ExtensionSuggestion(
importData: importData,
element: element.asElement2 as ExtensionElement2,
element: element.asElement2,
matcherScore: matcherScore,
);
collector.addSuggestion(suggestion);
Expand Down Expand Up @@ -1857,7 +1857,7 @@ class DeclarationHelper {
if (matcherScore != -1) {
var suggestion = MixinSuggestion(
importData: importData,
element: element.asElement2 as MixinElement2,
element: element.asElement2,
matcherScore: matcherScore,
);
collector.addSuggestion(suggestion);
Expand All @@ -1878,7 +1878,7 @@ class DeclarationHelper {
var matcherScore = state.matcher.score(element.displayName);
if (matcherScore != -1) {
var suggestion = FormalParameterSuggestion(
element: element.asElement2 as FormalParameterElement,
element: element.asElement2,
distance: _variableDistance++,
matcherScore: matcherScore,
);
Expand Down Expand Up @@ -2054,7 +2054,7 @@ class DeclarationHelper {
if (matcherScore != -1) {
collector.addSuggestion(
SuperParameterSuggestion(
element: element.asElement2 as FormalParameterElement,
element: element.asElement2,
matcherScore: matcherScore,
),
);
Expand Down Expand Up @@ -2132,7 +2132,7 @@ class DeclarationHelper {
if (matcherScore != -1) {
var suggestion = TopLevelVariableSuggestion(
importData: importData,
element: element.asElement2 as TopLevelVariableElement2,
element: element.asElement2,
matcherScore: matcherScore,
);
collector.addSuggestion(suggestion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@ class IdentifierHelper {
if (candidateName == null) {
return;
}
for (var unit in state.libraryElement.units) {
for (var childElement in unit.children) {
if (childElement.name == candidateName) {
for (var childElement in state.libraryElement.children2) {
if (childElement.name3 == candidateName) {
// Don't suggest a name that's already declared in the library.
return;
}
}
}
var matcherScore = state.matcher.score(candidateName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import 'package:analyzer/dart/ast/syntactic_entity.dart';
import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/dart/ast/visitor.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/source/source_range.dart';
import 'package:analyzer/src/dart/ast/ast.dart';
Expand Down Expand Up @@ -380,7 +379,7 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
var isWidget = isFlutterWidgetParameter(parameter);
collector.addSuggestion(
NamedArgumentSuggestion(
parameter: parameter.asElement2 as FormalParameterElement,
parameter: parameter.asElement2,
appendColon: true,
appendComma: appendComma,
replacementLength: replacementLength,
Expand Down Expand Up @@ -742,7 +741,7 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
if (constructorElement == null) {
return;
}
var libraryElement = state.libraryElement;
var libraryElement = state.libraryElement.asElement as LibraryElement;
declarationHelper(
mustBeConstant: constructorElement.isConst,
).addPossibleRedirectionsInLibrary(constructorElement, libraryElement);
Expand Down Expand Up @@ -2022,7 +2021,7 @@ class InScopeCompletionPass extends SimpleAstVisitor<void> {
collector.addSuggestion(
NamedArgumentSuggestion(
parameter:
parameter.asElement2 as FormalParameterElement,
parameter.asElement2,
matcherScore: matcherScore,
appendColon: appendColon,
appendComma: false,
Expand Down
2 changes: 1 addition & 1 deletion pkg/analysis_server/lib/src/services/search/hierarchy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ Future<List<FormalParameterElement>> getHierarchyNamedParameters2(
searchEngine,
element.asElement as ParameterElement,
);
return result.map((e) => e.asElement2 as FormalParameterElement).toList();
return result.map((e) => e.asElement2).toList();
}

/// Returns non-synthetic members of the given [InterfaceElement] and its super
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,7 @@ class SearchMatchImpl implements SearchMatch {
Element2 get element2 => element.asElement2!;

@override
LibraryElement2 get libraryElement2 =>
libraryElement.asElement2 as LibraryElement2;
LibraryElement2 get libraryElement2 => libraryElement.asElement2;

@override
String toString() {
Expand Down
3 changes: 1 addition & 2 deletions pkg/analysis_server/test/abstract_single_unit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class AbstractSingleUnitTest extends AbstractContextTest {
late FindElement findElement;
late FindElement2 findElement2;

LibraryElement2 get testLibraryElement2 =>
testLibraryElement.asElement2 as LibraryElement2;
LibraryElement2 get testLibraryElement2 => testLibraryElement.asElement2;

void addTestSource(String code) {
testCode = code;
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 7.0.0 (Not yet released - breaking changes)
## 7.0.0
* Remove deprecated `DartType.element2`.
* Remove deprecated `DartType.isDynamic`.
* Remove deprecated `DartType.isVoid`.
Expand Down
1 change: 0 additions & 1 deletion pkg/analyzer/analyzer_use_new_elements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ lib/src/utilities/extensions/ast.dart
lib/src/utilities/extensions/element.dart
lib/src/utilities/extensions/flutter.dart
lib/src/utilities/extensions/library_element.dart
test/dart/sdk/build_sdk_summary_test.dart
test/error/error_reporter_test.dart
test/generated/element_resolver_test.dart
test/generated/elements_types_mixin.dart
Expand Down
3 changes: 3 additions & 0 deletions pkg/analyzer/lib/dart/element/element2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,9 @@ abstract class LibraryElement2 implements Element2, Annotatable {
///
/// This is the same URI as `firstFragment.source.uri` returns.
Uri get uri;

/// Returns the class defined in this library that has the given [name].
ClassElement2? getClass2(String name);
}

/// An `export` directive within a library fragment.
Expand Down
31 changes: 25 additions & 6 deletions pkg/analyzer/lib/src/dart/analysis/analysis_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ final class AnalysisOptionsBuilder {
}
}

void _applyPluginsOptions(YamlNode? plugins) {
void _applyPluginsOptions(
YamlNode? plugins, ResourceProvider? resourceProvider) {
if (plugins is! YamlMap) {
return;
}
Expand Down Expand Up @@ -232,8 +233,23 @@ final class AnalysisOptionsBuilder {
source = VersionedPluginSource(constraint: value);
} else {
var pathSource = pluginNode.valueAt(AnalysisOptionsFile.path);
if (pathSource case YamlScalar(:String value)) {
source = PathPluginSource(path: value);
if (pathSource case YamlScalar(value: String pathValue)) {
var file = this.file;
assert(
file != null,
"AnalysisOptionsImpl must be initialized with a non-null 'file' if "
'plugins are specified with path constraints.',
);
if (file != null &&
resourceProvider != null &&
resourceProvider.pathContext.isRelative(pathValue)) {
// We need to store the absolute path, before this value is used in
// a synthetic pub package.
pathValue =
resourceProvider.pathContext.join(file.parent.path, pathValue);
pathValue = resourceProvider.pathContext.normalize(pathValue);
}
source = PathPluginSource(path: pathValue);
}
}

Expand Down Expand Up @@ -379,8 +395,11 @@ class AnalysisOptionsImpl implements AnalysisOptions {
/// [optionsMap].
///
/// Optionally pass [file] as the file where the YAML can be found.
factory AnalysisOptionsImpl.fromYaml(
{required YamlMap optionsMap, File? file}) {
factory AnalysisOptionsImpl.fromYaml({
required YamlMap optionsMap,
File? file,
ResourceProvider? resourceProvider,
}) {
var builder = AnalysisOptionsBuilder()..file = file;

var analyzer = optionsMap.valueAt(AnalysisOptionsFile.analyzer);
Expand Down Expand Up @@ -433,7 +452,7 @@ class AnalysisOptionsImpl implements AnalysisOptions {

// Process the 'plugins' option.
var plugins = optionsMap.valueAt(AnalysisOptionsFile.plugins);
builder._applyPluginsOptions(plugins);
builder._applyPluginsOptions(plugins, resourceProvider);

var ruleConfigs = parseLinterSection(optionsMap);
if (ruleConfigs != null) {
Expand Down
6 changes: 5 additions & 1 deletion pkg/analyzer/lib/src/dart/analysis/context_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ class ContextBuilderImpl {
for (var entry in optionsMappings) {
var file = entry.value;
var options = AnalysisOptionsImpl.fromYaml(
file: file, optionsMap: provider.getOptionsFromFile(file));
optionsMap: provider.getOptionsFromFile(file),
file: file,
resourceProvider: resourceProvider,
);

_optionsMap.add(entry.key, options);
}
Expand Down Expand Up @@ -291,6 +294,7 @@ class ContextBuilderImpl {
options = AnalysisOptionsImpl.fromYaml(
optionsMap: provider.getOptionsFromFile(optionsFile),
file: optionsFile,
resourceProvider: resourceProvider,
);
} catch (e) {
// Ignore exception.
Expand Down
3 changes: 2 additions & 1 deletion pkg/analyzer/lib/src/dart/analysis/context_locator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,9 @@ class ContextLocatorImpl {
AnalysisOptionsProvider(workspace.createSourceFactory(null, null));

var options = AnalysisOptionsImpl.fromYaml(
file: optionsFile,
optionsMap: provider.getOptionsFromFile(optionsFile),
file: optionsFile,
resourceProvider: resourceProvider,
);

return options.enabledLegacyPluginNames.toSet();
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/ast/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ final class ArgumentListImpl extends AstNodeImpl implements ArgumentList {

List<FormalParameterElement?>? get correspondingStaticParameters2 =>
_correspondingStaticParameters
?.map((parameter) => parameter.asElement2 as FormalParameterElement)
?.map((parameter) => parameter?.asElement2)
.toList();

@override
Expand Down
Loading

0 comments on commit 26cc983

Please sign in to comment.