import{_ as o,r as l,o as t,c as i,b as e,d as s,a as c,e as a}from"./app--CGKFO0X.js";const p={},r=a('<h1 id="hikage-compiler" tabindex="-1"><a class="header-anchor" href="#hikage-compiler" aria-hidden="true">#</a> hikage-compiler</h1><p><img src="https://img.shields.io/maven-central/v/com.highcapable.hikage/hikage-compiler?logo=apachemaven&amp;logoColor=orange&amp;style=flat-square" alt="Maven Central"><span style="margin-left:5px;"></span><img src="https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Fraw.githubusercontent.com%2FHighCapable%2Fmaven-repository%2Frefs%2Fheads%2Fmain%2Frepository%2Freleases%2Fcom%2Fhighcapable%2Fhikage%2Fhikage-compiler%2Fmaven-metadata.xml&amp;logo=apachemaven&amp;logoColor=orange&amp;label=highcapable-maven-releases&amp;style=flat-square" alt="Maven metadata URL"><span style="margin-left:5px;"></span><img src="https://img.shields.io/badge/Min SDK-21-orange?logo=android&amp;style=flat-square" alt="Android Min SDK"></p><p>This is a Hikage automatic compilation module.</p><h2 id="configure-dependency" tabindex="-1"><a class="header-anchor" href="#configure-dependency" aria-hidden="true">#</a> Configure Dependency</h2><p>You can add this module to your project using the following method.</p>',5),d={class:"custom-container warning"},u=e("p",{class:"custom-container-title"},"Notice",-1),m={href:"https://github.com/google/ksp/releases",target:"_blank",rel:"noopener noreferrer"},y=a(`<h3 id="version-catalog-recommended" tabindex="-1"><a class="header-anchor" href="#version-catalog-recommended" aria-hidden="true">#</a> Version Catalog (Recommended)</h3><p>Add dependency in your project&#39;s <code>gradle/libs.versions.toml</code>.</p><div class="language-toml line-numbers-mode" data-ext="toml"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#ADBAC7;">[</span><span style="color:#F69D50;">versions</span><span style="color:#ADBAC7;">]</span></span>
<span class="line"><span style="color:#ADBAC7;">ksp = </span><span style="color:#96D0FF;">&quot;&lt;ksp-version&gt;&quot;</span></span>
<span class="line"><span style="color:#ADBAC7;">hikage-compiler = </span><span style="color:#96D0FF;">&quot;&lt;version&gt;&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#ADBAC7;">[</span><span style="color:#F69D50;">plugins</span><span style="color:#ADBAC7;">]</span></span>
<span class="line"><span style="color:#ADBAC7;">ksp = { id = </span><span style="color:#96D0FF;">&quot;com.google.devtools.ksp&quot;</span><span style="color:#ADBAC7;">, version.ref = </span><span style="color:#96D0FF;">&quot;ksp&quot;</span><span style="color:#ADBAC7;"> }</span></span>
<span class="line"></span>
<span class="line"><span style="color:#ADBAC7;">[</span><span style="color:#F69D50;">libraries</span><span style="color:#ADBAC7;">]</span></span>
<span class="line"><span style="color:#ADBAC7;">hikage-compiler = { module = </span><span style="color:#96D0FF;">&quot;com.highcapable.hikage:hikage-compiler&quot;</span><span style="color:#ADBAC7;">, version.ref = </span><span style="color:#96D0FF;">&quot;hikage-compiler&quot;</span><span style="color:#ADBAC7;"> }</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>Configure dependency in your root project&#39;s <code>build.gradle.kts</code>.</p><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#DCBDFB;">plugins</span><span style="color:#ADBAC7;"> {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#DCBDFB;">alias</span><span style="color:#ADBAC7;">(libs.plugins.ksp) apply </span><span style="color:#6CB6FF;">false</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>Configure dependency in your project&#39;s <code>build.gradle.kts</code>.</p><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#DCBDFB;">plugins</span><span style="color:#ADBAC7;"> {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#DCBDFB;">alias</span><span style="color:#ADBAC7;">(libs.plugins.ksp)</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#DCBDFB;">dependencies</span><span style="color:#ADBAC7;"> {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#DCBDFB;">ksp</span><span style="color:#ADBAC7;">(libs.hikage.compiler)</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>Please change <code>&lt;version&gt;</code> to the version displayed at the top of this document, and change <code>&lt;ksp-version&gt;</code> to the KSP version corresponding to the Kotlin version currently used by your project.</p><h3 id="traditional-method" tabindex="-1"><a class="header-anchor" href="#traditional-method" aria-hidden="true">#</a> Traditional Method</h3><p>Configure dependency in your root project <code>build.gradle.kts</code>.</p><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#DCBDFB;">plugins</span><span style="color:#ADBAC7;"> {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#DCBDFB;">id</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;com.google.devtools.ksp&quot;</span><span style="color:#ADBAC7;">) version </span><span style="color:#96D0FF;">&quot;&lt;ksp-version&gt;&quot;</span><span style="color:#ADBAC7;"> apply </span><span style="color:#6CB6FF;">false</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>Configure dependency in your project&#39;s <code>build.gradle.kts</code>.</p><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#DCBDFB;">plugins</span><span style="color:#ADBAC7;"> {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#DCBDFB;">id</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;com.google.devtools.ksp&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#DCBDFB;">dependencies</span><span style="color:#ADBAC7;"> {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#DCBDFB;">ksp</span><span style="color:#ADBAC7;">(</span><span style="color:#96D0FF;">&quot;com.highcapable.hikage:hikage-compiler:&lt;version&gt;&quot;</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>Please change <code>&lt;version&gt;</code> to the version displayed at the top of this document, and change <code>&lt;ksp-version&gt;</code> to the KSP version corresponding to the Kotlin version currently used by your project.</p><h2 id="function-introduction" tabindex="-1"><a class="header-anchor" href="#function-introduction" aria-hidden="true">#</a> Function Introduction</h2><p>Hikage&#39;s compilation module will automatically generate code at runtime. After update, please re-run the <code>assembleDebug</code> or <code>assembleRelease</code> task to generate the latest code.</p><h3 id="generate-layout-components" tabindex="-1"><a class="header-anchor" href="#generate-layout-components" aria-hidden="true">#</a> Generate Layout Components</h3><p>Hikage can automatically generate the <code>Hikageable</code> function corresponding to the layout component for the specified layout component at compile time.</p><h4 id="custom-view" tabindex="-1"><a class="header-anchor" href="#custom-view" aria-hidden="true">#</a> Custom View</h4><p>You can add the <code>HikageView</code> annotation on your custom <code>View</code> to mark it as a Hikage layout component.</p><table><thead><tr><th>Parameter Name</th><th>Description</th></tr></thead><tbody><tr><td><code>lparams</code></td><td>LayoutParams <code>Class</code> object, if your custom <code>View</code> is a subclass of <code>ViewGroup</code>, you can declare or leave it blank to use the default value</td></tr><tr><td><code>alias</code></td><td>The alias of the layout component, that is, the function name to be generated, gets the name of the current Class by default</td></tr><tr><td><code>requireInit</code></td><td>Whether to fill in the initialization method block of the layout, the default is the omitted parameters</td></tr><tr><td><code>requirePerformer</code></td><td>Whether to fill in the <code>performer</code> method block of the layout, the default is an omitted parameter, which only takes effect when your custom <code>View</code> is a subclass of <code>ViewGroup</code></td></tr><tr><td><code>final</code></td><td>Whether to declare the layout as &quot;final layout&quot;, the default is false, that is, whether this layout is <code>ViewGroup</code> or its subclasses will not generate the <code>performer</code> method block. After set to <code>true</code>, <code>lparams</code> and <code>requirePerformer</code> will no longer be valid.</td></tr></tbody></table><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#F69D50;">@HikageView</span><span style="color:#ADBAC7;">(lparams </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> LinearLayout.LayoutParams::</span><span style="color:#DCBDFB;">class</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#F47067;">class</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">MyLayout</span><span style="color:#ADBAC7;">(context: </span><span style="color:#F69D50;">Context</span><span style="color:#ADBAC7;">, attrs: </span><span style="color:#F69D50;">AttributeSet</span><span style="color:#ADBAC7;">? </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">null</span><span style="color:#ADBAC7;">) : </span><span style="color:#F69D50;">LinearLayout</span><span style="color:#ADBAC7;">(</span><span style="color:#F69D50;">context</span><span style="color:#ADBAC7;">, </span><span style="color:#F69D50;">attrs</span><span style="color:#ADBAC7;">) {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>Once compiled, you can use <code>MyLayout</code> as the layout component in the Hikage layout.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#DCBDFB;">Hikageable</span><span style="color:#ADBAC7;"> {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#DCBDFB;">MyLayout</span><span style="color:#ADBAC7;"> {</span></span>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#DCBDFB;">TextView</span><span style="color:#ADBAC7;">(</span></span>
<span class="line"><span style="color:#ADBAC7;">            lparams </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#DCBDFB;">LayoutParams</span><span style="color:#ADBAC7;"> {</span></span>
<span class="line"><span style="color:#ADBAC7;">                topMargin </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#6CB6FF;">16</span><span style="color:#ADBAC7;">.dp</span></span>
<span class="line"><span style="color:#ADBAC7;">            }</span></span>
<span class="line"><span style="color:#ADBAC7;">        ) {</span></span>
<span class="line"><span style="color:#ADBAC7;">            text </span><span style="color:#F47067;">=</span><span style="color:#ADBAC7;"> </span><span style="color:#96D0FF;">&quot;Hello, World!&quot;</span></span>
<span class="line"><span style="color:#ADBAC7;">        }</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="third-party-components" tabindex="-1"><a class="header-anchor" href="#third-party-components" aria-hidden="true">#</a> Third-party Components</h4><p>Hikage can also automatically generate layout component functions for the <code>View</code> component provided by third parties, and you can use the <code>HikageViewDeclaration</code> annotation to complete it.</p><table><thead><tr><th>Parameter Name</th><th>Description</th></tr></thead><tbody><tr><td><code>view</code></td><td>Class object of layout component that needs to be declared</td></tr><tr><td><code>lparams</code></td><td>LayoutParams <code>Class</code> object, if your custom <code>View</code> is a subclass of <code>ViewGroup</code>, you can declare or leave it blank to use the default value</td></tr><tr><td><code>alias</code></td><td>The alias of the layout component, that is, the name of the function to be generated, obtains the name of the <code>view</code> Class by default</td></tr><tr><td><code>requireInit</code></td><td>Whether to fill in the initialization method block of the layout, the default is the omitted parameters</td></tr><tr><td><code>requirePerformer</code></td><td>Whether to fill in the <code>performer</code> method block of the layout, the default is an omitted parameter, which only takes effect when your custom <code>View</code> is a subclass of <code>ViewGroup</code></td></tr><tr><td><code>final</code></td><td>Whether to declare the layout as &quot;final layout&quot;, the default is false, that is, whether this layout is <code>ViewGroup</code> or its subclasses will not generate the <code>performer</code> method block. After set to <code>true</code>, <code>lparams</code> and <code>requirePerformer</code> will no longer be valid.</td></tr></tbody></table><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#F69D50;">@HikageViewDeclaration</span><span style="color:#ADBAC7;">(ThirdPartyView::</span><span style="color:#DCBDFB;">class</span><span style="color:#ADBAC7;">)</span></span>
<span class="line"><span style="color:#F47067;">object</span><span style="color:#ADBAC7;"> </span><span style="color:#F69D50;">ThirdPartyViewDeclaration</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div></div></div><p>This annotation can be declared on any <code>object</code> class and is only used as a class that needs to be automatically included by the annotation scanner. You can set visibility to <code>private</code>, but make sure that the annotated class must be modified with <code>object</code>.</p><p>Similarly, after compilation, you can use <code>ThirdPartyView</code> as the layout component in the Hikage layout.</p><blockquote><p>The following example</p></blockquote><div class="language-kotlin line-numbers-mode" data-ext="kt"><pre class="shiki github-dark-dimmed" style="background-color:#22272e;" tabindex="0"><code><span class="line"><span style="color:#DCBDFB;">Hikageable</span><span style="color:#ADBAC7;"> {</span></span>
<span class="line"><span style="color:#ADBAC7;">    </span><span style="color:#DCBDFB;">ThirdPartyView</span><span style="color:#ADBAC7;"> {</span></span>
<span class="line"><span style="color:#ADBAC7;">        </span><span style="color:#768390;">// ...</span></span>
<span class="line"><span style="color:#ADBAC7;">    }</span></span>
<span class="line"><span style="color:#ADBAC7;">}</span></span>
<span class="line"></span></code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><div class="custom-container tip"><p class="custom-container-title">Tips</p><p>Hikage The function package name path for generating layout components is <code>com.highcapable.hikage.widget</code> + the full package name of your <code>View</code> or third-party <code>View</code> component.</p></div>`,36);function h(v,b){const n=l("ExternalLinkIcon");return t(),i("div",null,[r,e("div",d,[u,e("p",null,[s("You need to integrate the "),e("a",m,[s("Google KSP"),c(n)]),s(" plugin in your project that is suitable for the current Kotlin version of your project.")])]),y])}const g=o(p,[["render",h],["__file","hikage-compiler.html.vue"]]);export{g as default};
