NativeScript / NativeScript/android

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

Đang mở
#526 5 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

feature severity: low
Ngôn ngữ chính
C++
Star
563
Fork
144
Merge trung bình
10 giờ 46 phút
Pull request đã merge (30 ngày)
14

Mô tả

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Issue cung cấp các ví dụ bằng JavaScript và Java nhưng không nêu tệp nguồn, kiểm thử hoặc điểm vào nào. Hãy bắt đầu bằng việc xác định đường dẫn tạo constructor cho các phần mở rộng lớp; công việc được xem là hoàn tất khi một phần mở rộng của lớp cơ sở không có constructor không tham số có thể cung cấp một constructor không tham số được tạo tự động, constructor này ủy quyền như đã chỉ định, kèm theo việc bao phủ trường hợp được minh họa.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
android, cpp, java, javascript
Lĩnh vực
mobile, tooling
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
30/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.