agentleFS
HeathWangHeathWang/hw-cc-plugin/skills/java-to-swift/SKILL.md

java-to-swift

Skill1 starsChanged 3 months agoMITView on GitHub

Use when converting Java 1.8 classes to Swift 5.0+ Codable structs - handling type mapping, nullability, inheritance flattening, BaseReq exclusions, and property naming conventions.

The file

We split this skill into the rules it gives an agent

9 rules. About 0 are common, 6 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Default: All properties are optional unless explicitly marked non-null.

    line 40
  2. Distinctive:

    Document property source with inline comments

    line 65
  3. Distinctive:

    Place comments immediately above each property

    line 83
  4. Distinctive:

    All converted structs must:

    line 88
  5. Very specific:

    Use let for all properties (immutable)

    line 91
  6. Distinctive:

    If inheritance detected → request/read parent class files

    line 97
  7. Very specific:

    Create Swift struct with Codable conformance

    line 99
  8. Very specific:

    Use let for all properties

    line 102
  9. Distinctive:

    Keep property names identical to Java/server-side

    line 103

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Java to Swift Conversion

Overview

Converts Java 1.8 classes to Swift 5.0+ struct objects conforming to Codable. Output as markdown code blocks only — never modify project files.

Core Constraint

CRITICAL: Output Swift struct definitions as markdown code blocks only. Do NOT modify, edit, or alter any project files.

Type Mapping

Java TypeSwift Type
int / IntegerInt
long / LongInt64
float / FloatFloat
double / DoubleDouble
boolean / BooleanBool
StringString
BigDecimal / decimalDouble (default) or String (with @BigDecimalToString)
DateDate
TimestampTimeInterval
List<T>[T]
Map<K,V>[K: V]

Nullability Rules

Java AnnotationSwift Type
@NonNull / @NotNullNon-optional (String)
No annotation / @NullableOptional (String?)

Default: All properties are optional unless explicitly marked non-null.

Naming Conventions

Struct names: PascalCase (OrderDetails, UserProfile, PaymentRequest)

Property names: ⚠️ KEEP IDENTICAL TO JAVA/SERVER-SIDE — preserves Codable serialization.

// ✅ Correct
struct OrderRequest: Codable {
    let orderId: String        // matches Java field name
    let total_amount: String?  // preserves snake_case
}

Swift's Codable maps property names directly to JSON keys — changing names breaks serialization.

Inheritance Handling

Swift structs don't support inheritance. Always flatten the hierarchy:

  1. Trace full inheritance chain — read all parent class files
  2. If any parent is BaseReq → EXCLUDE all BaseReq properties (handled by network layer)
  3. Combine all remaining properties from parent + child into one struct
  4. Document property source with inline comments
struct OrderRequest: Codable {
    // From ApiRequest
    let userId: String

    // From OrderRequest
    let orderId: Int64

    // Note: BaseReq properties (token, timestamp) excluded — handled by network layer
}

Documentation

Migrate Java comments to Swift using /// triple-slash format:

  • Preserve original language (Chinese stays Chinese, English stays English)
  • Place comments immediately above each property
  • For properties without Java comments, add brief descriptive comment

Structure Requirements

All converted structs must:

  • Be defined as struct (not class)
  • Conform to Codable protocol
  • Use let for all properties (immutable)
  • Flatten all inherited properties into a single struct

Step-by-Step Workflow

  1. Analyze Java class — properties, annotations, types, inheritance
  2. If inheritance detected → request/read parent class files
  3. Handle BaseReq exclusion if applicable
  4. Create Swift struct with Codable conformance
  5. Apply type mapping (including @BigDecimalToString)
  6. Apply nullability (@NonNull → non-optional, else optional)
  7. Use let for all properties
  8. Keep property names identical to Java/server-side
  9. Migrate comments with /// preserving original language

Validation Checklist

  • @NonNull/@NotNull properties are non-optional
  • All other properties are optional (?)
  • Struct conforms to Codable
  • All properties use let
  • Inheritance detected and parent classes analyzed
  • All inherited properties flattened into single struct
  • BaseReq properties excluded if applicable
  • Property names identical to server-side model
  • Output is markdown code block only (no file modifications)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.