pub trait Ctx {
Show 29 methods
// Required methods
fn class_name(&self) -> &str;
fn find_outer(&self, internal: &str) -> Option<String>;
fn family(&self, root: &str) -> Family;
fn nested_is_static(&self, internal: &str) -> bool;
fn class_has_this0(&self, internal: &str) -> bool;
fn is_subtype_of(&self, sub: &JavaType, sup: &str) -> bool;
fn class_supers_args(
&self,
internal: &str,
args: &[GenericType],
) -> Vec<(String, Vec<GenericType>)>;
fn is_generic_call(&self, e: &Expr) -> bool;
fn generic_call_formals(
&self,
e: &Expr,
) -> Option<(Vec<GenericType>, Vec<String>)>;
fn polymorphic_ret_cast(
&self,
cls: &str,
name: &str,
desc: &MethodDescriptor,
) -> Option<JavaType>;
fn ctor_formals_by_arity(
&self,
internal: &str,
arity: usize,
) -> Option<Vec<GenericType>>;
fn is_interface(&self, internal: &str) -> bool;
fn is_sealed(&self, internal: &str) -> bool;
fn has_class(&self, internal: &str) -> bool;
fn class_bases(
&self,
internal: &str,
) -> Option<(Vec<String>, Option<String>)>;
fn outer_param_via_super(&self, internal: &str) -> bool;
fn nested_method(
&self,
l: &LambdaExpr,
outer_vt: &VarTable,
) -> Option<MethodBody>;
// Provided methods
fn source_level(&self) -> u16 { ... }
fn local_class_internal(&self, simple: &str) -> Option<String> { ... }
fn class_type_params(&self, internal: &str) -> Vec<TypeParam> { ... }
fn generic_call_mt_typevars(&self, e: &Expr) -> Vec<String> { ... }
fn super_name(&self, internal: &str) -> Option<String> { ... }
fn field_flags(
&self,
internal: &str,
name: &str,
) -> Option<FieldAccessFlags> { ... }
fn method_flags(
&self,
internal: &str,
name: &str,
desc: &str,
) -> Option<MethodAccessFlags> { ... }
fn declares_field(&self, internal: &str, name: &str) -> bool { ... }
fn declares_method_named(&self, internal: &str, name: &str) -> bool { ... }
fn ctor_param_types(
&self,
internal: &str,
skip: usize,
n: usize,
args: &[Expr],
) -> Option<Vec<JavaType>> { ... }
fn sam_ret_cast(&self, g: &GenericType, sam_name: &str) -> Option<TypeRef> { ... }
fn class_declares_generics(&self, internal: &str) -> bool { ... }
}Expand description
Front-end services used by the shared passes and the emitter.
Required Methods§
Sourcefn class_name(&self) -> &str
fn class_name(&self) -> &str
Internal name of the class currently being emitted
(e.g. java/util/ArrayList).
Sourcefn find_outer(&self, internal: &str) -> Option<String>
fn find_outer(&self, internal: &str) -> Option<String>
The class that internal is nested in, when the container records the
nesting (JVM InnerClasses/NestHost; DEX inner-class annotations).
None for a top-level class — including literal-$ names that only
look nested.
Sourcefn family(&self, root: &str) -> Family
fn family(&self, root: &str) -> Family
Nested-class family of root, as far as the container records it.
Sourcefn nested_is_static(&self, internal: &str) -> bool
fn nested_is_static(&self, internal: &str) -> bool
True when a nested class is static (Outer$Inner with ACC_STATIC), so
it is not constructed with an enclosing instance.
Sourcefn class_has_this0(&self, internal: &str) -> bool
fn class_has_this0(&self, internal: &str) -> bool
True when the class carries a synthetic this$0 field (an inner class
with an enclosing instance parameter).
Sourcefn is_subtype_of(&self, sub: &JavaType, sup: &str) -> bool
fn is_subtype_of(&self, sub: &JavaType, sup: &str) -> bool
True when sub is assignable to sup (both internal names).
Sourcefn class_supers_args(
&self,
internal: &str,
args: &[GenericType],
) -> Vec<(String, Vec<GenericType>)>
fn class_supers_args( &self, internal: &str, args: &[GenericType], ) -> Vec<(String, Vec<GenericType>)>
Superclasses/interfaces of internal with the given type arguments
applied: [(java/lang/Object, []), ...], most-derived first.
Sourcefn is_generic_call(&self, e: &Expr) -> bool
fn is_generic_call(&self, e: &Expr) -> bool
True when the call carries inferred type arguments that the source must spell out.
Sourcefn generic_call_formals(
&self,
e: &Expr,
) -> Option<(Vec<GenericType>, Vec<String>)>
fn generic_call_formals( &self, e: &Expr, ) -> Option<(Vec<GenericType>, Vec<String>)>
Instantiated formal parameter types of a generic call plus the callee’s
own method type variables (for witness casts). None when the call has
no inferred type arguments to spell out.
Sourcefn polymorphic_ret_cast(
&self,
cls: &str,
name: &str,
desc: &MethodDescriptor,
) -> Option<JavaType>
fn polymorphic_ret_cast( &self, cls: &str, name: &str, desc: &MethodDescriptor, ) -> Option<JavaType>
The instantiated return type of a call whose methodref owner redeclares the method with a self-covariant return (Stream over BaseStream).
Sourcefn ctor_formals_by_arity(
&self,
internal: &str,
arity: usize,
) -> Option<Vec<GenericType>>
fn ctor_formals_by_arity( &self, internal: &str, arity: usize, ) -> Option<Vec<GenericType>>
Constructor parameter types of internal matching arity, for
rendering new arguments against the right overload.
Sourcefn is_interface(&self, internal: &str) -> bool
fn is_interface(&self, internal: &str) -> bool
True when internal is an interface.
Sourcefn is_sealed(&self, internal: &str) -> bool
fn is_sealed(&self, internal: &str) -> bool
True when internal is sealed (its permitted subclasses are recorded).
Sourcefn has_class(&self, internal: &str) -> bool
fn has_class(&self, internal: &str) -> bool
True when the container holds this class at all (naming probes use
it to test Outer$1Local-style candidates).
Sourcefn class_bases(&self, internal: &str) -> Option<(Vec<String>, Option<String>)>
fn class_bases(&self, internal: &str) -> Option<(Vec<String>, Option<String>)>
Interfaces and superclass of internal (internal names, declaration
order). None when the class is unknown to the front-end.
Sourcefn outer_param_via_super(&self, internal: &str) -> bool
fn outer_param_via_super(&self, internal: &str) -> bool
True when internal is an inner class whose constructor forwards its
enclosing instance straight to super (javac 21+ drops this$0 in
that case, but call sites still need the qualified-new form).
Sourcefn nested_method(
&self,
l: &LambdaExpr,
outer_vt: &VarTable,
) -> Option<MethodBody>
fn nested_method( &self, l: &LambdaExpr, outer_vt: &VarTable, ) -> Option<MethodBody>
Decompile the nested method a lambda site refers to — a lambda body, an anonymous-class method, or a local-class method — and run the front-end’s own idiom recovery on it.
This is where machine-specific desugaring lives: the shared emitter
asks for a finished statement tree and prints it. The LambdaExpr
carries the call-site facts (impl owner/name/descriptor, the SAM’s
parameter names, the capture expressions, and any front-end
annotations it attached, e.g. capture snapshots); outer_vt is the
enclosing method’s variable table — the lexical scope the body will be
printed in.
Provided Methods§
Sourcefn source_level(&self) -> u16
fn source_level(&self) -> u16
Source level gate for version-dependent rendering: the JVM front-end
returns the class-file major version; a DEX front-end returns the
equivalent language level it decided to target. 52 means “Java 8
features available” (lambdas, diamond, …).
Sourcefn local_class_internal(&self, simple: &str) -> Option<String>
fn local_class_internal(&self, simple: &str) -> Option<String>
Local-class name recorded for a $-style synthetic marker, when the
container records one (Outer$1Local -> Local).
Sourcefn class_type_params(&self, internal: &str) -> Vec<TypeParam>
fn class_type_params(&self, internal: &str) -> Vec<TypeParam>
Generic type parameters declared by internal (from its class
signature); empty when the container records none.
Sourcefn generic_call_mt_typevars(&self, e: &Expr) -> Vec<String>
fn generic_call_mt_typevars(&self, e: &Expr) -> Vec<String>
Type variables of the method the call refers to (used to decide whether a formal still carries the callee’s own typevars).
Sourcefn super_name(&self, internal: &str) -> Option<String>
fn super_name(&self, internal: &str) -> Option<String>
Superclass of internal (internal name); None at Object/unknown.
Sourcefn field_flags(&self, internal: &str, name: &str) -> Option<FieldAccessFlags>
fn field_flags(&self, internal: &str, name: &str) -> Option<FieldAccessFlags>
Access flags of the field internal.name; None when absent.
Sourcefn method_flags(
&self,
internal: &str,
name: &str,
desc: &str,
) -> Option<MethodAccessFlags>
fn method_flags( &self, internal: &str, name: &str, desc: &str, ) -> Option<MethodAccessFlags>
Access flags of the method internal.name(desc); None when absent.
Sourcefn declares_field(&self, internal: &str, name: &str) -> bool
fn declares_field(&self, internal: &str, name: &str) -> bool
True when internal declares any field named name.
Sourcefn declares_method_named(&self, internal: &str, name: &str) -> bool
fn declares_method_named(&self, internal: &str, name: &str) -> bool
True when internal declares a method named name (any descriptor).
Sourcefn ctor_param_types(
&self,
internal: &str,
skip: usize,
n: usize,
args: &[Expr],
) -> Option<Vec<JavaType>>
fn ctor_param_types( &self, internal: &str, skip: usize, n: usize, args: &[Expr], ) -> Option<Vec<JavaType>>
Parameter types of the <init> of internal matching skip + n
descriptor args, with skip leading synthetic parameters removed.
Used to print new arguments with boolean/char constant adjustment.
Sourcefn sam_ret_cast(&self, g: &GenericType, sam_name: &str) -> Option<TypeRef>
fn sam_ret_cast(&self, g: &GenericType, sam_name: &str) -> Option<TypeRef>
Instantiated SAM return of a functional interface’s method, resolved
against a cast’s type arguments ((Function<I,R>) lambda needs
(R) value witnesses on the impl body’s returns).
Sourcefn class_declares_generics(&self, internal: &str) -> bool
fn class_declares_generics(&self, internal: &str) -> bool
True when internal declares class-level type parameters (so
new internal<>(...) should carry a diamond).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".