mirror of
https://github.com/adelphes/android-dev-ext.git
synced 2025-12-23 01:48:18 +00:00
add SourceInitialiser support
This commit is contained in:
@@ -5,13 +5,13 @@
|
|||||||
* Each token also contains detailed state information used for completion suggestions.
|
* Each token also contains detailed state information used for completion suggestions.
|
||||||
*/
|
*/
|
||||||
const { JavaType, CEIType, PrimitiveType, ArrayType, UnresolvedType, WildcardType, TypeVariable, Field, Method, Parameter, Constructor, signatureToType } = require('java-mti');
|
const { JavaType, CEIType, PrimitiveType, ArrayType, UnresolvedType, WildcardType, TypeVariable, Field, Method, Parameter, Constructor, signatureToType } = require('java-mti');
|
||||||
const { SourceMethod, SourceConstructor } = require('./source-type');
|
const { SourceMethod, SourceConstructor, SourceInitialiser } = require('./source-type');
|
||||||
const ResolvedImport = require('./parsetypes/resolved-import');
|
const ResolvedImport = require('./parsetypes/resolved-import');
|
||||||
const ParseProblem = require('./parsetypes/parse-problem');
|
const ParseProblem = require('./parsetypes/parse-problem');
|
||||||
const { getOperatorType, Token } = require('./tokenizer');
|
const { getOperatorType, Token } = require('./tokenizer');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {SourceMethod|SourceConstructor} SourceMC
|
* @typedef {SourceMethod|SourceConstructor|SourceInitialiser} SourceMC
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ function parseBody(method, imports, typemap) {
|
|||||||
const tokenlist = new TokenList(flattenBlocks(body.blocks));
|
const tokenlist = new TokenList(flattenBlocks(body.blocks));
|
||||||
let block = null;
|
let block = null;
|
||||||
try {
|
try {
|
||||||
statementBlock(tokenlist, [], method, imports, typemap);
|
block = statementBlock(tokenlist, [], method, imports, typemap);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
addproblem(tokenlist, ParseProblem.Information(tokenlist.current, `Parse failed: ${err.message}`));
|
addproblem(tokenlist, ParseProblem.Information(tokenlist.current, `Parse failed: ${err.message}`));
|
||||||
|
|
||||||
|
|||||||
@@ -504,6 +504,15 @@ class InitialiserBlock extends DeclarationBlock {
|
|||||||
constructor(section, simplified, match) {
|
constructor(section, simplified, match) {
|
||||||
super(section, simplified);
|
super(section, simplified);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the TextBlock associated with the method body
|
||||||
|
*/
|
||||||
|
body() {
|
||||||
|
// always the last block atm
|
||||||
|
const blocks = this.blockArray();
|
||||||
|
return blocks.blocks[blocks.blocks.length - 1];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TypeDeclBlock extends DeclarationBlock {
|
class TypeDeclBlock extends DeclarationBlock {
|
||||||
@@ -601,6 +610,11 @@ class TypeDeclBlock extends DeclarationBlock {
|
|||||||
return this.parsed.constructors;
|
return this.parsed.constructors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get initialisers() {
|
||||||
|
this._ensureParsed();
|
||||||
|
return this.parsed.initialisers;
|
||||||
|
}
|
||||||
|
|
||||||
get types() {
|
get types() {
|
||||||
this._ensureParsed();
|
this._ensureParsed();
|
||||||
return this.parsed.types;
|
return this.parsed.types;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const { JavaType, CEIType, Constructor, Method, Field, Parameter, TypeVariable, UnresolvedType } = require('java-mti');
|
const { JavaType, CEIType, PrimitiveType, Constructor, Method, MethodBase, Field, Parameter, TypeVariable, UnresolvedType } = require('java-mti');
|
||||||
const { ModuleBlock, TypeDeclBlock, FieldBlock, ConstructorBlock, MethodBlock, ParameterBlock, TextBlock, TextBlockArray } = require('./parser9');
|
const { ModuleBlock, TypeDeclBlock, FieldBlock, ConstructorBlock, MethodBlock, InitialiserBlock, ParameterBlock, TextBlock } = require('./parser9');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -58,8 +58,9 @@ class SourceType extends CEIType {
|
|||||||
// add a default public constructor if this is a class with no explicit constructors
|
// add a default public constructor if this is a class with no explicit constructors
|
||||||
this.constructors.push(new DefaultConstructor(this));
|
this.constructors.push(new DefaultConstructor(this));
|
||||||
}
|
}
|
||||||
|
this.initers = type.initialisers.map(i => new SourceInitialiser(this, i));
|
||||||
super.typevars = type.typevars.map(tv => {
|
super.typevars = type.typevars.map(tv => {
|
||||||
const typevar = new TypeVariable(tv.name);
|
const typevar = new TypeVariable(this, tv.name);
|
||||||
// automatically add the Object bound
|
// automatically add the Object bound
|
||||||
typevar.bounds.push(new TypeVariable.Bound(this, 'Ljava/lang/Object;', false));
|
typevar.bounds.push(new TypeVariable.Bound(this, 'Ljava/lang/Object;', false));
|
||||||
return typevar;
|
return typevar;
|
||||||
@@ -181,6 +182,22 @@ class DefaultConstructor extends Constructor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class SourceInitialiser extends MethodBase {
|
||||||
|
/**
|
||||||
|
* @param {SourceType} owner
|
||||||
|
* @param {InitialiserBlock} decl
|
||||||
|
*/
|
||||||
|
constructor(owner, decl) {
|
||||||
|
super(mapmods(decl), decl.docs);
|
||||||
|
this._owner = owner;
|
||||||
|
this._decl = decl;
|
||||||
|
}
|
||||||
|
|
||||||
|
get returnType() {
|
||||||
|
return PrimitiveType.map.V;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class SourceMethod extends Method {
|
class SourceMethod extends Method {
|
||||||
/**
|
/**
|
||||||
* @param {SourceType} owner
|
* @param {SourceType} owner
|
||||||
@@ -254,3 +271,4 @@ exports.SourceMethod = SourceMethod;
|
|||||||
exports.SourceParameter = SourceParameter;
|
exports.SourceParameter = SourceParameter;
|
||||||
exports.SourceConstructor = SourceConstructor;
|
exports.SourceConstructor = SourceConstructor;
|
||||||
exports.DefaultConstructor = DefaultConstructor;
|
exports.DefaultConstructor = DefaultConstructor;
|
||||||
|
exports.SourceInitialiser = SourceInitialiser;
|
||||||
|
|||||||
@@ -58,6 +58,12 @@ function validate(mod, androidLibrary) {
|
|||||||
|
|
||||||
let probs = [];
|
let probs = [];
|
||||||
source_types.forEach(t => {
|
source_types.forEach(t => {
|
||||||
|
t.initers.forEach(i => {
|
||||||
|
console.log('<clinit>()');
|
||||||
|
const parsed = parseBody(i, imports.resolved, imports.typemap);
|
||||||
|
if (parsed)
|
||||||
|
probs = probs.concat(parsed.problems)
|
||||||
|
})
|
||||||
t.constructors.forEach(c => {
|
t.constructors.forEach(c => {
|
||||||
// ignore any default constructors
|
// ignore any default constructors
|
||||||
if (!(c instanceof SourceConstructor)) {
|
if (!(c instanceof SourceConstructor)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user