Upgrade to Pro — share decks privately, control downloads, hide ads and more …

J2Kコンバータをカスタマイズする

Bb0be4b9096f12090920d85107ad44cd?s=47 Paraya
July 03, 2018

 J2Kコンバータをカスタマイズする

2018/7/3 #love_kotlin vol2
paraya3636

Bb0be4b9096f12090920d85107ad44cd?s=128

Paraya

July 03, 2018
Tweet

Transcript

  1. +,ίϯόʔλΛΧελϚΠζ͢Δ MPWF@LPUMJOWPM QBSBZB ͠Ύͬͪΐ͏͹Μ

  2. ࣗݾ঺հ ɾ ࡾӜՂ༞QBSBZB ɾ גࣜձࣾΠάχεॴଐ ɾ XJUI"OESPJE୲౰ ɾ ,PUMJO͸ͷࠒ͔Β ೥ఔ

  3. ςʔϚ ɾ +BWB͔Β,PUMJOʹม׵͢Δͷ͸ͱͯ΋େม ɾ ,PUMJOԽ͢Δ্Ͱ௨ৗͷํ๏Ҏ֎ʹ΋΍Γํ ͸͋Δ

  4. ΋͘͡ ɾ +BWB͔Β,PUMJOʹม׵͢Δࡍʹۤ࿑͢Δ఺ ɾ +,ίϯόʔλΛΧελϚΠζ

  5. +BWB͔Β,PUMJOʹม׵͢Δ ࡍʹۤ࿑͢Δ఺

  6. ௨ৗ+BWB͔Β,PUMJOʹม׵͢ Δࡍ͸ɺ"OESPJE4UVEJP *OUFMMJK*%&"͔Βίϯόʔτ͢ Δͱࢥ͍·͢

  7. "OESPJE4UVEJP*OUFMMJK*%&" Ͱͷ+,ίϯόʔτ ϝχϡʔ ➔ Code ➔ Convert Java File to

    Kotlin File
  8. ͨͩ͠ɺ͜ͷ௨ৗͷ+,ίϯ όʔλΛ༻͍ͨ,PUMJOԽͷํ ๏ʹ͸໰୊͕͋Γ·ͨ͠

  9. +,ίϯόʔλ͕ڧ੍తʹ /PO/VMMม׵ͯ͠͠·͏ ໰୊

  10. ७ਖ਼+,ίϯόʔλ͕ڧ੍తʹ /PO/VMMม׵͢Δ໰୊ public interface SampleInterface { String getText(Context context); int

    getValue(Context context); } interface SampleInterface { fun getText(context: Context): String fun getValue(context: Context): Int } /VMMBCMFͳ ίʔυͩͬͨͷ͕ /PO/VMMίʔυʹ ม׵͞Εͯ͠·͏ ʁ͕ͳ͍ʂ +BWB ,PUMJO
  11. ७ਖ਼+,ίϯόʔλ͕ڧ੍తʹ /PO/VMMม׵͢Δ໰୊ +BWBίʔυଆ͔Β͸/PU/VMMΞϊςʔγϣϯ෇͍ͯ ΔͷʹOVMMΛ୅ೖͯ͠ΔΑXBSOJOH͕දࣔ͞Εͯ͠ ·͏ʂʂ +BWB

  12. ७ਖ਼+,ίϯόʔλ͕ڧ੍తʹ /PO/VMMม׵͢Δ໰୊ Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is

    null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter context at org.paradrops.sample.SampleClass.getText(SampleClass.kt) at org.paradrops.sample.Main2Activity.onCreate(Main2Activity.java:14) at android.app.Activity.performCreate(Activity.java:6664) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599) IllegalArgumentException: Parameter specified as non-null is null Ϋϥογϡͯ͠͠·͏ʂʂ
  13. ७ਖ਼+,ίϯόʔλ͕ڧ੍తʹ /PO/VMMม׵͢Δ ɾ ਌$MBTT*OUFSGBDFBCTUSBDUΫϥεͳͲϝιο υΛܧঝPS࣮૷ͨ͠৔߹ɺҾ਺ʹ/VMMBCMFΞ ϊςʔγϣϯ͕ͳ͍৔߹͸+,͕/PO/VMMม׵ ͯ͠͠·͏ ɾ ,PUMJO͸/PO/VMMɺ+BWB͸/VMMBCMF؀ڥʹͳͬ ͯ͠·͍ͱͯ΋Ϋϥογϡ͠΍͍͢

  14. Ͳ͏ղܾ͢Δ͔ʁ ղܾࡦ͸ͲΜͳ΋ͷ͕͋Δ͔ʁ

  15. ղܾҊ ɾ ख௚͠Ҋɿ֤Ҿ਺໭Γ஋ͷܕͷ/VMMBCMF /PO/VMM͕ਖ਼͍͔͠ɺ໨ࢹͰνΣοΫͯ͠ख ௚͢͠Δ ɾ શಈ࡞νΣοΫҊɿͱΓ͋͑ͣ,PUMJOԽͯ͠ ΞϓϦͷશಈ࡞νΣοΫͯ͠मਖ਼͢Δ

  16. ͲͪΒ΋͵͘΋ΓҲΕ͍ͯΔର ԠͰͱͯ΋΍Γͨ͘ͳ͍ ,PUMJOԽ͢Δͱߦͷίʔυ ม׵ͱ͔ී௨ʹ͋Δɻ ͦΕΛख࡞ۀͰमਖ਼ͨ͠ίʔυ ͷϨϏϡʔ͢Δͷ͸ਏ͗͢Δ

  17. ͜͜·Ͱߟ͑ͯҰͭ ࢥ͍͖ͭ·ͨ͠

  18. ,PUMJOͬͯ044ͩ͠ ίϯόʔλΛվ଄͢Ε͹Α͍ ͷͰ͸ʜʁ

  19. +BWB͸/VMMBCMF͕ඪ४ͩ͠ɺ ,PUJOଆ΋Ҿ਺ͱ໭Γ஋Λ /VMMBCMFʹ͢Ε͹͍͚ͦ͏

  20. ΍ΔՁ஋͸͋Δ

  21. +,ίϯόʔλΛ ΧελϚΠζ͢Δ

  22. +,ίϯόʔλΧελϚΠζ· Ͱͷεςοϓ ɾ ,PUMJOͷ։ൃ؀ڥΛ༻ҙ͢Δ ɾ ,PUMJOͷ5ZQF$POWFSUFSLUΛฤू͢Δ ɾ ,PUMJOΛνϟΠϧυ*%&"࣮ߦ͢Δ ɾ ίʔυΛίϯόʔτͯ͠ΈΔ

  23. ,PUMJOͷ։ൃ؀ڥΛ༻ҙ ɾ *OUFMMJ+*%&" ɾ +%, ɾ CSFXJOTUBMMBOU ɾ IUUQTHJUIVCDPN+FU#SBJOTLPUMJO ɾ

    ৄࡉ͸!TIJSBKJ͞ΜͷϒϩάهࣄͳͲͰIUUQT TIJSBKJHJUIVCJPCMPHIPXUPLPOUSJCVUF WTFUVQ
  24. ,PUMJOͷ5ZQF$POWFSUFSLUΛฤ ू͢Δ IUUQTHJUIVCDPN+FU#SBJOTLPUMJOCMPCNBTUFS KLTSDPSHKFUCSBJOTLPUMJOKL5ZQF$POWFSUFSLU fun variableNullability(variable: PsiVariable): Nullability = Nullability.Nullable

    fun methodNullability(method: PsiMethod): Nullability = Nullability.Nullable
  25. ,PUMJOΛνϟΠϧυ*%&"࣮ߦ͢ Δ

  26. ࣮ࡍʹ,PUMJOίʔυίϯόʔτ ͯ͠ΈΔ public interface SampleInterface { String getText(Context context); int

    getValue(Context context); } interface SampleInterface { fun getText(context: Context?): String? fun getValue(context: Context?): Int } /VMMBCMFͳ +BWBίʔυ ͩͬͨͷ͕ ͔ͬ͠Γͱ /VMMBCMFΛ อ࣋ͨ͠·· ม׵͞Ε͍ͯΔ +BWB ,PUMJO
  27. ࣮ࡍʹΧελϜ+,Ͱίϯόʔ τͨ͠ίʔυΛ࢖ͬͯΈΔ /VMMBCMFʹOVMMΛ୅ೖ͢Δͷ͸ී௨ͷ͜ͱͳͷͰ XBSOJOH͸ग़ͣɺΫϥογϡ΋͠ͳ͍ ར༻͢Δ+BWBίʔυଆʹมߋΛՃ͑Δඞཁͳ͠

  28. ͿͬͪΌ͚ΧελϜίϯόʔλ ͷ࢖༻ײͲ͏ʁ ɾ ࢖͍࢝Ίͨͷ͸ࠓ೥ͷࠒ ɾ ϦϦʔε➔Ϋϥογϡ➔IPUGJYͷܹݮ ɾ ίϯόʔλ͕ੜ੒͢Δίʔυʹ৴པײˠίʔ υϨϏϡʔͷ؆ૉԽ ɾ

    ,PUMJOԽ͕ؾܰʹͰ͖ΔΑ͏ʹ➔͜Εେࣄ
  29. ͓·͚

  30. ΧελϜ+,ίϯόʔλ΋ͬͯ ͖ͨΑ

  31. ͓·͚ͷXJUI·Μ͕ IUUQIFMQXJUIJT Q Α͔ͬͨΒಡΜͰΈͯͶ ແྉͩΑʂ ͠Ύͬͪΐ͏͹Μ

  32. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ ͠Ύͬͪΐ͏͹Μ

  33. XJUI͸"OESPJEΤϯδχΞΛେઈࢍืूதʂ ϕςϥϯ,PUMJOΤϯδχΞ͕αϙʔτ͢ΔͷͰ ॳ৺ऀͰ΋,PUMJOʹڵຯ͕͋ΔͳΒ ؾܰʹԠืͯ͠ΈͯͶʂ IUUQTXXXXBOUFEMZDPNQSPKFDUT ͠Ύͬͪΐ͏͹Μ