NativeScript / NativeScript/android
Enable generation of default (0-arguments) constructor when extending classes
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- C++
- Sterne
- 563
- Forks
- 144
- Ø Merge
- 10 Std. 46 Min.
- Gemergte PRs (30 T.)
- 14
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Das Issue enthält Beispiele in JavaScript und Java, nennt aber keine Quelldatei, keinen Test und keinen Einstiegspunkt. Beginne damit, den Pfad zur Generierung von Konstruktoren für Klassenerweiterungen zu ermitteln; fertig ist es, wenn eine Erweiterung einer Basisklasse ohne Konstruktor ohne Argumente einen generierten Konstruktor ohne Argumente bereitstellen kann, der wie angegeben delegiert, mit Testabdeckung für den gezeigten Fall.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- android, cpp, java, javascript
- Bereich
- mobile, tooling
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 30/100