SMALI File Structure
📌Key components
Class Reference
Super Class
Annotations
Static Fields
Instance Fields
Direct Methods
Virtual Methods
📍Example code
.class public Lde/fgerbig/spacepeng/components/Player;
.super Lcom/artemis/Component;
.source "Player.java"
# annotations
.annotation build Lcom/artemis/annotations/PooledWeaver;
.end annotation
.annotation system Ldalvik/annotation/MemberClasses;
value = {
Lde/fgerbig/spacepeng/components/Player$State;
}
.end annotation
# static fields
.field public static final DEFAULT_LIVES:I = 0x3e7
.field public static final SPRITE_NAME:Ljava/lang/String; = "player"
.field public static final SPRITE_NAME_SHIELD:Ljava/lang/String; = "playershield"
# instance fields
.field public lives:I
.field public score:I
.field private state:Lde/fgerbig/spacepeng/components/Player$State;
# direct methods
.method public constructor <init>()V
.locals 1
.prologue
.line 24
invoke-direct {p0}, Lcom/artemis/Component;-><init>()V
.line 37
sget-object v0, Lde/fgerbig/spacepeng/components/Player$State;->ALIVE:Lde/fgerbig/spacepeng/components/Player$State;
iput-object v0, p0, Lde/fgerbig/spacepeng/components/Player;->state:Lde/fgerbig/spacepeng/components/Player$State;
.line 39
const v0, 0x3e7
iput v0, p0, Lde/fgerbig/spacepeng/components/Player;->lives:I
return-void
.end method
# virtual methods
.method public isState(Lde/fgerbig/spacepeng/components/Player$State;)Z
.locals 1
.param p1, "state" # Lde/fgerbig/spacepeng/components/Player$State;
.prologue
.line 47
iget-object v0, p0, Lde/fgerbig/spacepeng/components/Player;->state:Lde/fgerbig/spacepeng/components/Player$State;
invoke-virtual {v0, p1}, Lde/fgerbig/spacepeng/components/Player$State;->equals(Ljava/lang/Object;)Z
move-result v0
return v0
.end method
.method public setState(Lde/fgerbig/spacepeng/components/Player$State;)V
.locals 0
.param p1, "state" # Lde/fgerbig/spacepeng/components/Player$State;
.prologue
.line 43
iput-object p1, p0, Lde/fgerbig/spacepeng/components/Player;->state:Lde/fgerbig/spacepeng/components/Player$State;
.line 44
return-void
.end method📍Here's a breakdown of the code
Class Definition
publicclass: Declares a public class namedPlayer.Superclass: Inherits from
Lcom/artemis/Component, indicating the class belongs to a component-based architecture.Source file: The Java source file is
Player.java.
Annotations
Annotations provide metadata to the Android runtime or tools:
PooledWeaver: Likely an annotation for component pooling in the Artemis entity framework, improving memory efficiency.
MemberClasses: Declares an inner class calledStateinsidePlayer.
Static Fields
Static fields are shared across all instances of the class:
DEFAULT_LIVES: A constant integer initialized to0x3e7(hexadecimal for999)
SPRITE_NAME: String constant"player".SPRITE_NAME_SHIELD: String constant"playershield".
Instance Fields
Instance fields belong to specific objects of the class:
lives: Public integer field representing the player's lives.score: Public integer field for the player's score.state: A private reference to the inner classPlayer$State.
Direct Methods
Direct methods include constructors and private/static methods.
Constructor
<init>(): Constructor for the class.invoke-direct: Calls the superclass (Component) constructor.
sget-object: Retrieves the static valueALIVEfrom the inner classPlayer$State.iput-object: Assigns theALIVEstate to thestatefield.
Initializes the
livesfield to999(0x3e7in hex).
Virtual Methods
Virtual methods can be overridden by subclasses.
isState Method
isState: Checks if the player's state matches the given state.
iget-object: Loads the currentstatefield intov0.invoke-virtual: Calls theequalsmethod on thestateto compare it with the parameterp1.
Returns the result of the comparison (
trueorfalse).
Last updated