InsertIntoMethodInClass class
Inserts statements into the body of a method, after the statements that
contain an anchor text, such as a call in initState after
super.initState();.
The target is the first method named method in the first class named className. insert goes after each statement of its body whose source, as the parser prints it, contains afterStatement. Only the statements directly in the body are checked, not those nested in blocks, and when none matches nothing is inserted.
Throws an Exception when the class or the method is missing or the
method body is an expression, and a FormatterException when insert
leaves invalid code.
When the body already has the statements of insert in a row, as the parser prints them, nothing is inserted, so running it again changes nothing; an insert of nothing but comments is added on every run.
Only the new lines are added: the comments and blank lines of the body stay, and a comment that trails a statement stays on its line. The whole file is then reformatted, or returned as it is when nothing is inserted.
- Inheritance
-
- Object
- Contribution
- InsertIntoMethodInClass
Constructors
Properties
- afterStatement → String
-
Text that marks the statements to insert after, such as
super.initState().final - className → String
-
The name of the class that declares method, such as
_HomePageState.final - 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
- insert → String
-
The statements to insert. PatchEngine renders its placeholders.
final
- method → String
-
The name of the method to patch, such as
initState.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