InsertImport class
Adds an import directive to file, unless the file already has it.
An existing import counts as the same when it has the same URI, prefix and combinators, whatever its quotes or line breaks, so running this again changes nothing. Commented-out imports don't count.
The import goes on a new line after the last import, or else after the library directive, past any comment that trails it on that line. A file with neither gets it above its first directive or declaration, below leading comments such as a license header, or at the end when it holds only comments. Only the new line is added: the rest of the file keeps its formatting, and syntax errors elsewhere in the file don't stop it.
- Inheritance
-
- Object
- Contribution
- InsertImport
Constructors
- InsertImport({required String file, required String import})
-
Creates a contribution that adds
importtofile.const
Properties
- dartFormater → DartFormatter
-
The formatter contributions run over the code they produce.
no setterinherited
- file → String
-
The path of the file to change, relative to the project root.
finalinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- import → String
-
A single import directive, such as
import 'package:a/a.dart';.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
apply(
String original) → Future< String> -
Returns
original, the content of file, with this change applied.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited