Skip to content

Commit 53d805f

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer: Move the PluginSource classes to be private; add to signature
This week we moved some other "plugin analysis options" code into the private API. This continues that work, in order to add plugin source options into the AnalysisOptionsImpl signature code. The classes are deprecated as far as the public API is concerned, encoded with a `@Deprecated` export. This is not reflected in api.txt. Change-Id: Ie95851a7b0d54ef6abb8fb1e2b41294fbc5db836 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/447841 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent 3f120e0 commit 53d805f

File tree

5 files changed

+133
-96
lines changed

5 files changed

+133
-96
lines changed

pkg/analysis_server/lib/src/plugin2/generator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:analyzer/dart/analysis/analysis_options.dart';
5+
import 'package:analyzer/src/dart/analysis/analysis_options.dart';
66

77
/// This class can generate various files to make up the shared plugin package.
88
class PluginPackageGenerator {

pkg/analysis_server_plugin/lib/src/plugin_server.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import 'package:analysis_server_plugin/src/registry.dart';
1616
import 'package:analyzer/analysis_rule/rule_context.dart';
1717
import 'package:analyzer/dart/analysis/analysis_context.dart';
1818
import 'package:analyzer/dart/analysis/analysis_context_collection.dart';
19-
import 'package:analyzer/dart/analysis/analysis_options.dart';
2019
import 'package:analyzer/dart/analysis/results.dart';
2120
import 'package:analyzer/dart/analysis/session.dart';
2221
import 'package:analyzer/dart/ast/ast.dart';

pkg/analyzer/lib/dart/analysis/analysis_options.dart

Lines changed: 10 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@ import 'package:analyzer/dart/analysis/features.dart';
77
import 'package:analyzer/dart/analysis/formatter_options.dart';
88
import 'package:analyzer/source/error_processor.dart';
99
import 'package:analyzer/src/analysis_rule/rule_context.dart';
10-
import 'package:analyzer/src/lint/config.dart';
10+
import 'package:analyzer/src/dart/analysis/analysis_options.dart';
11+
12+
@Deprecated("The 'PluginSource' classes are no longer public API")
13+
export 'package:analyzer/src/dart/analysis/analysis_options.dart'
14+
show
15+
GitPluginSource,
16+
PathPluginSource,
17+
PluginConfiguration,
18+
PluginSource,
19+
VersionedPluginSource;
1120

1221
/// A set of analysis options used to control the behavior of an analysis
1322
/// context.
@@ -73,95 +82,3 @@ abstract class AnalysisOptions {
7382
/// Return `true` the lint with the given [name] is enabled.
7483
bool isLintEnabled(String name);
7584
}
76-
77-
final class GitPluginSource implements PluginSource {
78-
final String _url;
79-
80-
final String? _path;
81-
82-
final String? _ref;
83-
84-
GitPluginSource({required String url, String? path, String? ref})
85-
: _url = url,
86-
_path = path,
87-
_ref = ref;
88-
89-
@override
90-
String toYaml({required String name}) {
91-
var buffer = StringBuffer()
92-
..writeln(' $name:')
93-
..writeln(' git:')
94-
..writeln(' url: $_url');
95-
if (_ref != null) {
96-
buffer.writeln(' ref: $_ref');
97-
}
98-
if (_path != null) {
99-
buffer.writeln(' path: $_path');
100-
}
101-
return buffer.toString();
102-
}
103-
}
104-
105-
final class PathPluginSource implements PluginSource {
106-
final String _path;
107-
108-
PathPluginSource({required String path}) : _path = path;
109-
110-
@override
111-
String toYaml({required String name}) =>
112-
'''
113-
$name:
114-
path: $_path
115-
''';
116-
}
117-
118-
/// The configuration of a Dart Analysis Server plugin, as specified by
119-
/// analysis options.
120-
final class PluginConfiguration {
121-
/// The name of the plugin being configured.
122-
final String name;
123-
124-
/// The source of the plugin being configured.
125-
final PluginSource source;
126-
127-
/// The list of specified [DiagnosticConfig]s.
128-
// ignore: analyzer_public_api_bad_type
129-
final Map<String, DiagnosticConfig> diagnosticConfigs;
130-
131-
/// Whether the plugin is enabled.
132-
final bool isEnabled;
133-
134-
// ignore: analyzer_public_api_bad_type
135-
PluginConfiguration({
136-
required this.name,
137-
required this.source,
138-
this.diagnosticConfigs = const {},
139-
this.isEnabled = true,
140-
});
141-
142-
String sourceYaml() => source.toYaml(name: name);
143-
}
144-
145-
/// A description of the source of a plugin.
146-
147-
/// We support all of the source formats documented at
148-
/// https://dart.dev/tools/pub/dependencies.
149-
sealed class PluginSource {
150-
/// Returns the YAML-formatted source, using [name] as a key, for writing into
151-
/// a pubspec 'dependencies' section.
152-
String toYaml({required String name});
153-
}
154-
155-
/// A plugin source using a version constraint, hosted either at pub.dev or
156-
/// another host.
157-
// TODO(srawlins): Support a different 'hosted' URL.
158-
final class VersionedPluginSource implements PluginSource {
159-
/// The specified version constraint.
160-
final String _constraint;
161-
162-
VersionedPluginSource({required String constraint})
163-
: _constraint = constraint;
164-
165-
@override
166-
String toYaml({required String name}) => ' $name: $_constraint\n';
167-
}

pkg/analyzer/lib/src/dart/analysis/analysis_options.dart

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'dart:typed_data';
66

7+
import 'package:_fe_analyzer_shared/src/base/analyzer_public_api.dart';
78
import 'package:analyzer/dart/analysis/analysis_options.dart';
89
import 'package:analyzer/dart/analysis/code_style_options.dart';
910
import 'package:analyzer/dart/analysis/features.dart';
@@ -599,6 +600,20 @@ class AnalysisOptionsImpl implements AnalysisOptions {
599600
)) {
600601
buffer.addString(pluginConfiguration.name);
601602
buffer.addBool(pluginConfiguration.isEnabled);
603+
switch (pluginConfiguration.source) {
604+
case GitPluginSource source:
605+
buffer.addString(source._url);
606+
if (source._path case var path?) {
607+
buffer.addString(path);
608+
}
609+
if (source._ref case var ref?) {
610+
buffer.addString(ref);
611+
}
612+
case PathPluginSource source:
613+
buffer.addString(source._path);
614+
case VersionedPluginSource source:
615+
buffer.addString(source._constraint);
616+
}
602617
buffer.addInt(pluginConfiguration.diagnosticConfigs.length);
603618
for (var diagnosticConfig
604619
in pluginConfiguration.diagnosticConfigs.values) {
@@ -660,6 +675,83 @@ class AnalysisOptionsImpl implements AnalysisOptions {
660675
}
661676
}
662677

678+
@AnalyzerPublicApi(
679+
message: 'exported by lib/dart/analysis/analysis_options.dart',
680+
)
681+
final class GitPluginSource implements PluginSource {
682+
final String _url;
683+
684+
final String? _path;
685+
686+
final String? _ref;
687+
688+
GitPluginSource({required String url, String? path, String? ref})
689+
: _url = url,
690+
_path = path,
691+
_ref = ref;
692+
693+
@override
694+
String toYaml({required String name}) {
695+
var buffer = StringBuffer()
696+
..writeln(' $name:')
697+
..writeln(' git:')
698+
..writeln(' url: $_url');
699+
if (_ref != null) {
700+
buffer.writeln(' ref: $_ref');
701+
}
702+
if (_path != null) {
703+
buffer.writeln(' path: $_path');
704+
}
705+
return buffer.toString();
706+
}
707+
}
708+
709+
@AnalyzerPublicApi(
710+
message: 'exported by lib/dart/analysis/analysis_options.dart',
711+
)
712+
final class PathPluginSource implements PluginSource {
713+
final String _path;
714+
715+
PathPluginSource({required String path}) : _path = path;
716+
717+
@override
718+
String toYaml({required String name}) =>
719+
'''
720+
$name:
721+
path: $_path
722+
''';
723+
}
724+
725+
/// The configuration of a Dart Analysis Server plugin, as specified by
726+
/// analysis options.
727+
@AnalyzerPublicApi(
728+
message: 'exported by lib/dart/analysis/analysis_options.dart',
729+
)
730+
final class PluginConfiguration {
731+
/// The name of the plugin being configured.
732+
final String name;
733+
734+
/// The source of the plugin being configured.
735+
final PluginSource source;
736+
737+
/// The list of specified [DiagnosticConfig]s.
738+
// ignore: analyzer_public_api_bad_type
739+
final Map<String, DiagnosticConfig> diagnosticConfigs;
740+
741+
/// Whether the plugin is enabled.
742+
final bool isEnabled;
743+
744+
// ignore: analyzer_public_api_bad_type
745+
PluginConfiguration({
746+
required this.name,
747+
required this.source,
748+
this.diagnosticConfigs = const {},
749+
this.isEnabled = true,
750+
});
751+
752+
String sourceYaml() => source.toYaml(name: name);
753+
}
754+
663755
/// The analysis options for plugins, as specified in the top-level `plugins`
664756
/// section.
665757
final class PluginsOptions {
@@ -675,6 +767,36 @@ final class PluginsOptions {
675767
});
676768
}
677769

