NativeScript / NativeScript/android

Enable generation of default (0-arguments) constructor when extending classes

オープン
#526 コメント 5 件 リアクション 2 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

feature severity: low
主要言語
C++
スター
563
フォーク
144
平均マージ
10時間 46分
マージ済み PR(30日)
14

説明

If the developer extends a base class with no default constructor, they have no way of explicitly specifying that they want a default constructor code to be generated in Java. This is a certain limitation if the class needs to be declared in the AndroidManifest and is instantiated by the system (attempting to use IntentService is one such case - Android will attempt to create an instance of the implementation of IntentService, but will crash, as it tries to invoke a default constructor, which the developer cannot declare).

Given the following Java class:

package a.b;

public class Base {
    public Base(String a) { ... }       
}

and the following implementation in JavaScript:

a.b.Base.extend("a.b.ExtendedBase", {
    init: function() {
     _this("arbitrary string");      
     // -> will introduce additional logic in the sole ctor block
     // in Java, but will not create an additional constructor
    }  
});

will output

package a.b;

@com.tns.JavaScriptImplementation(javaScriptFile = "./ExtendedBase.js")
public class ExtendedBase extends a.b.Base implements com.tns.NativeScriptHashCodeProvider {
        /* No default constructor */

    public ExtendedBase (java.lang.String param_0){
        super(param_0);
                /* 
                    Additional logic to handle more arguments -> a result of the init function
                */                 
        com.tns.Runtime.initInstance(this);
    }

    public boolean equals__super(java.lang.Object other) {
        return super.equals(other);
    }

    public int hashCode__super() {
        return super.hashCode();
    }
}

Developers have no way to declare a default constructor for a.b.ExtendedBase.

Instead what I need is

package a.b;

@com.tns.JavaScriptImplementation(javaScriptFile = "./ExtendedBase.js")
public class ExtendedBase extends a.b.Base implements com.tns.NativeScriptHashCodeProvider {
        /* default constructor */
        public ExtendedBase () {
        this("Arbitrary String");
    }

    public ExtendedBase (java.lang.String param_0){
        super(param_0);
                /* 
                    Additional logic to handle more arguments -> a result of the init function
                */                 
        com.tns.Runtime.initInstance(this);
    }
}

Generating custom constructors based on the javascript code will require additional analysis, and may not be worth looking into at the moment.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

この issue には JavaScript と Java の例がありますが、ソースファイル、テスト、エントリポイントは示されていません。まず、クラス拡張に対するコンストラクター生成の経路を特定してください。完了の条件は、引数なしコンストラクターを持たない基底クラスの拡張が、指定どおりに委譲する生成された引数なしコンストラクターを公開でき、示されたケースをカバーしていることです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
android, cpp, java, javascript
領域
mobile, tooling
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。