# SMALI File Structure

## 📌Key components

* Class Reference
* Super Class
* Annotations
* Static Fields
* Instance Fields
* Direct Methods
* Virtual Methods

### ��*Example code*

```java
.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**

1. **Class Definition**

   ```java
   .class public Lde/fgerbig/spacepeng/components/Player;
   .super Lcom/artemis/Component;
   .source "Player.java"
   ```

   * **`public` class**: Declares a public class named `Player`.
   * **Superclass**: Inherits from `Lcom/artemis/Component`, indicating the class belongs to a component-based architecture.
   * **Source file**: The Java source file is `Player.java`.
2. **Annotations**

   Annotations provide metadata to the Android runtime or tools:

   ```java
   .annotation build Lcom/artemis/annotations/PooledWeaver;
   .end annotation
   ```

   * **`PooledWeaver`**: Likely an annotation for component pooling in the **Artemis** entity framework, improving memory efficiency.

   ```java
   .annotation system Ldalvik/annotation/MemberClasses;
       value = {
           Lde/fgerbig/spacepeng/components/Player$State;
       }
   .end annotation
   ```

   * **`MemberClasses`**: Declares an **inner class** called `State` inside `Player`.
3. **Static Fields**

   Static fields are shared across all instances of the class:

   ```java
   .field public static final DEFAULT_LIVES:I = 0x3e7
   ```

   * **`DEFAULT_LIVES`**: A constant integer initialized to `0x3e7` (hexadecimal for `999`)

   ```java
   .field public static final SPRITE_NAME:Ljava/lang/String; = "player"
   .field public static final SPRITE_NAME_SHIELD:Ljava/lang/String; = "playershield"
   ```

   * **`SPRITE_NAME`**: String constant `"player"`.
   * **`SPRITE_NAME_SHIELD`**: String constant `"playershield"`.
4. **Instance Fields**

   Instance fields belong to specific objects of the class:

   ```java
   .field public lives:I
   .field public score:I
   .field private state:Lde/fgerbig/spacepeng/components/Player$State;
   ```

   * **`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 class `Player$State`.
5. **Direct Methods**

   Direct methods include **constructors** and **private**/static methods.

   * ***Constructor***

     ```java
     .method public constructor <init>()V
         .locals 1

         .prologue
         .line 24
         invoke-direct {p0}, Lcom/artemis/Component;-><init>()V

     ```

     * **`<init>()`**: Constructor for the class.
     * **`invoke-direct`**: Calls the superclass (`Component`) constructor.

     ```java
         .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;
     ```

     * **`sget-object`**: Retrieves the static value `ALIVE` from the inner class `Player$State`.
     * **`iput-object`**: Assigns the `ALIVE` state to the `state` field.

     ```java
         .line 39
         const v0, 0x3e7
         iput v0, p0, Lde/fgerbig/spacepeng/components/Player;->lives:I
     ```

     * Initializes the `lives` field to `999` (`0x3e7` in hex).
6. **Virtual Methods**

   Virtual methods can be **overridden** by subclasses.

   * **isState Method**

     ```java
     .method public isState(Lde/fgerbig/spacepeng/components/Player$State;)Z
         .locals 1
         .param p1, "state"    # Lde/fgerbig/spacepeng/components/Player$State;
     ```

     * **`isState`**: Checks if the player's state matches the given state.

     ```java
         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
     ```

     * **`iget-object`**: Loads the current `state` field into `v0`.
     * **`invoke-virtual`**: Calls the `equals` method on the `state` to compare it with the parameter `p1`.

     ```java
       move-result v0
         return v0
     .end method
     ```

     * Returns the result of the comparison (`true` or `false`).

***
