Skip to main content

KotlinFile

Struct KotlinFile 

Source
pub struct KotlinFile {
    pub package: String,
    pub decls: Vec<KtDecl>,
    pub extra_imports: Vec<String>,
    pub banner: Option<String>,
}
Expand description

One Kotlin source file fragment: a package plus top-level declarations. Fragments of the same package are merged by super::file::merge_files.

Fields§

§package: String§decls: Vec<KtDecl>§extra_imports: Vec<String>

FQNs referenced only inside raw text the model can’t see (e.g. body strings built with pre-shortened type names). Registered into the file’s import set before any declaration renders.

§banner: Option<String>

Override the banner line prepended to the rendered file. None uses the default banner constant from the renderer. Some("") suppresses it.

Implementations§

Source§

impl KtFile

Source

pub fn new(package: impl Into<String>) -> KtFile

Source

pub fn banner(self, text: impl Into<String>) -> KtFile

Override the banner comment prepended to the rendered file. Pass "" to suppress the banner entirely.

Source

pub fn decl(self, d: impl Into<KtDecl>) -> KtFile

Source

pub fn import(self, fqn: impl Into<String>) -> KtFile

Register an FQN referenced only inside raw text.

Source

pub fn imports(self, fqns: impl IntoIterator<Item = String>) -> KtFile

Source§

impl KtFile

Source

pub fn render(&self) -> String

Render the complete file: banner, package, sorted imports, then declarations in insertion order separated by blank lines.

Source§

impl KtFile

Source

pub fn validate(&self) -> Vec<Diagnostic>

Every problem in this file, with each check at its default severity (error).

An empty result means the file is as good as the model can prove: names, redeclarations and declaration shapes are checked, and Check enumerates exactly which. Anything needing type resolution, or reading the raw text inside KtCode bodies, stays the Kotlin compiler’s job.

Source

pub fn validate_with(&self, policy: &ValidationPolicy) -> Vec<Diagnostic>

KtFile::validate with per-check severities.

Trait Implementations§

Source§

impl Clone for KtFile

Source§

fn clone(&self) -> KtFile

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for KtFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.