770+
/// A description of the source of a plugin.
771+
///
772+
/// We support all of the source formats documented at
773+
/// https://dart.dev/tools/pub/dependencies.
774+
@AnalyzerPublicApi(
775+
message: 'exported by lib/dart/analysis/analysis_options.dart',
776+
)
777+
sealed class PluginSource {
778+
/// Returns the YAML-formatted source, using [name] as a key, for writing into
779+
/// a pubspec 'dependencies' section.
780+
String toYaml({required String name});
781+
}
782+
783+
/// A plugin source using a version constraint, hosted either at pub.dev or
784+
/// another host.
785+
// TODO(srawlins): Support a different 'hosted' URL.
786+
@AnalyzerPublicApi(
787+
message: 'exported by lib/dart/analysis/analysis_options.dart',
788+
)
789+
final class VersionedPluginSource implements PluginSource {
790+
/// The specified version constraint.
791+
final String _constraint;
792+
793+
VersionedPluginSource({required String constraint})
794+
: _constraint = constraint;
795+
796+
@override
797+
String toYaml({required String name}) => ' $name: $_constraint\n';
798+
}
799+
678800
extension on YamlNode? {
679801
bool? get boolValue {
680802
var self = this;

pkg/analyzer/test/src/options/analysis_options_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:analyzer/dart/analysis/analysis_options.dart';
65
import 'package:analyzer/diagnostic/diagnostic.dart';
76
import 'package:analyzer/error/error.dart';
87
import 'package:analyzer/file_system/memory_file_system.dart';

0 commit comments

Comments
 (0)