mirror of
https://github.com/adelphes/android-dev-ext.git
synced 2025-12-23 09:59:25 +00:00
add default constructor for class types with no explicit constructors
This commit is contained in:
@@ -52,7 +52,12 @@ class SourceType extends CEIType {
|
|||||||
|
|
||||||
this.fields = type.fields.map(f => new SourceField(this, f));
|
this.fields = type.fields.map(f => new SourceField(this, f));
|
||||||
this.methods = type.methods.map(m => new SourceMethod(this, m));
|
this.methods = type.methods.map(m => new SourceMethod(this, m));
|
||||||
|
/** @type {Constructor[]} */
|
||||||
this.constructors = type.constructors.map(c => new SourceConstructor(this, c));
|
this.constructors = type.constructors.map(c => new SourceConstructor(this, c));
|
||||||
|
if (!type.constructors[0] && type.kind() === 'class') {
|
||||||
|
// add a default public constructor if this is a class with no explicit constructors
|
||||||
|
this.constructors.push(new DefaultConstructor(this));
|
||||||
|
}
|
||||||
super.typevars = type.typevars.map(tv => {
|
super.typevars = type.typevars.map(tv => {
|
||||||
const typevar = new TypeVariable(tv.name);
|
const typevar = new TypeVariable(tv.name);
|
||||||
// automatically add the Object bound
|
// automatically add the Object bound
|
||||||
@@ -147,9 +152,30 @@ class SourceConstructor extends Constructor {
|
|||||||
get returnType() {
|
get returnType() {
|
||||||
return this._owner;
|
return this._owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class DefaultConstructor extends Constructor {
|
||||||
|
/**
|
||||||
|
* @param {SourceType} owner
|
||||||
|
*/
|
||||||
|
constructor(owner) {
|
||||||
|
super(['public']);
|
||||||
|
this._owner = owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
get methodSignature() {
|
||||||
|
return `()V`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {SourceType}
|
||||||
|
*/
|
||||||
|
get returnType() {
|
||||||
|
return this._owner;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class SourceMethod extends Method {
|
class SourceMethod extends Method {
|
||||||
/**
|
/**
|
||||||
* @param {SourceType} owner
|
* @param {SourceType} owner
|
||||||
@@ -226,3 +252,4 @@ exports.SourceField = SourceField;
|
|||||||
exports.SourceMethod = SourceMethod;
|
exports.SourceMethod = SourceMethod;
|
||||||
exports.SourceParameter = SourceParameter;
|
exports.SourceParameter = SourceParameter;
|
||||||
exports.SourceConstructor = SourceConstructor;
|
exports.SourceConstructor = SourceConstructor;
|
||||||
|
exports.DefaultConstructor = DefaultConstructor;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ const { ModuleBlock, TypeDeclBlock } = require('./parser9');
|
|||||||
const { resolveImports } = require('../java/import-resolver');
|
const { resolveImports } = require('../java/import-resolver');
|
||||||
const ResolvedImport = require('../java/parsetypes/resolved-import');
|
const ResolvedImport = require('../java/parsetypes/resolved-import');
|
||||||
const { resolveType } = require('../java/type-resolver');
|
const { resolveType } = require('../java/type-resolver');
|
||||||
const { SourceType } = require('./source-type');
|
const { SourceType, SourceConstructor } = require('./source-type');
|
||||||
const { parseBody } = require('./body-parser3');
|
const { parseBody } = require('./body-parser3');
|
||||||
|
|
||||||
|
|
||||||
@@ -59,6 +59,10 @@ function validate(mod, androidLibrary) {
|
|||||||
let probs = [];
|
let probs = [];
|
||||||
source_types.forEach(t => {
|
source_types.forEach(t => {
|
||||||
t.constructors.forEach(c => {
|
t.constructors.forEach(c => {
|
||||||
|
// ignore any default constructors
|
||||||
|
if (!(c instanceof SourceConstructor)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
console.log(c.label);
|
console.log(c.label);
|
||||||
const parsed = parseBody(c._owner._decl.mod.source, c, imports.resolved, imports.typemap);
|
const parsed = parseBody(c._owner._decl.mod.source, c, imports.resolved, imports.typemap);
|
||||||
if (parsed)
|
if (parsed)
|
||||||
|
|||||||
Reference in New Issue
Block a user