Flex SDK 4.6のコンパイラ拡張することができます。
これによって、メタデータによってクラスを自動生成したり
コンパイルの最後に後処理を書いたりすることができます。
拡張ポイント
- extensions-prelink: SystemManagerサブクラスやFlexInitが生成される前
- extensions-mxmlc: mxmlcコマンドの終わり
- extensions-compc: compcコマンドの終わり
- extensions-application: OEM API アプリケーションコンパイルの終わり
- extensions-library: OEM API ライブラリコンパイルの終わり
- extensions-pre-compile: コンパイルの前
コンパイラ拡張API
コンパイラ拡張APIは、 flex2.compiler.extensions パッケージにあります。
その配下に、拡張ポイント毎にインターフェイスが用意されています。
コンパイラ拡張java作り方
拡張ポイント毎にインターフェイスを実装します。
public class TestPreCompileExtension implements IPreCompileExtension {
@Override
public void run(FileSpec arg0, SourceList arg1, Collection<Source> arg2,
SourcePath arg3, ResourceContainer arg4, ResourceBundlePath arg5,
CompilerSwcContext arg6, SymbolTable arg7, Configuration arg8,
SubCompiler[] arg9, PreLink arg10, Map arg11, List<Source> arg12) {
System.out.println("IPreCompileExtension:"+this);
}
}
public class TestPreLinkExtension implements IPreLinkExtension {
@Override
public void run(List<Source> arg0, List<CompilationUnit> arg1,
FileSpec arg2, SourceList arg3, SourcePath arg4,
ResourceBundlePath arg5, ResourceContainer arg6, SymbolTable arg7,
CompilerSwcContext arg8, Configuration arg9) {
System.out.println("IPreLinkExtension:"+this);
}
}
コンパイラ拡張jar作り方
jarの中に入れるMANIFESTを下記のようにします。
コンパイル拡張するクラスを記述する必要があります。
Manifest-Version: 1.0 Sealed: true Implementation-Title: Apache Flex SDK - MXML Compiler Extension Implementation-Version: 1.0.0 Implementation-Vendor: AKABANA extensions-pre-compile: net.akb7.flex.compiler.ext.TestPreCompileExtension extensions-prelink: net.akb7.flex.compiler.ext.TestPreLinkExtension
実行
mxmlc -compiler.extensions.extension=MXMLExtension.jar Test.mxml
結果
設定ファイル "C:\Program Files (x86)\Adobe\Adobe Flash Builder 4.6\sdks\4.6.0_AIR33\frameworks\flex-config.xml" をロードしています
IPreCompileExtension:net.akb7.flex.compiler.ext.TestPreCompileExtension@b86944
IPreLinkExtension:net.akb7.flex.compiler.ext.TestPreLinkExtension@e69696
IPreLinkExtension:net.akb7.flex.compiler.ext.TestPreLinkExtension@d85409
IPreLinkExtension:net.akb7.flex.compiler.ext.TestPreLinkExtension@1cc7e90
必要な RSL :
http://fpdownload.adobe.com/pub/swz/flex/4.6.0.23201/framework_4.6.0.23201.swz (1 フェイルオーバー)。
http://fpdownload.adobe.com/pub/swz/tlf/2.0.0.232/textLayout_2.0.0.232.swz (1 フェイルオーバー)。
http://fpdownload.adobe.com/pub/swz/flex/4.6.0.23201/spark_4.6.0.23201.swz (1 フェイルオーバー)。
D:\profile\apache_flex\workspace01\MXMLExtensionTest\Test.swf (41962 バイト)
IMxmlcExtension:net.akb7.flex.compiler.ext.TestMxmlcExtension@5b04ae
