簡體   English   中英

自動生成委托/封裝代碼 class(在 Intellij 中)

[英]auto-generate code for delegation/encapsulation class (in Intellij)

我的問題:

我有:

public class Bla {
    static {
        System.loadLibrary("blaNative");
    }
    public static native T3 method1(T1 p1, T2 p2);
    public static native T6 method2(T4 p4, T5 p5);
    ...
    hundreds of other native methods here
    ...
}

我想自動生成:

public class BlaWrapper implements BlaInterface {

    public T3 method1(T1 p1, T2 p2) {
        return Bla.method1(p1,p2);
    }
    public T6 method2(T4 p4, T5 p5) {
        return Bla.method2(p4,p5);
    }
    ...
    hundreds of other methods here
    ...
}
    
public interface BlaInterface {
    public T3 method1(T1 p1, T2 p2);
    public T6 method2(T4 p4, T5 p5);
    ...
    hundreds of other methods here
    ...
}

注意:生成 BlaInterface 很簡單。

非常感謝您的時間和專業知識

此致

以防萬一其他人遇到同樣的問題:

劇透警報:秘訣是 intellij 菜單中的“代碼->覆蓋方法”:

  1. 暫時從 Bla class 中刪除“靜態”關鍵字
  2. 創建一個空的 BlaWraper 子 class 擴展 Bla
  3. 在 Intellij 菜單 select“代碼->覆蓋方法”中,將自動插入對父 class 的委托調用...萬歲!!
  4. 您現在只需幾個“查找和替換”即可完成:
    a) 在覆蓋方法中替換“super”。 與“布拉”。
    b) 在父 class 中重新引入“static”關鍵字
    c) 在 BlaWrapper 中將“extends Bla”替換為“implements BlaInterface”

瞧::-)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM