Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/lib/src/multiplier_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import '../annotations.dart';

class MultiplierGenerator extends GeneratorForAnnotation<Multiplier> {
@override
String generateForAnnotatedElement2(
String generateForAnnotatedElement(
Element2 element,
ConstantReader annotation,
BuildStep buildStep,
Expand Down
2 changes: 1 addition & 1 deletion source_gen/lib/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class CombiningBuilder implements Builder {
.join('\n\n');
if (assets.isEmpty) return;

final inputLibrary = await buildStep.inputLibrary2;
final inputLibrary = await buildStep.inputLibrary;
final outputId = buildStep.allowedOutputs.single;
final partOfUri = uriOfPartial(inputLibrary, buildStep.inputId, outputId);

Expand Down
2 changes: 1 addition & 1 deletion source_gen/lib/source_gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export 'src/generator.dart'
export 'src/generator_for_annotation.dart' show GeneratorForAnnotation;
export 'src/library.dart'
show AnnotatedDirective, AnnotatedElement, LibraryReader;
export 'src/span_for_element.dart' show spanForElement, spanForElement2;
export 'src/span_for_element.dart' show spanForElement;
export 'src/type_checker.dart' show TypeChecker, UnresolvedAnnotationException;
export 'src/utils.dart' show typeNameOf;
6 changes: 1 addition & 5 deletions source_gen/lib/src/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class _Builder extends Builder {
}

final lib = await buildStep.resolver
.libraryFor2(buildStep.inputId, allowSyntaxErrors: allowSyntaxErrors);
.libraryFor(buildStep.inputId, allowSyntaxErrors: allowSyntaxErrors);
await _generateForLibrary(lib, buildStep);
}

Expand Down Expand Up @@ -431,10 +431,6 @@ String languageOverrideForLibrary(LibraryElement2 library) {
: '// @dart=${override.major}.${override.minor}\n';
}

@Deprecated('Use languageOverrideForLibrary instead')
String languageOverrideForLibrary2(LibraryElement2 library) =>
languageOverrideForLibrary(library);

/// A comment configuring `dart_style` to use the default code width so no
/// configuration discovery is required.
const dartFormatWidth = '// dart format width=80';
7 changes: 0 additions & 7 deletions source_gen/lib/src/constants/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ void assertHasField(InterfaceElement2 root, String name) {
);
}

/// Throws a [FormatException] if [root] does not have a given field [name].
///
/// Super types [InterfaceElement2.supertype] are also checked before throwing.
@Deprecated('Use assertHasField() instead')
void assertHasField2(InterfaceElement2 root, String name) =>
assertHasField(root, name);

/// Returns whether or not [object] is or represents a `null` value.
bool isNullLike(DartObject? object) => object?.isNull != false;

Expand Down
11 changes: 0 additions & 11 deletions source_gen/lib/src/generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,6 @@ class InvalidGenerationSource implements Exception {
this.node,
});

@Deprecated('use the unnamed constructor instead')
InvalidGenerationSource.v2(
this.message, {
this.todo = '',
this.element,
this.node,
});

@Deprecated('use element instead')
Element2? get element2 => element;

@override
String toString() {
final buffer = StringBuffer(message);
Expand Down
31 changes: 1 addition & 30 deletions source_gen/lib/src/generator_for_annotation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,7 @@ abstract class GeneratorForAnnotation<T> extends Generator {
typeChecker,
throwOnUnresolved: throwOnUnresolved,
)) {
var generatedValue = generateForAnnotatedElement(
annotatedElement.element,
annotatedElement.annotation,
buildStep,
);
generatedValue ??= generateForAnnotatedElement2(
final generatedValue = generateForAnnotatedElement(
annotatedElement.element,
annotatedElement.annotation,
buildStep,
Expand Down Expand Up @@ -115,30 +110,6 @@ abstract class GeneratorForAnnotation<T> extends Generator {
BuildStep buildStep,
) {}

/// Implement to return source code to generate for [element].
///
/// This method is invoked based on finding elements annotated with an
/// instance of [T]. The [annotation] is provided as a [ConstantReader].
///
/// Supported return values include a single [String] or multiple [String]
/// instances within an [Iterable] or [Stream]. It is also valid to return a
/// [Future] of [String], [Iterable], or [Stream]. When multiple values are
/// returned through an iterable or stream they will be deduplicated.
/// Typically each value will be an independent unit of code and the
/// deduplication prevents re-defining the same member multiple times. For
/// example if multiple annotated elements may need a specific utility method
/// available it can be output for each one, and the single deduplicated
/// definition can be shared.
///
/// Implementations should return `null` when no content is generated. Empty
/// or whitespace-only [String] instances are also ignored.
@Deprecated('use generateForAnnotatedElement instead')
dynamic generateForAnnotatedElement2(
Element2 element,
ConstantReader annotation,
BuildStep buildStep,
) {}

/// Implement to return source code to generate for [directive]:
/// - [LibraryImport]
/// - [LibraryExport]
Expand Down
35 changes: 0 additions & 35 deletions source_gen/lib/src/library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ class AnnotatedElement {

const AnnotatedElement(this.annotation, this.element);

@Deprecated('use element instead')
Element2 get element2 => element;

Metadata? get metadata2 {
if (element case final Annotatable annotatable) {
return annotatable.metadata2;
Expand All @@ -44,33 +41,15 @@ class LibraryReader {

LibraryReader(this.element);

@Deprecated('use the default constructor instead')
LibraryReader.v2(this.element);

@Deprecated('use element instead')
LibraryElement2 get element2 => element;

/// All of the declarations in this library.
Iterable<Element2> get allElements => [element, ...element.children2];

/// All of the declarations in this library.
@Deprecated('use allElements instead')
Iterable<Element2> get allElements2 => allElements;

/// All of the elements representing classes in this library.
Iterable<ClassElement2> get classes => element.classes;

/// All of the elements representing classes in this library.
@Deprecated('use classes instead')
Iterable<ClassElement2> get classes2 => classes;

/// All of the elements representing enums in this library.
Iterable<EnumElement2> get enums => element.enums;

/// All of the elements representing enums in this library.
@Deprecated('use enums instead')
Iterable<EnumElement2> get enums3 => enums;

/// All of the declarations in this library annotated with [checker].
Iterable<AnnotatedElement> annotatedWith(
TypeChecker checker, {
Expand Down Expand Up @@ -137,13 +116,6 @@ class LibraryReader {
return type is ClassElement2 ? type : null;
}

/// Returns a top-level [ClassElement2] publicly visible in by [name].
///
/// Unlike `LibraryElement2.getClass`, this also correctly traverses
/// identifiers that are accessible via one or more `export` directives.
@Deprecated('Use findType() instead')
ClassElement2? findType2(String name) => findType(name);

/// Returns a [Uri] from the current library to the target [asset].
///
/// This is a typed convenience function for using [pathToUrl], and the same
Expand All @@ -157,13 +129,6 @@ class LibraryReader {
Uri pathToElement(Element2 element) =>
pathToUrl(element.firstFragment.libraryFragment!.source.uri);

/// Returns a [Uri] from the current library to the target [element].
///
/// This is a typed convenience function for using [pathToUrl], and the same
/// API restrictions hold around supported schemes and relative paths.
@Deprecated('use pathToElement instead')
Uri pathToElement2(Element2 element) => pathToElement(element);

/// Returns a [Uri] from the current library to the one provided.
///
/// If possible, a `package:` or `dart:` URL scheme will be used to reference
Expand Down
15 changes: 0 additions & 15 deletions source_gen/lib/src/span_for_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,6 @@ SourceSpan spanForElement(Element2 element, [SourceFile? file]) {
);
}

/// Returns a source span that spans the location where [element] is defined.
///
/// May be used to emit user-friendly warning and error messages:
/// ```dart
/// void invalidClass(ClassElement class) {
/// log.warning(spanForElement.message('Cannot implement "Secret"'));
/// }
/// ```
///
/// Not all results from the analyzer API may return source information as part
/// of the element, so [file] may need to be manually provided in those cases.
@Deprecated('use spanForElement instead')
SourceSpan spanForElement2(Element2 element, [SourceFile? file]) =>
spanForElement(element, file);

/// Returns a source span that spans the location where [node] is written.
SourceSpan spanForNode(AstNode node) {
final unit = node.thisOrAncestorOfType<CompilationUnit>()!;
Expand Down
Loading